add birectional option for set Chain
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Fri, 6 May 2016 16:28:57 +0000 (18:28 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Fri, 6 May 2016 16:28:57 +0000 (18:28 +0200)
src/emuvim/api/zerorpc/network.py
src/emuvim/cli/network.py
src/emuvim/dcemulator/net.py

index 78083b0..af11bc3 100644 (file)
@@ -76,7 +76,8 @@ class DCNetworkApi(object):
                 vnf_dst_interface=kwargs.get('vnf_dst_interface'),
                 weight=kwargs.get('weight'),
                 match=kwargs.get('match'),
-                bidirectional=kwargs.get('bidirectional'))
+                bidirectional=kwargs.get('bidirectional'),
+                cookie=kwargs.get('cookie'))
             return str(c)
         except Exception as ex:
             logging.exception("RPC error.")
index a4b0233..911c5ef 100755 (executable)
@@ -36,7 +36,8 @@ class ZeroRpcClient(object):
             vnf_dst_interface=self._parse_vnf_interface(args.get("destination")),\r
             weight=args.get("weight"),\r
             match=args.get("match"),\r
-            bidirectional=args.get("bidirectional"))\r
+            bidirectional=args.get("bidirectional"),\r
+            cookie=args.get("cookie"))\r
 \r
         # note zerorpc does not support named arguments\r
         r = self.c.network_action_start(\r
@@ -54,7 +55,8 @@ class ZeroRpcClient(object):
             vnf_src_interface=self._parse_vnf_interface(args.get("source")),\r
             vnf_dst_interface=self._parse_vnf_interface(args.get("destination")),\r
             weight=args.get("weight"),\r
-            match=args.get("match"))\r
+            match=args.get("match"),\r
+            cookie=args.get("cookie"))\r
 \r
         r = self.c.network_action_stop(\r
             #args.get("datacenter"),\r
@@ -101,7 +103,9 @@ parser.add_argument(
     "--bidirectional", "-b", dest="bidirectional",\r
     action='store_true',\r
     help="add/remove the flow entries in 2 directions")\r
-\r
+parser.add_argument(\r
+    "--cookie", "-c", dest="cookie",\r
+    help="cookie for this flow")\r
 \r
 def main(argv):\r
     args = vars(parser.parse_args(argv))\r
index 3ded28e..36fc921 100755 (executable)
@@ -306,10 +306,11 @@ class DCNetwork(Dockernet):
             # TODO this only sets port in to out, no match, so this will give trouble when multiple services are deployed...
             # TODO need multiple matches to do this (VLAN tags)
             if isinstance( current_node, OVSSwitch ):
+                cookie = kwargs.get('cookie')
                 match_input = kwargs.get('match')
-                self._set_flow_entry_dpctl(current_node, switch_inport_nr, switch_outport_nr, match_input, cmd)
+                self._set_flow_entry_dpctl(current_node, switch_inport_nr, switch_outport_nr, match_input, cmd, cookie)
                 if kwargs.get('bidirectional'):
-                    self._set_flow_entry_dpctl(current_node, switch_outport_nr, switch_inport_nr, match_input, cmd)
+                    self._set_flow_entry_dpctl(current_node, switch_outport_nr, switch_inport_nr, match_input, cmd, cookie)
                 '''
                 match = 'in_port=%s' % switch_inport_nr
                 #add additional match entries from the argument
@@ -340,18 +341,19 @@ class DCNetwork(Dockernet):
         return "path added between {0} and {1}".format(vnf_src_name, vnf_dst_name)
         #return "destination node: {0} not reached".format(vnf_dst_name)
 
-    def _set_flow_entry_dpctl(self, node, switch_inport_nr, switch_outport_nr, match_input, cmd):
+    def _set_flow_entry_dpctl(self, node, switch_inport_nr, switch_outport_nr, match_input, cmd, cookie):
         match = 'in_port=%s' % switch_inport_nr
         # add additional match entries from the argument
         #match_input = kwargs.get('match')
         # logging.info('match input:{0}'.format(match_input))
+        s = ','
+        if cookie:
+            cookie = 'cookie=%s' % cookie
+            match = s.join([cookie, match])
         if match_input:
-            s = ','
             match = s.join([match, match_input])
-
         if cmd == 'add-flow':
             action = 'action=%s' % switch_outport_nr
-            s = ','
             ofcmd = s.join([match, action])
         elif cmd == 'del-flows':
             ofcmd = match