Will be used for NX learn implementation.

Signed-off-by: YAMAMOTO Takashi <[email protected]>
---
 ryu/lib/type_desc.py        | 73 +++++++++++++++++++++++++++++++++++++
 ryu/ofproto/ofproto_v1_2.py | 73 +++++++++++++++++++------------------
 ryu/ofproto/ofproto_v1_3.py | 89 +++++++++++++++++++++++----------------------
 ryu/ofproto/ofproto_v1_4.py | 87 ++++++++++++++++++++++----------------------
 ryu/ofproto/oxm_fields.py   | 62 ++-----------------------------
 5 files changed, 202 insertions(+), 182 deletions(-)
 create mode 100644 ryu/lib/type_desc.py

diff --git a/ryu/lib/type_desc.py b/ryu/lib/type_desc.py
new file mode 100644
index 0000000..c50d2e6
--- /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 0976d26..fd5f1cf 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 4a6dcfe..7535dfd 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 0198c6e..bb045d8 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 0004f86..13e45eb 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
 
-- 
2.1.0


------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to