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"
11 from gi.repository
import GooCanvas
14 from ns3.visualizer.base
import Link, transform_distance_canvas_to_simulation
15 except ModuleNotFoundError:
16 from visualizer.base import Link, transform_distance_canvas_to_simulation
33 def __init__(self, parent_canvas_item, sta, dev):
34 """! Initialize function.
35 @param self The object pointer.
36 @param parent_canvas_item: parent canvas
37 @param sta The STA node
44 self.
canvas_itemcanvas_item = GooCanvas.CanvasGroup(parent=parent_canvas_item)
48 visibility=GooCanvas.CanvasItemVisibility.HIDDEN,
53 stroke_color_rgba=0xC00000FF,
54 line_dash=GooCanvas.CanvasLineDash.newv([2.0, 2.0]),
65 @param self The object pointer.
69 if ap
is self.
node2node2:
71 if self.
node2node2
is not None:
72 self.
node2node2.remove_link(self)
74 if self.
node2node2
is None:
75 self.
canvas_itemcanvas_item.set_property(
"visibility", GooCanvas.CanvasItemVisibility.HIDDEN)
77 self.
node2node2.add_link(self)
78 self.
canvas_itemcanvas_item.set_property(
"visibility", GooCanvas.CanvasItemVisibility.VISIBLE)
82 """! Update points function.
83 @param self The object pointer.
86 if self.
node2node2
is None:
88 pos1_x, pos1_y = self.
node1node1.get_position()
89 pos2_x, pos2_y = self.
node2node2.get_position()
90 points = GooCanvas.CanvasPoints.new(2)
91 points.set_point(0, pos1_x, pos1_y)
92 points.set_point(1, pos2_x, pos2_y)
93 self.
visible_linevisible_line.set_property(
"points", points)
97 """! Destroy function.
98 @param self The object pointer.
102 self.
node1node1 =
None
103 self.
node2node2 =
None
106 """! Destroy function.
107 @param self The object pointer.
108 @param tooltip The tooltip.
111 pos1_x, pos1_y = self.
node1node1.get_position()
112 pos2_x, pos2_y = self.
node2node2.get_position()
116 mac = self.
devdev.GetMac()
119 "WiFi link between STA Node %i and AP Node %i; distance=%.2f m.\n"
123 % (self.
node1node1.node_index, self.
node2node2.node_index, d, mac.GetSsid(), mac.GetBssid())
134 """! Initialize function.
135 @param self The object pointer.
136 @param dummy_viz A dummy visualizer
142 """! Scan nodes function.
143 @param self The object pointer.
144 @param viz The visualizer object
147 for sta_netdevice, viz_node, wifi_link
in self.
stationsstations:
153 for node
in viz.nodes.values():
154 ns3_node = ns.network.NodeList.GetNode(node.node_index)
155 for devI
in range(ns3_node.GetNDevices()):
156 dev = ns3_node.GetDevice(devI)
157 if not isinstance(dev, ns.wifi.WifiNetDevice):
159 wifi_mac = dev.GetMac()
160 if isinstance(wifi_mac, ns.wifi.StaWifiMac):
161 wifi_link =
WifiLink(viz.links_group, node, dev)
162 self.
stationsstations.append((dev, node, wifi_link))
163 elif isinstance(wifi_mac, ns.wifi.ApWifiMac):
164 bssid = ns.network.Mac48Address.ConvertFrom(dev.GetAddress())
170 """! Simulation Periodic Update function.
171 @param self The object pointer.
172 @param viz The visualizer object
175 for sta_netdevice, viz_node, wifi_link
in self.
stationsstations:
176 if not sta_netdevice.IsLinkUp():
177 wifi_link.set_ap(
None)
179 bssid = str(sta_netdevice.GetMac().GetBssid())
180 if bssid ==
"00:00:00:00:00:00":
181 wifi_link.set_ap(
None)
187 """! Update View function.
188 @param self The object pointer.
189 @param viz The visualizer object
192 for dummy_sta_netdevice, dummy_viz_node, wifi_link
in self.
stationsstations:
193 if wifi_link
is not None:
194 wifi_link.update_points()
199 viz.connect(
"simulation-periodic-update", link_monitor.simulation_periodic_update)
200 viz.connect(
"update-view", link_monitor.update_view)
201 viz.connect(
"topology-scanned", link_monitor.scan_nodes)
canvas_item
parent_canvas_item
def destroy(self)
Destroy function.
def update_points(self)
Update points function.
def tooltip_query(self, tooltip)
Destroy function.
invisible_line
invisible line
def set_ap(self, ap)
Set AP.
def __init__(self, parent_canvas_item, sta, dev)
Initialize function.
def scan_nodes(self, viz)
Scan nodes function.
def simulation_periodic_update(self, viz)
Simulation Periodic Update function.
def __init__(self, dummy_viz)
Initialize function.
access_points
bssid -> node
def update_view(self, viz)
Update View function.
stations
list of (sta_netdevice, viz_node, wifi_link)
def transform_distance_canvas_to_simulation(d)