1 __author__
= 'Administrator'
5 from mininet
.node
import OVSSwitch
7 logging
.basicConfig(level
=logging
.INFO
)
10 class to read openflow stats from the Ryu controller of the DCNEtwork
13 class DCNetworkMonitor():
14 def __init__(self
, net
):
19 self
.REST_api
= 'http://{0}:{1}'.format(self
.ip
,self
.port
)
22 def get_rate(self
, vnf_name
, direction
='tx'):
24 vnf_switch
= self
.net
.DCNetwork_graph
.neighbors(str(vnf_name
))
26 if len(vnf_switch
) > 1:
27 logging
.info("vnf: {0} has multiple ports".format(vnf_name
))
29 elif len(vnf_switch
) == 0:
30 logging
.info("vnf: {0} is not connected".format(vnf_name
))
33 vnf_switch
= vnf_switch
[0]
34 next_node
= self
.net
.getNodeByName(vnf_switch
)
36 if not isinstance( next_node
, OVSSwitch
):
37 logging
.info("vnf: {0} is not connected to switch".format(vnf_name
))
40 mon_port
= self
.net
.DCNetwork_graph
[vnf_name
][vnf_switch
]['dst_port']
41 switch_dpid
= x
= int(str(next_node
.dpid
),16)
43 ret
= self
.REST_cmd('stats/port', switch_dpid
)
44 port_stat_dict
= ast
.literal_eval(ret
)
45 for port_stat
in port_stat_dict
[str(switch_dpid
)]:
46 if port_stat
['port_no'] == mon_port
:
52 except Exception as ex
:
53 logging
.exception("get_txrate error.")
58 def REST_cmd(self
, prefix
, dpid
):
59 url
= self
.REST_api
+ '/' + str(prefix
) + '/' + str(dpid
)
60 req
= urllib2
.Request(url
)
61 ret
= urllib2
.urlopen(req
).read()