From 0599edf75394a2118d53c1eaa420b54a4fbe2c74 Mon Sep 17 00:00:00 2001 From: IWAMOTO Toshihiro Date: Thu, 12 Nov 2015 15:53:31 +0900 Subject: [PATCH] Implement NXActionCT and related ct_* matches These are a Nicira extension for conntrack. Signed-off-by: IWAMOTO Toshihiro Signed-off-by: FUJITA Tomonori --- ryu/lib/type_desc.py | 1 + ryu/ofproto/nicira_ext.py | 1 + ryu/ofproto/nx_actions.py | 63 +++++++++++++++++++++++++++++++++++++++ ryu/ofproto/nx_match.py | 4 +++ 4 files changed, 69 insertions(+) diff --git a/ryu/lib/type_desc.py b/ryu/lib/type_desc.py index d96fc51f..3f158fc2 100644 --- a/ryu/lib/type_desc.py +++ b/ryu/lib/type_desc.py @@ -48,6 +48,7 @@ Int2 = IntDescr(2) Int3 = IntDescr(3) Int4 = IntDescr(4) Int8 = IntDescr(8) +Int16 = IntDescr(16) def _split_str(s, n): diff --git a/ryu/ofproto/nicira_ext.py b/ryu/ofproto/nicira_ext.py index f96c8876..ef7716ba 100644 --- a/ryu/ofproto/nicira_ext.py +++ b/ryu/ofproto/nicira_ext.py @@ -43,6 +43,7 @@ NXAST_DEC_TTL = 18 NXAST_FIN_TIMEOUT = 19 NXAST_CONTROLLER = 20 NXAST_CONJUNCTION = 34 +NXAST_CT = 35 NX_ACTION_RESUBMIT_PACK_STR = '!HHIHHB3x' NX_ACTION_RESUBMIT_SIZE = 16 diff --git a/ryu/ofproto/nx_actions.py b/ryu/ofproto/nx_actions.py index cc9c3f8e..2eba31b6 100644 --- a/ryu/ofproto/nx_actions.py +++ b/ryu/ofproto/nx_actions.py @@ -415,6 +415,68 @@ def generate(ofp_name, ofpp_name): msg_pack_into('!%ds' % len(data), buf, offset + payload_offset, bytes(data)) + class NXActionCT(NXAction): + _subtype = nicira_ext.NXAST_CT + + # flags, zone_src, zone_ofs_nbits (zone_imm), recirc_table, + # pad, alg + _fmt_str = '!HIHB3xH' + # Followed by actions + + def __init__(self, + flags, + zone_src, + zone_ofs_nbits, # is zone_imm if zone_src == 0 + recirc_table, + alg, + actions, + type_=None, len_=None, experimenter=None, subtype=None): + super(NXActionCT, self).__init__() + self.flags = flags + self.zone_src = zone_src + self.zone_ofs_nbits = zone_ofs_nbits + self.recirc_table = recirc_table + self.alg = alg + self.actions = actions + + @classmethod + def parse(cls, buf): + (flags, + zone_src, + zone_ofs_nbits, + recirc_table, + alg,) = struct.unpack_from( + NXActionCT._fmt_str, buf, 0) + rest = buf[struct.calcsize(NXActionCT._fmt_str):] + # actions + actions = [] + while len(rest) > 0: + action = ofpp.OFPAction.parser(rest, 0) + actions.append(action) + rest = rest[action.len:] + + return cls(flags, zone_src, zone_ofs_nbits, recirc_table, + alg, actions) + + def serialize(self, buf, offset): + data = bytearray() + msg_pack_into(NXActionCT._fmt_str, data, 0, + self.flags, + self.zone_src, + self.zone_ofs_nbits, + self.recirc_table, + self.alg) + for a in self.actions: + a.serialize(data, len(data)) + payload_offset = ( + ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE + + struct.calcsize(NXAction._fmt_str) + ) + self.len = utils.round_up(payload_offset + len(data), 8) + super(NXActionCT, self).serialize(buf, offset) + msg_pack_into('!%ds' % len(data), buf, offset + payload_offset, + bytes(data)) + def add_attr(k, v): v.__module__ = ofpp.__name__ # Necessary for stringify stuff setattr(ofpp, k, v) @@ -427,6 +489,7 @@ def generate(ofp_name, ofpp_name): 'NXActionLearn', 'NXActionConjunction', 'NXActionResubmitTable', + 'NXActionCT', '_NXFlowSpec', # exported for testing 'NXFlowSpecMatch', 'NXFlowSpecLoad', diff --git a/ryu/ofproto/nx_match.py b/ryu/ofproto/nx_match.py index b48888d9..ca4b270a 100644 --- a/ryu/ofproto/nx_match.py +++ b/ryu/ofproto/nx_match.py @@ -1202,6 +1202,10 @@ oxm_types = [ oxm_fields.NiciraExtended1('tun_ipv4_dst', 32, type_desc.IPv4Addr), oxm_fields.NiciraExtended1('pkt_mark', 33, type_desc.Int4), oxm_fields.NiciraExtended1('conj_id', 37, type_desc.Int4), + oxm_fields.NiciraExtended1('ct_state', 105, type_desc.Int4), + oxm_fields.NiciraExtended1('ct_zone', 106, type_desc.Int2), + oxm_fields.NiciraExtended1('ct_mark', 107, type_desc.Int4), + oxm_fields.NiciraExtended1('ct_label', 108, type_desc.Int16), # The following definition is merely for testing 64-bit experimenter OXMs. # Following Open vSwitch, we use dp_hash for this purpose.