83b158a57cdae2d3a762b824bc5a375c35693a98
2 Distributed Cloud Emulator (dcemulator)
3 (c) 2015 by Manuel Peuster <manuel.peuster@upb.de>
10 from subprocess
import Popen
12 logging
.basicConfig(level
=logging
.INFO
)
15 class ZeroRpcApiEndpointDCNetwork(object):
17 Simple API endpoint that offers a zerorpc-based
18 interface. This interface will be used by the
19 default command line client.
20 It can be used as a reference to implement
21 REST interfaces providing the same semantics,
22 like e.g. OpenStack compute API.
25 def __init__(self
, listenip
, port
, DCNetwork
=None):
27 self
.connectDCNetwork(DCNetwork
)
30 logging
.debug("Created monitoring API endpoint %s(%s:%d)" % (
31 self
.__class
__.__name
__, self
.ip
, self
.port
))
33 # start Ryu controller with rest-API
34 python_install_path
= site
.getsitepackages()[0]
35 ryu_path
= python_install_path
+ '/ryu/app/ofctl_rest.py'
36 ryu_cmd
= 'ryu-manager'
37 self
.ryu_process
= Popen([ryu_cmd
,ryu_path
])
40 def connectDCNetwork(self
, net
):
42 logging
.info("Connected DCNetwork to API endpoint %s(%s:%d)" % (
43 self
.__class
__.__name
__, self
.ip
, self
.port
))
46 thread
= threading
.Thread(target
=self
._api
_server
_thread
, args
=())
49 logging
.debug("Started API endpoint %s(%s:%d)" % (
50 self
.__class
__.__name
__, self
.ip
, self
.port
))
52 def _api_server_thread(self
):
53 s
= zerorpc
.Server(DCNetworkApi(self
.net
))
54 s
.bind("tcp://%s:%d" % (self
.ip
, self
.port
))
59 logging
.info("Stop the monitoring API endpoint")
60 self
.ryu_process
.terminate()
61 #self.ryu_process.kill()
65 class DCNetworkApi(object):
67 Just pass through the corresponding request to the
68 selected data center. Do not implement provisioning
69 logic here because will will have multiple API
70 endpoint implementations at the end.
73 def __init__(self
, net
):
76 def network_action_start(self
, vnf_src_name
, vnf_dst_name
):
77 # call DCNetwork method, not really datacenter specific API for now...
78 # provided dc name needs to be part of API endpoint
79 # no check if vnfs are really connected to this datacenter...
80 logging
.debug("RPC CALL: network chain start")
82 c
= self
.net
.setChain(
83 vnf_src_name
, vnf_dst_name
)
85 except Exception as ex
:
86 logging
.exception("RPC error.")
89 def network_action_stop(self
, vnf_src_name
, vnf_dst_name
):
90 # call DCNetwork method, not really datacenter specific API for now...
91 # provided dc name needs to be part of API endpoint
92 # no check if vnfs are really connected to this datacenter...
93 logging
.debug("RPC CALL: network chain stop")
95 c
= self
.net
.setChain(
96 vnf_src_name
, vnf_dst_name
, cmd
='del-flows')
98 except Exception as ex
:
99 logging
.exception("RPC error.")
102 # get egress(default) or ingress rate of a vnf
103 def monitor_get_rate(self
, vnf_name
, direction
):
104 logging
.debug("RPC CALL: get rate")
106 c
= self
.net
.monitor_agent
.get_rate(vnf_name
, direction
)
108 except Exception as ex
:
109 logging
.exception("RPC error.")