A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
olsr.py
Go to the documentation of this file.
1from gi.repository import Gdk, Gtk
2
3try:
4 from ns3.visualizer.base import InformationWindow
5except ModuleNotFoundError:
6 from visualizer.base import InformationWindow
7
8
9## ShowOlsrRoutingTable class
11 ## @var win
12 # window
13 ## @var visualizer
14 # visualizer
15 ## @var node_index
16 # node index
17 ## @var table_model
18 # table model
19 ## @var _response_cb
20 # _response_cb function
21 ## @var COLUMN_DESTINATION
22 # COLUMN_DESTINATION constant
23 ## @var COLUMN_NEXT_HOP
24 # COLUMN_NEXT_HOP constant
25 ## @var COLUMN_INTERFACE
26 # COLUMN_INTERFACE constant
27 ## @var COLUMN_NUM_HOPS
28 # COLUMN_NUM_HOPS constant
29 (
30 COLUMN_DESTINATION,
31 COLUMN_NEXT_HOP,
32 COLUMN_INTERFACE,
33 COLUMN_NUM_HOPS,
34 ) = range(4)
35
36 def __init__(self, visualizer, node_index):
37 """!
38 Initializer
39 @param self this object
40 @param visualizer visualizer object
41 @param node_index the node index
42 """
43 InformationWindow.__init__(self)
44 self.win = Gtk.Dialog(
45 parent=visualizer.window,
46 flags=Gtk.DialogFlags.DESTROY_WITH_PARENT,
47 buttons=("_Close", Gtk.ResponseType.CLOSE),
48 )
49 self.win.set_default_size(Gdk.Screen.width() / 2, Gdk.Screen.height() / 2)
50 self.win.connect("response", self._response_cb_response_cb)
51 self.win.set_title("OLSR routing table for node %i" % node_index)
52 self.visualizer = visualizer
53 self.node_index = node_index
54
55 self.table_model = Gtk.ListStore(str, str, str, int)
56
57 treeview = Gtk.TreeView(self.table_model)
58 treeview.show()
59 sw = Gtk.ScrolledWindow()
60 sw.set_properties(
61 hscrollbar_policy=Gtk.PolicyType.AUTOMATIC, vscrollbar_policy=Gtk.PolicyType.AUTOMATIC
62 )
63 sw.show()
64 sw.add(treeview)
65 self.win.vbox.add(sw)
66
67 # Dest.
68 column = Gtk.TreeViewColumn(
69 "Destination", Gtk.CellRendererText(), text=self.COLUMN_DESTINATION
70 )
71 treeview.append_column(column)
72
73 # Next hop
74 column = Gtk.TreeViewColumn("Next hop", Gtk.CellRendererText(), text=self.COLUMN_NEXT_HOP)
75 treeview.append_column(column)
76
77 # Interface
78 column = Gtk.TreeViewColumn("Interface", Gtk.CellRendererText(), text=self.COLUMN_INTERFACE)
79 treeview.append_column(column)
80
81 # Num. Hops
82 column = Gtk.TreeViewColumn("Num. Hops", Gtk.CellRendererText(), text=self.COLUMN_NUM_HOPS)
83 treeview.append_column(column)
84
85 self.visualizer.add_information_window(self)
86 self.win.show()
87
88 def _response_cb(self, win, response):
89 """!
90 Initializer
91 @param self this object
92 @param win the window
93 @param response the response
94 @return none
95 """
96 self.win.destroy()
97 self.visualizer.remove_information_window(self)
98
99 def update(self):
100 """!
101 Update function
102 @param self this object
103 @return none
104 """
105 node = ns.NodeList.GetNode(self.node_index)
106 ipv4 = node.GetObject(ns.Ipv4.GetTypeId())
107 olsr = ns3_node.GetObject[ns.olsr.RoutingProtocol]()
108 if not olsr:
109 return
110
111 self.table_model.clear()
112 for route in olsr.__deref__().GetRoutingTableEntries():
113 tree_iter = self.table_model.append()
114 netdevice = ipv4.GetNetDevice(route.interface)
115 if netdevice is None:
116 interface_name = "lo"
117 else:
118 interface_name = ns.Names.FindName(netdevice)
119 if not interface_name:
120 interface_name = "(interface %i)" % route.interface
121 self.table_model.set(
122 tree_iter,
124 str(route.destAddr),
126 str(route.nextAddr),
128 interface_name,
130 route.distance,
131 )
132
133
134def populate_node_menu(viz, node, menu):
135 ns3_node = ns.NodeList.GetNode(node.node_index)
136 if not ns3_node.GetObject[ns.olsr.RoutingProtocol]():
137 print("No OLSR")
138 return
139
140 menu_item = Gtk.MenuItem("Show OLSR Routing Table")
141 menu_item.show()
142
143 def _show_ipv4_routing_table(dummy_menu_item):
144 ShowOlsrRoutingTable(viz, node.node_index)
145
146 menu_item.connect("activate", _show_ipv4_routing_table)
147 menu.add(menu_item)
148
149
150def register(viz):
151 viz.connect("populate-node-menu", populate_node_menu)
ShowOlsrRoutingTable class.
Definition olsr.py:10
node_index
node index
Definition olsr.py:53
visualizer
visualizer
Definition olsr.py:52
table_model
table model
Definition olsr.py:55
__init__(self, visualizer, node_index)
Initializer.
Definition olsr.py:36
_response_cb(self, win, response)
Initializer.
Definition olsr.py:88
update(self)
Update function.
Definition olsr.py:99
COLUMN_NUM_HOPS
COLUMN_NUM_HOPS constant.
Definition olsr.py:129
_response_cb
_response_cb function
Definition olsr.py:50
COLUMN_INTERFACE
COLUMN_INTERFACE constant.
Definition olsr.py:127
COLUMN_DESTINATION
COLUMN_DESTINATION constant.
Definition olsr.py:123
COLUMN_NEXT_HOP
COLUMN_NEXT_HOP constant.
Definition olsr.py:125
InformationWindow class.
Definition base.py:28
populate_node_menu(viz, node, menu)
Definition olsr.py:134
register(viz)
Definition olsr.py:150