This is to handle ETH_TYPE NXM fields.
This will used when sending NXM_FLOW_MOD messages.

Signed-off-by: Simon Horman <[email protected]>
---
 ryu/ofproto/nx_match.py     |   27 ++++++++++++++++++++++++++-
 ryu/ofproto/ofproto_v1_0.py |    1 +
 2 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/ryu/ofproto/nx_match.py b/ryu/ofproto/nx_match.py
index a147e3f..cb402f1 100644
--- a/ryu/ofproto/nx_match.py
+++ b/ryu/ofproto/nx_match.py
@@ -30,10 +30,19 @@ UINT64_MAX = (1 << 64) - 1
 FWW_IN_PORT = 1 << 0
 FWW_DL_SRC = 1 << 2
 FWW_DL_DST = 1 << 3
+FWW_DL_TYPE = 1 << 4
 # No corresponding OFPFW_* bits
 FWW_ETH_MCAST = 1 << 1
 FWW_ALL = (1 << 13) - 1
 
+# Ethernet types, for set_dl_type()
+ETH_TYPE_IP = 0x0800
+ETH_TYPE_ARP = 0x0806
+ETH_TYPE_VLAN = 0x8100
+ETH_TYPE_IPV6 = 0x86dd
+ETH_TYPE_LACP = 0x8809
+
+
 MF_PACK_STRING_BE64 = '!Q'
 MF_PACK_STRING_BE16 = '!H'
 MF_PACK_STRING_MAC = '!6s'
@@ -113,6 +122,10 @@ class ClsRule(object):
         self.wc.wildcards &= ~FWW_DL_SRC
         self.flow.dl_src = dl_src
 
+    def set_dl_type(self, dl_type):
+        self.wc.wildcards &= ~FWW_DL_TYPE
+        self.flow.dl_type = dl_type
+
     def set_tun_id(self, tun_id):
         self.set_tun_id_masked(tun_id, UINT64_MAX)
 
@@ -215,6 +228,17 @@ class MFEthSrc(MFField):
 
 
 @_register_make
+@_set_nxm_headers([ofproto_v1_0.NXM_OF_ETH_TYPE])
+class MFEthType(MFField):
+    @classmethod
+    def make(cls):
+        return cls(MF_PACK_STRING_BE16)
+
+    def put(self, buf, offset, rule):
+        return self._put(buf, offset, rule.flow.dl_type)
+
+
+@_register_make
 @_set_nxm_headers([ofproto_v1_0.NXM_NX_TUN_ID, ofproto_v1_0.NXM_NX_TUN_ID_W])
 class MFTunId(MFField):
     @classmethod
@@ -235,7 +259,8 @@ def serialize_nxm_match(rule, buf, offset):
     offset += nxm_put_eth_dst(buf, offset, rule)
     if not rule.wc.wildcards & FWW_DL_SRC:
         offset += nxm_put(buf, offset, ofproto_v1_0.NXM_OF_ETH_SRC, rule)
-    # XXX: Ethernet Type
+    if not rule.wc.wildcards & FWW_DL_TYPE:
+        offset += nxm_put(buf, offset, ofproto_v1_0.NXM_OF_ETH_TYPE, rule)
 
     # XXX: 802.1Q
     # XXX: L3
diff --git a/ryu/ofproto/ofproto_v1_0.py b/ryu/ofproto/ofproto_v1_0.py
index a29e837..ad051d5 100644
--- a/ryu/ofproto/ofproto_v1_0.py
+++ b/ryu/ofproto/ofproto_v1_0.py
@@ -520,6 +520,7 @@ NXM_OF_IN_PORT = nxm_header(0x0000,  0, 2)
 NXM_OF_ETH_DST = nxm_header(0x0000,  1, 6)
 NXM_OF_ETH_DST_W = nxm_header_w(0x0000,  1, 6)
 NXM_OF_ETH_SRC = nxm_header(0x0000,  2, 6)
+NXM_OF_ETH_TYPE = nxm_header(0x0000,  3, 2)
 
 NXM_NX_TUN_ID = nxm_header(0x0001, 16, 8)
 NXM_NX_TUN_ID_W = nxm_header_w(0x0001, 16, 8)
-- 
1.7.6.3


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to