Allow send_flow_mod() to send NXTFlowMod messages in place of OFPFlowMod
messages if the match includes fields chat can't be encoded by OFPMatch

The flow format will be upgraded as necessary

Signed-off-by: Simon Horman <[email protected]>
---
 ryu/app/cbench.py            |    8 ++---
 ryu/app/simple_isolation.py  |   56 +++++++++++++++--------------------------
 ryu/app/simple_switch.py     |   17 +++++-------
 ryu/controller/controller.py |   31 +++++++++++++++-------
 4 files changed, 52 insertions(+), 60 deletions(-)

diff --git a/ryu/app/cbench.py b/ryu/app/cbench.py
index a85415d..5dc64a9 100644
--- a/ryu/app/cbench.py
+++ b/ryu/app/cbench.py
@@ -4,6 +4,7 @@
 from ryu.controller import ofp_event
 from ryu.controller.handler import MAIN_DISPATCHER
 from ryu.controller.handler import set_ev_cls
+from ryu.ofproto import nx_match
 
 
 class Cbench(object):
@@ -16,11 +17,8 @@ class Cbench(object):
         datapath = msg.datapath
         ofproto = datapath.ofproto
 
-        match = datapath.ofproto_parser.OFPMatch(ofproto.OFPFW_ALL,
-                                                 0, 0, 0, 0, 0,
-                                                 0, 0, 0, 0, 0, 0, 0)
-
+        rule = nx_match.ClsRule()
         datapath.send_flow_mod(
-            match=match, cookie=0, command=ofproto.OFPFC_ADD,
+            rule=rule, cookie=0, command=ofproto.OFPFC_ADD,
             idle_timeout=0, hard_timeout=0, priority=32768,
             flags=0, actions=None)
diff --git a/ryu/app/simple_isolation.py b/ryu/app/simple_isolation.py
index f547529..667739c 100644
--- a/ryu/app/simple_isolation.py
+++ b/ryu/app/simple_isolation.py
@@ -25,6 +25,7 @@ from ryu.controller import ofp_event
 from ryu.controller.handler import MAIN_DISPATCHER
 from ryu.controller.handler import CONFIG_DISPATCHER
 from ryu.controller.handler import set_ev_cls
+from ryu.ofproto import nx_match
 from ryu.lib.mac import haddr_to_str
 from ryu.lib import mac
 
@@ -55,16 +56,12 @@ class SimpleIsolation(object):
         #
         # install flow and then send packet
         #
-        wildcards = datapath.ofproto.OFPFW_ALL
-        wildcards &= ~(datapath.ofproto.OFPFW_IN_PORT |
-                       datapath.ofproto.OFPFW_DL_SRC |
-                       datapath.ofproto.OFPFW_DL_DST)
-        match = datapath.ofproto_parser.OFPMatch(wildcards,
-                                                 msg.in_port, src, dst,
-                                                 0, 0, 0, 0, 0, 0, 0, 0, 0)
-
+        rule = nx_match.ClsRule()
+        rule.set_in_port(msg.in_port)
+        rule.set_dl_dst(dst)
+        rule.set_dl_src(src)
         datapath.send_flow_mod(
-            match=match, cookie=0, command=datapath.ofproto.OFPFC_ADD,
+            rule=rule, cookie=0, command=datapath.ofproto.OFPFC_ADD,
             idle_timeout=0, hard_timeout=0, priority=32768,
             buffer_id=0xffffffff, out_port=datapath.ofproto.OFPP_NONE,
             flags=datapath.ofproto.OFPFF_SEND_FLOW_REM, actions=actions)
@@ -153,13 +150,9 @@ class SimpleIsolation(object):
             # We really overwrite already learned mac address.
             # So discard already installed stale flow entry which conflicts
             # new port.
