Hi Ricardo,
I guess you caught a TCP SYN (or SYN+ACK or ACK) packet leading the BGP
handshake, so the received packet has no TCP payload.
I could get the BGP packets with the following modification of simple_switch_13.
diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py
index 06a5d0e..5437a7f 100644
--- a/ryu/app/simple_switch_13.py
+++ b/ryu/app/simple_switch_13.py
@@ -21,6 +21,9 @@ from ryu.ofproto import ofproto_v1_3
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
from ryu.lib.packet import ether_types
+from ryu.lib.packet import ipv4
+from ryu.lib.packet import tcp
+from ryu.lib.packet import bgp
class SimpleSwitch13(app_manager.RyuApp):
@@ -85,13 +88,26 @@ class SimpleSwitch13(app_manager.RyuApp):
dst = eth.dst
src = eth.src
+ipv4_pkt = pkt.get_protocol(ipv4.ipv4)
+if ipv4_pkt:
+self.logger.info("*** ipv4: %s", ipv4_pkt)
+
+tcp_pkt = pkt.get_protocol(tcp.tcp)
+if tcp_pkt:
+self.logger.info("*** tcp: %s", tcp_pkt)
+
+bgp_pkt = pkt.get_protocol(bgp.BGPMessage)
+if bgp_pkt:
+self.logger.info("*** bgp: %s", bgp_pkt)
+
dpid = datapath.id
self.mac_to_port.setdefault(dpid, {})
self.logger.info("packet in %s %s %s %s", dpid, src, dst, in_port)
# learn a mac address to avoid FLOOD next time.
-self.mac_to_port[dpid][src] = in_port
+# ---> suppress learning in order to get all packets sent from hosts.
+# self.mac_to_port[dpid][src] = in_port
if dst in self.mac_to_port[dpid]:
out_port = self.mac_to_port[dpid][dst]
$ ryu-manager ryu/app/simple_switch_13.py --verbose
...(snip)...
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
*** ipv4:
ipv4(csum=29812,dst='10.0.0.2',flags=2,header_length=5,identification=61765,offset=0,option=None,proto=6,src='10.0.0.1',tos=0,total_length=60,ttl=1,version=4)
*** tcp:
tcp(ack=0,bits=2,csum=17646,dst_port=179,offset=10,option=[TCPOptionMaximumSegmentSize(kind=2,length=4,max_seg_size=1460),
TCPOptionSACKPermitted(kind=4,length=2),
TCPOptionTimestamps(kind=8,length=10,ts_ecr=0,ts_val=3591680),
TCPOptionNoOperation(kind=1,length=1),
TCPOptionWindowScale(kind=3,length=3,shift_cnt=9)],seq=3591782213,src_port=39095,urgent=0,window_size=29200)
packet in 1 6a:ac:ab:96:a2:cd ea:6f:1f:bf:38:3d 1
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
*** ipv4:
ipv4(csum=26553,dst='10.0.0.1',flags=2,header_length=5,identification=0,offset=0,option=None,proto=6,src='10.0.0.2',tos=0,total_length=60,ttl=255,version=4)
*** tcp:
tcp(ack=3591782214,bits=18,csum=24208,dst_port=39095,offset=10,option=[TCPOptionMaximumSegmentSize(kind=2,length=4,max_seg_size=1460),
TCPOptionSACKPermitted(kind=4,length=2),
TCPOptionTimestamps(kind=8,length=10,ts_ecr=3591680,ts_val=3591682),
TCPOptionNoOperation(kind=1,length=1),
TCPOptionWindowScale(kind=3,length=3,shift_cnt=9)],seq=3896193224,src_port=179,urgent=0,window_size=28960)
packet in 1 ea:6f:1f:bf:38:3d 6a:ac:ab:96:a2:cd 2
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
*** ipv4:
ipv4(csum=29819,dst='10.0.0.2',flags=2,header_length=5,identification=61766,offset=0,option=None,proto=6,src='10.0.0.1',tos=0,total_length=52,ttl=1,version=4)
*** tcp:
tcp(ack=3896193225,bits=16,csum=65089,dst_port=179,offset=8,option=[TCPOptionNoOperation(kind=1,length=1),
TCPOptionNoOperation(kind=1,length=1),
TCPOptionTimestamps(kind=8,length=10,ts_ecr=3591682,ts_val=3591683)],seq=3591782214,src_port=39095,urgent=0,window_size=58)
packet in 1 6a:ac:ab:96:a2:cd ea:6f:1f:bf:38:3d 1
*** ipv4:
ipv4(csum=29767,dst='10.0.0.2',flags=2,header_length=5,identification=61767,offset=0,option=None,proto=6,src='10.0.0.1',tos=0,total_length=103,ttl=1,version=4)
*** tcp:
tcp(ack=3896193225,bits=24,csum=55108,dst_port=179,offset=8,option=[TCPOptionNoOperation(kind=1,length=1),
TCPOptionNoOperation(kind=1,length=1),
TCPOptionTimestamps(kind=8,length=10,ts_ecr=3591682,ts_val=3591683)],seq=3591782214,src_port=39095,urgent=0,window_size=58)
*** bgp:
BGPOpen(bgp_identifier='1.1.1.1',hold_time=90,len=57,my_as=65001,opt_param=[BGPOptParamCapabilityRouteRefresh(cap_code=2,cap_length=0,length=2,type=2),
BGPOptParamCapabilityMultiprotocol(afi=1,cap_code=1,cap_length=4,length=6,reserved=0,safi=1,type=2),
BGPOptParamCapabilityMultiprotocol(afi=2,cap_code=1,cap_length=4,length=6,reserved=0,safi=1,type=2),
BGPOptParamCapabilityFourOctetAsNumber(as_number=65001,cap_code=65,cap_length=4,length=6,type=2)],opt_param_len=28,type=1,version=4)
packet in 1 6a:ac:ab:96:a2:cd ea:6f:1f:bf:38:3d 1
Thanks,
Iwase
On 2018年02月27日 23:16, Ricardo Bennesby wrote:
Hi,
I am running ExaBGP from a Mininet node and modified the simple_switch_13 app to
parse the BGP messages received from a peer. However, I can correctly parse the
IP and TCP fields of the packet, while the BGP part returns *None:*
_*The code:*_
de