1 from gi.repository
import GObject, Gtk
5 except ModuleNotFoundError:
7 "Error: ns3 Python module not found;"
8 " Python bindings may not be enabled"
9 " or your PYTHONPATH might not be properly configured"
13 from ns3.visualizer.base
import InformationWindow
14 except ModuleNotFoundError:
17 from kiwi.ui.objectlist
import Column, ObjectList
74 @param self this object
78 hscrollbar_policy=Gtk.PolicyType.AUTOMATIC,
79 vscrollbar_policy=Gtk.PolicyType.AUTOMATIC,
82 treeview = Gtk.TreeView(self.
table_modeltable_model)
86 def add_column(descr, colid):
87 column = Gtk.TreeViewColumn(descr, Gtk.CellRendererText(), text=colid)
88 treeview.append_column(column)
90 add_column(
"Time", self.COLUMN_TIME)
91 add_column(
"Interface", self.COLUMN_INTERFACE)
92 add_column(
"Size", self.COLUMN_SIZE)
93 add_column(
"Contents", self.COLUMN_CONTENTS)
98 @param self this object
100 @param packet_list packet list
104 for sample
in packet_list:
106 if sample.device
is None:
107 interface_name =
"(unknown)"
109 interface_name = ns.core.Names.FindName(sample.device)
110 if not interface_name:
111 interface_name =
"(interface %i)" % sample.device.GetIfIndex()
115 str(sample.time.GetSeconds()),
116 self.COLUMN_INTERFACE,
119 str(sample.packet.GetSize()),
120 self.COLUMN_CONTENTS,
127 @param self this object
128 @param visualizer the visualizer object
129 @param node_index the node index
131 InformationWindow.__init__(self)
133 parent=visualizer.window,
134 flags=Gtk.DialogFlags.DESTROY_WITH_PARENT,
135 buttons=(
"_Close", Gtk.ResponseType.CLOSE),
138 self.
winwin.set_title(
"Last packets for node %i" % node_index)
140 self.
viz_nodeviz_node = visualizer.get_node(node_index)
141 self.
nodenode = ns.network.NodeList.GetNode(node_index)
143 def smart_expand(expander, vbox):
144 if expander.get_expanded():
145 vbox.set_child_packing(
146 expander, expand=
True, fill=
True, padding=0, pack_type=Gtk.PACK_START
149 vbox.set_child_packing(
150 expander, expand=
False, fill=
False, padding=0, pack_type=Gtk.PACK_START
153 main_hbox = Gtk.HBox(
False, 4)
155 main_vbox = Gtk.VBox(
False, 4)
157 self.
winwin.vbox.add(main_hbox)
158 main_hbox.add(main_vbox)
162 group = Gtk.Expander(
"Last transmitted packets")
165 main_vbox.pack_start(group, expand=
False, fill=
False)
166 group.connect_after(
"activate", smart_expand, main_vbox)
170 group = Gtk.Expander(
"Last received packets")
173 main_vbox.pack_start(group, expand=
False, fill=
False)
174 group.connect_after(
"activate", smart_expand, main_vbox)
178 group = Gtk.Expander(
"Last dropped packets")
181 main_vbox.pack_start(group, expand=
False, fill=
False)
182 group.connect_after(
"activate", smart_expand, main_vbox)
190 packet_filter_vbox = Gtk.VBox(
False, 4)
191 packet_filter_vbox.show()
192 main_hbox.add(packet_filter_vbox)
194 sel_buttons_box = Gtk.HButtonBox()
195 sel_buttons_box.show()
196 packet_filter_vbox.pack_start(sel_buttons_box,
False,
False, 4)
197 select_all_button = GObject.new(Gtk.Button, label=
"Sel. All", visible=
True)
198 select_none_button = GObject.new(Gtk.Button, label=
"Sel. None", visible=
True)
199 sel_buttons_box.add(select_all_button)
200 sel_buttons_box.add(select_none_button)
204 Column(
"selected", title=
"Sel.", data_type=bool, editable=
True),
205 Column(
"name", title=
"Header"),
212 class TypeIdConfig(
object):
213 __slots__ = [
"name",
"selected",
"typeid"]
217 Header = ns.core.TypeId.LookupByName(
"ns3::Header")
218 Trailer = ns.core.TypeId.LookupByName(
"ns3::Trailer")
219 for typeid_i
in range(ns.core.TypeId.GetRegisteredN()):
220 typeid = ns.core.TypeId.GetRegistered(typeid_i)
225 if typeid_tmp == Header
or typeid_tmp == Trailer:
228 if typeid_tmp.HasParent():
229 typeid_tmp = typeid_tmp.GetParent()
234 if typeid
in [Header, Trailer]:
238 c.name = typeid.GetName()
243 def update_capture_options():
246 ns.visualizer.PyViz.PACKET_CAPTURE_FILTER_HEADERS_AND
250 ns.visualizer.PyViz.PACKET_CAPTURE_FILTER_HEADERS_OR
256 self.
visualizervisualizer.simulation.lock.acquire()
258 self.
visualizervisualizer.simulation.sim_helper.SetPacketCaptureOptions(
262 self.
visualizervisualizer.simulation.lock.release()
268 update_capture_options()
274 update_capture_options()
276 select_all_button.connect(
"clicked", sel_all_cb)
277 select_none_button.connect(
"clicked", sel_none_cb)
279 op_buttons_box = Gtk.HButtonBox()
280 op_buttons_box.show()
281 packet_filter_vbox.pack_start(op_buttons_box,
False,
False, 4)
282 self.
op_AND_buttonop_AND_button = GObject.new(Gtk.RadioButton, label=
"AND", visible=
True)
284 Gtk.RadioButton, label=
"OR", visible=
True, group=self.
op_AND_buttonop_AND_button
290 self.
op_AND_buttonop_AND_button.connect(
"toggled",
lambda b: update_capture_options())
292 def cell_edited(l, obj, attribute):
293 update_capture_options()
297 update_capture_options()
299 self.
visualizervisualizer.add_information_window(self)
300 self.
winwin.set_default_size(600, 300)
305 Response callback function
306 @param self this object
307 @param win the window
308 @param response the response
311 self.
winwin.destroy()
312 self.
visualizervisualizer.remove_information_window(self)
317 @param self this object
320 last_packets = self.
visualizervisualizer.simulation.sim_helper.GetLastPackets(self.
nodenode.GetId())
328 menu_item = Gtk.MenuItem(
"Show Last Packets")
331 def _show_it(dummy_menu_item):
334 menu_item.connect(
"activate", _show_it)
339 viz.connect(
"populate-node-menu", populate_node_menu)
def update(self, node, packet_list)
Update function.
tx_list
packet transmit list
packet_capture_options
packet capture options
def _response_cb(self, win, response)
Response callback function.
drop_list
packet drop list
rx_list
packet receive list
packet_filter_widget
packet filter widget
def update(self)
Update function.
def __init__(self, visualizer, node_index)
Initializer.
packet_filter_list
list of TypeIdConfig instances
def populate_node_menu(viz, node, menu)