1 from gi.repository 
import Gtk
     6 NODE_STATISTICS_MEMORY = 10
    12     Collects interface statistics for all nodes.    23         __slots__ = [
'rxPackets', 
'rxBytes', 
'txPackets', 
'txBytes',
    24                      'rxPacketRate', 
'rxBitRate', 
'txPacketRate', 
'txBitRate']
    28         Collects interface statistics for all nodes.    29         @param self this object    30         @param visualizer visualizer object    37         Simulation Periodic Update function.    38         @param self this object    39         @param viz visualizer object    42         nodes_statistics = viz.simulation.sim_helper.GetNodesStatistics()
    43         for stats 
in nodes_statistics:
    49             raw_stats_list.append(stats.statistics)
    50             while len(raw_stats_list) > NODE_STATISTICS_MEMORY:
    55         Get interface statistics function.    56         @param self this object    58         @return the statistics    65         if len(raw_stats_list) < NODE_STATISTICS_MEMORY:
    67         assert len(raw_stats_list) == NODE_STATISTICS_MEMORY
    72         for iface, stats 
in enumerate(raw_stats_list[0]):
    73             tx_packets1.append(stats.transmittedPackets)
    74             tx_bytes1.append(stats.transmittedBytes)
    75             rx_packets1.append(stats.receivedPackets)
    76             rx_bytes1.append(stats.receivedBytes)
    80         k = self.
visualizer.sample_period*(NODE_STATISTICS_MEMORY-1)
    81         for iface, stats 
in enumerate(raw_stats_list[-1]):
    83             outStat.txPackets = stats.transmittedPackets
    84             outStat.txBytes = stats.transmittedBytes
    85             outStat.rxPackets = stats.receivedPackets
    86             outStat.rxBytes = stats.receivedBytes
    88             outStat.txPacketRate = (stats.transmittedPackets - tx_packets1[iface])/k
    89             outStat.rxPacketRate = (stats.receivedPackets - rx_packets1[iface])/k
    90             outStat.txBitRate = (stats.transmittedBytes - tx_bytes1[iface])*8/k
    91             outStat.rxBitRate = (stats.receivedBytes - rx_bytes1[iface])*8/k
    92             retval.append(outStat)
   115         COLUMN_TX_PACKET_RATE,
   120         COLUMN_RX_PACKET_RATE,
   125     def __init__(self, visualizer, node_index, statistics_collector):
   128         @param self this object   129         @param visualizer the visualizer object   130         @param node_index the node index   131         @param statistics_collector statistics collector class   133         InformationWindow.__init__(self)
   134         self.
win = Gtk.Dialog(parent=visualizer.window,
   135                               flags=Gtk.DialogFlags.DESTROY_WITH_PARENT,
   136                               buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
   138         self.
win.set_title(
"Statistics for node %i" % node_index)
   148         self.
win.vbox.add(treeview)
   150         def add_column(descr, colid):
   151             column = Gtk.TreeViewColumn(descr, Gtk.CellRendererText(), text=colid)
   152             treeview.append_column(column)
   154         add_column(
"Interface", self.COLUMN_INTERFACE)
   156         add_column(
"Tx Packets", self.COLUMN_TX_PACKETS)
   157         add_column(
"Tx Bytes", self.COLUMN_TX_BYTES)
   158         add_column(
"Tx pkt/1s", self.COLUMN_TX_PACKET_RATE)
   159         add_column(
"Tx bit/1s", self.COLUMN_TX_BIT_RATE)
   161         add_column(
"Rx Packets", self.COLUMN_RX_PACKETS)
   162         add_column(
"Rx Bytes", self.COLUMN_RX_BYTES)
   163         add_column(
"Rx pkt/1s", self.COLUMN_RX_PACKET_RATE)
   164         add_column(
"Rx bit/1s", self.COLUMN_RX_BIT_RATE)
   171         Response callback function.   172         @param self this object   173         @param win the window   174         @param response the response   178         self.
visualizer.remove_information_window(self)
   183         @param self this object   186         node = ns.network.NodeList.GetNode(self.
node_index)
   189         for iface, stats 
in enumerate(stats_list):
   191             netdevice = node.GetDevice(iface)
   192             interface_name = ns.core.Names.FindName(netdevice)
   193             if not interface_name:
   194                 interface_name = 
"(interface %i)" % iface
   196                                  self.COLUMN_INTERFACE, interface_name,
   198                                  self.COLUMN_TX_PACKETS, str(stats.txPackets),
   199                                  self.COLUMN_TX_BYTES, str(stats.txBytes),
   200                                  self.COLUMN_TX_PACKET_RATE, str(stats.txPacketRate),
   201                                  self.COLUMN_TX_BIT_RATE, str(stats.txBitRate),
   203                                  self.COLUMN_RX_PACKETS, str(stats.rxPackets),
   204                                  self.COLUMN_RX_BYTES, str(stats.rxBytes),
   205                                  self.COLUMN_RX_PACKET_RATE, str(stats.rxPacketRate),
   206                                  self.COLUMN_RX_BIT_RATE, str(stats.rxBitRate)
   212     menu_item = Gtk.MenuItem(
"Show Interface Statistics")
   215     def _show_it(dummy_menu_item):
   218     menu_item.connect(
"activate", _show_it)
   224     viz.connect(
"populate-node-menu", populate_node_menu, statistics_collector)
   225     viz.connect(
"simulation-periodic-update", statistics_collector.simulation_periodic_update)
 StatisticsCollector class. 
def __init__(self, visualizer)
node_statistics
node statistics 
def populate_node_menu(viz, node, menu, statistics_collector)
def simulation_periodic_update(self, viz)
Simulation Periodic Update function. 
statistics_collector
statistics collector 
ShowInterfaceStatistics class. 
def get_interface_statistics(self, nodeId)
Get interface statistics function. 
def __init__(self, visualizer, node_index, statistics_collector)
def _response_cb(self, win, response)
Response callback function. 
def update(self)
Update function.