2 Copyright (c) 2015 SONATA-NFV
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
17 Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION]
18 nor the names of its contributors may be used to endorse or promote
19 products derived from this software without specific prior written
22 This work has been performed in the framework of the SONATA project,
23 funded by the European Commission under Grant number 671517 through
24 the Horizon 2020 and 5G-PPP programmes. The authors would like to
25 acknowledge the contributions of their colleagues of the SONATA
26 partner consortium (www.sonata-nfv.eu).
31 from tabulate
import tabulate
35 pp
= pprint
.PrettyPrinter(indent
=4)
37 class ZeroRpcClient(object):
40 self
.c
= zerorpc
.Client()
41 # TODO connect to DCNetwork API
42 #self.c.connect("tcp://127.0.0.1:4242") # TODO hard coded for now. we'll change this later
43 self
.c
.connect("tcp://127.0.0.1:5151")
46 def execute_command(self
, args
):
47 if getattr(self
, args
["command"]) is not None:
48 # call the local method with the same name as the command arg
49 getattr(self
, args
["command"])(args
)
51 print("Command not implemented.")
54 vnf_src_name
= self
._parse
_vnf
_name
(args
.get("source"))
55 vnf_dst_name
= self
._parse
_vnf
_name
(args
.get("destination"))
57 params
= self
._create
_dict
(
58 vnf_src_interface
=self
._parse
_vnf
_interface
(args
.get("source")),
59 vnf_dst_interface
=self
._parse
_vnf
_interface
(args
.get("destination")),
60 weight
=args
.get("weight"),
61 match
=args
.get("match"),
62 bidirectional
=args
.get("bidirectional"),
63 cookie
=args
.get("cookie"))
65 # note zerorpc does not support named arguments
66 r
= self
.c
.network_action_start(
67 #args.get("datacenter"),
73 def remove(self
, args
):
74 vnf_src_name
= self
._parse
_vnf
_name
(args
.get("source"))
75 vnf_dst_name
= self
._parse
_vnf
_name
(args
.get("destination"))
77 params
= self
._create
_dict
(
78 vnf_src_interface
=self
._parse
_vnf
_interface
(args
.get("source")),
79 vnf_dst_interface
=self
._parse
_vnf
_interface
(args
.get("destination")),
80 weight
=args
.get("weight"),
81 match
=args
.get("match"),
82 bidirectional
=args
.get("bidirectional"),
83 cookie
=args
.get("cookie"))
85 r
= self
.c
.network_action_stop(
86 #args.get("datacenter"),
92 def _parse_vnf_name(self
, vnf_name_str
):
93 vnf_name
= vnf_name_str
.split(':')[0]
96 def _parse_vnf_interface(self
, vnf_name_str
):
98 vnf_interface
= vnf_name_str
.split(':')[1]
104 def _create_dict(self
, **kwargs
):
107 parser
= argparse
.ArgumentParser(description
='son-emu network')
110 choices
=['add', 'remove'],
111 help="Action to be executed.")
113 "--datacenter", "-d", dest
="datacenter",
114 help="Data center to in which the network action should be initiated")
116 "--source", "-src", dest
="source",
117 help="vnf name of the source of the chain")
119 "--destination", "-dst", dest
="destination",
120 help="vnf name of the destination of the chain")
122 "--weight", "-w", dest
="weight",
123 help="weight metric to calculate the path")
125 "--match", "-m", dest
="match",
126 help="string holding extra matches for the flow entries")
128 "--bidirectional", "-b", dest
="bidirectional",
130 help="add/remove the flow entries from src to dst and back")
132 "--cookie", "-c", dest
="cookie",
133 help="cookie for this flow, as easy to use identifier (eg. per tenant/service)")
136 args
= vars(parser
.parse_args(argv
))
138 c
.execute_command(args
)