A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
base.py
Go to the documentation of this file.
1
import
os.path
2
import
sys
3
4
from
gi.repository
import
GObject
5
6
PIXELS_PER_METER = 3.0
# pixels-per-meter, at 100% zoom level
7
8
9
## PyVizObject class
10
class
PyVizObject
(GObject.GObject):
11
## global type name
12
__gtype_name__ =
"PyVizObject"
13
14
## Returns tooltip text string.
15
#
16
## @param tooltip: tooltip object.
17
## @return: Tooltip text.
18
def
tooltip_query
(self, tooltip):
19
tooltip.set_text(
"TODO: tooltip for %r"
% self)
20
21
22
## Link class
23
class
Link
(
PyVizObject
):
24
pass
25
26
27
## InformationWindow class
28
class
InformationWindow(
object
):
29
## update function
30
#
31
## @return: NotImplementedError exception
32
def
update
(self):
33
raise
NotImplementedError
34
35
36
## NetDeviceTraits class
37
class
NetDeviceTraits
(
object
):
38
## class variables
39
## @var is_wireless
40
# is wireless
41
## @var is_virtual
42
# is virtual
43
def
__init__
(self, is_wireless=None, is_virtual=False):
44
"""!
45
Initialize function.
46
@param self The current class
47
@param is_wireless is wireless flag
48
@param is_virtual is virtual flag
49
"""
50
assert
is_virtual
or
is_wireless
is
not
None
51
self.
is_wireless
= is_wireless
52
self.
is_virtual
= is_virtual
53
54
55
netdevice_traits = {
56
ns.PointToPointNetDevice:
NetDeviceTraits
(is_wireless=
False
),
57
ns.CsmaNetDevice:
NetDeviceTraits
(is_wireless=
False
),
58
ns.WifiNetDevice:
NetDeviceTraits
(is_wireless=
True
),
59
ns.BridgeNetDevice:
NetDeviceTraits
(is_virtual=
True
),
60
ns.LoopbackNetDevice:
NetDeviceTraits
(is_virtual=
True
, is_wireless=
False
),
61
ns.MeshPointDevice:
NetDeviceTraits
(is_virtual=
True
),
62
ns.SubscriberStationNetDevice:
NetDeviceTraits
(is_wireless=
True
),
63
ns.BaseStationNetDevice:
NetDeviceTraits
(is_wireless=
True
),
64
ns.LteUeNetDevice:
NetDeviceTraits
(is_wireless=
True
),
65
ns.LteEnbNetDevice:
NetDeviceTraits
(is_wireless=
True
),
66
}
67
68
69
def
lookup_netdevice_traits
(class_type):
70
try
:
71
return
netdevice_traits[class_type]
72
except
KeyError:
73
sys.stderr.write(
74
"WARNING: no NetDeviceTraits registered for device type %r; "
75
"I will assume this is a non-virtual wireless device, "
76
"but you should edit %r, variable 'netdevice_traits',"
77
" to make sure.\n"
% (class_type.__name__, __file__)
78
)
79
t =
NetDeviceTraits
(is_virtual=
False
, is_wireless=
True
)
80
netdevice_traits[class_type] = t
81
return
t
82
83
84
def
transform_distance_simulation_to_canvas
(d):
85
return
d * PIXELS_PER_METER
86
87
88
def
transform_point_simulation_to_canvas
(x, y):
89
return
x * PIXELS_PER_METER, y * PIXELS_PER_METER
90
91
92
def
transform_distance_canvas_to_simulation
(d):
93
return
d / PIXELS_PER_METER
94
95
96
def
transform_point_canvas_to_simulation
(x, y):
97
return
x / PIXELS_PER_METER, y / PIXELS_PER_METER
98
99
100
plugins = []
101
plugin_modules = {}
102
103
104
def
register_plugin
(plugin_init_func, plugin_name=None, plugin_module=None):
105
"""
106
Register a plugin.
107
108
@param plugin: a callable object that will be invoked whenever a
109
Visualizer object is created, like this: plugin(visualizer)
110
"""
111
assert
callable(plugin_init_func)
112
plugins.append(plugin_init_func)
113
if
plugin_module
is
not
None
:
114
plugin_modules[plugin_name] = plugin_module
115
116
117
plugins_loaded =
False
118
119
120
def
load_plugins
():
121
global
plugins_loaded
122
if
plugins_loaded:
123
return
124
plugins_loaded =
True
125
plugins_dir = os.path.join(os.path.dirname(__file__),
"plugins"
)
126
old_path = list(sys.path)
127
sys.path.insert(0, plugins_dir)
128
for
filename
in
os.listdir(plugins_dir):
129
name, ext = os.path.splitext(filename)
130
if
ext !=
".py"
:
131
continue
132
try
:
133
plugin_module = __import__(name)
134
except
ImportError
as
ex:
135
print(
"Could not load plugin %r: %s"
% (filename, str(ex)), file=sys.stderr)
136
continue
137
try
:
138
plugin_func = plugin_module.register
139
except
AttributeError:
140
print(
"Plugin %r has no 'register' function"
% name, file=sys.stderr)
141
else
:
142
# print("Plugin %r registered" % name, file=sys.stderr)
143
register_plugin(plugin_func, name, plugin_module)
144
sys.path = old_path
object
visualizer.base.InformationWindow.update
update(self)
update function
Definition
base.py:32
visualizer.base.Link
Link class.
Definition
base.py:23
visualizer.base.NetDeviceTraits
NetDeviceTraits class.
Definition
base.py:37
visualizer.base.NetDeviceTraits.__init__
__init__(self, is_wireless=None, is_virtual=False)
Initialize function.
Definition
base.py:43
visualizer.base.NetDeviceTraits.is_wireless
is_wireless
class variablesis wireless
Definition
base.py:51
visualizer.base.NetDeviceTraits.is_virtual
is_virtual
is virtual
Definition
base.py:52
visualizer.base.PyVizObject
PyVizObject class.
Definition
base.py:10
visualizer.base.PyVizObject.tooltip_query
tooltip_query(self, tooltip)
Returns tooltip text string.
Definition
base.py:18
visualizer.base.transform_distance_canvas_to_simulation
transform_distance_canvas_to_simulation(d)
Definition
base.py:92
visualizer.base.transform_point_canvas_to_simulation
transform_point_canvas_to_simulation(x, y)
Definition
base.py:96
visualizer.base.transform_distance_simulation_to_canvas
transform_distance_simulation_to_canvas(d)
Definition
base.py:84
visualizer.base.lookup_netdevice_traits
lookup_netdevice_traits(class_type)
Definition
base.py:69
visualizer.base.load_plugins
load_plugins()
Definition
base.py:120
visualizer.base.transform_point_simulation_to_canvas
transform_point_simulation_to_canvas(x, y)
Definition
base.py:88
visualizer.base.register_plugin
register_plugin(plugin_init_func, plugin_name=None, plugin_module=None)
Definition
base.py:104
src
visualizer
visualizer
base.py
Generated on Fri Nov 8 2024 13:59:07 for ns-3 by
1.11.0