ndn: Add NLSR experiments
Change-Id: I0b86b121a5c8bf6a6e6e8df5027fe49561a9283b
diff --git a/ndn/nlsr.py b/ndn/nlsr.py
index de9ec86..03719e5 100644
--- a/ndn/nlsr.py
+++ b/ndn/nlsr.py
@@ -1,10 +1,12 @@
#!/usr/bin/env python
+import os
class Nlsr:
def __init__(self, node):
self.node = 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
@@ -17,8 +19,23 @@
node.cmd("sudo sed -i 's|prefix .*netlab|prefix /ndn/edu/%s|g' %s" % (node.name, self.confFile))
def start(self):
- self.node.cmd("nlsr -d")
+ 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
class NlsrConfigGenerator:
@@ -26,7 +43,7 @@
ROUTING_HYPERBOLIC = "hr"
def __init__(self, node, home):
- node.cmd("sudo cp %s/mn-ndn/ndn_utils/nlsr.conf nlsr.conf" % home)
+ node.cmd("sudo cp %s/mini-ndn/ndn_utils/nlsr.conf nlsr.conf" % home)
self.node = node
parameters = node.nlsrParameters