1from gi.repository
import Gtk
4 from nsnam.visualizer.base
import InformationWindow
5except ModuleNotFoundError:
8NODE_STATISTICS_MEMORY = 10
14 Collects interface statistics for all nodes.
24 __slots__ = [
'rxPackets',
'rxBytes',
'txPackets',
'txBytes',
25 'rxPacketRate',
'rxBitRate',
'txPacketRate',
'txBitRate']
29 Collects interface statistics for all nodes.
30 @param self this object
31 @param visualizer visualizer object
38 Simulation Periodic Update function.
39 @param self this object
40 @param viz visualizer object
43 nodes_statistics = viz.simulation.sim_helper.GetNodesStatistics()
44 for stats
in nodes_statistics:
50 raw_stats_list.append(stats.statistics)
51 while len(raw_stats_list) > NODE_STATISTICS_MEMORY:
56 Get interface statistics function.
57 @param self this object
59 @return the statistics
66 if len(raw_stats_list) < NODE_STATISTICS_MEMORY:
68 assert len(raw_stats_list) == NODE_STATISTICS_MEMORY
73 for iface, stats
in enumerate(raw_stats_list[0]):
74 tx_packets1.append(stats.transmittedPackets)
75 tx_bytes1.append(stats.transmittedBytes)
76 rx_packets1.append(stats.receivedPackets)
77 rx_bytes1.append(stats.receivedBytes)
81 k = self.
visualizer.sample_period*(NODE_STATISTICS_MEMORY-1)
82 for iface, stats
in enumerate(raw_stats_list[-1]):
84 outStat.txPackets = stats.transmittedPackets
85 outStat.txBytes = stats.transmittedBytes
86 outStat.rxPackets = stats.receivedPackets
87 outStat.rxBytes = stats.receivedBytes
89 outStat.txPacketRate = (stats.transmittedPackets - tx_packets1[iface])/k
90 outStat.rxPacketRate = (stats.receivedPackets - rx_packets1[iface])/k
91 outStat.txBitRate = (stats.transmittedBytes - tx_bytes1[iface])*8/k
92 outStat.rxBitRate = (stats.receivedBytes - rx_bytes1[iface])*8/k
93 retval.append(outStat)
116 COLUMN_TX_PACKET_RATE,
121 COLUMN_RX_PACKET_RATE,
126 def __init__(self, visualizer, node_index, statistics_collector):
129 @param self this object
130 @param visualizer the visualizer object
131 @param node_index the node index
132 @param statistics_collector statistics collector
class
134 InformationWindow.__init__(self)
135 self.win = Gtk.Dialog(parent=visualizer.window,
136 flags=Gtk.DialogFlags.DESTROY_WITH_PARENT,
137 buttons=("_Close", Gtk.ResponseType.CLOSE))
139 self.
win.set_title(
"Statistics for node %i" % node_index)
149 self.
win.vbox.add(treeview)
151 def add_column(descr, colid):
152 column = Gtk.TreeViewColumn(descr, Gtk.CellRendererText(), text=colid)
153 treeview.append_column(column)
155 add_column(
"Interface", self.COLUMN_INTERFACE)
157 add_column(
"Tx Packets", self.COLUMN_TX_PACKETS)
158 add_column(
"Tx Bytes", self.COLUMN_TX_BYTES)
159 add_column(
"Tx pkt/1s", self.COLUMN_TX_PACKET_RATE)
160 add_column(
"Tx bit/1s", self.COLUMN_TX_BIT_RATE)
162 add_column(
"Rx Packets", self.COLUMN_RX_PACKETS)
163 add_column(
"Rx Bytes", self.COLUMN_RX_BYTES)
164 add_column(
"Rx pkt/1s", self.COLUMN_RX_PACKET_RATE)
165 add_column(
"Rx bit/1s", self.COLUMN_RX_BIT_RATE)
172 Response callback function.
173 @param self this object
174 @param win the window
175 @param response the response
179 self.visualizer.remove_information_window(self)
184 @param self this object
190 for iface, stats
in enumerate(stats_list):
192 netdevice = node.GetDevice(iface)
193 interface_name = ns.Names.FindName(netdevice)
194 if not interface_name:
195 interface_name =
"(interface %i)" % iface
197 self.COLUMN_INTERFACE, interface_name,
199 self.COLUMN_TX_PACKETS, str(stats.txPackets),
200 self.COLUMN_TX_BYTES, str(stats.txBytes),
201 self.COLUMN_TX_PACKET_RATE, str(stats.txPacketRate),
202 self.COLUMN_TX_BIT_RATE, str(stats.txBitRate),
204 self.COLUMN_RX_PACKETS, str(stats.rxPackets),
205 self.COLUMN_RX_BYTES, str(stats.rxBytes),
206 self.COLUMN_RX_PACKET_RATE, str(stats.rxPacketRate),
207 self.COLUMN_RX_BIT_RATE, str(stats.rxBitRate)
213 menu_item = Gtk.MenuItem(
"Show Interface Statistics")
216 def _show_it(dummy_menu_item):
219 menu_item.connect(
"activate", _show_it)
225 viz.connect(
"populate-node-menu", populate_node_menu, statistics_collector)
226 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)