1 from gi.repository
import Gtk
4 from ns3.visualizer.base
import InformationWindow
5 except ModuleNotFoundError:
8 NODE_STATISTICS_MEMORY = 10
14 Collects interface statistics for all nodes.
38 Collects interface statistics for all nodes.
39 @param self this object
40 @param visualizer visualizer object
47 Simulation Periodic Update function.
48 @param self this object
49 @param viz visualizer object
52 nodes_statistics = viz.simulation.sim_helper.GetNodesStatistics()
53 for stats
in nodes_statistics:
59 raw_stats_list.append(stats.statistics)
60 while len(raw_stats_list) > NODE_STATISTICS_MEMORY:
65 Get interface statistics function.
66 @param self this object
68 @return the statistics
75 if len(raw_stats_list) < NODE_STATISTICS_MEMORY:
77 assert len(raw_stats_list) == NODE_STATISTICS_MEMORY
82 for iface, stats
in enumerate(raw_stats_list[0]):
83 tx_packets1.append(stats.transmittedPackets)
84 tx_bytes1.append(stats.transmittedBytes)
85 rx_packets1.append(stats.receivedPackets)
86 rx_bytes1.append(stats.receivedBytes)
90 k = self.
visualizervisualizer.sample_period * (NODE_STATISTICS_MEMORY - 1)
91 for iface, stats
in enumerate(raw_stats_list[-1]):
93 outStat.txPackets = stats.transmittedPackets
94 outStat.txBytes = stats.transmittedBytes
95 outStat.rxPackets = stats.receivedPackets
96 outStat.rxBytes = stats.receivedBytes
98 outStat.txPacketRate = (stats.transmittedPackets - tx_packets1[iface]) / k
99 outStat.rxPacketRate = (stats.receivedPackets - rx_packets1[iface]) / k
100 outStat.txBitRate = (stats.transmittedBytes - tx_bytes1[iface]) * 8 / k
101 outStat.rxBitRate = (stats.receivedBytes - rx_bytes1[iface]) * 8 / k
102 retval.append(outStat)
144 COLUMN_TX_PACKET_RATE,
148 COLUMN_RX_PACKET_RATE,
152 def __init__(self, visualizer, node_index, statistics_collector):
155 @param self this object
156 @param visualizer the visualizer object
157 @param node_index the node index
158 @param statistics_collector statistics collector class
160 InformationWindow.__init__(self)
162 parent=visualizer.window,
163 flags=Gtk.DialogFlags.DESTROY_WITH_PARENT,
164 buttons=(
"_Close", Gtk.ResponseType.CLOSE),
167 self.
winwin.set_title(
"Statistics for node %i" % node_index)
171 self.
viz_nodeviz_node = visualizer.get_node(node_index)
175 treeview = Gtk.TreeView(self.
table_modeltable_model)
177 self.
winwin.vbox.add(treeview)
179 def add_column(descr, colid):
180 column = Gtk.TreeViewColumn(descr, Gtk.CellRendererText(), text=colid)
181 treeview.append_column(column)
183 add_column(
"Interface", self.COLUMN_INTERFACE)
185 add_column(
"Tx Packets", self.COLUMN_TX_PACKETS)
186 add_column(
"Tx Bytes", self.COLUMN_TX_BYTES)
187 add_column(
"Tx pkt/1s", self.COLUMN_TX_PACKET_RATE)
188 add_column(
"Tx bit/1s", self.COLUMN_TX_BIT_RATE)
190 add_column(
"Rx Packets", self.COLUMN_RX_PACKETS)
191 add_column(
"Rx Bytes", self.COLUMN_RX_BYTES)
192 add_column(
"Rx pkt/1s", self.COLUMN_RX_PACKET_RATE)
193 add_column(
"Rx bit/1s", self.COLUMN_RX_BIT_RATE)
195 self.
visualizervisualizer.add_information_window(self)
200 Response callback function.
201 @param self this object
202 @param win the window
203 @param response the response
206 self.
winwin.destroy()
207 self.
visualizervisualizer.remove_information_window(self)
212 @param self this object
215 node = ns.NodeList.GetNode(self.
node_indexnode_index)
218 for iface, stats
in enumerate(stats_list):
220 netdevice = node.GetDevice(iface)
221 interface_name = ns.Names.FindName(netdevice)
222 if not interface_name:
223 interface_name =
"(interface %i)" % iface
226 self.COLUMN_INTERFACE,
228 self.COLUMN_TX_PACKETS,
229 str(stats.txPackets),
230 self.COLUMN_TX_BYTES,
232 self.COLUMN_TX_PACKET_RATE,
233 str(stats.txPacketRate),
234 self.COLUMN_TX_BIT_RATE,
235 str(stats.txBitRate),
236 self.COLUMN_RX_PACKETS,
237 str(stats.rxPackets),
238 self.COLUMN_RX_BYTES,
240 self.COLUMN_RX_PACKET_RATE,
241 str(stats.rxPacketRate),
242 self.COLUMN_RX_BIT_RATE,
243 str(stats.rxBitRate),
248 menu_item = Gtk.MenuItem(
"Show Interface Statistics")
251 def _show_it(dummy_menu_item):
254 menu_item.connect(
"activate", _show_it)
260 viz.connect(
"populate-node-menu", populate_node_menu, statistics_collector)
261 viz.connect(
"simulation-periodic-update", statistics_collector.simulation_periodic_update)
ShowInterfaceStatistics class.
def _response_cb(self, win, response)
Response callback function.
def update(self)
Update function.
def __init__(self, visualizer, node_index, statistics_collector)
Initializer.
statistics_collector
statistics collector
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)