Add NdnApplication class to handle start and stop
refs: #2909 Change-Id: Ibe5760b155e0edf2227d2d7146f8b6552149a63b
This commit is contained in:
1 parent
3a4afb19d5
commit
792c6aa970
3 files changed
+35
-43
No files matched your search
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
|
||||
class NdnApplication:
|
||||
def __init__(self, node):
|
||||
self.node = node
|
||||
self.isRunning = False
|
||||
|
||||
def start(self, command):
|
||||
if self.isRunning is True:
|
||||
try:
|
||||
os.kill(int(self.processId), 0)
|
||||
except OSError:
|
||||
self.isRunning = False
|
||||
|
||||
if self.isRunning is False:
|
||||
self.node.cmd(command)
|
||||
self.processId = self.node.cmd("echo $!")[:-1]
|
||||
|
||||
self.isRunning = True
|
||||
|
||||
def stop(self):
|
||||
if self.isRunning:
|
||||
self.node.cmd("sudo kill %s" % self.processId)
|
||||
|
||||
self.isRunning = False
|
||||
+5
-22
@@ -1,14 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import time
|
||||
from ndn.ndn_application import NdnApplication
|
||||
|
||||
class Nfd:
|
||||
class Nfd(NdnApplication):
|
||||
STRATEGY_BEST_ROUTE_V3 = "best-route/%FD%03"
|
||||
STRATEGY_NCC = "ncc"
|
||||
|
||||
def __init__(self, node):
|
||||
self.node = node
|
||||
self.isRunning = False
|
||||
NdnApplication.__init__(self, node)
|
||||
|
||||
self.logLevel = node.params["params"].get("nfd-log-level", "NONE")
|
||||
|
||||
@@ -43,25 +43,8 @@ class Nfd:
|
||||
node.cmd("export HOME=%s" % self.homeFolder)
|
||||
|
||||
def start(self):
|
||||
if self.isRunning is True:
|
||||
try:
|
||||
os.kill(int(self.processId), 0)
|
||||
except OSError:
|
||||
self.isRunning = False
|
||||
|
||||
if self.isRunning is False:
|
||||
self.node.cmd("sudo nfd --config %s 2>> %s &" % (self.confFile, self.logFile))
|
||||
self.processId = self.node.cmd("echo $!")[:-1]
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
self.isRunning = True
|
||||
|
||||
def stop(self):
|
||||
if self.isRunning is True:
|
||||
self.node.cmd("sudo kill %s" % self.processId)
|
||||
|
||||
self.isRunning = False
|
||||
NdnApplication.start(self, "sudo nfd --config %s 2>> %s &" % (self.confFile, self.logFile))
|
||||
time.sleep(2)
|
||||
|
||||
def setStrategy(self, name, strategy):
|
||||
self.node.cmd("nfdc set-strategy %s ndn:/localhost/nfd/strategy/%s" % (name, strategy))
|
||||
|
||||
+4
-21
@@ -1,12 +1,11 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
from ndn.ndn_application import NdnApplication
|
||||
|
||||
class Nlsr:
|
||||
class Nlsr(NdnApplication):
|
||||
def __init__(self, node):
|
||||
self.node = node
|
||||
NdnApplication.__init__(self, node)
|
||||
self.routerName = "/%sC1.Router/cs/%s" % ('%', node.name)
|
||||
self.confFile = "/tmp/%s/nlsr.conf" % node.name
|
||||
self.isRunning = False
|
||||
|
||||
# Make directory for log file
|
||||
self.logDir = "/tmp/%s/log" % node.name
|
||||
@@ -19,23 +18,7 @@ class Nlsr:
|
||||
node.cmd("sudo sed -i 's|prefix .*netlab|prefix /ndn/edu/%s|g' %s" % (node.name, self.confFile))
|
||||
|
||||
def start(self):
|
||||
if self.isRunning is True:
|
||||
try:
|
||||
os.kill(int(self.processId), 0)
|
||||
except OSError:
|
||||
self.isRunning = False
|
||||
|
||||
if self.isRunning is False:
|
||||
self.node.cmd("nlsr -d")
|
||||
self.processId = self.node.cmd("echo $!")[:-1]
|
||||
|
||||
self.isRunning = True
|
||||
|
||||
def stop(self):
|
||||
if self.isRunning:
|
||||
self.node.cmd("sudo kill %s" % self.processId)
|
||||
|
||||
self.isRunning = False
|
||||
NdnApplication.start(self, "nlsr -d")
|
||||
|
||||
class NlsrConfigGenerator:
|
||||
|
||||
|
||||
Reference in new issue
Block a user