From 5eba3a439322b97e92f55bdeb882fa933f5a8f78 Mon Sep 17 00:00:00 2001 From: gpotter2 Date: Sat, 14 Oct 2017 18:26:54 +0200 Subject: [PATCH] Python 3: fix OPENFLOW --- scapy/contrib/openflow.py | 11 ++++++----- scapy/contrib/openflow.uts | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/scapy/contrib/openflow.py b/scapy/contrib/openflow.py index d5690ee61..df74b112a 100755 --- a/scapy/contrib/openflow.py +++ b/scapy/contrib/openflow.py @@ -16,6 +16,7 @@ import struct from scapy.fields import * from scapy.layers.l2 import * from scapy.layers.inet import * +from scapy.compat import orb ### If prereq_autocomplete is True then match prerequisites will be ### automatically handled. See OFPMatch class. @@ -199,7 +200,7 @@ class OFPMatch(Packet): p = p[:25] + struct.pack("!B", 0x06) + p[26:] l = l[:-6] + "0" + l[-5:] - ins = "".join(chr(int("".join(x),2)) for x in zip(*[iter(l)]*8)) + ins = b"".join(chb(int("".join(x),2)) for x in zip(*[iter(l)]*8)) p = ins + p[4:] return p + pay @@ -1187,18 +1188,18 @@ def OpenFlow(self, payload): if self is None or self.dport == 6653 or self.dport == 6633 or self.sport == 6653 or self.sport == 6633: # port 6653 has been allocated by IANA, port 6633 should no longer be used # OpenFlow function may be called with None self in OFPPacketField - of_type = ord(payload[1]) + of_type = orb(payload[1]) if of_type == 1: - err_type = ord(payload[9]) + err_type = orb(payload[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 = ord(payload[9]) + mp_type = orb(payload[9]) if mp_type == 255: mp_type = 65535 return ofp_stats_request_cls[mp_type] elif of_type == 17: - mp_type = ord(payload[9]) + mp_type = orb(payload[9]) if mp_type == 255: mp_type = 65535 return ofp_stats_reply_cls[mp_type] else: diff --git a/scapy/contrib/openflow.uts b/scapy/contrib/openflow.uts index c58541b1d..168fc5a97 100755 --- a/scapy/contrib/openflow.uts +++ b/scapy/contrib/openflow.uts @@ -4,21 +4,21 @@ = OFPTHello(), simple hello message ofm = OFPTHello() -str(ofm) == b'\x01\x00\x00\x08\x00\x00\x00\x00' +raw(ofm) == b'\x01\x00\x00\x08\x00\x00\x00\x00' = OFPTEchoRequest(), echo request ofm = OFPTEchoRequest() -str(ofm) == b'\x01\x02\x00\x08\x00\x00\x00\x00' +raw(ofm) == b'\x01\x02\x00\x08\x00\x00\x00\x00' = OFPMatch(), check wildcard completion ofm = OFPMatch(in_port=1, nw_tos=8) -ofm = OFPMatch(str(ofm)) +ofm = OFPMatch(raw(ofm)) assert(ofm.wildcards1 == 0x1) ofm.wildcards2 == 0xfe = OpenFlow(), generic method test with OFPTEchoRequest() ofm = OFPTEchoRequest() -s = str(ofm) +s = raw(ofm) isinstance(OpenFlow(None,s)(s), OFPTEchoRequest) = OFPTFlowMod(), check codes and defaults values @@ -36,20 +36,20 @@ act1 = OFPATSetNwSrc(nw_addr='192.168.42.1') act2 = OFPATOutput(port='CONTROLLER') act3 = OFPATSetDlSrc(dl_addr='1a:d5:cb:4e:3c:64') ofm = OFPTFlowMod(priority=1000, match=mtc, flags='CHECK_OVERLAP', actions=[act1,act2,act3]) -str(ofm) +raw(ofm) s = b'\x01\x0e\x00h\x00\x00\x00\x00\x00?\xc8\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x00\xc0\xa8*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\xe8\xff\xff\xff\xff\xff\xff\x00\x02\x00\x06\x00\x08\xc0\xa8*\x01\x00\x00\x00\x08\xff\xfd\xff\xff\x00\x04\x00\x10\x1a\xd5\xcbN