diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-06-25 06:59:49 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-06-26 09:38:14 +0900 |
commit | 9cf752cbb265c4f87c6b1c47e7e6e1675e5ee11f (patch) | |
tree | 6eda7f15efd8b1f38b697ffd4653e473e1073a0e | |
parent | ff5e007b0d7dec9e8284d6cdae3b5bb3361911d6 (diff) |
of1.2: add OXM_OF_IPV6_SRC and XM_OF_IPV6_DST
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/ofproto/ofproto_v1_2_parser.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/ryu/ofproto/ofproto_v1_2_parser.py b/ryu/ofproto/ofproto_v1_2_parser.py index 1649e0ad..c24a77c4 100644 --- a/ryu/ofproto/ofproto_v1_2_parser.py +++ b/ryu/ofproto/ofproto_v1_2_parser.py @@ -16,6 +16,7 @@ import collections import struct +import itertools from ryu.lib import mac from ofproto_parser import MsgBase, msg_pack_into, msg_str_attr @@ -936,6 +937,8 @@ class Flow(object): self.arp_tpa = 0 self.arp_sha = 0 self.arp_tha = 0 + self.ipv6_src = [] + self.ipv6_dst = [] self.mpls_lable = 0 self.mpls_tc = 0 @@ -951,6 +954,8 @@ class FlowWildcards(object): self.arp_tpa_mask = 0 self.arp_sha_mask = 0 self.arp_tha_mask = 0 + self.ipv6_src_mask = [] + self.ipv6_dst_mask = [] self.wildcards = (1 << 64) - 1 def ft_set(self, shift): @@ -1084,6 +1089,22 @@ class OFPMatch(object): self.fields.append( OFPMatchField.make(ofproto_v1_2.OXM_OF_ARP_THA)) + if self.wc.ft_test(ofproto_v1_2.OFPXMT_OFB_IPV6_SRC): + if len(self.wc.ipv6_src_mask): + self.fields.append( + OFPMatchField.make(ofproto_v1_2.OXM_OF_IPV6_SRC_W)) + else: + self.fields.append( + OFPMatchField.make(ofproto_v1_2.OXM_OF_IPV6_SRC)) + + if self.wc.ft_test(ofproto_v1_2.OFPXMT_OFB_IPV6_DST): + if len(self.wc.ipv6_dst_mask): + self.fields.append( + OFPMatchField.make(ofproto_v1_2.OXM_OF_IPV6_DST_W)) + else: + self.fields.append( + OFPMatchField.make(ofproto_v1_2.OXM_OF_IPV6_DST)) + if self.wc.ft_test(ofproto_v1_2.OFPXMT_OFB_MPLS_LABEL): self.fields.append( OFPMatchField.make(ofproto_v1_2.OXM_OF_MPLS_LABEL)) @@ -1262,6 +1283,24 @@ class OFPMatch(object): self.wc.arp_tha_mask = mask self.flow.arp_tha = mac.haddr_bitand(arp_tha, mask) + def set_ipv6_src(self, src): + self.wc.ft_set(ofproto_v1_2.OFPXMT_OFB_IPV6_SRC) + self.flow.ipv6_src = src + + def set_ipv6_src_masked(self, src, mask): + self.wc.ft_set(ofproto_v1_2.OFPXMT_OFB_IPV6_SRC) + self.wc.ipv6_src_mask = mask + self.flow.ipv6_src = [x & y for (x, y) in itertools.izip(src, mask)] + + def set_ipv6_dst(self, dst): + self.wc.ft_set(ofproto_v1_2.OFPXMT_OFB_IPV6_DST) + self.flow.ipv6_dst = dst + + def set_ipv6_dst_masked(self, dst, mask): + self.wc.ft_set(ofproto_v1_2.OFPXMT_OFB_IPV6_DST) + self.wc.ipv6_dst_mask = mask + self.flow.ipv6_dst = [x & y for (x, y) in itertools.izip(dst, mask)] + def set_mpls_label(self, mpls_label): self.wc.ft_set(ofproto_v1_2.OFPXMT_OFB_MPLS_LABEL) self.flow.mpls_label = mpls_label @@ -1319,6 +1358,17 @@ class OFPMatchField(object): self._put_header(buf, offset) self._put(buf, offset + self.length, value) + def _putv6(self, buf, offset, value): + ofproto_parser.msg_pack_into(self.pack_str, buf, offset, + *value) + self.length += self.n_bytes + + def putv6(self, buf, offset, value, mask): + self._put_header(buf, offset) + self._putv6(buf, offset + self.length, value) + if len(mask): + self._putv6(buf, offset + self.length, mask) + @OFPMatchField.register_field_header([ofproto_v1_2.OXM_OF_IN_PORT]) class MTInPort(OFPMatchField): @@ -1692,6 +1742,36 @@ class MTArpTha(OFPMatchField): return MTArpTha(header) +@OFPMatchField.register_field_header([ofproto_v1_2.OXM_OF_IPV6_SRC, + ofproto_v1_2.OXM_OF_IPV6_SRC_W]) +class MTIPv6Src(OFPMatchField): + def __init__(self, header): + super(MTIPv6Src, self).__init__(header, '!4I') + + def serialize(self, buf, offset, match): + self.putv6(buf, offset, match.flow.ipv6_src, + match.wc.ipv6_src_mask) + + @classmethod + def parser(cls, header, buf, offset): + return MTIPv6Src(header) + + +@OFPMatchField.register_field_header([ofproto_v1_2.OXM_OF_IPV6_DST, + ofproto_v1_2.OXM_OF_IPV6_DST_W]) +class MTIPv6Dst(OFPMatchField): + def __init__(self, header): + super(MTIPv6Dst, self).__init__(header, '!4I') + + def serialize(self, buf, offset, match): + self.putv6(buf, offset, match.flow.ipv6_dst, + match.wc.ipv6_dst_mask) + + @classmethod + def parser(cls, header, buf, offset): + return MTIPv6Dst(header) + + @OFPMatchField.register_field_header([ofproto_v1_2.OXM_OF_MPLS_LABEL]) class MTMplsLabel(OFPMatchField): def __init__(self, header): |