ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import time |
| 4 | import sys |
| 5 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 6 | from ndn import ExperimentManager |
| 7 | |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 8 | class Experiment: |
| 9 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 10 | def __init__(self, args): |
| 11 | self.net = args["net"] |
| 12 | self.nodes = args["nodes"] |
| 13 | self.convergenceTime = args["ctime"] |
| 14 | self.nPings = args["nPings"] |
| 15 | self.strategy = args["strategy"] |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 16 | |
| 17 | def start(self): |
| 18 | self.setup() |
| 19 | self.run() |
| 20 | |
| 21 | def setup(self): |
| 22 | for host in self.net.hosts: |
| 23 | # Set strategy |
| 24 | host.nfd.setStrategy("/ndn/edu", self.strategy) |
| 25 | |
| 26 | # Start ping server |
| 27 | host.cmd("ndnpingserver /ndn/edu/" + str(host) + " > ping-server &") |
| 28 | |
| 29 | # Create folder to store ping data |
| 30 | host.cmd("mkdir ping-data") |
| 31 | |
| 32 | # Wait for convergence time period |
| 33 | print "Waiting " + str(self.convergenceTime) + " seconds for convergence..." |
| 34 | time.sleep(self.convergenceTime) |
| 35 | print "...done" |
| 36 | |
| 37 | # To check whether all the nodes of NLSR have converged |
| 38 | didNlsrConverge = True |
| 39 | |
| 40 | # Checking for convergence |
| 41 | for host in self.net.hosts: |
| 42 | statusRouter = host.cmd("nfd-status -b | grep /ndn/edu/%C1.Router/cs/") |
| 43 | statusPrefix = host.cmd("nfd-status -b | grep /ndn/edu/") |
| 44 | didNodeConverge = True |
| 45 | for node in self.nodes.split(","): |
| 46 | if ("/ndn/edu/%C1.Router/cs/" + node) not in statusRouter: |
| 47 | didNodeConverge = False |
| 48 | didNlsrConverge = False |
| 49 | if str(host) != node and ("/ndn/edu/" + node) not in statusPrefix: |
| 50 | didNodeConverge = False |
| 51 | didNlsrConverge = False |
| 52 | |
| 53 | host.cmd("echo " + str(didNodeConverge) + " > convergence-result &") |
| 54 | |
| 55 | if didNlsrConverge: |
| 56 | print("NLSR has successfully converged.") |
| 57 | else: |
| 58 | print("NLSR has not converged. Exiting...") |
| 59 | for host in self.net.hosts: |
| 60 | host.nfd.stop() |
| 61 | sys.exit(1) |
| 62 | |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 63 | def ping(self, source, dest, nPings): |
| 64 | # Use "&" to run in background and perform parallel pings |
| 65 | print "Scheduling ping(s) from %s to %s" % (source.name, dest.name) |
| 66 | source.cmd("ndnping -t -c "+ str(nPings) + " /ndn/edu/" + dest.name + " >> ping-data/" + dest.name + ".txt &") |
| 67 | time.sleep(0.2) |
| 68 | |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 69 | def startPings(self): |
| 70 | for host in self.net.hosts: |
| 71 | for other in self.net.hosts: |
| 72 | # Do not ping self |
| 73 | if host.name != other.name: |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 74 | self.ping(host, other, self.nPings) |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 75 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 76 | @staticmethod |
| 77 | def register(name, experimentClass): |
| 78 | ExperimentManager.register(name, experimentClass) |
| 79 | |