experiments: Allow pinging a percentage of nodes
refs: #3265
Change-Id: I80a37d4a8cf6ca5a25d03f1f98cdcf9394feb92f
diff --git a/ndn/experiments/experiment.py b/ndn/experiments/experiment.py
index d6d5df7..385ff2a 100644
--- a/ndn/experiments/experiment.py
+++ b/ndn/experiments/experiment.py
@@ -23,6 +23,7 @@
import time
import sys
+from itertools import cycle
from ndn import ExperimentManager
@@ -34,6 +35,11 @@
self.convergenceTime = args["ctime"]
self.nPings = args["nPings"]
self.strategy = args["strategy"]
+ self.pctTraffic = float(args["pctTraffic"])
+
+ # Used to restart pings on the recovered node if any
+ self.pingedDict = {}
+
def start(self):
self.setup()
@@ -105,6 +111,36 @@
host.nfd.setStrategy("/ndn/edu", self.strategy)
host.cmd("ndnpingserver /ndn/edu/" + str(host) + " > ping-server &")
+ def startPctPings(self):
+ nNodesToPing = int(round(len(self.net.hosts)*self.pctTraffic))
+ print "Each node will ping %d node(s)" % nNodesToPing
+ # Temporarily store all the nodes being pinged by a particular node
+ nodesPingedList = []
+
+ for host in self.net.hosts:
+ # Create a circular list
+ pool = cycle(self.net.hosts)
+
+ # Move iterator to current node
+ next(x for x in pool if host.name == x.name)
+
+ # Track number of nodes to ping scheduled for this node
+ nNodesScheduled = 0
+
+ while nNodesScheduled < nNodesToPing:
+ other = pool.next()
+
+ # Do not ping self
+ if host.name != other.name:
+ self.ping(host, other, self.nPings)
+ nodesPingedList.append(other)
+
+ # Always increment because in 100% case a node should not ping itself
+ nNodesScheduled = nNodesScheduled + 1
+
+ self.pingedDict[host] = nodesPingedList
+ nodesPingedList = []
+
@staticmethod
def register(name, experimentClass):
ExperimentManager.register(name, experimentClass)