A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4_routing_table.py
Go to the documentation of this file.
1from gi.repository import Gtk
2
3from visualizer.base import InformationWindow
4
5
7
15 (
16 COLUMN_DESTINATION,
17 COLUMN_NEXT_HOP,
18 COLUMN_INTERFACE,
19 COLUMN_TYPE,
20 COLUMN_PRIO
21 ) = range(5)
22
23 def __init__(self, visualizer, node_index):
24 """!
25 Initializer
26 @param self this object
27 @param visualizer visualizer object
28 @param node_index the node index
29 """
30 InformationWindow.__init__(self)
31 self.win = Gtk.Dialog(parent=visualizer.window,
32 flags=Gtk.DialogFlags.DESTROY_WITH_PARENT,
33 buttons=("_Close", Gtk.ResponseType.CLOSE))
34 self.win.connect("response", self._response_cb)
35 self.win.set_title("IPv4 routing table for node %i" % node_index)
36 self.visualizer = visualizer
37 self.node_index = node_index
38
39 self.table_model = Gtk.ListStore(str, str, str, str, int)
40
41 treeview = Gtk.TreeView(self.table_model)
42 treeview.show()
43 sw = Gtk.ScrolledWindow()
44 sw.set_properties(hscrollbar_policy=Gtk.PolicyType.AUTOMATIC,
45 vscrollbar_policy=Gtk.PolicyType.AUTOMATIC)
46 sw.show()
47 sw.add(treeview)
48 self.win.vbox.add(sw)
49 self.win.set_default_size(600, 300)
50
51 # Dest.
52 column = Gtk.TreeViewColumn('Destination', Gtk.CellRendererText(),
53 text=self.COLUMN_DESTINATION)
54 treeview.append_column(column)
55
56 # Next hop
57 column = Gtk.TreeViewColumn('Next hop', Gtk.CellRendererText(),
58 text=self.COLUMN_NEXT_HOP)
59 treeview.append_column(column)
60
61 # Interface
62 column = Gtk.TreeViewColumn('Interface', Gtk.CellRendererText(),
63 text=self.COLUMN_INTERFACE)
64 treeview.append_column(column)
65
66 # Type
67 column = Gtk.TreeViewColumn('Type', Gtk.CellRendererText(),
68 text=self.COLUMN_TYPE)
69 treeview.append_column(column)
70
71 # Prio
72 column = Gtk.TreeViewColumn('Prio', Gtk.CellRendererText(),
73 text=self.COLUMN_PRIO)
74 treeview.append_column(column)
75
76 self.visualizer.add_information_window(self)
77 self.win.show()
78
79 def _response_cb(self, win, response):
80 """!
81 Response callback function
82 @param self this object
83 @param win the window
84 @param response the response
85 @return none
86 """
87 self.win.destroy()
88 self.visualizer.remove_information_window(self)
89
90 def update(self):
91 """!
92 Update function
93 @param self this object
94 @return none
95 """
96 node = ns.NodeList.GetNode(self.node_index)
97 ipv4 = ns.cppyy.gbl.getNodeIpv4(node)
98 routing = ipv4.GetRoutingProtocol()
99 if routing is None:
100 return
101
102 routing_protocols = [] # list of (protocol, type_string, priority)
103
104 if isinstance(routing, ns.Ipv4StaticRouting):
105 ipv4_routing = routing_protocols.append((routing, "static", 0))
106 elif isinstance(routing, ns.Ipv4ListRouting):
107 list_routing = routing
108 for rI in range(list_routing.GetNRoutingProtocols()):
109 routing, prio = list_routing.GetRoutingProtocol(rI)
110 if isinstance(routing, ns.Ipv4StaticRouting):
111 routing_protocols.append((routing, "static", prio))
112 elif isinstance(routing, ns.Ipv4GlobalRouting):
113 routing_protocols.append((routing, "global", prio))
114 if not routing_protocols:
115 return
116
117 self.table_model.clear()
118 for route_proto, type_string, prio in routing_protocols:
119 for routeI in range(route_proto.GetNRoutes()):
120 route = route_proto.GetRoute(routeI)
121 tree_iter = self.table_model.append()
122 netdevice = ipv4.GetNetDevice(route.GetInterface())
123 if netdevice is None:
124 interface_name = 'lo'
125 else:
126 interface_name = ns.Names.FindName(netdevice)
127 if not interface_name:
128 interface_name = "(interface %i)" % route.GetInterface()
129 self.table_model.set(tree_iter,
130 self.COLUMN_DESTINATION, str(route.GetDest()),
131 self.COLUMN_NEXT_HOP, str(route.GetGateway()),
132 self.COLUMN_INTERFACE, interface_name,
133 self.COLUMN_TYPE, type_string,
134 self.COLUMN_PRIO, prio)
135
136
137def populate_node_menu(viz, node, menu):
138 menu_item = Gtk.MenuItem("Show IPv4 Routing Table")
139 menu_item.show()
140
141 def _show_ipv4_routing_table(dummy_menu_item):
142 ShowIpv4RoutingTable(viz, node.node_index)
143
144 menu_item.connect("activate", _show_ipv4_routing_table)
145 menu.add(menu_item)
146
147def register(viz):
148 viz.connect("populate-node-menu", populate_node_menu)
def _response_cb(self, win, response)
Response callback function.
def __init__(self, visualizer, node_index)
Initializer.
InformationWindow class.
Definition: base.py:25
def populate_node_menu(viz, node, menu)