Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
| 3 | # Copyright (C) 2015 The University of Memphis, |
| 4 | # Arizona Board of Regents, |
| 5 | # Regents of the University of California. |
| 6 | # |
| 7 | # This file is part of Mini-NDN. |
| 8 | # See AUTHORS.md for a complete list of Mini-NDN authors and contributors. |
| 9 | # |
| 10 | # Mini-NDN is free software: you can redistribute it and/or modify |
| 11 | # it under the terms of the GNU General Public License as published by |
| 12 | # the Free Software Foundation, either version 3 of the License, or |
| 13 | # (at your option) any later version. |
| 14 | # |
| 15 | # Mini-NDN is distributed in the hope that it will be useful, |
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | # GNU General Public License for more details. |
| 19 | # |
| 20 | # You should have received a copy of the GNU General Public License |
| 21 | # along with Mini-NDN, e.g., in COPYING.md file. |
| 22 | # If not, see <http://www.gnu.org/licenses/>. |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 23 | |
| 24 | import time |
| 25 | import sys |
| 26 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 27 | from ndn import ExperimentManager |
| 28 | |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 29 | class Experiment: |
| 30 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 31 | def __init__(self, args): |
| 32 | self.net = args["net"] |
| 33 | self.nodes = args["nodes"] |
| 34 | self.convergenceTime = args["ctime"] |
| 35 | self.nPings = args["nPings"] |
| 36 | self.strategy = args["strategy"] |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 37 | |
| 38 | def start(self): |
| 39 | self.setup() |
| 40 | self.run() |
| 41 | |
| 42 | def setup(self): |
| 43 | for host in self.net.hosts: |
| 44 | # Set strategy |
| 45 | host.nfd.setStrategy("/ndn/edu", self.strategy) |
| 46 | |
| 47 | # Start ping server |
| 48 | host.cmd("ndnpingserver /ndn/edu/" + str(host) + " > ping-server &") |
| 49 | |
| 50 | # Create folder to store ping data |
| 51 | host.cmd("mkdir ping-data") |
| 52 | |
| 53 | # Wait for convergence time period |
| 54 | print "Waiting " + str(self.convergenceTime) + " seconds for convergence..." |
| 55 | time.sleep(self.convergenceTime) |
| 56 | print "...done" |
| 57 | |
| 58 | # To check whether all the nodes of NLSR have converged |
| 59 | didNlsrConverge = True |
| 60 | |
| 61 | # Checking for convergence |
| 62 | for host in self.net.hosts: |
| 63 | statusRouter = host.cmd("nfd-status -b | grep /ndn/edu/%C1.Router/cs/") |
| 64 | statusPrefix = host.cmd("nfd-status -b | grep /ndn/edu/") |
| 65 | didNodeConverge = True |
| 66 | for node in self.nodes.split(","): |
| 67 | if ("/ndn/edu/%C1.Router/cs/" + node) not in statusRouter: |
| 68 | didNodeConverge = False |
| 69 | didNlsrConverge = False |
| 70 | if str(host) != node and ("/ndn/edu/" + node) not in statusPrefix: |
| 71 | didNodeConverge = False |
| 72 | didNlsrConverge = False |
| 73 | |
| 74 | host.cmd("echo " + str(didNodeConverge) + " > convergence-result &") |
| 75 | |
| 76 | if didNlsrConverge: |
| 77 | print("NLSR has successfully converged.") |
| 78 | else: |
| 79 | print("NLSR has not converged. Exiting...") |
| 80 | for host in self.net.hosts: |
| 81 | host.nfd.stop() |
| 82 | sys.exit(1) |
| 83 | |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 84 | def ping(self, source, dest, nPings): |
| 85 | # Use "&" to run in background and perform parallel pings |
| 86 | print "Scheduling ping(s) from %s to %s" % (source.name, dest.name) |
| 87 | source.cmd("ndnping -t -c "+ str(nPings) + " /ndn/edu/" + dest.name + " >> ping-data/" + dest.name + ".txt &") |
| 88 | time.sleep(0.2) |
| 89 | |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 90 | def startPings(self): |
| 91 | for host in self.net.hosts: |
| 92 | for other in self.net.hosts: |
| 93 | # Do not ping self |
| 94 | if host.name != other.name: |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 95 | self.ping(host, other, self.nPings) |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 96 | |
Vince Lehman | d96eed3 | 2015-10-22 13:57:27 -0500 | [diff] [blame] | 97 | def failNode(self, host): |
| 98 | print("Bringing %s down" % host.name) |
| 99 | host.nfd.stop() |
| 100 | |
| 101 | def recoverNode(self, host): |
| 102 | print("Bringing %s up" % host.name) |
| 103 | host.nfd.start() |
| 104 | host.nlsr.start() |
| 105 | host.nfd.setStrategy("/ndn/edu", self.strategy) |
| 106 | host.cmd("ndnpingserver /ndn/edu/" + str(host) + " > ping-server &") |
| 107 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 108 | @staticmethod |
| 109 | def register(name, experimentClass): |
| 110 | ExperimentManager.register(name, experimentClass) |
| 111 | |