blob: d549828f7902cc474a03731bd2459a254c413da6 [file] [log] [blame]
ashu34c3ee02015-03-25 14:41:14 -05001#!/usr/bin/python
2
3import time
4import sys
5
Vince Lehman3b8bc652015-06-18 15:01:47 -05006from ndn import ExperimentManager
7
ashu34c3ee02015-03-25 14:41:14 -05008class Experiment:
9
Vince Lehman3b8bc652015-06-18 15:01:47 -050010 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"]
ashu34c3ee02015-03-25 14:41:14 -050016
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 Lehmancb20c542015-05-12 14:04:47 -050063 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
ashu34c3ee02015-03-25 14:41:14 -050069 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 Lehmancb20c542015-05-12 14:04:47 -050074 self.ping(host, other, self.nPings)
ashu34c3ee02015-03-25 14:41:14 -050075
Vince Lehman3b8bc652015-06-18 15:01:47 -050076 @staticmethod
77 def register(name, experimentClass):
78 ExperimentManager.register(name, experimentClass)
79