-            wildcards = datapath.ofproto.OFPFW_ALL
-            wildcards &= ~datapath.ofproto.OFPFW_DL_DST
-            match = datapath.ofproto_parser.OFPMatch(wildcards,
-                                                     0, 0, src,
-                                                     0, 0, 0, 0, 0, 0, 0, 0, 0)
-
-            datapath.send_flow_mod(match=match, cookie=0,
+            rule = nx_match.ClsRule()
+            rule.set_dl_dst(src)
+            datapath.send_flow_mod(rule=rule, cookie=0,
                 command=datapath.ofproto.OFPFC_DELETE, idle_timeout=0,
                 hard_timeout=0, priority=32768, out_port=old_port)
 
@@ -281,15 +274,12 @@ class SimpleIsolation(object):
         datapath_id = datapath.id
         port_no = msg.desc.port_no
 
-        wildcards = datapath.ofproto.OFPFW_ALL
-        wildcards &= ~datapath.ofproto.OFPFW_IN_PORT
-        match = datapath.ofproto_parser.OFPMatch(wildcards, port_no, 0, 0,
-                                                 0, 0, 0, 0, 0, 0, 0, 0, 0)
-        datapath.send_flow_del(match=match, cookie=0)
+        rule = nx_match.ClsRule()
+        rule.set_in_port(port_no)
+        datapath.send_flow_del(rule=rule, cookie=0)
 
-        match = datapath.ofproto_parser.OFPMatch(
-            datapath.ofproto.OFPFW_ALL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
-        datapath.send_flow_del(match=match, cookie=0, out_port=port_no)
+        rule = nx_match.ClsRule()
+        datapath.send_flow_del(rule=rule, cookie=0, out_port=port_no)
         dps_needs_barrier.add(datapath)
 
         try:
@@ -308,17 +298,13 @@ class SimpleIsolation(object):
                 if self.mac2port.port_get(dp.id, mac_) is None:
                     continue
 
-                wildcards = dp.ofproto.OFPFW_ALL
-                wildcards &= ~dp.ofproto.OFPFW_DL_SRC
-                match = dp.ofproto_parser.OFPMatch(
-                    wildcards, 0, mac_, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
-                dp.send_flow_del(match=match, cookie=0)
-
-                wildcards = dp.ofproto.OFPFW_ALL
-                wildcards &= ~dp.ofproto.OFPFW_DL_DST
-                match = dp.ofproto_parser.OFPMatch(
-                    wildcards, 0, 0, mac_, 0, 0, 0, 0, 0, 0, 0, 0, 0)
-                dp.send_flow_del(match=match, cookie=0)
+                rule = nx_match.ClsRule()
+                rule.set_dl_src(mac_)
+                dp.send_flow_del(rule=rule, cookie=0)
+
+                rule = nx_match.ClsRule()
+                rule.set_dl_dst(mac_)
+                dp.send_flow_del(rule=rule, cookie=0)
                 dps_needs_barrier.add(dp)
 
                 self.mac2port.mac_del(dp.id, mac_)
diff --git a/ryu/app/simple_switch.py b/ryu/app/simple_switch.py
index 4d3a21b..0d3436e 100644
--- a/ryu/app/simple_switch.py
+++ b/ryu/app/simple_switch.py
@@ -19,6 +19,7 @@ from ryu.controller import mac_to_port
 from ryu.controller import ofp_event
 from ryu.controller.handler import MAIN_DISPATCHER
 from ryu.controller.handler import set_ev_cls
+from ryu.ofproto import nx_match
 from ryu.lib.mac import haddr_to_str
 
 
@@ -59,17 +60,13 @@ class SimpleSwitch(object):
         actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]
 
         if out_port != ofproto.OFPP_FLOOD:
-            wildcards = ofproto.OFPFW_ALL
-            wildcards &= ~(ofproto.OFPFW_IN_PORT |
-                           ofproto.OFPFW_DL_DST |
-                           ofproto.OFPFW_NW_TOS)
-            match = datapath.ofproto_parser.OFPMatch(
-                wildcards, msg.in_port,
-                0, dst,
-                0, 0, 0, 0, 0, 0, 0, 0, 0)
-
+            rule = nx_match.ClsRule()
+            rule.set_in_port(msg.in_port)
+            rule.set_dl_dst(dst)
+            rule.set_dl_type(nx_match.ETH_TYPE_IP)
+            rule.set_nw_dscp(0)
             datapath.send_flow_mod(
-                match=match, cookie=0, command=ofproto.OFPFC_ADD,
+                rule=rule, cookie=0, command=ofproto.OFPFC_ADD,
                 idle_timeout=0, hard_timeout=0, priority=32768,
                 flags=ofproto.OFPFF_SEND_FLOW_REM, actions=actions)
 
diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py
index 3c5dc47..04c2c14 100644
--- a/ryu/controller/controller.py
+++ b/ryu/controller/controller.py
@@ -28,6 +28,7 @@ from ryu.ofproto import ofproto_v1_0
 from ryu.ofproto import ofproto_v1_0_parser
 from ryu.ofproto import ofproto_v1_2
 from ryu.ofproto import ofproto_v1_2_parser
+from ryu.ofproto import nx_match
 
 from ryu.controller import dispatcher
 from ryu.controller import handler
@@ -200,28 +201,38 @@ class Datapath(object):
             self, buffer_id, in_port, actions, data)
         self.send_msg(packet_out)
 
-    def send_flow_mod(self, match, cookie, command, idle_timeout, hard_timeout,
+    def send_flow_mod(self, rule, cookie, command, idle_timeout, hard_timeout,
                       priority, buffer_id=0xffffffff,
                       out_port=None, flags=0, actions=None):
         if out_port is None:
             out_port = self.ofproto.OFPP_NONE
-        flow_mod = self.ofproto_parser.OFPFlowMod(
-            self, match, cookie, command, idle_timeout, hard_timeout,
-            priority, buffer_id, out_port, flags, actions)
+        flow_format = rule.flow_format()
+        assert (flow_format == ofproto_v1_0.NXFF_OPENFLOW10 or
+                flow_format == ofproto_v1_0.NXFF_NXM)
+        if self.flow_format < flow_format:
+            self.send_nxt_set_flow_format(flow_format)
+        if flow_format == ofproto_v1_0.NXFF_OPENFLOW10:
+            match_tuple = rule.match_tuple()
+            match = self.ofproto_parser.OFPMatch(*match_tuple)
+            flow_mod = self.ofproto_parser.OFPFlowMod(
+                self, match, cookie, command, idle_timeout, hard_timeout,
+                priority, buffer_id, out_port, flags, actions)
+        else:
+            flow_mod = self.ofproto_parser.NXTFlowMod(
+                self, cookie, command, idle_timeout, hard_timeout,
+                priority, buffer_id, out_port, flags, rule, actions)
         self.send_msg(flow_mod)
 
-    def send_flow_del(self, match, cookie, out_port=None):
-        self.send_flow_mod(match=match, cookie=cookie,
+    def send_flow_del(self, rule, cookie, out_port=None):
+        self.send_flow_mod(rule=rule, cookie=cookie,
                            command=self.ofproto.OFPFC_DELETE,
                            idle_timeout=0, hard_timeout=0, priority=0,
                            out_port=out_port)
 
     def send_delete_all_flows(self):
-        match = self.ofproto_parser.OFPMatch(self.ofproto.OFPFW_ALL,
-                                             0, 0, 0, 0, 0,
-                                             0, 0, 0, 0, 0, 0, 0)
+        rule = nx_match.ClsRule()
         self.send_flow_mod(
-            match=match, cookie=0, command=self.ofproto.OFPFC_DELETE,
+            rule=rule, cookie=0, command=self.ofproto.OFPFC_DELETE,
             idle_timeout=0, hard_timeout=0, priority=0, buffer_id=0,
             out_port=self.ofproto.OFPP_NONE, flags=0, actions=None)
 
-- 
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