Пример #1
0
 def dispatch_hook(cls, _pkt=None, *args, **kargs):
     if _pkt and len(_pkt) >= 2:
         version = orb(_pkt[0])
         if version == 0x04:  # OpenFlow 1.3
             from scapy.contrib.openflow3 import OpenFlow3
             return OpenFlow3.dispatch_hook(_pkt, *args, **kargs)
         elif version == 0x01:  # OpenFlow 1.0
             # port 6653 has been allocated by IANA, port 6633 should no
             # longer be used
             # OpenFlow function may be called with a None
             # self in OFPPacketField
             of_type = orb(_pkt[1])
             if of_type == 1:
                 err_type = orb(_pkt[9])
                 # err_type is a short int, but last byte is enough
                 if err_type == 255:
                     err_type = 65535
                 return ofp_error_cls[err_type]
             elif of_type == 16:
                 mp_type = orb(_pkt[9])
                 if mp_type == 255:
                     mp_type = 65535
                 return ofp_stats_request_cls[mp_type]
             elif of_type == 17:
                 mp_type = orb(_pkt[9])
                 if mp_type == 255:
                     mp_type = 65535
                 return ofp_stats_reply_cls[mp_type]
             else:
                 return ofpt_cls[of_type]
         else:
             warning("Unknown OpenFlow packet")
     return _UnknownOpenFlow
Пример #2
0
 def dispatch_hook(cls, _pkt=None, *args, **kargs):
     if _pkt and len(_pkt) >= 2:
         version = orb(_pkt[0])
         if version == 0x04:  # OpenFlow 1.3
             from scapy.contrib.openflow3 import OpenFlow3
             return OpenFlow3.dispatch_hook(_pkt, *args, **kargs)
         elif version == 0x01:  # OpenFlow 1.0
             # port 6653 has been allocated by IANA, port 6633 should no
             # longer be used
             # OpenFlow function may be called with a None
             # self in OFPPacketField
             of_type = orb(_pkt[1])
             if of_type == 1:
                 err_type = orb(_pkt[9])
                 # err_type is a short int, but last byte is enough
                 if err_type == 255:
                     err_type = 65535
                 return ofp_error_cls[err_type]
             elif of_type == 16:
                 mp_type = orb(_pkt[9])
                 if mp_type == 255:
                     mp_type = 65535
                 return ofp_stats_request_cls[mp_type]
             elif of_type == 17:
                 mp_type = orb(_pkt[9])
                 if mp_type == 255:
                     mp_type = 65535
                 return ofp_stats_reply_cls[mp_type]
             else:
                 return ofpt_cls[of_type]
         else:
             warning("Unknown OpenFlow packet")
     return _UnknownOpenFlow