Hello Fujita,
Attached file is my new patch, please check it, thanks.
By the way, I remove some unused import (struct, logging and mac_to_port).
2015-07-10 9:57 GMT+08:00 FUJITA Tomonori <[email protected]>:
> On Fri, 10 Jul 2015 09:55:53 +0800
> Yi Tseng <[email protected]> wrote:
>
> > from ryu.lib.packet import ether_types
> >
> > if eth.ethertype == types.ETH_TYPE_LLDP:
> > # ignore lldp packet
> > return
> >
> >
> > It's easier to understand
>
> Yeah, please send a patch to do such.
>
--
Yi Tseng (a.k.a Takeshi)
Taiwan National Chiao Tung University
Department of Computer Science
W2CNLab
From 999451cc70e4f0d42c1c24ec44872af9904b2676 Mon Sep 17 00:00:00 2001
From: Takeshi <[email protected]>
Date: Fri, 10 Jul 2015 10:14:22 +0800
Subject: [PATCHv2] ignore lldp packet to avoid wrong links
Signed-off-by: Takeshi <[email protected]>
---
ryu/app/simple_switch.py | 15 ++++-----------
ryu/app/simple_switch_12.py | 14 ++++----------
ryu/app/simple_switch_13.py | 12 ++++--------
ryu/app/simple_switch_14.py | 11 ++++-------
4 files changed, 16 insertions(+), 36 deletions(-)
diff --git a/ryu/app/simple_switch.py b/ryu/app/simple_switch.py
index a443fa4..862b830 100644
--- a/ryu/app/simple_switch.py
+++ b/ryu/app/simple_switch.py
@@ -17,11 +17,8 @@
An OpenFlow 1.0 L2 learning switch implementation.
"""
-import logging
-import struct
from ryu.base import app_manager
-from ryu.controller import mac_to_port
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls
@@ -29,7 +26,7 @@ from ryu.ofproto import ofproto_v1_0
from ryu.lib.mac import haddr_to_bin
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
-from ryu.topology.switches import LLDPPacket
+from ryu.lib.packet import ether_types
class SimpleSwitch(app_manager.RyuApp):
@@ -55,19 +52,15 @@ class SimpleSwitch(app_manager.RyuApp):
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def _packet_in_handler(self, ev):
msg = ev.msg
-
- try:
- # ignore lldp packet
- LLDPPacket.lldp_parse(msg.data)
- return
- except LLDPPacket.LLDPUnknownFormat:
- pass
datapath = msg.datapath
ofproto = datapath.ofproto
pkt = packet.Packet(msg.data)
eth = pkt.get_protocol(ethernet.ethernet)
+ if eth.ethertype == ether_types.ETH_TYPE_LLDP:
+ # ignore lldp packet
+ return
dst = eth.dst
src = eth.src
diff --git a/ryu/app/simple_switch_12.py b/ryu/app/simple_switch_12.py
index ee53d9e..6895b07 100644
--- a/ryu/app/simple_switch_12.py
+++ b/ryu/app/simple_switch_12.py
@@ -13,9 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import logging
-import struct
-
from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER
@@ -23,7 +20,7 @@ from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_2
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
-from ryu.topology.switches import LLDPPacket
+from ryu.lib.packet import ether_types
class SimpleSwitch12(app_manager.RyuApp):
@@ -53,12 +50,6 @@ class SimpleSwitch12(app_manager.RyuApp):
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def _packet_in_handler(self, ev):
msg = ev.msg
- try:
- # ignore lldp packet
- LLDPPacket.lldp_parse(msg.data)
- return
- except LLDPPacket.LLDPUnknownFormat:
- pass
datapath = msg.datapath
ofproto = datapath.ofproto
in_port = msg.match['in_port']
@@ -66,6 +57,9 @@ class SimpleSwitch12(app_manager.RyuApp):
pkt = packet.Packet(msg.data)
eth = pkt.get_protocols(ethernet.ethernet)[0]
+ if eth.ethertype == ether_types.ETH_TYPE_LLDP:
+ # ignore lldp packet
+ return
dst = eth.dst
src = eth.src
diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py
index e224958..3e7c598 100644
--- a/ryu/app/simple_switch_13.py
+++ b/ryu/app/simple_switch_13.py
@@ -20,7 +20,7 @@ from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_3
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
-from ryu.topology.switches import LLDPPacket
+from ryu.lib.packet import ether_types
class SimpleSwitch13(app_manager.RyuApp):
@@ -71,13 +71,6 @@ class SimpleSwitch13(app_manager.RyuApp):
self.logger.debug("packet truncated: only %s of %s bytes",
ev.msg.msg_len, ev.msg.total_len)
msg = ev.msg
-
- try:
- # ignore lldp packet
- LLDPPacket.lldp_parse(msg.data)
- return
- except LLDPPacket.LLDPUnknownFormat:
- pass
datapath = msg.datapath
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
@@ -86,6 +79,9 @@ class SimpleSwitch13(app_manager.RyuApp):
pkt = packet.Packet(msg.data)
eth = pkt.get_protocols(ethernet.ethernet)[0]
+ if eth.ethertype == ether_types.ETH_TYPE_LLDP:
+ # ignore lldp packet
+ return
dst = eth.dst
src = eth.src
diff --git a/ryu/app/simple_switch_14.py b/ryu/app/simple_switch_14.py
index 4cf66a8..d3151bc 100644
--- a/ryu/app/simple_switch_14.py
+++ b/ryu/app/simple_switch_14.py
@@ -20,7 +20,7 @@ from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_4
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
-from ryu.topology.switches import LLDPPacket
+from ryu.lib.packet import ether_types
class SimpleSwitch14(app_manager.RyuApp):
@@ -62,12 +62,6 @@ class SimpleSwitch14(app_manager.RyuApp):
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def _packet_in_handler(self, ev):
msg = ev.msg
- try:
- # ignore lldp packet
- LLDPPacket.lldp_parse(msg.data)
- return
- except LLDPPacket.LLDPUnknownFormat:
- pass
datapath = msg.datapath
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
@@ -76,6 +70,9 @@ class SimpleSwitch14(app_manager.RyuApp):
pkt = packet.Packet(msg.data)
eth = pkt.get_protocols(ethernet.ethernet)[0]
+ if eth.ethertype == ether_types.ETH_TYPE_LLDP:
+ # ignore lldp packet
+ return
dst = eth.dst
src = eth.src
--
2.3.2 (Apple Git-55)
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel