PyViz: integrate Ipv4GlobalRouting entries into the results show by the ipv4_routing_table plugin.
This commit is contained in:
@@ -7,7 +7,9 @@ class ShowIpv4RoutingTable(InformationWindow):
|
||||
COLUMN_DESTINATION,
|
||||
COLUMN_NEXT_HOP,
|
||||
COLUMN_INTERFACE,
|
||||
) = range(3)
|
||||
COLUMN_TYPE,
|
||||
COLUMN_PRIO
|
||||
) = range(5)
|
||||
|
||||
def __init__(self, visualizer, node_index):
|
||||
InformationWindow.__init__(self)
|
||||
@@ -19,11 +21,17 @@ class ShowIpv4RoutingTable(InformationWindow):
|
||||
self.visualizer = visualizer
|
||||
self.node_index = node_index
|
||||
|
||||
self.table_model = gtk.ListStore(str, str, str)
|
||||
self.table_model = gtk.ListStore(str, str, str, str, int)
|
||||
|
||||
treeview = gtk.TreeView(self.table_model)
|
||||
treeview.show()
|
||||
self.win.vbox.add(treeview)
|
||||
sw = gtk.ScrolledWindow()
|
||||
sw.set_properties(hscrollbar_policy=gtk.POLICY_AUTOMATIC,
|
||||
vscrollbar_policy=gtk.POLICY_AUTOMATIC)
|
||||
sw.show()
|
||||
sw.add(treeview)
|
||||
self.win.vbox.add(sw)
|
||||
self.win.set_default_size(600, 300)
|
||||
|
||||
# Dest.
|
||||
column = gtk.TreeViewColumn('Destination', gtk.CellRendererText(),
|
||||
@@ -40,6 +48,16 @@ class ShowIpv4RoutingTable(InformationWindow):
|
||||
text=self.COLUMN_INTERFACE)
|
||||
treeview.append_column(column)
|
||||
|
||||
# Type
|
||||
column = gtk.TreeViewColumn('Type', gtk.CellRendererText(),
|
||||
text=self.COLUMN_TYPE)
|
||||
treeview.append_column(column)
|
||||
|
||||
# Prio
|
||||
column = gtk.TreeViewColumn('Prio', gtk.CellRendererText(),
|
||||
text=self.COLUMN_PRIO)
|
||||
treeview.append_column(column)
|
||||
|
||||
self.visualizer.add_information_window(self)
|
||||
self.win.show()
|
||||
|
||||
@@ -53,32 +71,40 @@ class ShowIpv4RoutingTable(InformationWindow):
|
||||
routing = ipv4.GetRoutingProtocol()
|
||||
if routing is None:
|
||||
return
|
||||
|
||||
routing_protocols = [] # list of (protocol, type_string, priority)
|
||||
|
||||
if isinstance(routing, ns3.Ipv4StaticRouting):
|
||||
ipv4_routing = routing
|
||||
ipv4_routing = routing_protocols.append((routing, "static", 0))
|
||||
elif isinstance(routing, ns3.Ipv4ListRouting):
|
||||
for rI in range(routing.GetNRoutingProtocols()):
|
||||
ipv4_routing, prio = routing.GetRoutingProtocol(rI)
|
||||
if isinstance(ipv4_routing, ns3.Ipv4StaticRouting):
|
||||
break
|
||||
else:
|
||||
return
|
||||
else:
|
||||
list_routing = routing
|
||||
for rI in range(list_routing.GetNRoutingProtocols()):
|
||||
routing, prio = list_routing.GetRoutingProtocol(rI)
|
||||
if isinstance(routing, ns3.Ipv4StaticRouting):
|
||||
routing_protocols.append((routing, "static", prio))
|
||||
elif isinstance(routing, ns3.Ipv4GlobalRouting):
|
||||
routing_protocols.append((routing, "global", prio))
|
||||
if not routing_protocols:
|
||||
return
|
||||
|
||||
self.table_model.clear()
|
||||
for routeI in range(ipv4_routing.GetNRoutes()):
|
||||
route = ipv4_routing.GetRoute(routeI)
|
||||
tree_iter = self.table_model.append()
|
||||
netdevice = ipv4.GetNetDevice(route.GetInterface())
|
||||
if netdevice is None:
|
||||
interface_name = 'lo'
|
||||
else:
|
||||
interface_name = ns3.Names.FindName(netdevice)
|
||||
if not interface_name:
|
||||
interface_name = "(interface %i)" % route.GetInterface()
|
||||
self.table_model.set(tree_iter,
|
||||
self.COLUMN_DESTINATION, str(route.GetDest()),
|
||||
self.COLUMN_NEXT_HOP, str(route.GetGateway()),
|
||||
self.COLUMN_INTERFACE, interface_name)
|
||||
for route_proto, type_string, prio in routing_protocols:
|
||||
for routeI in range(route_proto.GetNRoutes()):
|
||||
route = route_proto.GetRoute(routeI)
|
||||
tree_iter = self.table_model.append()
|
||||
netdevice = ipv4.GetNetDevice(route.GetInterface())
|
||||
if netdevice is None:
|
||||
interface_name = 'lo'
|
||||
else:
|
||||
interface_name = ns3.Names.FindName(netdevice)
|
||||
if not interface_name:
|
||||
interface_name = "(interface %i)" % route.GetInterface()
|
||||
self.table_model.set(tree_iter,
|
||||
self.COLUMN_DESTINATION, str(route.GetDest()),
|
||||
self.COLUMN_NEXT_HOP, str(route.GetGateway()),
|
||||
self.COLUMN_INTERFACE, interface_name,
|
||||
self.COLUMN_TYPE, type_string,
|
||||
self.COLUMN_PRIO, prio)
|
||||
|
||||
|
||||
def populate_node_menu(viz, node, menu):
|
||||
|
||||
Reference in New Issue
Block a user