From 006c7cb4078b2ba6a4abdb28cdeef69bb002a5fb Mon Sep 17 00:00:00 2001 From: Simon Horman Date: Tue, 13 Mar 2012 09:06:24 +0900 Subject: Add NXActionSetTunnel and NXActionSetTunnel64 These actions allow setting of the tunnel id when a packet is transmitted over a tunnel. For example, to set a tenant-specific id when transmitting packets over a tunnel used by more than one tenant. The NXActionSetTunnel64 was added to OpenvSwtich after NXActionSetTunnel. NXActionSetTunnel64 seems to be the preferred action although GRE tunnels only support 32bit keys.t Signed-off-by: Simon Horman Signed-off-by: FUJITA Tomonori --- ryu/ofproto/ofproto_v1_0.py | 17 ++++++++++++++++ ryu/ofproto/ofproto_v1_0_parser.py | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/ryu/ofproto/ofproto_v1_0.py b/ryu/ofproto/ofproto_v1_0.py index 74ec3c8b..e666ad93 100644 --- a/ryu/ofproto/ofproto_v1_0.py +++ b/ryu/ofproto/ofproto_v1_0.py @@ -230,6 +230,23 @@ OFP_ACTION_PACK_STR = '!H' # OFP_ACTION_SIZE = 8 # assert calcsize(OFP_ACTION_PACK_STR) == OFP_ACTION_SIZE +# enum nx_action_subtype (truncated) +NXAST_SET_TUNNEL = 2 +NXAST_SET_TUNNEL64 = 9 + +NX_ACTION_SET_TUNNEL_PACK_STR = '!HHIH2xI' +NX_ACTION_SET_TUNNEL_SIZE = 16 +assert calcsize(NX_ACTION_SET_TUNNEL_PACK_STR) == NX_ACTION_SET_TUNNEL_SIZE + +NX_ACTION_SET_TUNNEL64_PACK_STR = '!HHIH6xQ' +NX_ACTION_SET_TUNNEL64_SIZE = 24 +assert calcsize(NX_ACTION_SET_TUNNEL64_PACK_STR) == NX_ACTION_SET_TUNNEL64_SIZE + +NX_ACTION_HEADER_PACK_STR = '!H' +NX_ACTION_HEADER_SIZE = 10 +assert (OFP_ACTION_VENDOR_HEADER_SIZE + + calcsize(NX_ACTION_HEADER_PACK_STR)) == NX_ACTION_HEADER_SIZE + OFP_PACKET_OUT_PACK_STR = '!IHH' OFP_PACKET_OUT_SIZE = 16 assert (calcsize(OFP_PACKET_OUT_PACK_STR) + OFP_HEADER_SIZE == diff --git a/ryu/ofproto/ofproto_v1_0_parser.py b/ryu/ofproto/ofproto_v1_0_parser.py index 629c5992..13d5688d 100644 --- a/ryu/ofproto/ofproto_v1_0_parser.py +++ b/ryu/ofproto/ofproto_v1_0_parser.py @@ -352,6 +352,46 @@ class OFPActionEnqueue(OFPAction): # TODO:XXX OFPActionVendor +# NXAction* is a partial implementatoin, only handling serilalisation +# of a subset of Nicira vendor actions + + +class NXActionHeader(object): + def __init__(self, subtype_, len_): + self.type = ofproto_v1_0.OFPAT_VENDOR + self.len = len_ + self.vendor = ofproto_v1_0.NX_VENDOR_ID + self.subtype = subtype_ + + def serialise(self, buf, offset): + msg_pack_into(ofproto_v1_0.OFP_ACTION_HEADER_PACK_STR, + buf, offset, self.type, self.len) + + +class NXActionSetTunnel(NXActionHeader): + def __init__(self, tun_id_): + self.tun_id = tun_id_ + super(NXActionSetTunnel, self).__init__( + ofproto_v1_0.NXAST_SET_TUNNEL, + ofproto_v1_0.NX_ACTION_SET_TUNNEL_SIZE) + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_0.NX_ACTION_SET_TUNNEL_PACK_STR, buf, + offset, self.type, self.len, self.vendor, self.subtype, + self.tun_id) + + +class NXActionSetTunnel64(NXActionHeader): + def __init__(self, tun_id_): + self.tun_id = tun_id_ + super(NXActionSetTunnel64, self).__init__( + ofproto_v1_0.NXAST_SET_TUNNEL64, + ofproto_v1_0.NX_ACTION_SET_TUNNEL64_SIZE) + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_0.NX_ACTION_SET_TUNNEL64_PACK_STR, buf, + offset, self.type, self.len, self.vendor, self.subtype, + self.tun_id) class OFPDescStats(collections.namedtuple('OFPDescStats', -- cgit v1.2.3