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