1 from gi.repository
import Gtk
4 NODE_STATISTICS_MEMORY = 10
10 Collects interface statistics for all nodes.
20 __slots__ = [
'rxPackets',
'rxBytes',
'txPackets',
'txBytes',
21 'rxPacketRate',
'rxBitRate',
'txPacketRate',
'txBitRate']
25 Collects interface statistics for all nodes.
26 @param self this object
27 @param visualizer visualizer object
34 Simulation Periodic Update function.
35 @param self this object
36 @param viz visualizer object
39 nodes_statistics = viz.simulation.sim_helper.GetNodesStatistics()
40 for stats
in nodes_statistics:
46 raw_stats_list.append(stats.statistics)
47 while len(raw_stats_list) > NODE_STATISTICS_MEMORY:
52 Get interface statistics function.
53 @param self this object
55 @return the statistics
62 if len(raw_stats_list) < NODE_STATISTICS_MEMORY:
64 assert len(raw_stats_list) == NODE_STATISTICS_MEMORY
69 for iface, stats
in enumerate(raw_stats_list[0]):
70 tx_packets1.append(stats.transmittedPackets)
71 tx_bytes1.append(stats.transmittedBytes)
72 rx_packets1.append(stats.receivedPackets)
73 rx_bytes1.append(stats.receivedBytes)
77 k = self.
visualizervisualizer.sample_period*(NODE_STATISTICS_MEMORY-1)
78 for iface, stats
in enumerate(raw_stats_list[-1]):
80 outStat.txPackets = stats.transmittedPackets
81 outStat.txBytes = stats.transmittedBytes
82 outStat.rxPackets = stats.receivedPackets
83 outStat.rxBytes = stats.receivedBytes
85 outStat.txPacketRate = (stats.transmittedPackets - tx_packets1[iface])/k
86 outStat.rxPacketRate = (stats.receivedPackets - rx_packets1[iface])/k
87 outStat.txBitRate = (stats.transmittedBytes - tx_bytes1[iface])*8/k
88 outStat.rxBitRate = (stats.receivedBytes - rx_bytes1[iface])*8/k
89 retval.append(outStat)
112 COLUMN_TX_PACKET_RATE,
117 COLUMN_RX_PACKET_RATE,
122 def __init__(self, visualizer, node_index, statistics_collector):
125 @param self this object
126 @param visualizer the visualizer object
127 @param node_index the node index
128 @param statistics_collector statistics collector class
130 InformationWindow.__init__(self)
131 self.
winwin = Gtk.Dialog(parent=visualizer.window,
132 flags=Gtk.DialogFlags.DESTROY_WITH_PARENT,
133 buttons=(
"_Close", Gtk.ResponseType.CLOSE))
135 self.
winwin.set_title(
"Statistics for node %i" % node_index)
139 self.
viz_nodeviz_node = visualizer.get_node(node_index)
143 treeview = Gtk.TreeView(self.
table_modeltable_model)
145 self.
winwin.vbox.add(treeview)
147 def add_column(descr, colid):
148 column = Gtk.TreeViewColumn(descr, Gtk.CellRendererText(), text=colid)
149 treeview.append_column(column)
151 add_column(
"Interface", self.COLUMN_INTERFACE)
153 add_column(
"Tx Packets", self.COLUMN_TX_PACKETS)
154 add_column(
"Tx Bytes", self.COLUMN_TX_BYTES)
155 add_column(
"Tx pkt/1s", self.COLUMN_TX_PACKET_RATE)
156 add_column(
"Tx bit/1s", self.COLUMN_TX_BIT_RATE)
158 add_column(
"Rx Packets", self.COLUMN_RX_PACKETS)
159 add_column(
"Rx Bytes", self.COLUMN_RX_BYTES)
160 add_column(
"Rx pkt/1s", self.COLUMN_RX_PACKET_RATE)
161 add_column(
"Rx bit/1s", self.COLUMN_RX_BIT_RATE)
163 self.
visualizervisualizer.add_information_window(self)
168 Response callback function.
169 @param self this object
170 @param win the window
171 @param response the response
174 self.
winwin.destroy()
175 self.
visualizervisualizer.remove_information_window(self)
180 @param self this object
183 node = ns.NodeList.GetNode(self.
node_indexnode_index)
186 for iface, stats
in enumerate(stats_list):
188 netdevice = node.GetDevice(iface)
189 interface_name = ns.Names.FindName(netdevice)
190 if not interface_name:
191 interface_name =
"(interface %i)" % iface
193 self.COLUMN_INTERFACE, interface_name,
195 self.COLUMN_TX_PACKETS, str(stats.txPackets),
196 self.COLUMN_TX_BYTES, str(stats.txBytes),
197 self.COLUMN_TX_PACKET_RATE, str(stats.txPacketRate),
198 self.COLUMN_TX_BIT_RATE, str(stats.txBitRate),
200 self.COLUMN_RX_PACKETS, str(stats.rxPackets),
201 self.COLUMN_RX_BYTES, str(stats.rxBytes),
202 self.COLUMN_RX_PACKET_RATE, str(stats.rxPacketRate),
203 self.COLUMN_RX_BIT_RATE, str(stats.rxBitRate)
209 menu_item = Gtk.MenuItem(
"Show Interface Statistics")
212 def _show_it(dummy_menu_item):
215 menu_item.connect(
"activate", _show_it)
221 viz.connect(
"populate-node-menu", populate_node_menu, statistics_collector)
222 viz.connect(
"simulation-periodic-update", statistics_collector.simulation_periodic_update)
ShowInterfaceStatistics class.
def update(self)
Update function.
def __init__(self, visualizer, node_index, statistics_collector)
Initializer.
statistics_collector
statistics collector
def _response_cb(self, win, response)
Response callback function.
StatisticsCollector class.
def get_interface_statistics(self, nodeId)
Get interface statistics function.
node_statistics
node statistics
def __init__(self, visualizer)
Collects interface statistics for all nodes.
def simulation_periodic_update(self, viz)
Simulation Periodic Update function.
def populate_node_menu(viz, node, menu, statistics_collector)