From a1e59c710ed694b97cb4aed76af6e8ee34a7bfbe Mon Sep 17 00:00:00 2001 From: stevenvanrossem Date: Fri, 6 May 2016 14:32:39 +0200 Subject: [PATCH] extra match field for SDN chaining commands --- src/emuvim/api/zerorpc/network.py | 9 +++++---- src/emuvim/cli/network.py | 23 ++++++++++++++++------- src/emuvim/dcemulator/net.py | 9 ++++++++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/emuvim/api/zerorpc/network.py b/src/emuvim/api/zerorpc/network.py index b1e5d41..e5d5ca0 100644 --- a/src/emuvim/api/zerorpc/network.py +++ b/src/emuvim/api/zerorpc/network.py @@ -64,7 +64,7 @@ class DCNetworkApi(object): def __init__(self, net): self.net = net - def network_action_start(self, vnf_src_name, vnf_dst_name, vnf_src_interface=None, vnf_dst_interface=None, weight=None): + def network_action_start(self, vnf_src_name, vnf_dst_name, kwargs): # call DCNetwork method, not really datacenter specific API for now... # provided dc name needs to be part of API endpoint # no check if vnfs are really connected to this datacenter... @@ -72,9 +72,10 @@ class DCNetworkApi(object): try: c = self.net.setChain( vnf_src_name, vnf_dst_name, - vnf_src_interface=vnf_src_interface, - vnf_dst_interface=vnf_dst_interface, - weight=weight) + vnf_src_interface=kwargs.get('vnf_src_interface'), + vnf_dst_interface=kwargs.get('vnf_dst_interface'), + weight=kwargs.get('weight'), + match=kwargs.get('match')) 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 c524226..5fa9993 100755 --- a/src/emuvim/cli/network.py +++ b/src/emuvim/cli/network.py @@ -29,18 +29,20 @@ class ZeroRpcClient(object): def add(self, args): vnf_src_name = self._parse_vnf_name(args.get("source")) - vnf_src_interface = self._parse_vnf_interface(args.get("source")) vnf_dst_name = self._parse_vnf_name(args.get("destination")) - vnf_dst_interface = self._parse_vnf_interface(args.get("destination")) - weight = args.get("weight") + + params = self._create_dict( + 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")) + # note zerorpc does not support named arguments r = self.c.network_action_start( #args.get("datacenter"), vnf_src_name, vnf_dst_name, - vnf_src_interface, - vnf_dst_interface, - weight) + params) pp.pprint(r) def remove(self, args): @@ -49,13 +51,15 @@ class ZeroRpcClient(object): vnf_dst_name = self._parse_vnf_name(args.get("destination")) vnf_dst_interface = self._parse_vnf_interface(args.get("destination")) weight = args.get("weight") + match = args.get("match") r = self.c.network_action_stop( #args.get("datacenter"), vnf_src_name, vnf_dst_name, vnf_src_interface, vnf_dst_interface, - weight) + weight, + match) pp.pprint(r) def _parse_vnf_name(self, vnf_name_str): @@ -70,6 +74,8 @@ class ZeroRpcClient(object): return vnf_interface + def _create_dict(self, **kwargs): + return kwargs parser = argparse.ArgumentParser(description='son-emu network') parser.add_argument( @@ -87,6 +93,9 @@ parser.add_argument( parser.add_argument( "--weight", "-w", dest="weight", help="weight metric to calculate the path") +parser.add_argument( + "--match", "-m", dest="match", + help="string holding extra matches for the flow entries") def main(argv): args = vars(parser.parse_args(argv)) diff --git a/src/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py index ac44d57..ec42b66 100755 --- a/src/emuvim/dcemulator/net.py +++ b/src/emuvim/dcemulator/net.py @@ -221,7 +221,8 @@ class DCNetwork(Dockernet): CLI(self) # to remove chain do setChain( src, dst, cmd='del-flows') - def setChain(self, vnf_src_name, vnf_dst_name, vnf_src_interface=None, vnf_dst_interface=None, cmd='add-flow', weight=None): + def setChain(self, vnf_src_name, vnf_dst_name, vnf_src_interface=None, vnf_dst_interface=None, cmd='add-flow', + weight=None, **kwargs): logging.info('vnf_src_if: {0}'.format(vnf_src_interface)) #check if port is specified (vnf:port) @@ -306,6 +307,12 @@ class DCNetwork(Dockernet): # TODO need multiple matches to do this (VLAN tags) if isinstance( current_node, OVSSwitch ): 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 -- 2.25.1