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