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