diff options
author | YAMAMOTO Takashi <yamamoto@valinux.co.jp> | 2015-01-23 11:16:19 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-25 21:50:37 +0900 |
commit | 4d06beda4fa3e87110107d34334cae2c726ec2fe (patch) | |
tree | c16e217f4f5fec99194b354dc4dab5f2c3a31f89 | |
parent | 820a7cf75cdc2540e59598cf36fea71a70080497 (diff) |
type_desc: Separate type conversion classes from oxm_fields
Will be used for NX learn implementation.
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/type_desc.py | 73 | ||||
-rw-r--r-- | ryu/ofproto/ofproto_v1_2.py | 73 | ||||
-rw-r--r-- | ryu/ofproto/ofproto_v1_3.py | 89 | ||||
-rw-r--r-- | ryu/ofproto/ofproto_v1_4.py | 87 | ||||
-rw-r--r-- | ryu/ofproto/oxm_fields.py | 62 |
5 files changed, 202 insertions, 182 deletions
diff --git a/ryu/lib/type_desc.py b/ryu/lib/type_desc.py new file mode 100644 index 00000000..c50d2e66 --- /dev/null +++ b/ryu/lib/type_desc.py @@ -0,0 +1,73 @@ +# Copyright (C) 2015 Nippon Telegraph and Telephone Corporation. +# Copyright (C) 2015 YAMAMOTO Takashi <yamamoto at valinux co jp> +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from ryu.lib import addrconv + + +class TypeDescr(object): + pass + + +class IntDescr(TypeDescr): + def __init__(self, size): + self.size = size + + def to_user(self, bin): + i = 0 + for x in xrange(self.size): + c = bin[:1] + i = i * 256 + ord(c) + bin = bin[1:] + return i + + def from_user(self, i): + bin = '' + for x in xrange(self.size): + bin = chr(i & 255) + bin + i /= 256 + return bin + +Int1 = IntDescr(1) +Int2 = IntDescr(2) +Int3 = IntDescr(3) +Int4 = IntDescr(4) +Int8 = IntDescr(8) + + +class MacAddr(TypeDescr): + size = 6 + to_user = addrconv.mac.bin_to_text + from_user = addrconv.mac.text_to_bin + + +class IPv4Addr(TypeDescr): + size = 4 + to_user = addrconv.ipv4.bin_to_text + from_user = addrconv.ipv4.text_to_bin + + +class IPv6Addr(TypeDescr): + size = 16 + to_user = addrconv.ipv6.bin_to_text + from_user = addrconv.ipv6.text_to_bin + + +class UnknownType(TypeDescr): + import base64 + + to_user = staticmethod(base64.b64encode) + from_user = staticmethod(base64.b64decode) diff --git a/ryu/ofproto/ofproto_v1_2.py b/ryu/ofproto/ofproto_v1_2.py index 0976d266..fd5f1cff 100644 --- a/ryu/ofproto/ofproto_v1_2.py +++ b/ryu/ofproto/ofproto_v1_2.py @@ -18,6 +18,7 @@ OpenFlow 1.2 definitions. """ +from ryu.lib import type_desc from ryu.ofproto import oxm_fields from struct import calcsize @@ -784,42 +785,42 @@ def oxm_tlv_header_extract_length(header): return length oxm_types = [ - oxm_fields.OpenFlowBasic('in_port', 0, oxm_fields.Int4), - oxm_fields.OpenFlowBasic('in_phy_port', 1, oxm_fields.Int4), - oxm_fields.OpenFlowBasic('metadata', 2, oxm_fields.Int8), - oxm_fields.OpenFlowBasic('eth_dst', 3, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('eth_src', 4, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('eth_type', 5, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('vlan_vid', 6, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('vlan_pcp', 7, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ip_dscp', 8, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ip_ecn', 9, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ip_proto', 10, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ipv4_src', 11, oxm_fields.IPv4Addr), - oxm_fields.OpenFlowBasic('ipv4_dst', 12, oxm_fields.IPv4Addr), - oxm_fields.OpenFlowBasic('tcp_src', 13, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('tcp_dst', 14, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('udp_src', 15, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('udp_dst', 16, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('sctp_src', 17, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('sctp_dst', 18, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('icmpv4_type', 19, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('icmpv4_code', 20, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('arp_op', 21, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('arp_spa', 22, oxm_fields.IPv4Addr), - oxm_fields.OpenFlowBasic('arp_tpa', 23, oxm_fields.IPv4Addr), - oxm_fields.OpenFlowBasic('arp_sha', 24, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('arp_tha', 25, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('ipv6_src', 26, oxm_fields.IPv6Addr), - oxm_fields.OpenFlowBasic('ipv6_dst', 27, oxm_fields.IPv6Addr), - oxm_fields.OpenFlowBasic('ipv6_flabel', 28, oxm_fields.Int4), - oxm_fields.OpenFlowBasic('icmpv6_type', 29, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('icmpv6_code', 30, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ipv6_nd_target', 31, oxm_fields.IPv6Addr), - oxm_fields.OpenFlowBasic('ipv6_nd_sll', 32, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('ipv6_nd_tll', 33, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('mpls_label', 34, oxm_fields.Int4), - oxm_fields.OpenFlowBasic('mpls_tc', 35, oxm_fields.Int1), + oxm_fields.OpenFlowBasic('in_port', 0, type_desc.Int4), + oxm_fields.OpenFlowBasic('in_phy_port', 1, type_desc.Int4), + oxm_fields.OpenFlowBasic('metadata', 2, type_desc.Int8), + oxm_fields.OpenFlowBasic('eth_dst', 3, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('eth_src', 4, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('eth_type', 5, type_desc.Int2), + oxm_fields.OpenFlowBasic('vlan_vid', 6, type_desc.Int2), + oxm_fields.OpenFlowBasic('vlan_pcp', 7, type_desc.Int1), + oxm_fields.OpenFlowBasic('ip_dscp', 8, type_desc.Int1), + oxm_fields.OpenFlowBasic('ip_ecn', 9, type_desc.Int1), + oxm_fields.OpenFlowBasic('ip_proto', 10, type_desc.Int1), + oxm_fields.OpenFlowBasic('ipv4_src', 11, type_desc.IPv4Addr), + oxm_fields.OpenFlowBasic('ipv4_dst', 12, type_desc.IPv4Addr), + oxm_fields.OpenFlowBasic('tcp_src', 13, type_desc.Int2), + oxm_fields.OpenFlowBasic('tcp_dst', 14, type_desc.Int2), + oxm_fields.OpenFlowBasic('udp_src', 15, type_desc.Int2), + oxm_fields.OpenFlowBasic('udp_dst', 16, type_desc.Int2), + oxm_fields.OpenFlowBasic('sctp_src', 17, type_desc.Int2), + oxm_fields.OpenFlowBasic('sctp_dst', 18, type_desc.Int2), + oxm_fields.OpenFlowBasic('icmpv4_type', 19, type_desc.Int1), + oxm_fields.OpenFlowBasic('icmpv4_code', 20, type_desc.Int1), + oxm_fields.OpenFlowBasic('arp_op', 21, type_desc.Int2), + oxm_fields.OpenFlowBasic('arp_spa', 22, type_desc.IPv4Addr), + oxm_fields.OpenFlowBasic('arp_tpa', 23, type_desc.IPv4Addr), + oxm_fields.OpenFlowBasic('arp_sha', 24, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('arp_tha', 25, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('ipv6_src', 26, type_desc.IPv6Addr), + oxm_fields.OpenFlowBasic('ipv6_dst', 27, type_desc.IPv6Addr), + oxm_fields.OpenFlowBasic('ipv6_flabel', 28, type_desc.Int4), + oxm_fields.OpenFlowBasic('icmpv6_type', 29, type_desc.Int1), + oxm_fields.OpenFlowBasic('icmpv6_code', 30, type_desc.Int1), + oxm_fields.OpenFlowBasic('ipv6_nd_target', 31, type_desc.IPv6Addr), + oxm_fields.OpenFlowBasic('ipv6_nd_sll', 32, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('ipv6_nd_tll', 33, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('mpls_label', 34, type_desc.Int4), + oxm_fields.OpenFlowBasic('mpls_tc', 35, type_desc.Int1), ] oxm_fields.generate(__name__) diff --git a/ryu/ofproto/ofproto_v1_3.py b/ryu/ofproto/ofproto_v1_3.py index 4a6dcfef..7535dfda 100644 --- a/ryu/ofproto/ofproto_v1_3.py +++ b/ryu/ofproto/ofproto_v1_3.py @@ -18,6 +18,7 @@ OpenFlow 1.3 definitions. """ +from ryu.lib import type_desc from ryu.ofproto import oxm_fields from struct import calcsize @@ -1136,55 +1137,55 @@ def oxm_tlv_header_extract_length(header): return length oxm_types = [ - oxm_fields.OpenFlowBasic('in_port', 0, oxm_fields.Int4), - oxm_fields.OpenFlowBasic('in_phy_port', 1, oxm_fields.Int4), - oxm_fields.OpenFlowBasic('metadata', 2, oxm_fields.Int8), - oxm_fields.OpenFlowBasic('eth_dst', 3, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('eth_src', 4, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('eth_type', 5, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('vlan_vid', 6, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('vlan_pcp', 7, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ip_dscp', 8, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ip_ecn', 9, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ip_proto', 10, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ipv4_src', 11, oxm_fields.IPv4Addr), - oxm_fields.OpenFlowBasic('ipv4_dst', 12, oxm_fields.IPv4Addr), - oxm_fields.OpenFlowBasic('tcp_src', 13, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('tcp_dst', 14, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('udp_src', 15, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('udp_dst', 16, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('sctp_src', 17, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('sctp_dst', 18, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('icmpv4_type', 19, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('icmpv4_code', 20, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('arp_op', 21, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('arp_spa', 22, oxm_fields.IPv4Addr), - oxm_fields.OpenFlowBasic('arp_tpa', 23, oxm_fields.IPv4Addr), - oxm_fields.OpenFlowBasic('arp_sha', 24, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('arp_tha', 25, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('ipv6_src', 26, oxm_fields.IPv6Addr), - oxm_fields.OpenFlowBasic('ipv6_dst', 27, oxm_fields.IPv6Addr), - oxm_fields.OpenFlowBasic('ipv6_flabel', 28, oxm_fields.Int4), - oxm_fields.OpenFlowBasic('icmpv6_type', 29, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('icmpv6_code', 30, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ipv6_nd_target', 31, oxm_fields.IPv6Addr), - oxm_fields.OpenFlowBasic('ipv6_nd_sll', 32, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('ipv6_nd_tll', 33, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('mpls_label', 34, oxm_fields.Int4), - oxm_fields.OpenFlowBasic('mpls_tc', 35, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('mpls_bos', 36, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('pbb_isid', 37, oxm_fields.Int3), - oxm_fields.OpenFlowBasic('tunnel_id', 38, oxm_fields.Int8), - oxm_fields.OpenFlowBasic('ipv6_exthdr', 39, oxm_fields.Int2), - oxm_fields.ONFExperimenter('pbb_uca', 2560, oxm_fields.Int1), - oxm_fields.NiciraExtended1('tun_ipv4_src', 31, oxm_fields.IPv4Addr), - oxm_fields.NiciraExtended1('tun_ipv4_dst', 32, oxm_fields.IPv4Addr), + oxm_fields.OpenFlowBasic('in_port', 0, type_desc.Int4), + oxm_fields.OpenFlowBasic('in_phy_port', 1, type_desc.Int4), + oxm_fields.OpenFlowBasic('metadata', 2, type_desc.Int8), + oxm_fields.OpenFlowBasic('eth_dst', 3, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('eth_src', 4, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('eth_type', 5, type_desc.Int2), + oxm_fields.OpenFlowBasic('vlan_vid', 6, type_desc.Int2), + oxm_fields.OpenFlowBasic('vlan_pcp', 7, type_desc.Int1), + oxm_fields.OpenFlowBasic('ip_dscp', 8, type_desc.Int1), + oxm_fields.OpenFlowBasic('ip_ecn', 9, type_desc.Int1), + oxm_fields.OpenFlowBasic('ip_proto', 10, type_desc.Int1), + oxm_fields.OpenFlowBasic('ipv4_src', 11, type_desc.IPv4Addr), + oxm_fields.OpenFlowBasic('ipv4_dst', 12, type_desc.IPv4Addr), + oxm_fields.OpenFlowBasic('tcp_src', 13, type_desc.Int2), + oxm_fields.OpenFlowBasic('tcp_dst', 14, type_desc.Int2), + oxm_fields.OpenFlowBasic('udp_src', 15, type_desc.Int2), + oxm_fields.OpenFlowBasic('udp_dst', 16, type_desc.Int2), + oxm_fields.OpenFlowBasic('sctp_src', 17, type_desc.Int2), + oxm_fields.OpenFlowBasic('sctp_dst', 18, type_desc.Int2), + oxm_fields.OpenFlowBasic('icmpv4_type', 19, type_desc.Int1), + oxm_fields.OpenFlowBasic('icmpv4_code', 20, type_desc.Int1), + oxm_fields.OpenFlowBasic('arp_op', 21, type_desc.Int2), + oxm_fields.OpenFlowBasic('arp_spa', 22, type_desc.IPv4Addr), + oxm_fields.OpenFlowBasic('arp_tpa', 23, type_desc.IPv4Addr), + oxm_fields.OpenFlowBasic('arp_sha', 24, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('arp_tha', 25, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('ipv6_src', 26, type_desc.IPv6Addr), + oxm_fields.OpenFlowBasic('ipv6_dst', 27, type_desc.IPv6Addr), + oxm_fields.OpenFlowBasic('ipv6_flabel', 28, type_desc.Int4), + oxm_fields.OpenFlowBasic('icmpv6_type', 29, type_desc.Int1), + oxm_fields.OpenFlowBasic('icmpv6_code', 30, type_desc.Int1), + oxm_fields.OpenFlowBasic('ipv6_nd_target', 31, type_desc.IPv6Addr), + oxm_fields.OpenFlowBasic('ipv6_nd_sll', 32, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('ipv6_nd_tll', 33, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('mpls_label', 34, type_desc.Int4), + oxm_fields.OpenFlowBasic('mpls_tc', 35, type_desc.Int1), + oxm_fields.OpenFlowBasic('mpls_bos', 36, type_desc.Int1), + oxm_fields.OpenFlowBasic('pbb_isid', 37, type_desc.Int3), + oxm_fields.OpenFlowBasic('tunnel_id', 38, type_desc.Int8), + oxm_fields.OpenFlowBasic('ipv6_exthdr', 39, type_desc.Int2), + oxm_fields.ONFExperimenter('pbb_uca', 2560, type_desc.Int1), + oxm_fields.NiciraExtended1('tun_ipv4_src', 31, type_desc.IPv4Addr), + oxm_fields.NiciraExtended1('tun_ipv4_dst', 32, type_desc.IPv4Addr), # The following definition is merely for testing 64-bit experimenter OXMs. # Following Open vSwitch, we use dp_hash for this purpose. # Prefix the name with '_' to indicate this is not intended to be used # in wild. - oxm_fields.NiciraExperimenter('_dp_hash', 0, oxm_fields.Int4), + oxm_fields.NiciraExperimenter('_dp_hash', 0, type_desc.Int4), ] oxm_fields.generate(__name__) diff --git a/ryu/ofproto/ofproto_v1_4.py b/ryu/ofproto/ofproto_v1_4.py index 0198c6e3..bb045d8e 100644 --- a/ryu/ofproto/ofproto_v1_4.py +++ b/ryu/ofproto/ofproto_v1_4.py @@ -18,6 +18,7 @@ OpenFlow 1.4 definitions. """ +from ryu.lib import type_desc from ryu.ofproto import oxm_fields from struct import calcsize @@ -347,49 +348,49 @@ def oxm_tlv_header_extract_length(header): return length oxm_types = [ - oxm_fields.OpenFlowBasic('in_port', 0, oxm_fields.Int4), - oxm_fields.OpenFlowBasic('in_phy_port', 1, oxm_fields.Int4), - oxm_fields.OpenFlowBasic('metadata', 2, oxm_fields.Int8), - oxm_fields.OpenFlowBasic('eth_dst', 3, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('eth_src', 4, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('eth_type', 5, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('vlan_vid', 6, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('vlan_pcp', 7, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ip_dscp', 8, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ip_ecn', 9, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ip_proto', 10, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ipv4_src', 11, oxm_fields.IPv4Addr), - oxm_fields.OpenFlowBasic('ipv4_dst', 12, oxm_fields.IPv4Addr), - oxm_fields.OpenFlowBasic('tcp_src', 13, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('tcp_dst', 14, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('udp_src', 15, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('udp_dst', 16, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('sctp_src', 17, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('sctp_dst', 18, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('icmpv4_type', 19, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('icmpv4_code', 20, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('arp_op', 21, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('arp_spa', 22, oxm_fields.IPv4Addr), - oxm_fields.OpenFlowBasic('arp_tpa', 23, oxm_fields.IPv4Addr), - oxm_fields.OpenFlowBasic('arp_sha', 24, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('arp_tha', 25, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('ipv6_src', 26, oxm_fields.IPv6Addr), - oxm_fields.OpenFlowBasic('ipv6_dst', 27, oxm_fields.IPv6Addr), - oxm_fields.OpenFlowBasic('ipv6_flabel', 28, oxm_fields.Int4), - oxm_fields.OpenFlowBasic('icmpv6_type', 29, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('icmpv6_code', 30, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('ipv6_nd_target', 31, oxm_fields.IPv6Addr), - oxm_fields.OpenFlowBasic('ipv6_nd_sll', 32, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('ipv6_nd_tll', 33, oxm_fields.MacAddr), - oxm_fields.OpenFlowBasic('mpls_label', 34, oxm_fields.Int4), - oxm_fields.OpenFlowBasic('mpls_tc', 35, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('mpls_bos', 36, oxm_fields.Int1), - oxm_fields.OpenFlowBasic('pbb_isid', 37, oxm_fields.Int3), - oxm_fields.OpenFlowBasic('tunnel_id', 38, oxm_fields.Int8), - oxm_fields.OpenFlowBasic('ipv6_exthdr', 39, oxm_fields.Int2), - oxm_fields.OpenFlowBasic('pbb_uca', 41, oxm_fields.Int1), - oxm_fields.NiciraExtended1('tun_ipv4_src', 31, oxm_fields.IPv4Addr), - oxm_fields.NiciraExtended1('tun_ipv4_dst', 32, oxm_fields.IPv4Addr), + oxm_fields.OpenFlowBasic('in_port', 0, type_desc.Int4), + oxm_fields.OpenFlowBasic('in_phy_port', 1, type_desc.Int4), + oxm_fields.OpenFlowBasic('metadata', 2, type_desc.Int8), + oxm_fields.OpenFlowBasic('eth_dst', 3, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('eth_src', 4, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('eth_type', 5, type_desc.Int2), + oxm_fields.OpenFlowBasic('vlan_vid', 6, type_desc.Int2), + oxm_fields.OpenFlowBasic('vlan_pcp', 7, type_desc.Int1), + oxm_fields.OpenFlowBasic('ip_dscp', 8, type_desc.Int1), + oxm_fields.OpenFlowBasic('ip_ecn', 9, type_desc.Int1), + oxm_fields.OpenFlowBasic('ip_proto', 10, type_desc.Int1), + oxm_fields.OpenFlowBasic('ipv4_src', 11, type_desc.IPv4Addr), + oxm_fields.OpenFlowBasic('ipv4_dst', 12, type_desc.IPv4Addr), + oxm_fields.OpenFlowBasic('tcp_src', 13, type_desc.Int2), + oxm_fields.OpenFlowBasic('tcp_dst', 14, type_desc.Int2), + oxm_fields.OpenFlowBasic('udp_src', 15, type_desc.Int2), + oxm_fields.OpenFlowBasic('udp_dst', 16, type_desc.Int2), + oxm_fields.OpenFlowBasic('sctp_src', 17, type_desc.Int2), + oxm_fields.OpenFlowBasic('sctp_dst', 18, type_desc.Int2), + oxm_fields.OpenFlowBasic('icmpv4_type', 19, type_desc.Int1), + oxm_fields.OpenFlowBasic('icmpv4_code', 20, type_desc.Int1), + oxm_fields.OpenFlowBasic('arp_op', 21, type_desc.Int2), + oxm_fields.OpenFlowBasic('arp_spa', 22, type_desc.IPv4Addr), + oxm_fields.OpenFlowBasic('arp_tpa', 23, type_desc.IPv4Addr), + oxm_fields.OpenFlowBasic('arp_sha', 24, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('arp_tha', 25, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('ipv6_src', 26, type_desc.IPv6Addr), + oxm_fields.OpenFlowBasic('ipv6_dst', 27, type_desc.IPv6Addr), + oxm_fields.OpenFlowBasic('ipv6_flabel', 28, type_desc.Int4), + oxm_fields.OpenFlowBasic('icmpv6_type', 29, type_desc.Int1), + oxm_fields.OpenFlowBasic('icmpv6_code', 30, type_desc.Int1), + oxm_fields.OpenFlowBasic('ipv6_nd_target', 31, type_desc.IPv6Addr), + oxm_fields.OpenFlowBasic('ipv6_nd_sll', 32, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('ipv6_nd_tll', 33, type_desc.MacAddr), + oxm_fields.OpenFlowBasic('mpls_label', 34, type_desc.Int4), + oxm_fields.OpenFlowBasic('mpls_tc', 35, type_desc.Int1), + oxm_fields.OpenFlowBasic('mpls_bos', 36, type_desc.Int1), + oxm_fields.OpenFlowBasic('pbb_isid', 37, type_desc.Int3), + oxm_fields.OpenFlowBasic('tunnel_id', 38, type_desc.Int8), + oxm_fields.OpenFlowBasic('ipv6_exthdr', 39, type_desc.Int2), + oxm_fields.OpenFlowBasic('pbb_uca', 41, type_desc.Int1), + oxm_fields.NiciraExtended1('tun_ipv4_src', 31, type_desc.IPv4Addr), + oxm_fields.NiciraExtended1('tun_ipv4_dst', 32, type_desc.IPv4Addr), ] oxm_fields.generate(__name__) diff --git a/ryu/ofproto/oxm_fields.py b/ryu/ofproto/oxm_fields.py index 0004f86b..13e45eb6 100644 --- a/ryu/ofproto/oxm_fields.py +++ b/ryu/ofproto/oxm_fields.py @@ -54,63 +54,7 @@ import itertools import struct import ofproto_common from ofproto_parser import msg_pack_into - -from ryu.lib import addrconv - - -class TypeDescr(object): - pass - - -class IntDescr(TypeDescr): - def __init__(self, size): - self.size = size - - def to_user(self, bin): - i = 0 - for x in xrange(self.size): - c = bin[:1] - i = i * 256 + ord(c) - bin = bin[1:] - return i - - def from_user(self, i): - bin = '' - for x in xrange(self.size): - bin = chr(i & 255) + bin - i /= 256 - return bin - -Int1 = IntDescr(1) -Int2 = IntDescr(2) -Int3 = IntDescr(3) -Int4 = IntDescr(4) -Int8 = IntDescr(8) - - -class MacAddr(TypeDescr): - size = 6 - to_user = addrconv.mac.bin_to_text - from_user = addrconv.mac.text_to_bin - - -class IPv4Addr(TypeDescr): - size = 4 - to_user = addrconv.ipv4.bin_to_text - from_user = addrconv.ipv4.text_to_bin - - -class IPv6Addr(TypeDescr): - size = 16 - to_user = addrconv.ipv6.bin_to_text - from_user = addrconv.ipv6.text_to_bin - - -class UnknownType(TypeDescr): - import base64 - - to_user = staticmethod(base64.b64encode) - from_user = staticmethod(base64.b64decode) +from ryu.lib import type_desc OFPXMC_NXM_0 = 0 # Nicira Extended Match (NXM_OF_) @@ -219,7 +163,7 @@ def _get_field_info_by_name(name_to_field, name): t = f.type num = f.num except KeyError: - t = UnknownType + t = type_desc.UnknownType if name.startswith('field_'): num = int(name.split('_')[1]) else: @@ -254,7 +198,7 @@ def _get_field_info_by_number(num_to_field, n): t = f.type name = f.name except KeyError: - t = UnknownType + t = type_desc.UnknownType name = 'field_%d' % (n,) return name, t |