-#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from util import _get_ipv4_protocol_guid, _get_node_guid, _get_dev_number
from nepi.core import testbed_impl
from nepi.core.attributes import Attribute
from constants import TESTBED_ID, TESTBED_VERSION
if factory_id in self.LOCAL_FACTORIES:
setattr(element, name, value)
elif not factory.box_attributes.is_attribute_metadata(name):
- ns3_value = self._to_ns3_value(guid, name, value)
- self._set_attribute(name, ns3_value, element)
+ if name == "Up":
+ ipv4_guid = _get_ipv4_protocol_guid(self, guid)
+ if not ipv4_guid in self._elements:
+ return
+ ipv4 = self._elements[ipv4_guid]
+ if value == False:
+ nint = ipv4.GetNInterfaces()
+ for i in xrange(0, nint):
+ ipv4.SetDown(i)
+ else:
+ nint = ipv4.GetNInterfaces()
+ for i in xrange(0, nint):
+ ipv4.SetUp(i)
+ else:
+ ns3_value = self._to_ns3_value(guid, name, value)
+ self._set_attribute(name, ns3_value, element)
def get(self, guid, name, time = TIME_NOW):
value = super(TestbedController, self).get(guid, name, time)
return getattr(element, name)
else:
return value
+ else:
+ if name == "Up":
+ ipv4_guid = _get_ipv4_protocol_guid(self, guid)
+ if not ipv4_guid in self._elements:
+ return True
+ ipv4 = self._elements[ipv4_guid]
+ nint = ipv4.GetNInterfaces()
+ value = True
+ for i in xrange(0, nint):
+ value = ipv4.IsUp(i)
+ if not value: break
+ return value
+
if factory.box_attributes.is_attribute_metadata(name):
return value
self._get_attribute(name, ns3_value, element)
value = ns3_value.SerializeToString(checker)
attr_type = factory.box_attributes.get_attribute_type(name)
+
if attr_type == Attribute.INTEGER:
return int(value)
if attr_type == Attribute.DOUBLE:
filename = self._traces[guid][trace_id]
return os.path.join(self.home_directory, filename)
+ def trace_filename(self, guid, trace_id):
+ return self._traces[guid][trace_id]
+
def follow_trace(self, guid, trace_id, filename):
if not guid in self._traces:
self._traces[guid] = dict()
for element in self._elements.itervalues():
if isinstance(element, self.LOCAL_TYPES):
# graceful shutdown of locally-implemented objects
- element.Cleanup()
+ element.cleanup()
if self.ns3:
if not self.ns3.Simulator.IsFinished():
self.stop()
# bool flag, a list is used as wrapper
has_event_occurred = [False]
condition.acquire()
- if not self.ns3.Simulator.IsFinished():
- self.ns3.Simulator.ScheduleWithContext(contextId, delay, execute_event,
- condition, has_event_occurred, func, *args)
- while not has_event_occurred[0] and not self.ns3.Simulator.IsFinished():
- condition.wait()
- condition.release()
+ try:
+ if not self.ns3.Simulator.IsFinished():
+ self.ns3.Simulator.ScheduleWithContext(contextId, delay, execute_event,
+ condition, has_event_occurred, func, *args)
+ while not has_event_occurred[0] and not self.ns3.Simulator.IsFinished():
+ condition.wait()
+ finally:
+ condition.release()
def _set_attribute(self, name, ns3_value, element):
if self.status() == TS.STATUS_STARTED: