blob: 450c3740b5d9d180f1be8a198b86077c2763ec39 [file] [log] [blame]
Alexander Afanasyev864522f2012-05-31 13:33:57 -07001From 84d6db685c4ee5cbce89b4424c68f5d40c2b976b Mon Sep 17 00:00:00 2001
2From: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
3Date: Wed, 29 Feb 2012 16:59:59 -0800
4Subject: [PATCH] visualizer: Adding plugin to display a CCNx FIB state
5
6---
7 src/visualizer/visualizer/plugins/ccnx_fib.py | 89 +++++++++++++++++++++++++
8 1 file changed, 89 insertions(+)
9 create mode 100644 src/visualizer/visualizer/plugins/ccnx_fib.py
10
11diff --git a/src/visualizer/visualizer/plugins/ccnx_fib.py b/src/visualizer/visualizer/plugins/ccnx_fib.py
12new file mode 100644
13index 0000000..3f09212
14--- /dev/null
15+++ b/src/visualizer/visualizer/plugins/ccnx_fib.py
16@@ -0,0 +1,89 @@
17+import gtk
18+
19+import ns.core
20+import ns.network
21+import ns.internet
22+import ns.NDNabstraction
23+
24+from visualizer.base import InformationWindow
25+
26+class ShowCcnxFib(InformationWindow):
27+ (
28+ COLUMN_PREFIX,
29+ COLUMN_FACE
30+ ) = range(2)
31+
32+ def __init__(self, visualizer, node_index):
33+ InformationWindow.__init__(self)
34+ self.win = gtk.Dialog(parent=visualizer.window,
35+ flags=gtk.DIALOG_DESTROY_WITH_PARENT|gtk.DIALOG_NO_SEPARATOR,
36+ buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
37+ self.win.connect("response", self._response_cb)
38+
39+ self.node = ns.network.NodeList.GetNode (node_index)
40+ node_name = ns.core.Names.FindName (self.node)
41+
42+ title = "CCNx FIB for node %i" % node_index
43+ if len(node_name) != 0:
44+ title += " (" + str(node_name) + ")"
45+
46+ self.win.set_title (title)
47+ self.visualizer = visualizer
48+ self.node_index = node_index
49+
50+ self.table_model = gtk.ListStore(str, str, int)
51+
52+ treeview = gtk.TreeView(self.table_model)
53+ treeview.show()
54+ sw = gtk.ScrolledWindow()
55+ sw.set_properties(hscrollbar_policy=gtk.POLICY_AUTOMATIC,
56+ vscrollbar_policy=gtk.POLICY_AUTOMATIC)
57+ sw.show()
58+ sw.add(treeview)
59+ self.win.vbox.add(sw)
60+ self.win.set_default_size(600, 300)
61+
62+ # Dest.
63+ column = gtk.TreeViewColumn('Destination', gtk.CellRendererText(),
64+ text=self.COLUMN_PREFIX)
65+ treeview.append_column(column)
66+
67+ # Interface
68+ column = gtk.TreeViewColumn('faceType[nodeId](routingCost,status,metric)', gtk.CellRendererText(),
69+ text=self.COLUMN_FACE)
70+ treeview.append_column(column)
71+
72+ self.visualizer.add_information_window(self)
73+ self.win.show()
74+
75+ def _response_cb(self, win, response):
76+ self.win.destroy()
77+ self.visualizer.remove_information_window(self)
78+
79+ def update(self):
80+ ccnxFib = self.node.GetObject(ns.NDNabstraction.CcnxFib.GetTypeId())
81+
82+ if ccnxFib is None:
83+ return
84+
85+ self.table_model.clear()
86+
87+ for fibI in range(ccnxFib.GetCcnxFibEntryCount()):
88+ entry = ccnxFib.GetCcnxFibEntry(fibI)
89+ tree_iter = self.table_model.append()
90+ self.table_model.set(tree_iter,
91+ self.COLUMN_PREFIX, str(entry.GetPrefix()),
92+ self.COLUMN_FACE, str(entry))
93+
94+def populate_node_menu(viz, node, menu):
95+ menu_item = gtk.MenuItem("Show CCNx FIB")
96+ menu_item.show()
97+
98+ def _show_ccnx_fib(dummy_menu_item):
99+ ShowCcnxFib(viz, node.node_index)
100+
101+ menu_item.connect("activate", _show_ccnx_fib)
102+ menu.add(menu_item)
103+
104+def register(viz):
105+ viz.connect("populate-node-menu", populate_node_menu)
106--
1071.7.10.2
108