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/simple_switch_13.py'
36 ryu_path2
= python_install_path
+ '/ryu/app/ofctl_rest.py'
37 # change the default Openflow controller port to 6653 (official IANA-assigned port number), as used by Mininet
38 # Ryu still uses 6633 as default
39 ryu_option
= '--ofp-tcp-listen-port'
41 ryu_cmd
= 'ryu-manager'
42 self
.ryu_process
= Popen([ryu_cmd
, ryu_path
, ryu_path2
, ryu_option
, ryu_of_port
])
44 def connectDCNetwork(self
, net
):
46 logging
.info("Connected DCNetwork to API endpoint %s(%s:%d)" % (
47 self
.__class
__.__name
__, self
.ip
, self
.port
))
50 thread
= threading
.Thread(target
=self
._api
_server
_thread
, args
=())
53 logging
.debug("Started API endpoint %s(%s:%d)" % (
54 self
.__class
__.__name
__, self
.ip
, self
.port
))
56 def _api_server_thread(self
):
57 s
= zerorpc
.Server(DCNetworkApi(self
.net
))
58 s
.bind("tcp://%s:%d" % (self
.ip
, self
.port
))
63 logging
.info("Stop the monitoring API endpoint")
64 self
.ryu_process
.terminate()
65 #self.ryu_process.kill()
69 class DCNetworkApi(object):
71 Just pass through the corresponding request to the
72 selected data center. Do not implement provisioning
73 logic here because will will have multiple API
74 endpoint implementations at the end.
77 def __init__(self
, net
):
80 def network_action_start(self
, vnf_src_name
, vnf_dst_name
):
81 # call DCNetwork method, not really datacenter specific API for now...
82 # provided dc name needs to be part of API endpoint
83 # no check if vnfs are really connected to this datacenter...
84 logging
.debug("RPC CALL: network chain start")
86 c
= self
.net
.setChain(
87 vnf_src_name
, vnf_dst_name
)
89 except Exception as ex
:
90 logging
.exception("RPC error.")
93 def network_action_stop(self
, vnf_src_name
, vnf_dst_name
):
94 # call DCNetwork method, not really datacenter specific API for now...
95 # provided dc name needs to be part of API endpoint
96 # no check if vnfs are really connected to this datacenter...
97 logging
.debug("RPC CALL: network chain stop")
99 c
= self
.net
.setChain(
100 vnf_src_name
, vnf_dst_name
, cmd
='del-flows')
102 except Exception as ex
:
103 logging
.exception("RPC error.")
106 # get egress(default) or ingress rate of a vnf
107 def monitor_get_rate(self
, vnf_name
, direction
):
108 logging
.debug("RPC CALL: get rate")
110 c
= self
.net
.monitor_agent
.get_rate(vnf_name
, direction
)
112 except Exception as ex
:
113 logging
.exception("RPC error.")