blob: 1c9209788eadeac2c9800edcc57b410164ecd114 [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
8from mininet.conf_parser import parse_hosts, parse_links
9
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
14
15import os.path, time
16import optparse
17import datetime
ashu01b62f72015-03-12 15:16:11 -050018from os.path import expanduser
ashuef3490b2015-02-17 11:01:04 -060019
20from ndn.nlsr import Nlsr, NlsrConfigGenerator
ashu34c3ee02015-03-25 14:41:14 -050021from ndn.nfd import Nfd
ashuef3490b2015-02-17 11:01:04 -060022
23def 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 Lehmancb20c542015-05-12 14:04:47 -050036 isMultipleFailure = False
ashuef3490b2015-02-17 11:01:04 -060037
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 Lehmancb20c542015-05-12 14:04:47 -050058 parser.add_option("--multiple-failure", action="store_true", dest="isMultipleFailure",
59 help="Run multiple failure experiment; each node will fail and recover once")
60
ashuef3490b2015-02-17 11:01:04 -060061 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 Lehmancb20c542015-05-12 14:04:47 -050072 isMultipleFailure = options.isMultipleFailure
ashuef3490b2015-02-17 11:01:04 -060073 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 Lehmancb20c542015-05-12 14:04:47 -050086 return file, testbed, pingall, ctime, hr, faces, failure, isMultipleFailure, isCliEnabled
ashuef3490b2015-02-17 11:01:04 -060087
88class 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 Lehmancb20c542015-05-12 14:04:47 -0500114def 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 -0600115 "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
ashu34c3ee02015-03-25 14:41:14 -0500167 host.nlsr = Nlsr(host)
168 host.nlsr.start()
ashuef3490b2015-02-17 11:01:04 -0600169
170 nodes = nodes[0:-1]
171
Vince Lehmancb20c542015-05-12 14:04:47 -0500172 if isMultipleFailure is True:
173 test = MultipleFailureExperiment(net, nodes, ctime, Nfd.STRATEGY_BEST_ROUTE_V3)
174 test.start()
175 elif failure is True:
ashu34c3ee02015-03-25 14:41:14 -0500176 test = FailureExperiment(net, nodes, ctime, Nfd.STRATEGY_BEST_ROUTE_V3)
177 test.start()
ashuef3490b2015-02-17 11:01:04 -0600178 elif pingall is not None:
ashu34c3ee02015-03-25 14:41:14 -0500179 test = PingallExperiment(net, nodes, ctime, pingall, Nfd.STRATEGY_BEST_ROUTE_V3)
180 test.start()
ashuef3490b2015-02-17 11:01:04 -0600181
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
192if __name__ == '__main__':
193 hosts_conf = []
194 links_conf = []
Vince Lehmancb20c542015-05-12 14:04:47 -0500195 template, testbed, pingall, ctime, hr, faces, failure, isMultipleFailure, isCliEnabled = parse_args()
ashuef3490b2015-02-17 11:01:04 -0600196
197 setLogLevel('info')
Vince Lehmancb20c542015-05-12 14:04:47 -0500198 execute(template, testbed, pingall, ctime, hr, faces, failure, isMultipleFailure, isCliEnabled)