Create a helper class to provide a wrapper around nfdc.
Refs #3491
Change-Id: I2cc7cbb480a6ca81ee32bbfee47ef060dd8c51f4
diff --git a/bin/minindn b/bin/minindn
index f4cdf4e..eda63de 100755
--- a/bin/minindn
+++ b/bin/minindn
@@ -73,6 +73,9 @@
from ndn.remote_ndn_link import RemoteNdnLink, RemoteGRENdnLink
from ndn.placer import GuidedPlacer, PopulatePlacement
from ndn.util import ssh, scp, MiniNDNCLI
+from ndn.nlsr import Nlsr, NlsrConfigGenerator
+from ndn.nfd import Nfd
+from ndn.apps.nfdc import Nfdc
import os.path, time
import shutil
@@ -86,9 +89,6 @@
from functools import partial
import re
-from ndn.nlsr import Nlsr, NlsrConfigGenerator
-from ndn.nfd import Nfd
-
try:
import argcomplete
except ImportError:
@@ -470,7 +470,7 @@
"net": net,
"ctime": options.ctime,
"nPings": options.nPings,
- "strategy": Nfd.STRATEGY_BEST_ROUTE,
+ "strategy": Nfdc.STRATEGY_BEST_ROUTE,
"pctTraffic": options.pctTraffic,
"nlsrSecurity": options.nlsrSecurity,
"workDir": options.workDir,
diff --git a/ndn/apps/nfdc.py b/ndn/apps/nfdc.py
new file mode 100644
index 0000000..2d38530
--- /dev/null
+++ b/ndn/apps/nfdc.py
@@ -0,0 +1,73 @@
+# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+#
+# Copyright (C) 2015-2018, The University of Memphis,
+# Arizona Board of Regents,
+# Regents of the University of California.
+#
+# This file is part of Mini-NDN.
+# See AUTHORS.md for a complete list of Mini-NDN authors and contributors.
+#
+# Mini-NDN is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Mini-NDN is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Mini-NDN, e.g., in COPYING.md file.
+# If not, see <http://www.gnu.org/licenses/>.
+
+import time
+
+class Nfdc:
+ STRATEGY_ASF = "asf"
+ STRATEGY_BEST_ROUTE = "best-route"
+ STRATEGY_MULTICAST = "multicast"
+ STRATEGY_NCC = "ncc"
+
+ @staticmethod
+ def registerRoute(node, namePrefix, remoteNode, origin=255, cost=0,
+ inheritFlag=True, captureFlag=False, expirationInMillis=0):
+ node.cmd("nfdc route add {} {} {} {} {}{}{}").format(
+ namePrefix,
+ remoteNode,
+ origin,
+ cost,
+ "no-inherit " if not inheritFlag else "",
+ "capture " if captureFlag else "",
+ "expires {}".format(expirationInMillis)
+ )
+ time.sleep(0.5)
+
+ @staticmethod
+ def unregisterRoute(node, namePrefix, remoteNode, origin=255):
+ node.cmd("nfdc route remove {} {} {}".format(namePrefix, remoteNode, origin))
+ time.sleep(0.5)
+
+ @staticmethod
+ def createFace(node, remoteNode, protocol="udp", isPermanent=False):
+ node.cmd("nfdc face create {}://{} {}".format(
+ protocol,
+ remoteNode,
+ "permanent" if isPermanent else "persistent"
+ ))
+ time.sleep(0.5)
+
+ @staticmethod
+ def destroyFace(node, remoteNode, protocol="udp"):
+ node.cmd("nfdc face destroy {}://{}".format(protocol, remoteNode))
+ time.sleep(0.5)
+
+ @staticmethod
+ def setStrategy(node, namePrefix, strategy):
+ node.cmd("nfdc strategy set {} ndn:/localhost/nfd/strategy/{}".format(namePrefix, strategy))
+ time.sleep(0.5)
+
+ @staticmethod
+ def unsetStrategy(node, namePrefix):
+ node.cmd("nfdc strategy unset {}".format(namePrefix))
+ time.sleep(0.5)
\ No newline at end of file
diff --git a/ndn/experiments/experiment.py b/ndn/experiments/experiment.py
index fa76370..347655d 100644
--- a/ndn/experiments/experiment.py
+++ b/ndn/experiments/experiment.py
@@ -27,6 +27,7 @@
from itertools import cycle
from ndn import ExperimentManager
+from ndn.apps.nfdc import Nfdc
class Experiment:
@@ -49,10 +50,10 @@
def setup(self):
for host in self.net.hosts:
# Set strategy
- host.nfd.setStrategy("/ndn/", self.strategy)
+ Nfdc.setStrategy(host, "/ndn/", self.strategy)
# Start ping server
- host.cmd("ndnpingserver /ndn/" + str(host) + "-site/" + str(host) + " > ping-server &")
+ host.cmd("ndnpingserver /ndn/{}-site/{} > ping-server &".format(host, host))
# Create folder to store ping data
host.cmd("mkdir ping-data")
@@ -108,8 +109,8 @@
host.nfd.start()
host.nlsr.createFaces()
host.nlsr.start()
- host.nfd.setStrategy("/ndn/", self.strategy)
- host.cmd("ndnpingserver /ndn/" + str(host) + "-site/" + str(host) + " > ping-server &")
+ Nfdc.setStrategy(host, "/ndn/", self.strategy)
+ host.cmd("ndnpingserver /ndn/{}-site/{} > ping-server &".format(host, host))
def startPctPings(self):
nNodesToPing = int(round(len(self.net.hosts)*self.pctTraffic))
diff --git a/ndn/nfd.py b/ndn/nfd.py
index 0368523..eb8cb34 100644
--- a/ndn/nfd.py
+++ b/ndn/nfd.py
@@ -26,8 +26,6 @@
from ndn.util import copyExistentFile
class Nfd(NdnApplication):
- STRATEGY_BEST_ROUTE = "best-route"
- STRATEGY_NCC = "ncc"
def __init__(self, node, csSize):
NdnApplication.__init__(self, node)
@@ -71,7 +69,3 @@
def start(self):
NdnApplication.start(self, "setsid nfd --config {} > {} 2>&1 &".format(self.confFile, self.logFile))
time.sleep(2)
-
- def setStrategy(self, name, strategy):
- self.node.cmd("nfdc strategy set {} ndn:/localhost/nfd/strategy/{}".format(name, strategy))
- time.sleep(0.5)
\ No newline at end of file
diff --git a/ndn/nlsr.py b/ndn/nlsr.py
index b6a6009..98efc78 100644
--- a/ndn/nlsr.py
+++ b/ndn/nlsr.py
@@ -26,6 +26,7 @@
from ndn.ndn_application import NdnApplication
from ndn.util import ssh, scp, copyExistentFile
+from apps.nfdc import Nfdc
import shutil
import os
@@ -41,8 +42,8 @@
self.node = node
self.neighbors = neighbors
self.faceType = faceType
- self.routerName = "/%sC1.Router/cs/%s" % ('%', node.name)
- self.confFile = "%s/nlsr.conf" % node.homeFolder
+ self.routerName = "/{}C1.Router/cs/{}".format('%', node.name)
+ self.confFile = "{}/nlsr.conf".format(node.homeFolder)
# Make directory for log file
self.logDir = "{}/log".format(node.homeFolder)
@@ -58,7 +59,7 @@
def createFaces(self):
for ip in self.neighbors:
- self.node.cmd("nfdc face create {}://{} permanent".format(self.faceType, ip))
+ Nfdc.createFace(self.node, ip, self.faceType, isPermanent=True)
@staticmethod
def createKey(host, name, outputFile):