10 from kiwi.ui.objectlist
import ObjectList, Column
23 self.set_properties(hscrollbar_policy=gtk.POLICY_AUTOMATIC,
24 vscrollbar_policy=gtk.POLICY_AUTOMATIC)
30 def add_column(descr, colid):
31 column = gtk.TreeViewColumn(descr, gtk.CellRendererText(), text=colid)
32 treeview.append_column(column)
34 add_column(
"Time", self.COLUMN_TIME)
35 add_column(
"Interface", self.COLUMN_INTERFACE)
36 add_column(
"Size", self.COLUMN_SIZE)
37 add_column(
"Contents", self.COLUMN_CONTENTS)
40 self.table_model.clear()
41 for sample
in packet_list:
42 tree_iter = self.table_model.append()
43 if sample.device
is None:
44 interface_name =
"(unknown)"
46 interface_name = ns.core.Names.FindName(sample.device)
47 if not interface_name:
48 interface_name =
"(interface %i)" % sample.device.GetIfIndex()
49 self.table_model.set(tree_iter,
50 self.COLUMN_TIME, str(sample.time.GetSeconds()),
51 self.COLUMN_INTERFACE, interface_name,
52 self.COLUMN_SIZE, str(sample.packet.GetSize ()),
53 self.COLUMN_CONTENTS, str(sample.packet)
58 InformationWindow.__init__(self)
59 self.
win = gtk.Dialog(parent=visualizer.window,
60 flags=gtk.DIALOG_DESTROY_WITH_PARENT|gtk.DIALOG_NO_SEPARATOR,
61 buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
63 self.win.set_title(
"Last packets for node %i" % node_index)
65 self.
viz_node = visualizer.get_node(node_index)
66 self.
node = ns.network.NodeList.GetNode(node_index)
68 def smart_expand(expander, vbox):
69 if expander.get_expanded():
70 vbox.set_child_packing(expander, expand=
True, fill=
True, padding=0, pack_type=gtk.PACK_START)
72 vbox.set_child_packing(expander, expand=
False, fill=
False, padding=0, pack_type=gtk.PACK_START)
74 main_hbox = gtk.HBox(
False, 4)
76 main_vbox = gtk.VBox(
False, 4)
78 self.win.vbox.add(main_hbox)
79 main_hbox.add(main_vbox)
83 group = gtk.Expander(
"Last transmitted packets")
86 main_vbox.pack_start(group, expand=
False, fill=
False)
87 group.connect_after(
"activate", smart_expand, main_vbox)
91 group = gtk.Expander(
"Last received packets")
94 main_vbox.pack_start(group, expand=
False, fill=
False)
95 group.connect_after(
"activate", smart_expand, main_vbox)
99 group = gtk.Expander(
"Last dropped packets")
102 main_vbox.pack_start(group, expand=
False, fill=
False)
103 group.connect_after(
"activate", smart_expand, main_vbox)
110 self.packet_capture_options.numLastPackets = 100
112 packet_filter_vbox = gtk.VBox(
False, 4)
113 packet_filter_vbox.show()
114 main_hbox.add(packet_filter_vbox)
116 sel_buttons_box = gtk.HButtonBox()
117 sel_buttons_box.show()
118 packet_filter_vbox.pack_start(sel_buttons_box,
False,
False, 4)
119 select_all_button = gobject.new(gtk.Button, label=
"Sel. All", visible=
True)
120 select_none_button = gobject.new(gtk.Button, label=
"Sel. None", visible=
True)
121 sel_buttons_box.add(select_all_button)
122 sel_buttons_box.add(select_none_button)
125 Column(
'selected', title=
"Sel.", data_type=bool, editable=
True),
126 Column(
'name', title=
"Header"),
128 self.packet_filter_widget.show()
131 class TypeIdConfig(object):
132 __slots__ = [
'name',
'selected',
'typeid']
136 Header = ns.core.TypeId.LookupByName(
"ns3::Header")
137 Trailer = ns.core.TypeId.LookupByName(
"ns3::Trailer")
138 for typeid_i
in range(ns.core.TypeId.GetRegisteredN()):
139 typeid = ns.core.TypeId.GetRegistered(typeid_i)
144 if typeid_tmp == Header
or typeid_tmp == Trailer:
147 if typeid_tmp.HasParent():
148 typeid_tmp = typeid_tmp.GetParent()
153 if typeid
in [Header, Trailer]:
157 c.name = typeid.GetName()
159 self.packet_filter_list.append(c)
162 def update_capture_options():
163 if self.op_AND_button.props.active:
164 self.packet_capture_options.mode = ns.visualizer.PyViz.PACKET_CAPTURE_FILTER_HEADERS_AND
166 self.packet_capture_options.mode = ns.visualizer.PyViz.PACKET_CAPTURE_FILTER_HEADERS_OR
167 self.packet_capture_options.numLastPackets = 100
168 self.packet_capture_options.headers = [c.typeid
for c
in self.
packet_filter_list if c.selected]
169 self.visualizer.simulation.lock.acquire()
171 self.visualizer.simulation.sim_helper.SetPacketCaptureOptions(
174 self.visualizer.simulation.lock.release()
179 self.packet_filter_widget.refresh()
180 update_capture_options()
185 self.packet_filter_widget.refresh()
186 update_capture_options()
188 select_all_button.connect(
"clicked", sel_all_cb)
189 select_none_button.connect(
"clicked", sel_none_cb)
191 op_buttons_box = gtk.HButtonBox()
192 op_buttons_box.show()
193 packet_filter_vbox.pack_start(op_buttons_box,
False,
False, 4)
194 self.
op_AND_button = gobject.new(gtk.RadioButton, label=
"AND", visible=
True)
198 self.op_OR_button.props.active =
True
200 self.op_AND_button.connect(
"toggled",
lambda b: update_capture_options())
202 def cell_edited(l, obj, attribute):
203 update_capture_options()
204 self.packet_filter_widget.connect(
"cell-edited", cell_edited)
206 update_capture_options()
208 self.visualizer.add_information_window(self)
209 self.win.set_default_size(600, 300)
214 self.visualizer.remove_information_window(self)
217 last_packets = self.visualizer.simulation.sim_helper.GetLastPackets(self.node.GetId())
219 self.tx_list.update(self.
node, last_packets.lastTransmittedPackets)
220 self.rx_list.update(self.
node, last_packets.lastReceivedPackets)
221 self.drop_list.update(self.
node, last_packets.lastDroppedPackets)
225 menu_item = gtk.MenuItem(
"Show Last Packets")
228 def _show_it(dummy_menu_item):
231 menu_item.connect(
"activate", _show_it)
235 viz.connect(
"populate-node-menu", populate_node_menu)