blob: 952c568185a90fead4eaee6bde2c89131ae1bff0 [file] [log] [blame]
ashuef3490b2015-02-17 11:01:04 -06001#!/usr/bin/env python
2
3from mininet.topo import Topo
4from mininet.net import Mininet
5from mininet.log import setLogLevel, output, info
6from mininet.cli import CLI
7from mininet.link import TCLink
ashu2ad32e22015-05-29 13:37:40 -05008from mininet.util import ipStr, ipParse
ashuef3490b2015-02-17 11:01:04 -06009
Vince Lehmancb20c542015-05-12 14:04:47 -050010from ndn.experiments.multiple_failure_experiment import MultipleFailureExperiment
ashu34c3ee02015-03-25 14:41:14 -050011from ndn.experiments.pingall_experiment import PingallExperiment
12from ndn.experiments.failure_experiment import FailureExperiment
ashuef3490b2015-02-17 11:01:04 -060013from ndn.ndn_host import NdnHost, CpuLimitedNdnHost
ashu2ad32e22015-05-29 13:37:40 -050014from ndn.conf_parser import parse_hosts, parse_links
ashuef3490b2015-02-17 11:01:04 -060015
16import os.path, time
17import optparse
18import datetime
ashu01b62f72015-03-12 15:16:11 -050019from os.path import expanduser
ashuef3490b2015-02-17 11:01:04 -060020
21from ndn.nlsr import Nlsr, NlsrConfigGenerator
ashu34c3ee02015-03-25 14:41:14 -050022from ndn.nfd import Nfd
ashuef3490b2015-02-17 11:01:04 -060023
24def 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 Lehmancb20c542015-05-12 14:04:47 -050037 isMultipleFailure = False
ashuef3490b2015-02-17 11:01:04 -060038
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 Lehmancb20c542015-05-12 14:04:47 -050059 parser.add_option("--multiple-failure", action="store_true", dest="isMultipleFailure",
60 help="Run multiple failure experiment; each node will fail and recover once")
61
ashuef3490b2015-02-17 11:01:04 -060062 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 Lehmancb20c542015-05-12 14:04:47 -050073 isMultipleFailure = options.isMultipleFailure
ashuef3490b2015-02-17 11:01:04 -060074 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 Lehmancb20c542015-05-12 14:04:47 -050087 return file, testbed, pingall, ctime, hr, faces, failure, isMultipleFailure, isCliEnabled
ashuef3490b2015-02-17 11:01:04 -060088
89class 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 Lehmancb20c542015-05-12 14:04:47 -0500115def execute(template_file='minindn.conf', testbed=False, pingall=None, ctime=None, hr=False, faces=3, failure=False, isMultipleFailure=False, isCliEnabled=True):
ashuef3490b2015-02-17 11:01:04 -0600116 "Create a network based on template_file"
117
ashuef3490b2015-02-17 11:01:04 -0600118 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()
ashuef3490b2015-02-17 11:01:04 -0600124 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
ashu2ad32e22015-05-29 13:37:40 -0500145 # 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
ashuef3490b2015-02-17 11:01:04 -0600161 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
ashu2ad32e22015-05-29 13:37:40 -0500177 configGenerator = NlsrConfigGenerator(host)
ashuef3490b2015-02-17 11:01:04 -0600178 configGenerator.createConfigFile()
179
180 # Start NLSR
ashu34c3ee02015-03-25 14:41:14 -0500181 host.nlsr = Nlsr(host)
182 host.nlsr.start()
ashuef3490b2015-02-17 11:01:04 -0600183
184 nodes = nodes[0:-1]
185
Vince Lehmancb20c542015-05-12 14:04:47 -0500186 if isMultipleFailure is True:
187 test = MultipleFailureExperiment(net, nodes, ctime, Nfd.STRATEGY_BEST_ROUTE_V3)
188 test.start()
189 elif failure is True:
ashu34c3ee02015-03-25 14:41:14 -0500190 test = FailureExperiment(net, nodes, ctime, Nfd.STRATEGY_BEST_ROUTE_V3)
191 test.start()
ashuef3490b2015-02-17 11:01:04 -0600192 elif pingall is not None:
ashu34c3ee02015-03-25 14:41:14 -0500193 test = PingallExperiment(net, nodes, ctime, pingall, Nfd.STRATEGY_BEST_ROUTE_V3)
194 test.start()
ashuef3490b2015-02-17 11:01:04 -0600195
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
206if __name__ == '__main__':
207 hosts_conf = []
208 links_conf = []
Vince Lehmancb20c542015-05-12 14:04:47 -0500209 template, testbed, pingall, ctime, hr, faces, failure, isMultipleFailure, isCliEnabled = parse_args()
ashuef3490b2015-02-17 11:01:04 -0600210
211 setLogLevel('info')
Vince Lehmancb20c542015-05-12 14:04:47 -0500212 execute(template, testbed, pingall, ctime, hr, faces, failure, isMultipleFailure, isCliEnabled)