6 NODE_STATISTICS_MEMORY = 10
11 Collects interface statistics for all nodes.
15 __slots__ = [
'rxPackets',
'rxBytes',
'txPackets',
'txBytes',
16 'rxPacketRate',
'rxBitRate',
'txPacketRate',
'txBitRate']
23 nodes_statistics = viz.simulation.sim_helper.GetNodesStatistics()
24 for stats
in nodes_statistics:
30 raw_stats_list.append(stats.statistics)
31 while len(raw_stats_list) > NODE_STATISTICS_MEMORY:
40 if len(raw_stats_list) < NODE_STATISTICS_MEMORY:
42 assert len(raw_stats_list) == NODE_STATISTICS_MEMORY
47 for iface, stats
in enumerate(raw_stats_list[0]):
48 tx_packets1.append(stats.transmittedPackets)
49 tx_bytes1.append(stats.transmittedBytes)
50 rx_packets1.append(stats.receivedPackets)
51 rx_bytes1.append(stats.receivedBytes)
55 k = self.visualizer.sample_period*(NODE_STATISTICS_MEMORY-1)
56 for iface, stats
in enumerate(raw_stats_list[-1]):
58 outStat.txPackets = stats.transmittedPackets
59 outStat.txBytes = stats.transmittedBytes
60 outStat.rxPackets = stats.receivedPackets
61 outStat.rxBytes = stats.receivedBytes
63 outStat.txPacketRate = (stats.transmittedPackets - tx_packets1[iface])/k
64 outStat.rxPacketRate = (stats.receivedPackets - rx_packets1[iface])/k
65 outStat.txBitRate = (stats.transmittedBytes - tx_bytes1[iface])*8/k
66 outStat.rxBitRate = (stats.receivedBytes - rx_bytes1[iface])*8/k
67 retval.append(outStat)
77 COLUMN_TX_PACKET_RATE,
82 COLUMN_RX_PACKET_RATE,
87 def __init__(self, visualizer, node_index, statistics_collector):
88 InformationWindow.__init__(self)
89 self.
win = gtk.Dialog(parent=visualizer.window,
90 flags=gtk.DIALOG_DESTROY_WITH_PARENT|gtk.DIALOG_NO_SEPARATOR,
91 buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
93 self.win.set_title(
"Statistics for node %i" % node_index)
97 self.
viz_node = visualizer.get_node(node_index)
103 self.win.vbox.add(treeview)
105 def add_column(descr, colid):
106 column = gtk.TreeViewColumn(descr, gtk.CellRendererText(), text=colid)
107 treeview.append_column(column)
109 add_column(
"Interface", self.COLUMN_INTERFACE)
111 add_column(
"Tx Packets", self.COLUMN_TX_PACKETS)
112 add_column(
"Tx Bytes", self.COLUMN_TX_BYTES)
113 add_column(
"Tx pkt/1s", self.COLUMN_TX_PACKET_RATE)
114 add_column(
"Tx bit/1s", self.COLUMN_TX_BIT_RATE)
116 add_column(
"Rx Packets", self.COLUMN_RX_PACKETS)
117 add_column(
"Rx Bytes", self.COLUMN_RX_BYTES)
118 add_column(
"Rx pkt/1s", self.COLUMN_RX_PACKET_RATE)
119 add_column(
"Rx bit/1s", self.COLUMN_RX_BIT_RATE)
121 self.visualizer.add_information_window(self)
126 self.visualizer.remove_information_window(self)
129 node = ns.network.NodeList.GetNode(self.
node_index)
130 stats_list = self.statistics_collector.get_interface_statistics(self.
node_index)
131 self.table_model.clear()
132 for iface, stats
in enumerate(stats_list):
133 tree_iter = self.table_model.append()
134 netdevice = node.GetDevice(iface)
135 interface_name = ns.core.Names.FindName(netdevice)
136 if not interface_name:
137 interface_name =
"(interface %i)" % iface
138 self.table_model.set(tree_iter,
139 self.COLUMN_INTERFACE, interface_name,
141 self.COLUMN_TX_PACKETS, str(stats.txPackets),
142 self.COLUMN_TX_BYTES, str(stats.txBytes),
143 self.COLUMN_TX_PACKET_RATE, str(stats.txPacketRate),
144 self.COLUMN_TX_BIT_RATE, str(stats.txBitRate),
146 self.COLUMN_RX_PACKETS, str(stats.rxPackets),
147 self.COLUMN_RX_BYTES, str(stats.rxBytes),
148 self.COLUMN_RX_PACKET_RATE, str(stats.rxPacketRate),
149 self.COLUMN_RX_BIT_RATE, str(stats.rxBitRate)
155 menu_item = gtk.MenuItem(
"Show Interface Statistics")
158 def _show_it(dummy_menu_item):
161 menu_item.connect(
"activate", _show_it)
167 viz.connect(
"populate-node-menu", populate_node_menu, statistics_collector)
168 viz.connect(
"simulation-periodic-update", statistics_collector.simulation_periodic_update)
def __init__(self, visualizer)
def populate_node_menu(viz, node, menu, statistics_collector)
def simulation_periodic_update(self, viz)
def get_interface_statistics(self, nodeId)
def __init__(self, visualizer, node_index, statistics_collector)
def _response_cb(self, win, response)