From 898a2af8cc32f6814fa3a0971ef71f4936f42171 Mon Sep 17 00:00:00 2001 From: stevenvanrossem Date: Fri, 6 May 2016 18:28:57 +0200 Subject: [PATCH] add birectional option for set Chain --- src/emuvim/api/zerorpc/network.py | 3 ++- src/emuvim/cli/network.py | 10 +++++++--- src/emuvim/dcemulator/net.py | 14 ++++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/emuvim/api/zerorpc/network.py b/src/emuvim/api/zerorpc/network.py index 78083b0..af11bc3 100644 --- a/src/emuvim/api/zerorpc/network.py +++ b/src/emuvim/api/zerorpc/network.py @@ -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.") diff --git a/src/emuvim/cli/network.py b/src/emuvim/cli/network.py index a4b0233..911c5ef 100755 --- a/src/emuvim/cli/network.py +++ b/src/emuvim/cli/network.py @@ -36,7 +36,8 @@ class ZeroRpcClient(object): vnf_dst_interface=self._parse_vnf_interface(args.get("destination")), weight=args.get("weight"), match=args.get("match"), - bidirectional=args.get("bidirectional")) + bidirectional=args.get("bidirectional"), + cookie=args.get("cookie")) # note zerorpc does not support named arguments r = self.c.network_action_start( @@ -54,7 +55,8 @@ class ZeroRpcClient(object): vnf_src_interface=self._parse_vnf_interface(args.get("source")), vnf_dst_interface=self._parse_vnf_interface(args.get("destination")), weight=args.get("weight"), - match=args.get("match")) + match=args.get("match"), + cookie=args.get("cookie")) r = self.c.network_action_stop( #args.get("datacenter"), @@ -101,7 +103,9 @@ parser.add_argument( "--bidirectional", "-b", dest="bidirectional", action='store_true', help="add/remove the flow entries in 2 directions") - +parser.add_argument( + "--cookie", "-c", dest="cookie", + help="cookie for this flow") def main(argv): args = vars(parser.parse_args(argv)) diff --git a/src/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py index 3ded28e..36fc921 100755 --- a/src/emuvim/dcemulator/net.py +++ b/src/emuvim/dcemulator/net.py @@ -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 -- 2.25.1