1 from gi.repository
import Gtk
6 NODE_STATISTICS_MEMORY = 10
12 Collects interface statistics for all nodes.
22 __slots__ = [
'rxPackets',
'rxBytes',
'txPackets',
'txBytes',
23 'rxPacketRate',
'rxBitRate',
'txPacketRate',
'txBitRate']
27 Collects interface statistics for all nodes.
28 @param self this object
29 @param visualizer visualizer object
36 Simulation Periodic Update function.
37 @param self this object
38 @param viz visualizer object
41 nodes_statistics = viz.simulation.sim_helper.GetNodesStatistics()
42 for stats
in nodes_statistics:
48 raw_stats_list.append(stats.statistics)
49 while len(raw_stats_list) > NODE_STATISTICS_MEMORY:
54 Get interface statistics function.
55 @param self this object
57 @return the statistics
64 if len(raw_stats_list) < NODE_STATISTICS_MEMORY:
66 assert len(raw_stats_list) == NODE_STATISTICS_MEMORY
71 for iface, stats
in enumerate(raw_stats_list[0]):
72 tx_packets1.append(stats.transmittedPackets)
73 tx_bytes1.append(stats.transmittedBytes)
74 rx_packets1.append(stats.receivedPackets)
75 rx_bytes1.append(stats.receivedBytes)
79 k = self.
visualizervisualizer.sample_period*(NODE_STATISTICS_MEMORY-1)
80 for iface, stats
in enumerate(raw_stats_list[-1]):
82 outStat.txPackets = stats.transmittedPackets
83 outStat.txBytes = stats.transmittedBytes
84 outStat.rxPackets = stats.receivedPackets
85 outStat.rxBytes = stats.receivedBytes
87 outStat.txPacketRate = (stats.transmittedPackets - tx_packets1[iface])/k
88 outStat.rxPacketRate = (stats.receivedPackets - rx_packets1[iface])/k
89 outStat.txBitRate = (stats.transmittedBytes - tx_bytes1[iface])*8/k
90 outStat.rxBitRate = (stats.receivedBytes - rx_bytes1[iface])*8/k
91 retval.append(outStat)
114 COLUMN_TX_PACKET_RATE,
119 COLUMN_RX_PACKET_RATE,
124 def __init__(self, visualizer, node_index, statistics_collector):
127 @param self this object
128 @param visualizer the visualizer object
129 @param node_index the node index
130 @param statistics_collector statistics collector class
132 InformationWindow.__init__(self)
133 self.
winwin = Gtk.Dialog(parent=visualizer.window,
134 flags=Gtk.DialogFlags.DESTROY_WITH_PARENT,
135 buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
137 self.
winwin.set_title(
"Statistics for node %i" % node_index)
141 self.
viz_nodeviz_node = visualizer.get_node(node_index)
145 treeview = Gtk.TreeView(self.
table_modeltable_model)
147 self.
winwin.vbox.add(treeview)
149 def add_column(descr, colid):
150 column = Gtk.TreeViewColumn(descr, Gtk.CellRendererText(), text=colid)
151 treeview.append_column(column)
153 add_column(
"Interface", self.COLUMN_INTERFACE)
155 add_column(
"Tx Packets", self.COLUMN_TX_PACKETS)
156 add_column(
"Tx Bytes", self.COLUMN_TX_BYTES)
157 add_column(
"Tx pkt/1s", self.COLUMN_TX_PACKET_RATE)
158 add_column(
"Tx bit/1s", self.COLUMN_TX_BIT_RATE)
160 add_column(
"Rx Packets", self.COLUMN_RX_PACKETS)
161 add_column(
"Rx Bytes", self.COLUMN_RX_BYTES)
162 add_column(
"Rx pkt/1s", self.COLUMN_RX_PACKET_RATE)
163 add_column(
"Rx bit/1s", self.COLUMN_RX_BIT_RATE)
165 self.
visualizervisualizer.add_information_window(self)
170 Response callback function.
171 @param self this object
172 @param win the window
173 @param response the response
176 self.
winwin.destroy()
177 self.
visualizervisualizer.remove_information_window(self)
182 @param self this object
185 node = ns.network.NodeList.GetNode(self.
node_indexnode_index)
188 for iface, stats
in enumerate(stats_list):
190 netdevice = node.GetDevice(iface)
191 interface_name = ns.core.Names.FindName(netdevice)
192 if not interface_name:
193 interface_name =
"(interface %i)" % iface
195 self.COLUMN_INTERFACE, interface_name,
197 self.COLUMN_TX_PACKETS, str(stats.txPackets),
198 self.COLUMN_TX_BYTES, str(stats.txBytes),
199 self.COLUMN_TX_PACKET_RATE, str(stats.txPacketRate),
200 self.COLUMN_TX_BIT_RATE, str(stats.txBitRate),
202 self.COLUMN_RX_PACKETS, str(stats.rxPackets),
203 self.COLUMN_RX_BYTES, str(stats.rxBytes),
204 self.COLUMN_RX_PACKET_RATE, str(stats.rxPacketRate),
205 self.COLUMN_RX_BIT_RATE, str(stats.rxBitRate)
211 menu_item = Gtk.MenuItem(
"Show Interface Statistics")
214 def _show_it(dummy_menu_item):
217 menu_item.connect(
"activate", _show_it)
223 viz.connect(
"populate-node-menu", populate_node_menu, statistics_collector)
224 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)