Simple switch will flood lldp packet after it received it.

It cause Switches app get wrong lldp packet, and there will be a lot of
links that doesn't exist

Attached file is my patch.

Thanks.

-- 
Yi Tseng (a.k.a Takeshi)
Taiwan National Chiao Tung University
Department of Computer Science
W2CNLab
From f96913c9e522adbc9925e53031afdc7ce00bdcc9 Mon Sep 17 00:00:00 2001
From: Takeshi <[email protected]>
Date: Thu, 9 Jul 2015 00:47:00 +0800
Subject: [PATCH] ignore lldp packet to avoid wrong links

Signed-off-by: Takeshi <[email protected]>
---
 ryu/app/simple_switch.py    | 8 ++++++++
 ryu/app/simple_switch_12.py | 7 +++++++
 ryu/app/simple_switch_13.py | 8 ++++++++
 ryu/app/simple_switch_14.py | 7 +++++++
 4 files changed, 30 insertions(+)

diff --git a/ryu/app/simple_switch.py b/ryu/app/simple_switch.py
index 8fd3d21..a443fa4 100644
--- a/ryu/app/simple_switch.py
+++ b/ryu/app/simple_switch.py
@@ -29,6 +29,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
 
 
 class SimpleSwitch(app_manager.RyuApp):
@@ -54,6 +55,13 @@ 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
 
diff --git a/ryu/app/simple_switch_12.py b/ryu/app/simple_switch_12.py
index 3df74e0..ee53d9e 100644
--- a/ryu/app/simple_switch_12.py
+++ b/ryu/app/simple_switch_12.py
@@ -23,6 +23,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
 
 
 class SimpleSwitch12(app_manager.RyuApp):
@@ -52,6 +53,12 @@ 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']
diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py
index b9cbad0..e224958 100644
--- a/ryu/app/simple_switch_13.py
+++ b/ryu/app/simple_switch_13.py
@@ -20,6 +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
 
 
 class SimpleSwitch13(app_manager.RyuApp):
@@ -70,6 +71,13 @@ 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
diff --git a/ryu/app/simple_switch_14.py b/ryu/app/simple_switch_14.py
index 052740a..4cf66a8 100644
--- a/ryu/app/simple_switch_14.py
+++ b/ryu/app/simple_switch_14.py
@@ -20,6 +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
 
 
 class SimpleSwitch14(app_manager.RyuApp):
@@ -61,6 +62,12 @@ 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
-- 
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

Reply via email to