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

index e80ceef..78083b0 100644 (file)
@@ -75,7 +75,8 @@ class DCNetworkApi(object):
                 vnf_src_interface=kwargs.get('vnf_src_interface'),
                 vnf_dst_interface=kwargs.get('vnf_dst_interface'),
                 weight=kwargs.get('weight'),
-                match=kwargs.get('match'))
+                match=kwargs.get('match'),
+                bidirectional=kwargs.get('bidirectional'))
             return str(c)
         except Exception as ex:
             logging.exception("RPC error.")
@@ -93,7 +94,8 @@ class DCNetworkApi(object):
                 vnf_dst_interface=kwargs.get('vnf_dst_interface'),
                 cmd='del-flows',
                 weight=kwargs.get('weight'),
-                match=kwargs.get('match'))
+                match=kwargs.get('match'),
+                bidirectional=kwargs.get('bidirectional'))
             return c
         except Exception as ex:
             logging.exception("RPC error.")
index bf107e8..a4b0233 100755 (executable)
@@ -35,7 +35,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
+            bidirectional=args.get("bidirectional"))\r
 \r
         # note zerorpc does not support named arguments\r
         r = self.c.network_action_start(\r
@@ -96,6 +97,11 @@ parser.add_argument(
 parser.add_argument(\r
     "--match", "-m", dest="match",\r
     help="string holding extra matches for the flow entries")\r
+parser.add_argument(\r
+    "--bidirectional", "-b", dest="bidirectional",\r
+    action='store_true',\r
+    help="add/remove the flow entries in 2 directions")\r
+\r
 \r
 def main(argv):\r
     args = vars(parser.parse_args(argv))\r
index 794d50e..3ded28e 100755 (executable)
@@ -306,6 +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 ):
+                match_input = kwargs.get('match')
+                self._set_flow_entry_dpctl(current_node, switch_inport_nr, switch_outport_nr, match_input, cmd)
+                if kwargs.get('bidirectional'):
+                    self._set_flow_entry_dpctl(current_node, switch_outport_nr, switch_inport_nr, match_input, cmd)
+                '''
                 match = 'in_port=%s' % switch_inport_nr
                 #add additional match entries from the argument
                 match_input = kwargs.get('match')
@@ -326,6 +331,7 @@ class DCNetwork(Dockernet):
                 current_node.dpctl(cmd, ofcmd)
                 logging.info("add flow in switch: {0} in_port: {1} out_port: {2}".format(current_node.name, switch_inport_nr,
                                                                                      switch_outport_nr))
+                '''
             # take first link between switches by default
             if isinstance( next_node, OVSSwitch ):
                 switch_inport_nr = self.DCNetwork_graph[current_hop][next_hop][0]['dst_port_nr']
@@ -334,6 +340,28 @@ 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):
+        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))
+        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
+        else:
+            ofcmd = ''
+
+        node.dpctl(cmd, ofcmd)
+        logging.info("add flow in switch: {0} in_port: {1} out_port: {2}".format(node.name, switch_inport_nr,
+                                                                                 switch_outport_nr))
+
     # start Ryu Openflow controller as Remote Controller for the DCNetwork
     def startRyu(self):
         # start Ryu controller with rest-API