fixed refactoring issues in mobility.py, fixed issue with parsing config files in a tuple string format
This commit is contained in:
parent
4d21314798
commit
05ce19b0c0
4 changed files with 24 additions and 15 deletions
|
@ -106,7 +106,9 @@ def maketuplefromstr(s, value_type):
|
||||||
:return: tuple from string
|
:return: tuple from string
|
||||||
:rtype: tuple
|
:rtype: tuple
|
||||||
"""
|
"""
|
||||||
return tuple(value_type(i) for i in s.split(","))
|
# remove tuple braces and strip commands and space from all values in the tuple string
|
||||||
|
values = [x.strip("' ") for x in s.strip("(), ").split(",")]
|
||||||
|
return tuple(value_type(i) for i in values)
|
||||||
|
|
||||||
|
|
||||||
def mutecall(*args, **kwargs):
|
def mutecall(*args, **kwargs):
|
||||||
|
|
|
@ -722,13 +722,13 @@ class WayPointMobility(WirelessModel):
|
||||||
nexttime = self.queue[0].time - now
|
nexttime = self.queue[0].time - now
|
||||||
if nexttime > (0.001 * self.refresh_ms):
|
if nexttime > (0.001 * self.refresh_ms):
|
||||||
nexttime -= 0.001 * self.refresh_ms
|
nexttime -= 0.001 * self.refresh_ms
|
||||||
self.session.evq.add_event(nexttime, self.runround)
|
self.session.event_loop.add_event(nexttime, self.runround)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# no more waypoints or queued items, loop?
|
# no more waypoints or queued items, loop?
|
||||||
if not self.empty_queue_stop:
|
if not self.empty_queue_stop:
|
||||||
# keep running every refresh_ms, even with empty queue
|
# keep running every refresh_ms, even with empty queue
|
||||||
self.session.evq.add_event(0.001 * self.refresh_ms, self.runround)
|
self.session.event_loop.add_event(0.001 * self.refresh_ms, self.runround)
|
||||||
return
|
return
|
||||||
if not self.loopwaypoints():
|
if not self.loopwaypoints():
|
||||||
return self.stop(move_initial=False)
|
return self.stop(move_initial=False)
|
||||||
|
@ -751,7 +751,7 @@ class WayPointMobility(WirelessModel):
|
||||||
self.session.mobility.updatewlans(moved, moved_netifs)
|
self.session.mobility.updatewlans(moved, moved_netifs)
|
||||||
|
|
||||||
# TODO: check session state
|
# TODO: check session state
|
||||||
self.session.evq.add_event(0.001 * self.refresh_ms, self.runround)
|
self.session.event_loop.add_event(0.001 * self.refresh_ms, self.runround)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1107,7 +1107,7 @@ class Ns2ScriptedMobility(WayPointMobility):
|
||||||
def findfile(self, file_name):
|
def findfile(self, file_name):
|
||||||
"""
|
"""
|
||||||
Locate a script file. If the specified file doesn't exist, look in the
|
Locate a script file. If the specified file doesn't exist, look in the
|
||||||
same directory as the scenario file (session.filename), or in the default
|
same directory as the scenario file, or in the default
|
||||||
configs directory (~/.core/configs). This allows for sample files without
|
configs directory (~/.core/configs). This allows for sample files without
|
||||||
absolute path names.
|
absolute path names.
|
||||||
|
|
||||||
|
@ -1118,8 +1118,8 @@ class Ns2ScriptedMobility(WayPointMobility):
|
||||||
if os.path.exists(file_name):
|
if os.path.exists(file_name):
|
||||||
return file_name
|
return file_name
|
||||||
|
|
||||||
if self.session.filename is not None:
|
if self.session.file_name is not None:
|
||||||
d = os.path.dirname(self.session.filename)
|
d = os.path.dirname(self.session.file_name)
|
||||||
sessfn = os.path.join(d, file_name)
|
sessfn = os.path.join(d, file_name)
|
||||||
if os.path.exists(sessfn):
|
if os.path.exists(sessfn):
|
||||||
return sessfn
|
return sessfn
|
||||||
|
@ -1163,7 +1163,7 @@ class Ns2ScriptedMobility(WayPointMobility):
|
||||||
try:
|
try:
|
||||||
return self.nodemap[nodenum]
|
return self.nodemap[nodenum]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.exception("error find value in node map")
|
logger.exception("error finding value in node map, ignored and returns node id")
|
||||||
return nodenum
|
return nodenum
|
||||||
|
|
||||||
def startup(self):
|
def startup(self):
|
||||||
|
@ -1186,7 +1186,7 @@ class Ns2ScriptedMobility(WayPointMobility):
|
||||||
self.movenodesinitial()
|
self.movenodesinitial()
|
||||||
logger.info("scheduling ns-2 script for %s autostart at %s" % (self.wlan.name, t))
|
logger.info("scheduling ns-2 script for %s autostart at %s" % (self.wlan.name, t))
|
||||||
self.state = self.STATE_RUNNING
|
self.state = self.STATE_RUNNING
|
||||||
self.session.evq.add_event(t, self.run)
|
self.session.event_loop.add_event(t, self.run)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -350,14 +350,17 @@ class CoreServices(ConfigurableManager):
|
||||||
:param bool use_startup_service: flag to use startup services or not
|
:param bool use_startup_service: flag to use startup services or not
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
logger.info("starting service %s (%s)(custom)" % (service._name, service._startindex))
|
logger.info("starting service(%s) %s (%s)(custom)",
|
||||||
|
service, service._name, service._startindex)
|
||||||
for directory in service._dirs:
|
for directory in service._dirs:
|
||||||
try:
|
try:
|
||||||
node.privatedir(directory)
|
node.privatedir(directory)
|
||||||
except:
|
except:
|
||||||
logger.exception("Error making node %s dir %s", node.name, directory)
|
logger.exception("error making node %s dir %s", node.name, directory)
|
||||||
|
|
||||||
|
logger.info("service configurations: %s", service._configs)
|
||||||
for i, filename in enumerate(service._configs):
|
for i, filename in enumerate(service._configs):
|
||||||
|
logger.info("generating service config: %s", filename)
|
||||||
if len(filename) == 0:
|
if len(filename) == 0:
|
||||||
continue
|
continue
|
||||||
cfg = self.getservicefiledata(service, filename)
|
cfg = self.getservicefiledata(service, filename)
|
||||||
|
|
|
@ -14,8 +14,11 @@ class Zebra(CoreService):
|
||||||
_name = "zebra"
|
_name = "zebra"
|
||||||
_group = "Quagga"
|
_group = "Quagga"
|
||||||
_dirs = ("/usr/local/etc/quagga", "/var/run/quagga")
|
_dirs = ("/usr/local/etc/quagga", "/var/run/quagga")
|
||||||
_configs = ("/usr/local/etc/quagga/Quagga.conf",
|
_configs = (
|
||||||
"quaggaboot.sh", "/usr/local/etc/quagga/vtysh.conf")
|
"/usr/local/etc/quagga/Quagga.conf",
|
||||||
|
"quaggaboot.sh",
|
||||||
|
"/usr/local/etc/quagga/vtysh.conf"
|
||||||
|
)
|
||||||
_startindex = 35
|
_startindex = 35
|
||||||
_startup = ("sh quaggaboot.sh zebra",)
|
_startup = ("sh quaggaboot.sh zebra",)
|
||||||
_shutdown = ("killall zebra",)
|
_shutdown = ("killall zebra",)
|
||||||
|
@ -33,7 +36,8 @@ class Zebra(CoreService):
|
||||||
elif filename == cls._configs[2]:
|
elif filename == cls._configs[2]:
|
||||||
return cls.generateVtyshConf(node, services)
|
return cls.generateVtyshConf(node, services)
|
||||||
else:
|
else:
|
||||||
raise ValueError
|
raise ValueError("file name (%s) is not a known configuration: %s",
|
||||||
|
filename, cls._configs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def generateVtyshConf(cls, node, services):
|
def generateVtyshConf(cls, node, services):
|
||||||
|
|
Loading…
Add table
Reference in a new issue