Oh, yeah, probably I should not put _NX_ACTION_SUBTYPES to NXActionHeader class.
On Tue, 8 May 2012 08:31:02 +0900 FUJITA Tomonori <[email protected]> wrote: > Only NXActionSetTunell is supported for now > > Signed-off-by: FUJITA Tomonori <[email protected]> > --- > ryu/ofproto/ofproto_v1_0.py | 5 +-- > ryu/ofproto/ofproto_v1_0_parser.py | 50 > +++++++++++++++++++++++++++++++++--- > 2 files changed, 48 insertions(+), 7 deletions(-) > > diff --git a/ryu/ofproto/ofproto_v1_0.py b/ryu/ofproto/ofproto_v1_0.py > index 43e4116..2f5f649 100644 > --- a/ryu/ofproto/ofproto_v1_0.py > +++ b/ryu/ofproto/ofproto_v1_0.py > @@ -254,10 +254,9 @@ NX_ACTION_MULTIPATH_PACK_STR = '!HHIHHH2xHHI2xHI' > NX_ACTION_MULTIPATH_SIZE = 32 > assert calcsize(NX_ACTION_MULTIPATH_PACK_STR) == NX_ACTION_MULTIPATH_SIZE > > -NX_ACTION_HEADER_PACK_STR = '!H' > +NX_ACTION_HEADER_PACK_STR = '!HHIH' > NX_ACTION_HEADER_SIZE = 10 > -assert (OFP_ACTION_VENDOR_HEADER_SIZE + > - calcsize(NX_ACTION_HEADER_PACK_STR)) == NX_ACTION_HEADER_SIZE > +assert calcsize(NX_ACTION_HEADER_PACK_STR) == NX_ACTION_HEADER_SIZE > > OFP_PACKET_OUT_PACK_STR = '!IHH' > OFP_PACKET_OUT_SIZE = 16 > diff --git a/ryu/ofproto/ofproto_v1_0_parser.py > b/ryu/ofproto/ofproto_v1_0_parser.py > index d1bdee3..e1921cd 100644 > --- a/ryu/ofproto/ofproto_v1_0_parser.py > +++ b/ryu/ofproto/ofproto_v1_0_parser.py > @@ -367,12 +367,41 @@ class OFPActionEnqueue(OFPAction): > self.type, self.len, self.port, self.queue_id) > > > -# TODO:XXX OFPActionVendor > -# NXAction* is a partial implementatoin, only handling serilalisation > -# of a subset of Nicira vendor actions > [email protected]_action_type(ofproto_v1_0.OFPAT_VENDOR, 0) > +class OFPActionVendor(OFPAction): > + _ACTION_VENDORS = {} > > + @staticmethod > + def register_action_vendor(vendor): > + def _register_action_vendor(cls): > + cls.cls_vendor = vendor > + OFPActionVendor._ACTION_VENDORS[cls.cls_vendor] = cls > + return cls > + return _register_action_vendor > + > + def __init__(self, vendor): > + super(OFPActionVendor, self).__init__() > + self.vendor = vendor > + > + @classmethod > + def parser(cls, buf, offset): > + type_, len_, vendor = struct.unpack_from( > + ofproto_v1_0.OFP_ACTION_VENDOR_HEADER_PACK_STR, buf, offset) > + cls_ = cls._ACTION_VENDORS.get(vendor) > + return cls_.parser(buf, offset) > > [email protected]_action_vendor(ofproto_v1_0.NX_VENDOR_ID) > class NXActionHeader(object): > + _NX_ACTION_SUBTYPES = {} > + > + @staticmethod > + def register_nx_action_subtype(subtype): > + def _register_nx_action_subtype(cls): > + cls.cls_subtype = subtype > + NXActionHeader._NX_ACTION_SUBTYPES[cls.cls_subtype] = cls > + return cls > + return _register_nx_action_subtype > + > def __init__(self, subtype_, len_): > self.type = ofproto_v1_0.OFPAT_VENDOR > self.len = len_ > @@ -383,6 +412,12 @@ class NXActionHeader(object): > msg_pack_into(ofproto_v1_0.OFP_ACTION_HEADER_PACK_STR, > buf, offset, self.type, self.len) > > + @classmethod > + def parser(cls, buf, offset): > + type_, len_, vendor, subtype = struct.unpack_from( > + ofproto_v1_0.NX_ACTION_HEADER_PACK_STR, buf, offset) > + cls_ = cls._NX_ACTION_SUBTYPES.get(subtype) > + return cls_.parser(buf, offset) > > class NXActionResubmitBase(NXActionHeader): > def __init__(self, subtype, in_port, table): > @@ -411,6 +446,7 @@ class NXActionResubmitTable(NXActionResubmitBase): > ofproto_v1_0.NXAST_RESUBMIT_TABLE, in_port, table) > > > [email protected]_nx_action_subtype(ofproto_v1_0.NXAST_SET_TUNNEL) > class NXActionSetTunnel(NXActionHeader): > def __init__(self, tun_id_): > self.tun_id = tun_id_ > @@ -423,6 +459,12 @@ class NXActionSetTunnel(NXActionHeader): > offset, self.type, self.len, self.vendor, self.subtype, > self.tun_id) > > + @classmethod > + def parser(cls, buf, offset): > + type_, len_, vendor, subtype, tun_id = struct.unpack_from( > + ofproto_v1_0.NX_ACTION_SET_TUNNEL_PACK_STR, buf, offset) > + return cls(tun_id) > + > > class NXActionSetTunnel64(NXActionHeader): > def __init__(self, tun_id_): > @@ -510,7 +552,7 @@ class OFPFlowStats(object): > while length < flow_stats.length: > action = OFPAction.parser(buf, offset) > flow_stats.actions.append(action) > - > + > offset += action.len > length += action.len > > -- > 1.7.4.4 > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Ryu-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/ryu-devel ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
