diff options
7 files changed, 101 insertions, 50 deletions
diff --git a/ryu/ofproto/nx_actions.py b/ryu/ofproto/nx_actions.py index a442868b..14bc4796 100644 --- a/ryu/ofproto/nx_actions.py +++ b/ryu/ofproto/nx_actions.py @@ -228,11 +228,11 @@ def generate(ofp_name, ofpp_name): ] } - def __init__(self, ofs, nbits, dst, value, + def __init__(self, start, end, dst, value, type_=None, len_=None, experimenter=None, subtype=None): super(NXActionRegLoad, self).__init__() - self.ofs = ofs - self.nbits = nbits + self.start = start + self.end = end self.dst = dst self.value = value @@ -240,11 +240,11 @@ def generate(ofp_name, ofpp_name): def parser(cls, buf): (ofs_nbits, dst, value,) = struct.unpack_from( cls._fmt_str, buf, 0) - ofs = ofs_nbits >> 6 - nbits = (ofs_nbits & ((1 << 6) - 1)) + 1 + start = ofs_nbits >> 6 + end = (ofs_nbits & 0x3f) + start # Right-shift instead of using oxm_parse_header for simplicity... dst_name = ofp.oxm_to_user_header(dst >> 9) - return cls(ofs, nbits, dst_name, value) + return cls(start, end, dst_name, value) def serialize_body(self): hdr_data = bytearray() @@ -252,7 +252,7 @@ def generate(ofp_name, ofpp_name): ofp.oxm_serialize_header(n, hdr_data, 0) (dst_num,) = struct.unpack_from('!I', six.binary_type(hdr_data), 0) - ofs_nbits = (self.ofs << 6) + self.nbits - 1 + ofs_nbits = (self.start << 6) + (self.end - self.start) data = bytearray() msg_pack_into(self._fmt_str, data, 0, ofs_nbits, dst_num, self.value) @@ -432,12 +432,14 @@ def generate(ofp_name, ofpp_name): _fmt_str = '!HIH6x' def __init__(self, - ofs_nbits, + start, + end, src, max_len, type_=None, len_=None, experimenter=None, subtype=None): super(NXActionOutputReg, self).__init__() - self.ofs_nbits = ofs_nbits + self.start = start + self.end = end self.src = src self.max_len = max_len @@ -447,12 +449,16 @@ def generate(ofp_name, ofpp_name): src, max_len) = struct.unpack_from( cls._fmt_str, buf, 0) - return cls(ofs_nbits, + start = ofs_nbits >> 6 + end = (ofs_nbits & 0x3f) + start + return cls(start, + end, src, max_len) def serialize_body(self): data = bytearray() + ofs_nbits = (self.start << 6) + (self.end - self.start) msg_pack_into(self._fmt_str, data, 0, ofs_nbits, self.src, @@ -660,7 +666,8 @@ def generate(ofp_name, ofpp_name): algorithm, max_link, arg, - ofs_nbits, + start, + end, dst, type_=None, len_=None, experimenter=None, subtype=None): super(NXActionMultipath, self).__init__() @@ -669,7 +676,8 @@ def generate(ofp_name, ofpp_name): self.algorithm = algorithm self.max_link = max_link self.arg = arg - self.ofs_nbits = ofs_nbits + self.start = start + self.end = end self.dst = dst @classmethod @@ -682,15 +690,19 @@ def generate(ofp_name, ofpp_name): ofs_nbits, dst) = struct.unpack_from( cls._fmt_str, buf, 0) + start = ofs_nbits >> 6 + end = (ofs_nbits & 0x3f) + start return cls(fields, basis, algorithm, max_link, arg, - ofs_nbits, + start, + end, dst) def serialize_body(self): + ofs_nbits = (self.start << 6) + (self.end - self.start) data = bytearray() msg_pack_into(self._fmt_str, data, 0, self.fields, @@ -698,7 +710,7 @@ def generate(ofp_name, ofpp_name): self.algorithm, self.max_link, self.arg, - self.ofs_nbits, + ofs_nbits, self.dst) return data @@ -708,7 +720,7 @@ def generate(ofp_name, ofpp_name): _fmt_str = '!HHHIHHI4x' def __init__(self, algorithm, fields, basis, slave_type, n_slaves, - ofs_nbits, dst, slaves): + start, end, dst, slaves): super(_NXActionBundleBase, self).__init__() self.len = utils.round_up( nicira_ext.NX_ACTION_BUNDLE_0_SIZE + len(slaves) * 2, 8) @@ -718,7 +730,8 @@ def generate(ofp_name, ofpp_name): self.basis = basis self.slave_type = slave_type self.n_slaves = n_slaves - self.ofs_nbits = ofs_nbits + self.start = start + self.end = end self.dst = dst assert isinstance(slaves, (list, tuple)) @@ -732,6 +745,8 @@ def generate(ofp_name, ofpp_name): (algorithm, fields, basis, slave_type, n_slaves, ofs_nbits, dst) = struct.unpack_from( cls._fmt_str, buf, 0) + start = ofs_nbits >> 6 + end = (ofs_nbits & 0x3f) + start slave_offset = (nicira_ext.NX_ACTION_BUNDLE_0_SIZE - nicira_ext.NX_ACTION_HEADER_0_SIZE) @@ -742,9 +757,10 @@ def generate(ofp_name, ofpp_name): slave_offset += 2 return cls(algorithm, fields, basis, slave_type, - n_slaves, ofs_nbits, dst, slaves) + n_slaves, start, end, dst, slaves) def serialize_body(self): + ofs_nbits = (self.start << 6) + (self.end - self.start) data = bytearray() slave_offset = (nicira_ext.NX_ACTION_BUNDLE_0_SIZE - nicira_ext.NX_ACTION_HEADER_0_SIZE) @@ -761,7 +777,7 @@ def generate(ofp_name, ofpp_name): msg_pack_into(self._fmt_str, data, 0, self.algorithm, self.fields, self.basis, self.slave_type, self.n_slaves, - self.ofs_nbits, self.dst) + ofs_nbits, self.dst) return data @@ -769,25 +785,25 @@ def generate(ofp_name, ofpp_name): _subtype = nicira_ext.NXAST_BUNDLE def __init__(self, algorithm, fields, basis, slave_type, n_slaves, - ofs_nbits, dst, slaves): + start, end, dst, slaves): # NXAST_BUNDLE actions should have 'ofs_nbits' and 'dst' zeroed. super(NXActionBundle, self).__init__( algorithm, fields, basis, slave_type, n_slaves, - ofs_nbits=0, dst=0, slaves=slaves) + start=0, end=0, dst=0, slaves=slaves) class NXActionBundleLoad(_NXActionBundleBase): _subtype = nicira_ext.NXAST_BUNDLE_LOAD def __init__(self, algorithm, fields, basis, slave_type, n_slaves, - ofs_nbits, dst, slaves): + start, end, dst, slaves): super(NXActionBundleLoad, self).__init__( algorithm, fields, basis, slave_type, n_slaves, - ofs_nbits, dst, slaves) + start, end, dst, slaves) class NXActionCT(NXAction): _subtype = nicira_ext.NXAST_CT - # flags, zone_src, zone_ofs_nbits (zone_imm), recirc_table, + # flags, zone_src, zone_ofs_nbits, recirc_table, # pad, alg _fmt_str = '!HIHB3xH' # Followed by actions @@ -795,7 +811,8 @@ def generate(ofp_name, ofpp_name): def __init__(self, flags, zone_src, - zone_ofs_nbits, # is zone_imm if zone_src == 0 + zone_start, + zone_end, recirc_table, alg, actions, @@ -803,7 +820,8 @@ def generate(ofp_name, ofpp_name): super(NXActionCT, self).__init__() self.flags = flags self.zone_src = zone_src - self.zone_ofs_nbits = zone_ofs_nbits + self.zone_start = zone_start + self.zone_end = zone_end self.recirc_table = recirc_table self.alg = alg self.actions = actions @@ -816,6 +834,8 @@ def generate(ofp_name, ofpp_name): recirc_table, alg,) = struct.unpack_from( cls._fmt_str, buf, 0) + zone_start = zone_ofs_nbits >> 6 + zone_end = (zone_ofs_nbits & 0x3f) + zone_start rest = buf[struct.calcsize(cls._fmt_str):] # actions actions = [] @@ -824,15 +844,17 @@ def generate(ofp_name, ofpp_name): actions.append(action) rest = rest[action.len:] - return cls(flags, zone_src, zone_ofs_nbits, recirc_table, + return cls(flags, zone_src, zone_start, zone_end, recirc_table, alg, actions) def serialize_body(self): + zone_ofs_nbits = ((self.zone_start << 6) + + (self.zone_end - self.zone_start)) data = bytearray() msg_pack_into(self._fmt_str, data, 0, self.flags, self.zone_src, - self.zone_ofs_nbits, + zone_ofs_nbits, self.recirc_table, self.alg) for a in self.actions: diff --git a/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct.packet.json b/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct.packet.json index 258da237..473b54f1 100644 --- a/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct.packet.json +++ b/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct.packet.json @@ -21,7 +21,8 @@ "recirc_table": 4, "subtype": 35, "type": 65535, - "zone_ofs_nbits": 0, + "zone_start": 0, + "zone_end": 0, "zone_src": 0 } } diff --git a/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct_exec.packet.json b/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct_exec.packet.json index 83276442..7cecad7d 100644 --- a/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct_exec.packet.json +++ b/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct_exec.packet.json @@ -35,7 +35,8 @@ "recirc_table": 255, "subtype": 35, "type": 65535, - "zone_ofs_nbits": 0, + "zone_start": 0, + "zone_end": 0, "zone_src": 0 } } diff --git a/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct_nat.packet.json b/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct_nat.packet.json index 85aae120..b63c2267 100644 --- a/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct_nat.packet.json +++ b/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct_nat.packet.json @@ -37,7 +37,8 @@ "recirc_table": 255, "subtype": 35, "type": 65535, - "zone_ofs_nbits": 0, + "zone_start": 0, + "zone_end": 0, "zone_src": 0 } } diff --git a/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct_nat_v6.packet.json b/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct_nat_v6.packet.json index 31f94374..e50d5610 100644 --- a/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct_nat_v6.packet.json +++ b/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-action_ct_nat_v6.packet.json @@ -37,7 +37,8 @@ "recirc_table": 255, "subtype": 35, "type": 65535, - "zone_ofs_nbits": 0, + "zone_start": 0, + "zone_end": 0, "zone_src": 0 } } diff --git a/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-match_load_nx_register.packet.json b/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-match_load_nx_register.packet.json index adf14ca7..e57d11a9 100644 --- a/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-match_load_nx_register.packet.json +++ b/ryu/tests/unit/ofproto/json/of13/ovs-ofctl-of13-match_load_nx_register.packet.json @@ -16,8 +16,8 @@ "dst": "reg0", "experimenter": 8992, "len": 24, - "nbits": 28, - "ofs": 4, + "end": 31, + "start": 4, "subtype": 7, "type": 65535, "value": 233495534 diff --git a/ryu/tests/unit/ofproto/test_parser_v10.py b/ryu/tests/unit/ofproto/test_parser_v10.py index c4dd4745..5143e119 100644 --- a/ryu/tests/unit/ofproto/test_parser_v10.py +++ b/ryu/tests/unit/ofproto/test_parser_v10.py @@ -1421,6 +1421,8 @@ class TestNXActionRegLoad(unittest.TestCase): dst = {'buf': b'\x9f\x9f\x88\x26', 'val': 2678032422} value = {'buf': b'\x33\x51\xcd\x43\x25\x28\x18\x99', 'val': 3697962457317775513} + start = 246 + end = 270 buf = type_['buf'] \ + len_['buf'] \ @@ -1430,7 +1432,8 @@ class TestNXActionRegLoad(unittest.TestCase): + dst['buf'] \ + value['buf'] - c = NXActionRegLoad(ofs_nbits['val'], + c = NXActionRegLoad(start, + end, dst['val'], value['val']) @@ -1445,13 +1448,15 @@ class TestNXActionRegLoad(unittest.TestCase): eq_(self.len_['val'], self.c.len) eq_(self.vendor['val'], self.c.vendor) eq_(self.subtype['val'], self.c.subtype) - eq_(self.ofs_nbits['val'], self.c.ofs_nbits) + eq_(self.start, self.c.start) + eq_(self.end, self.c.end) eq_(self.dst['val'], self.c.dst) eq_(self.value['val'], self.c.value) def test_parser(self): res = self.c.parser(self.buf, 0) - eq_(self.ofs_nbits['val'], res.ofs_nbits) + eq_(self.start, self.c.start) + eq_(self.end, self.c.end) eq_(self.dst['val'], res.dst) eq_(self.value['val'], res.value) @@ -1547,6 +1552,8 @@ class TestNXActionMultipath(unittest.TestCase): zfill1 = b'\x00' * 2 ofs_nbits = {'buf': b'\xa9\x9a', 'val': 43418} dst = {'buf': b'\xb9\x2f\x16\x64', 'val': 3106870884} + start = 678 + end = 704 buf = type_['buf'] \ + len_['buf'] \ @@ -1567,7 +1574,8 @@ class TestNXActionMultipath(unittest.TestCase): algorithm['val'], max_link['val'], arg['val'], - ofs_nbits['val'], + start, + end, dst['val']) def setUp(self): @@ -1582,7 +1590,8 @@ class TestNXActionMultipath(unittest.TestCase): eq_(self.algorithm['val'], self.c.algorithm) eq_(self.max_link['val'], self.c.max_link) eq_(self.arg['val'], self.c.arg) - eq_(self.ofs_nbits['val'], self.c.ofs_nbits) + eq_(self.start, self.c.start) + eq_(self.end, self.c.end) eq_(self.dst['val'], self.c.dst) def test_parser(self): @@ -1593,7 +1602,8 @@ class TestNXActionMultipath(unittest.TestCase): eq_(self.algorithm['val'], res.algorithm) eq_(self.max_link['val'], res.max_link) eq_(self.arg['val'], res.arg) - eq_(self.ofs_nbits['val'], res.ofs_nbits) + eq_(self.start, res.start) + eq_(self.end, res.end) eq_(self.dst['val'], res.dst) def test_serialize(self): @@ -1634,12 +1644,14 @@ class TestNXActionBundle(unittest.TestCase): basis = {'buf': b'\xfd\x6f', 'val': 64879} slave_type = {'buf': b'\x7c\x51\x0f\xe0', 'val': 2085687264} n_slaves = {'buf': b'\x00\x02', 'val': 2} - ofs_nbits = {'buf': b'\xec\xf7', 'val': 60663} - dst = {'buf': b'\x50\x7c\x75\xfe', 'val': 1350333950} + ofs_nbits = {'buf': b'\x00\x00', 'val': 0} + dst = {'buf': b'\x00\x00\x00\x00', 'val': 0} zfill = b'\x00' * 4 slaves_buf = (b'\x00\x01', b'\x00\x02') slaves_val = (1, 2) + start = 0 + end = 0 _len = len_['val'] + len(slaves_val) * 2 _len += (_len % 8) @@ -1664,7 +1676,8 @@ class TestNXActionBundle(unittest.TestCase): basis['val'], slave_type['val'], n_slaves['val'], - ofs_nbits['val'], + start, + end, dst['val'], slaves_val) @@ -1684,7 +1697,8 @@ class TestNXActionBundle(unittest.TestCase): eq_(self.basis['val'], self.c.basis) eq_(self.slave_type['val'], self.c.slave_type) eq_(self.n_slaves['val'], self.c.n_slaves) - eq_(self.ofs_nbits['val'], self.c.ofs_nbits) + eq_(self.start, self.c.start) + eq_(self.end, self.c.end) eq_(self.dst['val'], self.c.dst) # slaves @@ -1704,7 +1718,8 @@ class TestNXActionBundle(unittest.TestCase): eq_(self.basis['val'], res.basis) eq_(self.slave_type['val'], res.slave_type) eq_(self.n_slaves['val'], res.n_slaves) - eq_(self.ofs_nbits['val'], res.ofs_nbits) + eq_(self.start, res.start) + eq_(self.end, res.end) eq_(self.dst['val'], res.dst) # slaves @@ -1756,6 +1771,8 @@ class TestNXActionBundleLoad(unittest.TestCase): ofs_nbits = {'buf': b'\xd2\x9d', 'val': 53917} dst = {'buf': b'\x37\xfe\xb3\x60', 'val': 939438944} zfill = b'\x00' * 4 + start = 842 + end = 871 slaves_buf = (b'\x00\x01', b'\x00\x02') slaves_val = (1, 2) @@ -1783,7 +1800,8 @@ class TestNXActionBundleLoad(unittest.TestCase): basis['val'], slave_type['val'], n_slaves['val'], - ofs_nbits['val'], + start, + end, dst['val'], slaves_val) @@ -1803,7 +1821,8 @@ class TestNXActionBundleLoad(unittest.TestCase): eq_(self.basis['val'], self.c.basis) eq_(self.slave_type['val'], self.c.slave_type) eq_(self.n_slaves['val'], self.c.n_slaves) - eq_(self.ofs_nbits['val'], self.c.ofs_nbits) + eq_(self.start, self.c.start) + eq_(self.end, self.c.end) eq_(self.dst['val'], self.c.dst) # slaves @@ -1823,7 +1842,8 @@ class TestNXActionBundleLoad(unittest.TestCase): eq_(self.basis['val'], res.basis) eq_(self.slave_type['val'], res.slave_type) eq_(self.n_slaves['val'], res.n_slaves) - eq_(self.ofs_nbits['val'], res.ofs_nbits) + eq_(self.start, res.start) + eq_(self.end, res.end) eq_(self.dst['val'], res.dst) # slaves @@ -1870,6 +1890,8 @@ class TestNXActionOutputReg(unittest.TestCase): src = {'buf': b'\x5e\x3a\x04\x26', 'val': 1580860454} max_len = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_OUTPUT_SIZE} zfill = b'\x00' * 6 + start = 1017 + end = 1073 buf = type_['buf'] \ + len_['buf'] \ @@ -1880,7 +1902,8 @@ class TestNXActionOutputReg(unittest.TestCase): + max_len['buf'] \ + zfill - c = NXActionOutputReg(ofs_nbits['val'], + c = NXActionOutputReg(start, + end, src['val'], max_len['val']) @@ -1895,7 +1918,8 @@ class TestNXActionOutputReg(unittest.TestCase): eq_(self.len_['val'], self.c.len) eq_(self.vendor['val'], self.c.vendor) eq_(self.subtype['val'], self.c.subtype) - eq_(self.ofs_nbits['val'], self.c.ofs_nbits) + eq_(self.start, self.c.start) + eq_(self.end, self.c.end) eq_(self.src['val'], self.c.src) eq_(self.max_len['val'], self.c.max_len) @@ -1906,7 +1930,8 @@ class TestNXActionOutputReg(unittest.TestCase): eq_(self.len_['val'], res.len) eq_(self.vendor['val'], res.vendor) eq_(self.subtype['val'], res.subtype) - eq_(self.ofs_nbits['val'], res.ofs_nbits) + eq_(self.start, self.c.start) + eq_(self.end, self.c.end) eq_(self.src['val'], res.src) eq_(self.max_len['val'], res.max_len) |