-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataCollection
76 lines (59 loc) · 2.93 KB
/
dataCollection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#The local controller will collect
#real-time data such as buffer capacity, configured MAC layer protocol, energy, hop
#count, CPU usage from IoT devices using OpenFlow, OF-Config, OVS-DB protocol, and
#NETCONF. This data will then be forwarded to the global controller using the controller
#to controller communication protocols.
from pox.core import core
from pox.lib.util import dpidToStr
import pox.openflow.libopenflow_01 as of
log = core.getLogger()
class SimpleController(object)
def _handle_qeuestats_received (self, event):
"""
handler to manage queued packets statistics received
Args:
event: Event listening to QueueStatsReceived from openflow
"""
stats = flow_stats_to_list(event.stats)
# log.info("QueueStatsReceived from %s: %s", dpidToStr(event.connection.dpid), stats)
def _handle_flowstats_received (event):
stats = flow_stats_to_list(event.stats)
log.debug("FlowStatsReceived from %s: %s",
dpidToStr(event.connection.dpid), stats)
# handler to display port statistics received in JSON format
def _handle_portstats_received (event):
stats = flow_stats_to_list(event.stats)
log.debug("PortStatsReceived from %s: %s",
dpidToStr(event.connection.dpid), stats)
# main functiont to launch the module
def launch ():
from pox.lib.recoco import Timer
# attach handsers to listners
core.openflow.addListenerByName("FlowStatsReceived",
_handle_flowstats_received)
core.openflow.addListenerByName("PortStatsReceived",
_handle_portstats_received)
# timer set to execute every five seconds
Timer(5, _timer_func, recurring=True)
# def _handle_portstats_received(self,event):
# """
# Handler to manage port statistics received
# Args:
# event: Event listening to PortStatsReceived from openflow
# """
# for f in event.stats:
# if int(f.port_no)<65534: # used from hosts and switches interlinks
# current_bytes = f.rx_bytes + f.tx_bytes # transmitted and received
# try:
# last_bytes = self.switches_bw[int(event.connection.dpid)][int(f.port_no)]
# except:
# last_bytes = 0
# estim_bw = (((current_bytes - last_bytes)/1024)/1024)*8
# estim_bw = float(format(estim_bw, '.2f'))
# if estim_bw > 0:
# print pox.lib.util.dpidToStr(event.connection.dpid), f.port_no, estim_bw
self.switches_bw[int(event.connection.dpid)][int(f.port_no)] = (f.rx_bytes + f.tx_bytes)
# get stats START ------------------------------------------------------------------>
#core.openflow.addListenerByName("FlowStatsReceived", self._handle_flowstats_received)
#core.openflow.addListenerByName("PortStatsReceived", self._handle_portstats_received)
# core.openflow.addListenerByName("QueueStatsReceived", self._handle_qeuestats_received)