diff --git a/ryu/lib/packet/sctp.py b/ryu/lib/packet/sctp.py index 1806e375..a59ac680 100644 --- a/ryu/lib/packet/sctp.py +++ b/ryu/lib/packet/sctp.py @@ -138,7 +138,7 @@ class sctp(packet_base.PacketBase): if self.csum == 0: self.csum = self._checksum(buf) struct.pack_into('!I', buf, 8, self.csum) - return str(buf) + return six.binary_type(buf) def __len__(self): length = self._MIN_LEN diff --git a/ryu/ofproto/ofproto_v1_2_parser.py b/ryu/ofproto/ofproto_v1_2_parser.py index 66dbeaba..fa5d36c8 100644 --- a/ryu/ofproto/ofproto_v1_2_parser.py +++ b/ryu/ofproto/ofproto_v1_2_parser.py @@ -1535,7 +1535,7 @@ class OFPActionSetField(OFPAction): # serialize and parse to fill new fields buf = bytearray() o2.serialize(buf, 0) - o = OFPActionSetField.parser(str(buf), 0) + o = OFPActionSetField.parser(six.binary_type(buf), 0) else: o = self return { @@ -1553,7 +1553,7 @@ class OFPActionSetField(OFPAction): # serialize and parse to fill old attributes buf = bytearray() o.serialize(buf, 0) - return OFPActionSetField.parser(str(buf), 0) + return OFPActionSetField.parser(six.binary_type(buf), 0) # XXX old api compat def __str__(self): @@ -1564,7 +1564,7 @@ class OFPActionSetField(OFPAction): # serialize and parse to fill new fields buf = bytearray() o2.serialize(buf, 0) - o = OFPActionSetField.parser(str(buf), 0) + o = OFPActionSetField.parser(six.binary_type(buf), 0) else: o = self return super(OFPActionSetField, o).__str__() @@ -3433,7 +3433,7 @@ class OFPMatch(StringifyMixin): # serialize and parse to fill OFPMatch._fields2 buf = bytearray() o2.serialize(buf, 0) - o = OFPMatch.parser(str(buf), 0) + o = OFPMatch.parser(six.binary_type(buf), 0) else: o = self @@ -3458,7 +3458,7 @@ class OFPMatch(StringifyMixin): # serialize and parse to fill OFPMatch.fields buf = bytearray() o.serialize(buf, 0) - return OFPMatch.parser(str(buf), 0) + return OFPMatch.parser(six.binary_type(buf), 0) def __str__(self): # XXX old api compat @@ -3469,7 +3469,7 @@ class OFPMatch(StringifyMixin): # serialize and parse to fill OFPMatch._fields2 buf = bytearray() o2.serialize(buf, 0) - o = OFPMatch.parser(str(buf), 0) + o = OFPMatch.parser(six.binary_type(buf), 0) else: o = self return super(OFPMatch, o).__str__() diff --git a/ryu/ofproto/ofproto_v1_3_parser.py b/ryu/ofproto/ofproto_v1_3_parser.py index f3e51c48..930e8b5a 100644 --- a/ryu/ofproto/ofproto_v1_3_parser.py +++ b/ryu/ofproto/ofproto_v1_3_parser.py @@ -866,7 +866,7 @@ class OFPMatch(StringifyMixin): # serialize and parse to fill OFPMatch._fields2 buf = bytearray() o2.serialize(buf, 0) - o = OFPMatch.parser(str(buf), 0) + o = OFPMatch.parser(six.binary_type(buf), 0) else: o = self @@ -891,7 +891,7 @@ class OFPMatch(StringifyMixin): # serialize and parse to fill OFPMatch.fields buf = bytearray() o.serialize(buf, 0) - return OFPMatch.parser(str(buf), 0) + return OFPMatch.parser(six.binary_type(buf), 0) def __str__(self): # XXX old api compat @@ -902,7 +902,7 @@ class OFPMatch(StringifyMixin): # serialize and parse to fill OFPMatch._fields2 buf = bytearray() o2.serialize(buf, 0) - o = OFPMatch.parser(str(buf), 0) + o = OFPMatch.parser(six.binary_type(buf), 0) else: o = self return super(OFPMatch, o).__str__() @@ -3118,7 +3118,7 @@ class OFPActionSetField(OFPAction): # serialize and parse to fill new fields buf = bytearray() o2.serialize(buf, 0) - o = OFPActionSetField.parser(str(buf), 0) + o = OFPActionSetField.parser(six.binary_type(buf), 0) else: o = self return { @@ -3136,7 +3136,7 @@ class OFPActionSetField(OFPAction): # serialize and parse to fill old attributes buf = bytearray() o.serialize(buf, 0) - return OFPActionSetField.parser(str(buf), 0) + return OFPActionSetField.parser(six.binary_type(buf), 0) # XXX old api compat def __str__(self): @@ -3147,7 +3147,7 @@ class OFPActionSetField(OFPAction): # serialize and parse to fill new fields buf = bytearray() o2.serialize(buf, 0) - o = OFPActionSetField.parser(str(buf), 0) + o = OFPActionSetField.parser(six.binary_type(buf), 0) else: o = self return super(OFPActionSetField, o).__str__() diff --git a/ryu/tests/unit/ofproto/test_parser_v13.py b/ryu/tests/unit/ofproto/test_parser_v13.py index cc723538..dd00866f 100644 --- a/ryu/tests/unit/ofproto/test_parser_v13.py +++ b/ryu/tests/unit/ofproto/test_parser_v13.py @@ -17,6 +17,7 @@ import unittest import logging +import six import socket from struct import * from nose.tools import * @@ -61,7 +62,7 @@ class TestOFPMatch(unittest.TestCase): if mask and len(buf) > calcsize(fmt): fmt += pack_str - res = list(unpack_from(fmt, str(buf), 0)[3:]) + res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:]) if type(value) is list: res_value = res[:calcsize(pack_str) // 2] eq_(res_value, value) @@ -79,7 +80,7 @@ class TestOFPMatch(unittest.TestCase): eq_(res_mask, mask) # parser - res = match.parser(str(buf), 0) + res = match.parser(six.binary_type(buf), 0) eq_(res.type, ofproto.OFPMT_OXM) eq_(res.fields[0].header, header) eq_(res.fields[0].value, value) @@ -93,7 +94,7 @@ class TestOFPMatch(unittest.TestCase): match2 = match.from_jsondict(jsondict["OFPMatch"]) buf2 = bytearray() match2.serialize(buf2, 0) - eq_(str(match), str(match2)) + eq_(six.binary_type(match), six.binary_type(match2)) eq_(buf, buf2) # set_vlan_vid @@ -121,12 +122,12 @@ class TestOFPMatch(unittest.TestCase): length = match.serialize(buf, 0) eq_(length, len(buf)) - res = list(unpack_from(fmt, str(buf), 0)[3:]) + res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:]) res_value = res.pop(0) eq_(res_value, value) # parser - res = match.parser(str(buf), 0) + res = match.parser(six.binary_type(buf), 0) eq_(res.type, ofproto.OFPMT_OXM) eq_(res.fields[0].header, header) eq_(res.fields[0].value, value) @@ -138,7 +139,7 @@ class TestOFPMatch(unittest.TestCase): match2 = match.from_jsondict(jsondict["OFPMatch"]) buf2 = bytearray() match2.serialize(buf2, 0) - eq_(str(match), str(match2)) + eq_(six.binary_type(match), six.binary_type(match2)) eq_(buf, buf2) def test_set_vlan_vid_mid(self): diff --git a/ryu/tests/unit/packet/test_cfm.py b/ryu/tests/unit/packet/test_cfm.py index 4120f875..fb0749d7 100644 --- a/ryu/tests/unit/packet/test_cfm.py +++ b/ryu/tests/unit/packet/test_cfm.py @@ -17,6 +17,7 @@ import unittest import logging import inspect +import six import struct from nose.tools import * @@ -227,7 +228,7 @@ class Test_cfm(unittest.TestCase): self.test_init() def test_parser(self): - _res = self.ins.parser(str(self.buf)) + _res = self.ins.parser(six.binary_type(self.buf)) if type(_res) is tuple: res = _res[0] @@ -264,7 +265,7 @@ class Test_cfm(unittest.TestCase): data = bytearray() prev = None buf = self.ins.serialize(data, prev) - cc_message = cfm.cc_message.parser(str(buf)) + cc_message = cfm.cc_message.parser(six.binary_type(buf)) eq_(repr(self.message), repr(cc_message)) def test_serialize_with_loopback_message(self): @@ -273,7 +274,7 @@ class Test_cfm(unittest.TestCase): data = bytearray() prev = None buf = self.ins.serialize(data, prev) - loopback_message = cfm.loopback_message.parser(str(buf)) + loopback_message = cfm.loopback_message.parser(six.binary_type(buf)) eq_(repr(self.message), repr(loopback_message)) def test_serialize_with_loopback_reply(self): @@ -282,7 +283,7 @@ class Test_cfm(unittest.TestCase): data = bytearray() prev = None buf = self.ins.serialize(data, prev) - loopback_reply = cfm.loopback_reply.parser(str(buf)) + loopback_reply = cfm.loopback_reply.parser(six.binary_type(buf)) eq_(repr(self.message), repr(loopback_reply)) def test_serialize_with_link_trace_message(self): @@ -291,7 +292,7 @@ class Test_cfm(unittest.TestCase): data = bytearray() prev = None buf = self.ins.serialize(data, prev) - link_trace_message = cfm.link_trace_message.parser(str(buf)) + link_trace_message = cfm.link_trace_message.parser(six.binary_type(buf)) eq_(repr(self.message), repr(link_trace_message)) def test_serialize_with_link_trace_reply(self): @@ -300,7 +301,7 @@ class Test_cfm(unittest.TestCase): data = bytearray() prev = None buf = self.ins.serialize(data, prev) - link_trace_reply = cfm.link_trace_reply.parser(str(buf)) + link_trace_reply = cfm.link_trace_reply.parser(six.binary_type(buf)) eq_(repr(self.message), repr(link_trace_reply)) def test_to_string(self): @@ -511,7 +512,7 @@ class Test_cc_message(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -545,7 +546,7 @@ class Test_cc_message(unittest.TestCase): self.tlvs ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -580,7 +581,7 @@ class Test_cc_message(unittest.TestCase): self.tlvs ) buf = ins.serialize() - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -602,7 +603,7 @@ class Test_cc_message(unittest.TestCase): def test_default_args(self): ins = cfm.cc_message() buf = ins.serialize() - res = struct.unpack_from(cfm.cc_message._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.cc_message._PACK_STR, six.binary_type(buf)) eq_(res[0] >> 5, 0) eq_(res[0] & 0x1f, 0) eq_(res[1], 1) @@ -666,7 +667,7 @@ class Test_loopback_message(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -683,7 +684,7 @@ class Test_loopback_message(unittest.TestCase): ins = cfm.loopback_message() buf = ins.serialize() res = struct.unpack_from(cfm.loopback_message._PACK_STR, - str(buf)) + six.binary_type(buf)) eq_(res[0] >> 5, 0) eq_(res[0] & 0x1f, 0) eq_(res[1], 3) @@ -743,7 +744,7 @@ class Test_loopback_reply(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -759,7 +760,7 @@ class Test_loopback_reply(unittest.TestCase): def test_default_args(self): ins = cfm.loopback_reply() buf = ins.serialize() - res = struct.unpack_from(cfm.loopback_reply._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.loopback_reply._PACK_STR, six.binary_type(buf)) eq_(res[0] >> 5, 0) eq_(res[0] & 0x1f, 0) eq_(res[1], 2) @@ -838,7 +839,7 @@ class Test_link_trace_message(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -857,7 +858,7 @@ class Test_link_trace_message(unittest.TestCase): def test_default_args(self): ins = cfm.link_trace_message() buf = ins.serialize() - res = struct.unpack_from(cfm.link_trace_message._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.link_trace_message._PACK_STR, six.binary_type(buf)) eq_(res[0] >> 5, 0) eq_(res[0] & 0x1f, 0) eq_(res[1], 5) @@ -944,7 +945,7 @@ class Test_link_trace_reply(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -964,7 +965,7 @@ class Test_link_trace_reply(unittest.TestCase): def test_default_args(self): ins = cfm.link_trace_reply() buf = ins.serialize() - res = struct.unpack_from(cfm.link_trace_reply._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.link_trace_reply._PACK_STR, six.binary_type(buf)) eq_(res[0] >> 5, 0) eq_(res[0] & 0x1f, 0) eq_(res[1], 4) @@ -1043,7 +1044,7 @@ class Test_sender_id_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.chassis_id_length, res[2]) @@ -1062,7 +1063,7 @@ class Test_sender_id_tlv(unittest.TestCase): ) buf = ins.serialize() form = '!BHBB1sB2sB' - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(7, res[1]) eq_(self.chassis_id_length, res[2]) @@ -1079,7 +1080,7 @@ class Test_sender_id_tlv(unittest.TestCase): ) buf = ins.serialize() form = '!BHBB2sB3s' - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(8, res[1]) eq_(0, res[2]) @@ -1095,7 +1096,7 @@ class Test_sender_id_tlv(unittest.TestCase): ) buf = ins.serialize() form = '!BHBB1sB' - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(4, res[1]) eq_(self.chassis_id_length, res[2]) @@ -1109,7 +1110,7 @@ class Test_sender_id_tlv(unittest.TestCase): ) buf = ins.serialize() form = '!BHBB2sB' - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(5, res[1]) eq_(0, res[2]) @@ -1129,7 +1130,7 @@ class Test_sender_id_tlv(unittest.TestCase): self.ma, ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.chassis_id_length, res[2]) @@ -1147,7 +1148,7 @@ class Test_sender_id_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.sender_id_tlv() buf = ins.serialize() - res = struct.unpack_from(cfm.sender_id_tlv._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.sender_id_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_SENDER_ID_TLV) eq_(res[1], 1) eq_(res[2], 0) @@ -1189,7 +1190,7 @@ class Test_port_status_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.port_status, res[2]) @@ -1201,7 +1202,7 @@ class Test_port_status_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.port_status_tlv() buf = ins.serialize() - res = struct.unpack_from(cfm.port_status_tlv._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.port_status_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_PORT_STATUS_TLV) eq_(res[1], 1) eq_(res[2], 2) @@ -1243,7 +1244,7 @@ class Test_data_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.data_value, res[2]) @@ -1254,7 +1255,7 @@ class Test_data_tlv(unittest.TestCase): self.data_value ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.data_value, res[2]) @@ -1266,7 +1267,7 @@ class Test_data_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.data_tlv() buf = ins.serialize() - res = struct.unpack_from(cfm.data_tlv._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.data_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_DATA_TLV) eq_(res[1], 0) @@ -1307,7 +1308,7 @@ class Test_interface_status_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.interface_status, res[2]) @@ -1319,7 +1320,7 @@ class Test_interface_status_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.interface_status_tlv() buf = ins.serialize() - res = struct.unpack_from(cfm.interface_status_tlv._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.interface_status_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_INTERFACE_STATUS_TLV) eq_(res[1], 1) eq_(res[2], 1) @@ -1366,7 +1367,7 @@ class Test_ltm_egress_identifier_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.egress_id_ui, res[2]) @@ -1379,7 +1380,7 @@ class Test_ltm_egress_identifier_tlv(unittest.TestCase): self.egress_id_mac ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.egress_id_ui, res[2]) @@ -1393,7 +1394,7 @@ class Test_ltm_egress_identifier_tlv(unittest.TestCase): ins = cfm.ltm_egress_identifier_tlv() buf = ins.serialize() res = struct.unpack_from( - cfm.ltm_egress_identifier_tlv._PACK_STR, str(buf)) + cfm.ltm_egress_identifier_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_LTM_EGRESS_IDENTIFIER_TLV) eq_(res[1], 8) eq_(res[2], 0) @@ -1449,7 +1450,7 @@ class Test_ltr_egress_identifier_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.last_egress_id_ui, res[2]) @@ -1465,7 +1466,7 @@ class Test_ltr_egress_identifier_tlv(unittest.TestCase): self.next_egress_id_mac ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.last_egress_id_ui, res[2]) @@ -1481,7 +1482,7 @@ class Test_ltr_egress_identifier_tlv(unittest.TestCase): ins = cfm.ltr_egress_identifier_tlv() buf = ins.serialize() res = struct.unpack_from(cfm.ltr_egress_identifier_tlv._PACK_STR, - str(buf)) + six.binary_type(buf)) eq_(res[0], cfm.CFM_LTR_EGRESS_IDENTIFIER_TLV) eq_(res[1], 16) eq_(res[2], 0) @@ -1534,7 +1535,7 @@ class Test_organization_specific_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.oui, res[2]) @@ -1548,7 +1549,7 @@ class Test_organization_specific_tlv(unittest.TestCase): self.value ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.oui, res[2]) @@ -1563,7 +1564,7 @@ class Test_organization_specific_tlv(unittest.TestCase): ins = cfm.organization_specific_tlv() buf = ins.serialize() res = struct.unpack_from(cfm.organization_specific_tlv._PACK_STR, - str(buf)) + six.binary_type(buf)) eq_(res[0], cfm.CFM_ORGANIZATION_SPECIFIC_TLV) eq_(res[1], 4) eq_(res[2], b"\x00\x00\x00") @@ -1623,7 +1624,7 @@ class Test_reply_ingress_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.action, res[2]) @@ -1641,7 +1642,7 @@ class Test_reply_ingress_tlv(unittest.TestCase): self.port_id ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.action, res[2]) @@ -1657,7 +1658,7 @@ class Test_reply_ingress_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.reply_ingress_tlv() buf = ins.serialize() - res = struct.unpack_from(cfm.reply_ingress_tlv._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.reply_ingress_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_REPLY_INGRESS_TLV) eq_(res[1], 7) eq_(res[2], 1) @@ -1718,7 +1719,7 @@ class Test_reply_egress_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.action, res[2]) @@ -1736,7 +1737,7 @@ class Test_reply_egress_tlv(unittest.TestCase): self.port_id ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.action, res[2]) @@ -1752,7 +1753,8 @@ class Test_reply_egress_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.reply_egress_tlv() buf = ins.serialize() - res = struct.unpack_from(cfm.reply_egress_tlv._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.reply_egress_tlv._PACK_STR, + six.binary_type(buf)) eq_(res[0], cfm.CFM_REPLY_EGRESS_TLV) eq_(res[1], 7) eq_(res[2], 1) diff --git a/ryu/tests/unit/packet/test_dhcp.py b/ryu/tests/unit/packet/test_dhcp.py index d6f4aae2..92116ee8 100644 --- a/ryu/tests/unit/packet/test_dhcp.py +++ b/ryu/tests/unit/packet/test_dhcp.py @@ -16,6 +16,7 @@ import inspect import logging +import six import struct import unittest from nose.tools import eq_ @@ -104,7 +105,7 @@ class Test_dhcp_offer(unittest.TestCase): eq_(str(self.options), str(self.dh.options)) def test_parser(self): - _res = self.dh.parser(str(self.buf)) + _res = self.dh.parser(self.buf) if type(_res) is tuple: res = _res[0] else: @@ -137,7 +138,7 @@ class Test_dhcp_offer(unittest.TestCase): prev = None buf = self.dh.serialize(data, prev) - res = struct.unpack_from(dhcp.dhcp._DHCP_PACK_STR, str(buf)) + res = struct.unpack_from(dhcp.dhcp._DHCP_PACK_STR, six.binary_type(buf)) eq_(self.op, res[0]) eq_(self.htype, res[1]) diff --git a/ryu/tests/unit/packet/test_ethernet.py b/ryu/tests/unit/packet/test_ethernet.py index 2555404f..6fd767bd 100644 --- a/ryu/tests/unit/packet/test_ethernet.py +++ b/ryu/tests/unit/packet/test_ethernet.py @@ -17,6 +17,7 @@ import unittest import logging +import six import struct import netaddr from struct import * @@ -90,7 +91,7 @@ class Test_ethernet(unittest.TestCase): def test_default_args(self): e = ethernet() buf = e.serialize(bytearray(), None) - res = struct.unpack(e._PACK_STR, str(buf)) + res = struct.unpack(e._PACK_STR, six.binary_type(buf)) eq_(res[0], addrconv.mac.text_to_bin('ff:ff:ff:ff:ff:ff')) eq_(res[1], addrconv.mac.text_to_bin('00:00:00:00:00:00')) diff --git a/ryu/tests/unit/packet/test_icmp.py b/ryu/tests/unit/packet/test_icmp.py index 85045264..2858c84c 100644 --- a/ryu/tests/unit/packet/test_icmp.py +++ b/ryu/tests/unit/packet/test_icmp.py @@ -129,7 +129,7 @@ class Test_icmp(unittest.TestCase): self.test_init() def test_parser(self): - _res = icmp.icmp.parser(str(self.buf)) + _res = icmp.icmp.parser(six.binary_type(self.buf)) if type(_res) is tuple: res = _res[0] else: @@ -157,7 +157,7 @@ class Test_icmp(unittest.TestCase): prev = None buf = self.ic.serialize(data, prev) - res = struct.unpack_from(icmp.icmp._PACK_STR, str(buf)) + res = struct.unpack_from(icmp.icmp._PACK_STR, six.binary_type(buf)) eq_(self.type_, res[0]) eq_(self.code, res[1]) @@ -170,7 +170,7 @@ class Test_icmp(unittest.TestCase): data = bytearray() prev = None buf = self.ic.serialize(data, prev) - echo = icmp.echo.parser(str(buf), icmp.icmp._MIN_LEN) + echo = icmp.echo.parser(six.binary_type(buf), icmp.icmp._MIN_LEN) eq_(repr(self.data), repr(echo)) def test_serialize_with_dest_unreach(self): @@ -180,7 +180,7 @@ class Test_icmp(unittest.TestCase): data = bytearray() prev = None buf = self.ic.serialize(data, prev) - unreach = icmp.dest_unreach.parser(str(buf), icmp.icmp._MIN_LEN) + unreach = icmp.dest_unreach.parser(six.binary_type(buf), icmp.icmp._MIN_LEN) eq_(repr(self.data), repr(unreach)) def test_serialize_with_TimeExceeded(self): @@ -190,7 +190,7 @@ class Test_icmp(unittest.TestCase): data = bytearray() prev = None buf = self.ic.serialize(data, prev) - te = icmp.TimeExceeded.parser(str(buf), icmp.icmp._MIN_LEN) + te = icmp.TimeExceeded.parser(six.binary_type(buf), icmp.icmp._MIN_LEN) eq_(repr(self.data), repr(te)) def test_to_string(self): @@ -221,7 +221,7 @@ class Test_icmp(unittest.TestCase): def test_default_args(self): ic = icmp.icmp() buf = ic.serialize(bytearray(), None) - res = struct.unpack(icmp.icmp._PACK_STR, str(buf[:4])) + res = struct.unpack(icmp.icmp._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], 8) eq_(res[1], 0) @@ -230,7 +230,7 @@ class Test_icmp(unittest.TestCase): # with data ic = icmp.icmp(type_=icmp.ICMP_DEST_UNREACH, data=icmp.dest_unreach()) buf = ic.serialize(bytearray(), None) - res = struct.unpack(icmp.icmp._PACK_STR, str(buf[:4])) + res = struct.unpack(icmp.icmp._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], 3) eq_(res[1], 0) @@ -287,7 +287,7 @@ class Test_echo(unittest.TestCase): def test_serialize(self): buf = self.echo.serialize() - res = struct.unpack_from('!HH', str(buf)) + res = struct.unpack_from('!HH', six.binary_type(buf)) eq_(self.id_, res[0]) eq_(self.seq, res[1]) eq_(self.data, buf[struct.calcsize('!HH'):]) @@ -295,7 +295,7 @@ class Test_echo(unittest.TestCase): def test_default_args(self): ec = icmp.echo() buf = ec.serialize() - res = struct.unpack(icmp.echo._PACK_STR, str(buf)) + res = struct.unpack(icmp.echo._PACK_STR, six.binary_type(buf)) eq_(res[0], 0) eq_(res[1], 0) @@ -329,7 +329,7 @@ class Test_dest_unreach(unittest.TestCase): def test_serialize(self): buf = self.dest_unreach.serialize() - res = struct.unpack_from('!xBH', str(buf)) + res = struct.unpack_from('!xBH', six.binary_type(buf)) eq_(self.data_len, res[0]) eq_(self.mtu, res[1]) eq_(self.data, buf[struct.calcsize('!xBH'):]) @@ -337,7 +337,7 @@ class Test_dest_unreach(unittest.TestCase): def test_default_args(self): du = icmp.dest_unreach() buf = du.serialize() - res = struct.unpack(icmp.dest_unreach._PACK_STR, str(buf)) + res = struct.unpack(icmp.dest_unreach._PACK_STR, six.binary_type(buf)) eq_(res[0], 0) eq_(res[1], 0) @@ -368,13 +368,13 @@ class Test_TimeExceeded(unittest.TestCase): def test_serialize(self): buf = self.te.serialize() - res = struct.unpack_from('!xBxx', str(buf)) + res = struct.unpack_from('!xBxx', six.binary_type(buf)) eq_(self.data_len, res[0]) eq_(self.data, buf[struct.calcsize('!xBxx'):]) def test_default_args(self): te = icmp.TimeExceeded() buf = te.serialize() - res = struct.unpack(icmp.TimeExceeded._PACK_STR, str(buf)) + res = struct.unpack(icmp.TimeExceeded._PACK_STR, six.binary_type(buf)) eq_(res[0], 0) diff --git a/ryu/tests/unit/packet/test_icmpv6.py b/ryu/tests/unit/packet/test_icmpv6.py index b0fa18f3..b9b8201a 100644 --- a/ryu/tests/unit/packet/test_icmpv6.py +++ b/ryu/tests/unit/packet/test_icmpv6.py @@ -94,7 +94,7 @@ class Test_icmpv6_header(unittest.TestCase): ic = icmpv6.icmpv6() prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf)) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf)) eq_(res[0], 0) eq_(res[1], 0) @@ -204,13 +204,13 @@ class Test_icmpv6_echo_request(unittest.TestCase): type_=icmpv6.ICMPV6_ECHO_REQUEST, data=icmpv6.echo()) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ICMPV6_ECHO_REQUEST) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.echo._PACK_STR, str(buf[4:])) + res = struct.unpack(icmpv6.echo._PACK_STR, six.binary_type(buf[4:])) eq_(res[0], 0) eq_(res[1], 0) @@ -235,13 +235,13 @@ class Test_icmpv6_echo_reply(Test_icmpv6_echo_request): type_=icmpv6.ICMPV6_ECHO_REPLY, data=icmpv6.echo()) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ICMPV6_ECHO_REPLY) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.echo._PACK_STR, str(buf[4:])) + res = struct.unpack(icmpv6.echo._PACK_STR, six.binary_type(buf[4:])) eq_(res[0], 0) eq_(res[1], 0) @@ -380,13 +380,13 @@ class Test_icmpv6_neighbor_solicit(unittest.TestCase): type_=icmpv6.ND_NEIGHBOR_SOLICIT, data=icmpv6.nd_neighbor()) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_NEIGHBOR_SOLICIT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, str(buf[4:])) + res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, six.binary_type(buf[4:])) eq_(res[0], 0) eq_(res[1], addrconv.ipv6.text_to_bin('::')) @@ -399,18 +399,20 @@ class Test_icmpv6_neighbor_solicit(unittest.TestCase): option=icmpv6.nd_option_sla())) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_NEIGHBOR_SOLICIT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, str(buf[4:24])) + res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, + six.binary_type(buf[4:24])) eq_(res[0], 0) eq_(res[1], addrconv.ipv6.text_to_bin('::')) - res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, str(buf[24:])) + res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, + six.binary_type(buf[24:])) eq_(res[0], icmpv6.ND_OPTION_SLA) eq_(res[1], len(icmpv6.nd_option_sla()) // 8) @@ -503,13 +505,13 @@ class Test_icmpv6_neighbor_advert(Test_icmpv6_neighbor_solicit): type_=icmpv6.ND_NEIGHBOR_ADVERT, data=icmpv6.nd_neighbor()) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_NEIGHBOR_ADVERT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, str(buf[4:])) + res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, six.binary_type(buf[4:])) eq_(res[0], 0) eq_(res[1], addrconv.ipv6.text_to_bin('::')) @@ -522,18 +524,20 @@ class Test_icmpv6_neighbor_advert(Test_icmpv6_neighbor_solicit): option=icmpv6.nd_option_tla())) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_NEIGHBOR_ADVERT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, str(buf[4:24])) + res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, + six.binary_type(buf[4:24])) eq_(res[0], 0) eq_(res[1], addrconv.ipv6.text_to_bin('::')) - res = struct.unpack(icmpv6.nd_option_tla._PACK_STR, str(buf[24:])) + res = struct.unpack(icmpv6.nd_option_tla._PACK_STR, + six.binary_type(buf[24:])) eq_(res[0], icmpv6.ND_OPTION_TLA) eq_(res[1], len(icmpv6.nd_option_tla()) // 8) @@ -665,13 +669,14 @@ class Test_icmpv6_router_solicit(unittest.TestCase): type_=icmpv6.ND_ROUTER_SOLICIT, data=icmpv6.nd_router_solicit()) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_ROUTER_SOLICIT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_router_solicit._PACK_STR, str(buf[4:])) + res = struct.unpack(icmpv6.nd_router_solicit._PACK_STR, + six.binary_type(buf[4:])) eq_(res[0], 0) @@ -683,17 +688,19 @@ class Test_icmpv6_router_solicit(unittest.TestCase): option=icmpv6.nd_option_sla())) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_ROUTER_SOLICIT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_router_solicit._PACK_STR, str(buf[4:8])) + res = struct.unpack(icmpv6.nd_router_solicit._PACK_STR, + six.binary_type(buf[4:8])) eq_(res[0], 0) - res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, str(buf[8:])) + res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, + six.binary_type(buf[8:])) eq_(res[0], icmpv6.ND_OPTION_SLA) eq_(res[1], len(icmpv6.nd_option_sla()) // 8) @@ -722,13 +729,14 @@ class Test_icmpv6_router_advert(unittest.TestCase): type_=icmpv6.ND_ROUTER_ADVERT, data=icmpv6.nd_router_advert()) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_ROUTER_ADVERT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_router_advert._PACK_STR, str(buf[4:])) + res = struct.unpack(icmpv6.nd_router_advert._PACK_STR, + six.binary_type(buf[4:])) eq_(res[0], 0) eq_(res[1], 0) @@ -744,13 +752,14 @@ class Test_icmpv6_router_advert(unittest.TestCase): options=[icmpv6.nd_option_sla()])) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_ROUTER_ADVERT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_router_advert._PACK_STR, str(buf[4:16])) + res = struct.unpack(icmpv6.nd_router_advert._PACK_STR, + six.binary_type(buf[4:16])) eq_(res[0], 0) eq_(res[1], 0) @@ -758,7 +767,8 @@ class Test_icmpv6_router_advert(unittest.TestCase): eq_(res[3], 0) eq_(res[4], 0) - res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, str(buf[16:])) + res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, + six.binary_type(buf[16:])) eq_(res[0], icmpv6.ND_OPTION_SLA) eq_(res[1], len(icmpv6.nd_option_sla()) // 8) @@ -772,13 +782,14 @@ class Test_icmpv6_router_advert(unittest.TestCase): options=[icmpv6.nd_option_pi()])) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_ROUTER_ADVERT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_router_advert._PACK_STR, str(buf[4:16])) + res = struct.unpack(icmpv6.nd_router_advert._PACK_STR, + six.binary_type(buf[4:16])) eq_(res[0], 0) eq_(res[1], 0) @@ -786,7 +797,8 @@ class Test_icmpv6_router_advert(unittest.TestCase): eq_(res[3], 0) eq_(res[4], 0) - res = struct.unpack(icmpv6.nd_option_pi._PACK_STR, str(buf[16:])) + res = struct.unpack(icmpv6.nd_option_pi._PACK_STR, + six.binary_type(buf[16:])) eq_(res[0], icmpv6.ND_OPTION_PI) eq_(res[1], 4) @@ -805,13 +817,14 @@ class Test_icmpv6_router_advert(unittest.TestCase): options=[icmpv6.nd_option_sla(), icmpv6.nd_option_pi()])) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_ROUTER_ADVERT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_router_advert._PACK_STR, str(buf[4:16])) + res = struct.unpack(icmpv6.nd_router_advert._PACK_STR, + six.binary_type(buf[4:16])) eq_(res[0], 0) eq_(res[1], 0) @@ -819,13 +832,15 @@ class Test_icmpv6_router_advert(unittest.TestCase): eq_(res[3], 0) eq_(res[4], 0) - res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, str(buf[16:24])) + res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, + six.binary_type(buf[16:24])) eq_(res[0], icmpv6.ND_OPTION_SLA) eq_(res[1], len(icmpv6.nd_option_sla()) // 8) eq_(res[2], addrconv.mac.text_to_bin('00:00:00:00:00:00')) - res = struct.unpack(icmpv6.nd_option_pi._PACK_STR, str(buf[24:])) + res = struct.unpack(icmpv6.nd_option_pi._PACK_STR, + six.binary_type(buf[24:])) eq_(res[0], icmpv6.ND_OPTION_PI) eq_(res[1], len(icmpv6.nd_option_pi()) // 8) @@ -857,7 +872,7 @@ class Test_icmpv6_nd_option_la(unittest.TestCase): def test_default_args(self): la = icmpv6.nd_option_sla() buf = la.serialize() - res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, str(buf)) + res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, six.binary_type(buf)) eq_(res[0], icmpv6.ND_OPTION_SLA) eq_(res[1], len(icmpv6.nd_option_sla()) // 8) @@ -871,18 +886,20 @@ class Test_icmpv6_nd_option_la(unittest.TestCase): option=icmpv6.nd_option_tla())) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_NEIGHBOR_ADVERT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, str(buf[4:24])) + res = struct.unpack(icmpv6.nd_neighbor._PACK_STR, + six.binary_type(buf[4:24])) eq_(res[0], 0) eq_(res[1], addrconv.ipv6.text_to_bin('::')) - res = struct.unpack(icmpv6.nd_option_tla._PACK_STR, str(buf[24:])) + res = struct.unpack(icmpv6.nd_option_tla._PACK_STR, + six.binary_type(buf[24:])) eq_(res[0], icmpv6.ND_OPTION_TLA) eq_(res[1], len(icmpv6.nd_option_tla()) // 8) @@ -896,17 +913,19 @@ class Test_icmpv6_nd_option_la(unittest.TestCase): option=icmpv6.nd_option_sla())) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_ROUTER_SOLICIT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_router_solicit._PACK_STR, str(buf[4:8])) + res = struct.unpack(icmpv6.nd_router_solicit._PACK_STR, + six.binary_type(buf[4:8])) eq_(res[0], 0) - res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, str(buf[8:])) + res = struct.unpack(icmpv6.nd_option_sla._PACK_STR, + six.binary_type(buf[8:])) eq_(res[0], icmpv6.ND_OPTION_SLA) eq_(res[1], len(icmpv6.nd_option_sla()) // 8) @@ -924,7 +943,7 @@ class Test_icmpv6_nd_option_pi(unittest.TestCase): def test_default_args(self): pi = icmpv6.nd_option_pi() buf = pi.serialize() - res = struct.unpack(icmpv6.nd_option_pi._PACK_STR, str(buf)) + res = struct.unpack(icmpv6.nd_option_pi._PACK_STR, six.binary_type(buf)) eq_(res[0], icmpv6.ND_OPTION_PI) eq_(res[1], len(icmpv6.nd_option_pi()) // 8) @@ -943,13 +962,14 @@ class Test_icmpv6_nd_option_pi(unittest.TestCase): options=[icmpv6.nd_option_pi()])) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.ND_ROUTER_ADVERT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.nd_router_advert._PACK_STR, str(buf[4:16])) + res = struct.unpack(icmpv6.nd_router_advert._PACK_STR, + six.binary_type(buf[4:16])) eq_(res[0], 0) eq_(res[1], 0) @@ -957,7 +977,8 @@ class Test_icmpv6_nd_option_pi(unittest.TestCase): eq_(res[3], 0) eq_(res[4], 0) - res = struct.unpack(icmpv6.nd_option_pi._PACK_STR, str(buf[16:])) + res = struct.unpack(icmpv6.nd_option_pi._PACK_STR, + six.binary_type(buf[16:])) eq_(res[0], icmpv6.ND_OPTION_PI) eq_(res[1], 4) @@ -1049,13 +1070,13 @@ class Test_icmpv6_membership_query(unittest.TestCase): type_=icmpv6.MLD_LISTENER_QUERY, data=icmpv6.mld()) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.MLD_LISTENER_QUERY) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.mld._PACK_STR, str(buf[4:])) + res = struct.unpack(icmpv6.mld._PACK_STR, six.binary_type(buf[4:])) eq_(res[0], 0) eq_(res[1], addrconv.ipv6.text_to_bin('::')) @@ -1195,9 +1216,10 @@ class Test_mldv2_query(unittest.TestCase): icmp = icmpv6.icmpv6(self.type_, self.code, 0, self.mld) buf = icmp.serialize(bytearray(), prev) - (type_, code, csum) = struct.unpack_from(icmp._PACK_STR, str(buf)) + (type_, code, csum) = struct.unpack_from(icmp._PACK_STR, + six.binary_type(buf)) (maxresp, address, s_qrv, qqic, num) = struct.unpack_from( - self.mld._PACK_STR, str(buf), icmp._MIN_LEN) + self.mld._PACK_STR, six.binary_type(buf), icmp._MIN_LEN) eq_(type_, self.type_) eq_(code, self.code) @@ -1221,11 +1243,12 @@ class Test_mldv2_query(unittest.TestCase): icmp = icmpv6.icmpv6(self.type_, self.code, 0, self.mld) buf = icmp.serialize(bytearray(), prev) - (type_, code, csum) = struct.unpack_from(icmp._PACK_STR, str(buf)) + (type_, code, csum) = struct.unpack_from(icmp._PACK_STR, + six.binary_type(buf)) (maxresp, address, s_qrv, qqic, num) = struct.unpack_from( - self.mld._PACK_STR, str(buf), icmp._MIN_LEN) + self.mld._PACK_STR, six.binary_type(buf), icmp._MIN_LEN) (addr1, addr2) = struct.unpack_from( - '!16s16s', str(buf), icmp._MIN_LEN + self.mld._MIN_LEN) + '!16s16s', six.binary_type(buf), icmp._MIN_LEN + self.mld._MIN_LEN) eq_(type_, self.type_) eq_(code, self.code) @@ -1340,13 +1363,13 @@ class Test_mldv2_query(unittest.TestCase): type_=icmpv6.MLD_LISTENER_QUERY, data=icmpv6.mldv2_query()) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.MLD_LISTENER_QUERY) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.mldv2_query._PACK_STR, str(buf[4:])) + res = struct.unpack(icmpv6.mldv2_query._PACK_STR, six.binary_type(buf[4:])) eq_(res[0], 0) eq_(res[1], addrconv.ipv6.text_to_bin('::')) @@ -1359,7 +1382,7 @@ class Test_mldv2_query(unittest.TestCase): que = icmpv6.mldv2_query(srcs=srcs) buf = que.serialize() res = struct.unpack_from( - icmpv6.mldv2_query._PACK_STR, str(buf)) + icmpv6.mldv2_query._PACK_STR, six.binary_type(buf)) eq_(res[0], 0) eq_(res[1], addrconv.ipv6.text_to_bin('::')) @@ -1368,7 +1391,7 @@ class Test_mldv2_query(unittest.TestCase): eq_(res[4], len(srcs)) (src1, src2, src3) = struct.unpack_from( - '16s16s16s', str(buf), icmpv6.mldv2_query._MIN_LEN) + '16s16s16s', six.binary_type(buf), icmpv6.mldv2_query._MIN_LEN) eq_(src1, addrconv.ipv6.text_to_bin(srcs[0])) eq_(src2, addrconv.ipv6.text_to_bin(srcs[1])) @@ -1475,9 +1498,10 @@ class Test_mldv2_report(unittest.TestCase): icmp = icmpv6.icmpv6(self.type_, self.code, 0, self.mld) buf = icmp.serialize(bytearray(), prev) - (type_, code, csum) = struct.unpack_from(icmp._PACK_STR, str(buf)) + (type_, code, csum) = struct.unpack_from(icmp._PACK_STR, + six.binary_type(buf)) (record_num, ) = struct.unpack_from( - self.mld._PACK_STR, str(buf), icmp._MIN_LEN) + self.mld._PACK_STR, six.binary_type(buf), icmp._MIN_LEN) eq_(type_, self.type_) eq_(code, self.code) @@ -1494,9 +1518,10 @@ class Test_mldv2_report(unittest.TestCase): icmp = icmpv6.icmpv6(self.type_, self.code, 0, self.mld) buf = six.binary_type(icmp.serialize(bytearray(), prev)) - (type_, code, csum) = struct.unpack_from(icmp._PACK_STR, str(buf)) + (type_, code, csum) = struct.unpack_from(icmp._PACK_STR, + six.binary_type(buf)) (record_num, ) = struct.unpack_from( - self.mld._PACK_STR, str(buf), icmp._MIN_LEN) + self.mld._PACK_STR, six.binary_type(buf), icmp._MIN_LEN) offset = icmp._MIN_LEN + self.mld._MIN_LEN rec1 = icmpv6.mldv2_report_group.parser(buf[offset:]) offset += len(rec1) @@ -1625,13 +1650,13 @@ class Test_mldv2_report(unittest.TestCase): type_=icmpv6.MLDV2_LISTENER_REPORT, data=icmpv6.mldv2_report()) prev.serialize(ic, None) buf = ic.serialize(bytearray(), prev) - res = struct.unpack(icmpv6.icmpv6._PACK_STR, str(buf[:4])) + res = struct.unpack(icmpv6.icmpv6._PACK_STR, six.binary_type(buf[:4])) eq_(res[0], icmpv6.MLDV2_LISTENER_REPORT) eq_(res[1], 0) eq_(res[2], icmpv6_csum(prev, buf)) - res = struct.unpack(icmpv6.mldv2_report._PACK_STR, str(buf[4:])) + res = struct.unpack(icmpv6.mldv2_report._PACK_STR, six.binary_type(buf[4:])) eq_(res[0], 0) @@ -1645,12 +1670,12 @@ class Test_mldv2_report(unittest.TestCase): rep = icmpv6.mldv2_report(records=records) buf = rep.serialize() res = struct.unpack_from( - icmpv6.mldv2_report._PACK_STR, str(buf)) + icmpv6.mldv2_report._PACK_STR, six.binary_type(buf)) eq_(res[0], len(records)) res = struct.unpack_from( - icmpv6.mldv2_report_group._PACK_STR, str(buf), + icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf), icmpv6.mldv2_report._MIN_LEN) eq_(res[0], icmpv6.MODE_IS_INCLUDE) @@ -1659,7 +1684,7 @@ class Test_mldv2_report(unittest.TestCase): eq_(res[3], addrconv.ipv6.text_to_bin('ff00::1')) res = struct.unpack_from( - icmpv6.mldv2_report_group._PACK_STR, str(buf), + icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf), icmpv6.mldv2_report._MIN_LEN + icmpv6.mldv2_report_group._MIN_LEN) @@ -1669,7 +1694,7 @@ class Test_mldv2_report(unittest.TestCase): eq_(res[3], addrconv.ipv6.text_to_bin('ff00::2')) res = struct.unpack_from( - '16s16s', str(buf), + '16s16s', six.binary_type(buf), icmpv6.mldv2_report._MIN_LEN + icmpv6.mldv2_report_group._MIN_LEN + icmpv6.mldv2_report_group._MIN_LEN) @@ -1956,7 +1981,7 @@ class Test_mldv2_report_group(unittest.TestCase): rep = icmpv6.mldv2_report_group() buf = rep.serialize() res = struct.unpack_from( - icmpv6.mldv2_report_group._PACK_STR, str(buf)) + icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf)) eq_(res[0], 0) eq_(res[1], 0) @@ -1969,7 +1994,7 @@ class Test_mldv2_report_group(unittest.TestCase): buf = rep.serialize() LOG.info(repr(buf)) res = struct.unpack_from( - icmpv6.mldv2_report_group._PACK_STR, str(buf)) + icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf)) eq_(res[0], 0) eq_(res[1], 0) @@ -1977,7 +2002,7 @@ class Test_mldv2_report_group(unittest.TestCase): eq_(res[3], addrconv.ipv6.text_to_bin('::')) (src1, src2, src3) = struct.unpack_from( - '16s16s16s', str(buf), icmpv6.mldv2_report_group._MIN_LEN) + '16s16s16s', six.binary_type(buf), icmpv6.mldv2_report_group._MIN_LEN) eq_(src1, addrconv.ipv6.text_to_bin(srcs[0])) eq_(src2, addrconv.ipv6.text_to_bin(srcs[1])) @@ -1987,7 +2012,7 @@ class Test_mldv2_report_group(unittest.TestCase): rep = icmpv6.mldv2_report_group(aux=b'\x01\x02\x03') buf = rep.serialize() res = struct.unpack_from( - icmpv6.mldv2_report_group._PACK_STR, str(buf)) + icmpv6.mldv2_report_group._PACK_STR, six.binary_type(buf)) eq_(res[0], 0) eq_(res[1], 1) diff --git a/ryu/tests/unit/packet/test_igmp.py b/ryu/tests/unit/packet/test_igmp.py index b6913563..813b443d 100644 --- a/ryu/tests/unit/packet/test_igmp.py +++ b/ryu/tests/unit/packet/test_igmp.py @@ -155,7 +155,7 @@ class Test_igmp(unittest.TestCase): def test_default_args(self): ig = igmp() buf = ig.serialize(bytearray(), None) - res = unpack_from(igmp._PACK_STR, str(buf)) + res = unpack_from(igmp._PACK_STR, six.binary_type(buf)) eq_(res[0], 0x11) eq_(res[1], 0) @@ -391,7 +391,7 @@ class Test_igmpv3_query(unittest.TestCase): g = igmpv3_query() prev.serialize(g, None) buf = g.serialize(bytearray(), prev) - res = unpack_from(igmpv3_query._PACK_STR, str(buf)) + res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf)) buf = bytearray(buf) pack_into('!H', buf, 2, 0) buf = str(buf) @@ -410,10 +410,9 @@ class Test_igmpv3_query(unittest.TestCase): g = igmpv3_query(srcs=srcs) prev.serialize(g, None) buf = g.serialize(bytearray(), prev) - res = unpack_from(igmpv3_query._PACK_STR, str(buf)) + res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf)) buf = bytearray(buf) pack_into('!H', buf, 2, 0) - buf = str(buf) eq_(res[0], IGMP_TYPE_QUERY) eq_(res[1], 100) @@ -423,7 +422,7 @@ class Test_igmpv3_query(unittest.TestCase): eq_(res[5], 0) eq_(res[6], len(srcs)) - res = unpack_from('4s4s4s', str(buf), igmpv3_query._MIN_LEN) + res = unpack_from('4s4s4s', six.binary_type(buf), igmpv3_query._MIN_LEN) eq_(res[0], addrconv.ipv4.text_to_bin(srcs[0])) eq_(res[1], addrconv.ipv4.text_to_bin(srcs[1])) @@ -496,7 +495,7 @@ class Test_igmpv3_report(unittest.TestCase): self.test_init() def test_parser(self): - _res = self.g.parser(str(self.buf)) + _res = self.g.parser(six.binary_type(self.buf)) if type(_res) is tuple: res = _res[0] else: @@ -662,7 +661,7 @@ class Test_igmpv3_report(unittest.TestCase): g = igmpv3_report() prev.serialize(g, None) buf = g.serialize(bytearray(), prev) - res = unpack_from(igmpv3_report._PACK_STR, str(buf)) + res = unpack_from(igmpv3_report._PACK_STR, six.binary_type(buf)) buf = bytearray(buf) pack_into('!H', buf, 2, 0) buf = str(buf) @@ -687,7 +686,7 @@ class Test_igmpv3_report(unittest.TestCase): g = igmpv3_report(records=records) prev.serialize(g, None) buf = g.serialize(bytearray(), prev) - res = unpack_from(igmpv3_report._PACK_STR, str(buf)) + res = unpack_from(igmpv3_report._PACK_STR, six.binary_type(buf)) buf = bytearray(buf) pack_into('!H', buf, 2, 0) buf = str(buf) @@ -963,7 +962,7 @@ class Test_igmpv3_report_group(unittest.TestCase): def test_default_args(self): rep = igmpv3_report_group() buf = rep.serialize() - res = unpack_from(igmpv3_report_group._PACK_STR, str(buf)) + res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf)) eq_(res[0], 0) eq_(res[1], 0) @@ -974,14 +973,15 @@ class Test_igmpv3_report_group(unittest.TestCase): srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3'] rep = igmpv3_report_group(srcs=srcs) buf = rep.serialize() - res = unpack_from(igmpv3_report_group._PACK_STR, str(buf)) + res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf)) eq_(res[0], 0) eq_(res[1], 0) eq_(res[2], len(srcs)) eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0')) - res = unpack_from('4s4s4s', str(buf), igmpv3_report_group._MIN_LEN) + res = unpack_from('4s4s4s', six.binary_type(buf), + igmpv3_report_group._MIN_LEN) eq_(res[0], addrconv.ipv4.text_to_bin(srcs[0])) eq_(res[1], addrconv.ipv4.text_to_bin(srcs[1])) @@ -991,7 +991,7 @@ class Test_igmpv3_report_group(unittest.TestCase): aux = 'abcde' rep = igmpv3_report_group(aux=aux) buf = rep.serialize() - res = unpack_from(igmpv3_report_group._PACK_STR, str(buf)) + res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf)) eq_(res[0], 0) eq_(res[1], 2) diff --git a/ryu/tests/unit/packet/test_ipv4.py b/ryu/tests/unit/packet/test_ipv4.py index 38d6968c..69186f3f 100644 --- a/ryu/tests/unit/packet/test_ipv4.py +++ b/ryu/tests/unit/packet/test_ipv4.py @@ -17,6 +17,7 @@ import unittest import logging +import six import struct from struct import * from nose.tools import * @@ -107,7 +108,7 @@ class Test_ipv4(unittest.TestCase): def test_serialize(self): buf = self.ip.serialize(bytearray(), None) - res = struct.unpack_from(ipv4._PACK_STR, str(buf)) + res = struct.unpack_from(ipv4._PACK_STR, six.binary_type(buf)) option = buf[ipv4._MIN_LEN:ipv4._MIN_LEN + len(self.option)] eq_(res[0], self.ver_hlen) diff --git a/ryu/tests/unit/packet/test_sctp.py b/ryu/tests/unit/packet/test_sctp.py index 17f00b08..d7afb7cc 100644 --- a/ryu/tests/unit/packet/test_sctp.py +++ b/ryu/tests/unit/packet/test_sctp.py @@ -16,6 +16,7 @@ import inspect import logging +import six import struct import unittest @@ -588,7 +589,7 @@ class Test_sctp(unittest.TestCase): self.test_init() def test_parser(self): - _res = self.sc.parser(str(self.buf)) + _res = self.sc.parser(six.binary_type(self.buf)) if type(_res) is tuple: res = _res[0] else: