ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | from mininet.topo import Topo |
| 4 | from mininet.net import Mininet |
| 5 | from mininet.log import setLogLevel, output, info |
| 6 | from mininet.cli import CLI |
| 7 | from mininet.link import TCLink |
| 8 | from mininet.conf_parser import parse_hosts, parse_links |
| 9 | |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame^] | 10 | from ndn.experiments.multiple_failure_experiment import MultipleFailureExperiment |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 11 | from ndn.experiments.pingall_experiment import PingallExperiment |
| 12 | from ndn.experiments.failure_experiment import FailureExperiment |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 13 | from ndn.ndn_host import NdnHost, CpuLimitedNdnHost |
| 14 | |
| 15 | import os.path, time |
| 16 | import optparse |
| 17 | import datetime |
ashu | 01b62f7 | 2015-03-12 15:16:11 -0500 | [diff] [blame] | 18 | from os.path import expanduser |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 19 | |
| 20 | from ndn.nlsr import Nlsr, NlsrConfigGenerator |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 21 | from ndn.nfd import Nfd |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 22 | |
| 23 | def parse_args(): |
| 24 | usage="""Usage: minindn [template_file] [ -t | --testbed ] |
| 25 | If no template_file is given, will try to load template |
| 26 | from file minindn.conf in the current directory. |
| 27 | If --testbed is used, minindn will run the NDN Project Testbed. |
| 28 | This assumes you are in the testbed directory in the minindn installation |
| 29 | directory. |
| 30 | """ |
| 31 | |
| 32 | testbed = False |
| 33 | pingall = False |
| 34 | hr = False |
| 35 | failure = False |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame^] | 36 | isMultipleFailure = False |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 37 | |
| 38 | parser = optparse.OptionParser(usage) |
| 39 | |
| 40 | parser.add_option("-t", "--testbed", action="store_true", dest="testbed", |
| 41 | help="instantiates NDN Testbed") |
| 42 | |
| 43 | parser.add_option("--pingall", action="store", dest="pingall", type="int", |
| 44 | help="Sequentiall pings all the other nodes from each node") |
| 45 | |
| 46 | parser.add_option("--ctime", action="store", dest="ctime", type="int", |
| 47 | help="Specify convergence time for the topology (Default 60 seconds)") |
| 48 | |
| 49 | parser.add_option("--hr", action="store_true", dest="hr", |
| 50 | help="--hr is used to turn on hyperbolic routing") |
| 51 | |
| 52 | parser.add_option("--faces", action="store", dest="faces", type="int", |
| 53 | help="Specify number of faces 0-60") |
| 54 | |
| 55 | parser.add_option("--failure", action="store_true", dest="failure", |
| 56 | help="Run failure experiment, specify the number of pings using pingall") |
| 57 | |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame^] | 58 | parser.add_option("--multiple-failure", action="store_true", dest="isMultipleFailure", |
| 59 | help="Run multiple failure experiment; each node will fail and recover once") |
| 60 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 61 | parser.add_option("--no-cli", action="store_false", dest="isCliEnabled", |
| 62 | help="Run experiments and exit without showing the command line interface") |
| 63 | |
| 64 | (options, arg) = parser.parse_args() |
| 65 | |
| 66 | testbed = options.testbed |
| 67 | pingall = options.pingall |
| 68 | ctime = options.ctime |
| 69 | hr = options.hr |
| 70 | faces = options.faces |
| 71 | failure = options.failure |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame^] | 72 | isMultipleFailure = options.isMultipleFailure |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 73 | isCliEnabled = options.isCliEnabled |
| 74 | |
| 75 | if ctime is None: |
| 76 | ctime = 60 |
| 77 | |
| 78 | if isCliEnabled is None: |
| 79 | isCliEnabled = True |
| 80 | |
| 81 | if len(arg) == 0 or len(arg) > 2: |
| 82 | file = '' |
| 83 | else: |
| 84 | file = arg[0] |
| 85 | |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame^] | 86 | return file, testbed, pingall, ctime, hr, faces, failure, isMultipleFailure, isCliEnabled |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 87 | |
| 88 | class NdnTopo(Topo): |
| 89 | def __init__(self, conf_arq, **opts): |
| 90 | Topo.__init__(self, **opts) |
| 91 | |
| 92 | global hosts_conf |
| 93 | global links_conf |
| 94 | hosts_conf = parse_hosts(conf_arq) |
| 95 | links_conf = parse_links(conf_arq) |
| 96 | |
| 97 | self.isTCLink = False |
| 98 | self.isLimited = False |
| 99 | |
| 100 | for host in hosts_conf: |
| 101 | if host.cpu != None and self.isLimited != True: |
| 102 | self.isLimited = True |
| 103 | self.addHost(host.name, app=host.app, fib=host.uri_tuples,cpu=host.cpu,cores=host.cores,cache=host.cache) |
| 104 | |
| 105 | for link in links_conf: |
| 106 | if len(link.linkDict) == 0: |
| 107 | self.addLink(link.h1, link.h2) |
| 108 | else: |
| 109 | self.addLink(link.h1, link.h2, **link.linkDict) |
| 110 | self.isTCLink = True |
| 111 | |
| 112 | info('Parse of ' + conf_arq + ' done.\n') |
| 113 | |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame^] | 114 | def execute(template_file='minindn.conf', testbed=False, pingall=None, ctime=None, hr=False, faces=3, failure=False, isMultipleFailure=False, isCliEnabled=True): |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 115 | "Create a network based on template_file" |
| 116 | |
| 117 | home = expanduser("~") |
| 118 | |
| 119 | if template_file == '': |
| 120 | template_file='minindn.conf' |
| 121 | |
| 122 | if os.path.exists(template_file) == False: |
| 123 | info('No template file given and default template file minindn.conf not found. Exiting...\n') |
| 124 | quit() |
| 125 | |
| 126 | topo = NdnTopo(template_file) |
| 127 | |
| 128 | t = datetime.datetime.now() |
| 129 | |
| 130 | if topo.isTCLink == True and topo.isLimited == True: |
| 131 | net = Mininet(topo,host=CpuLimitedNdnHost,link=TCLink) |
| 132 | elif topo.isTCLink == True and topo.isLimited == False: |
| 133 | net = Mininet(topo,host=NdnHost,link=TCLink) |
| 134 | elif topo.isTCLink == False and topo.isLimited == True: |
| 135 | net = Mininet(topo,host=CpuLimitedNdnHost) |
| 136 | else: |
| 137 | net = Mininet(topo,host=NdnHost) |
| 138 | |
| 139 | t2 = datetime.datetime.now() |
| 140 | |
| 141 | delta = t2 - t |
| 142 | |
| 143 | info('Setup time: ' + str(delta.seconds) + '\n') |
| 144 | |
| 145 | net.start() |
| 146 | |
| 147 | nodes = "" # Used later to check prefix name in checkFIB |
| 148 | |
| 149 | # NLSR initialization |
| 150 | for host in net.hosts: |
| 151 | nodes += str(host.name) + "," |
| 152 | |
| 153 | conf = next(x for x in hosts_conf if x.name == host.name) |
| 154 | host.nlsrParameters = conf.nlsrParameters |
| 155 | |
| 156 | if faces is not None: |
| 157 | host.nlsrParameters["max-faces-per-prefix"] = faces |
| 158 | |
| 159 | if hr is True: |
| 160 | host.nlsrParameters["hyperbolic-state"] = "on" |
| 161 | |
| 162 | # Generate NLSR configuration file |
| 163 | configGenerator = NlsrConfigGenerator(host, home) |
| 164 | configGenerator.createConfigFile() |
| 165 | |
| 166 | # Start NLSR |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 167 | host.nlsr = Nlsr(host) |
| 168 | host.nlsr.start() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 169 | |
| 170 | nodes = nodes[0:-1] |
| 171 | |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame^] | 172 | if isMultipleFailure is True: |
| 173 | test = MultipleFailureExperiment(net, nodes, ctime, Nfd.STRATEGY_BEST_ROUTE_V3) |
| 174 | test.start() |
| 175 | elif failure is True: |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 176 | test = FailureExperiment(net, nodes, ctime, Nfd.STRATEGY_BEST_ROUTE_V3) |
| 177 | test.start() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 178 | elif pingall is not None: |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 179 | test = PingallExperiment(net, nodes, ctime, pingall, Nfd.STRATEGY_BEST_ROUTE_V3) |
| 180 | test.start() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 181 | |
| 182 | for host in net.hosts: |
| 183 | if 'app' in host.params: |
| 184 | if host.params['app'] != '_': |
| 185 | host.cmd(host.params['app']) |
| 186 | |
| 187 | if isCliEnabled is True: |
| 188 | CLI(net) |
| 189 | |
| 190 | net.stop() |
| 191 | |
| 192 | if __name__ == '__main__': |
| 193 | hosts_conf = [] |
| 194 | links_conf = [] |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame^] | 195 | template, testbed, pingall, ctime, hr, faces, failure, isMultipleFailure, isCliEnabled = parse_args() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 196 | |
| 197 | setLogLevel('info') |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame^] | 198 | execute(template, testbed, pingall, ctime, hr, faces, failure, isMultipleFailure, isCliEnabled) |