Arbitrary arguments
refs: #4360
Change-Id: I1c746c3349a72d1e262b75d4a864f096a2dfc018
diff --git a/ndn/experiment_manager.py b/ndn/experiment_manager.py
index f505646..5f2a174 100644
--- a/ndn/experiment_manager.py
+++ b/ndn/experiment_manager.py
@@ -35,6 +35,7 @@
def __init__(self):
self.experiments = {}
+ self.expArgs = {}
def loadModules(self):
currentDir = os.path.dirname(__file__)
@@ -51,6 +52,12 @@
def register(self, name, experimentClass):
if name not in self.experiments:
self.experiments[name] = experimentClass
+ try:
+ helpStr = experimentClass.arguments()
+ if type(helpStr) is str:
+ self.expArgs[name] = experimentClass.arguments()
+ except:
+ pass
else:
raise _ExperimentManager.Error("Experiment '%s' has already been registered" % name)
@@ -84,3 +91,8 @@
experimentNames.append(key)
return experimentNames
+
+def getExperimentArgs():
+ manager = __getInstance()
+
+ return manager.expArgs
diff --git a/ndn/experiments/arbitrary_arguments_experiment.py b/ndn/experiments/arbitrary_arguments_experiment.py
new file mode 100644
index 0000000..159e2a7
--- /dev/null
+++ b/ndn/experiments/arbitrary_arguments_experiment.py
@@ -0,0 +1,32 @@
+from ndn.experiments.experiment import Experiment
+
+class AbitraryArgumentsExperiment(Experiment):
+ def __init__(self, args):
+ Experiment.__init__(self, args)
+ if "ds" in self.arbArgs:
+ self.ds = int(self.arbArgs["ds"])
+ else:
+ self.ds = 1000
+
+ if "logging" in self.arbArgs:
+ self.logging = self.arbArgs["logging"]
+ if self.logging == "true":
+ self.logging = True
+ else:
+ self.logging = False
+ else:
+ self.logging = False
+
+ def setup(self):
+ pass
+
+ def run(self):
+ print("Argument ds: {}".format(self.ds))
+ print("Argument logging: {}".format(self.logging))
+
+ @staticmethod
+ def arguments():
+ ''' This will be printed in sudo minindn --list-experiments'''
+ return "--ds <num-data-streams> --logging <true/false>"
+
+Experiment.register("arbitrary-arguments", AbitraryArgumentsExperiment)
\ No newline at end of file
diff --git a/ndn/experiments/experiment.py b/ndn/experiments/experiment.py
index 4be2aac..23efebd 100644
--- a/ndn/experiments/experiment.py
+++ b/ndn/experiments/experiment.py
@@ -36,6 +36,7 @@
self.strategy = args["strategy"]
self.pctTraffic = args["pctTraffic"]
self.nlsrSecurity = args["nlsrSecurity"]
+ self.arbArgs = args["arbArgs"]
# Used to restart pings on the recovered node if any
self.pingedDict = {}