blob: 97d3c74a98f2fbae294b001df4ebde2697562bab [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 ]
Ashlesh Gawande20f70762015-06-17 15:18:19 -050026 If no template_file is given, ndn_utils/default-topology.conf (given sample file)
27 will be used.
ashuef3490b2015-02-17 11:01:04 -060028 If --testbed is used, minindn will run the NDN Project Testbed.
ashuef3490b2015-02-17 11:01:04 -060029 """
30
31 testbed = False
32 pingall = False
33 hr = False
34 failure = False
Vince Lehmancb20c542015-05-12 14:04:47 -050035 isMultipleFailure = False
ashuef3490b2015-02-17 11:01:04 -060036
37 parser = optparse.OptionParser(usage)
38
39 parser.add_option("-t", "--testbed", action="store_true", dest="testbed",
40 help="instantiates NDN Testbed")
41
42 parser.add_option("--pingall", action="store", dest="pingall", type="int",
43 help="Sequentiall pings all the other nodes from each node")
44
45 parser.add_option("--ctime", action="store", dest="ctime", type="int",
46 help="Specify convergence time for the topology (Default 60 seconds)")
47
48 parser.add_option("--hr", action="store_true", dest="hr",
49 help="--hr is used to turn on hyperbolic routing")
50
51 parser.add_option("--faces", action="store", dest="faces", type="int",
52 help="Specify number of faces 0-60")
53
54 parser.add_option("--failure", action="store_true", dest="failure",
55 help="Run failure experiment, specify the number of pings using pingall")
56
Vince Lehmancb20c542015-05-12 14:04:47 -050057 parser.add_option("--multiple-failure", action="store_true", dest="isMultipleFailure",
58 help="Run multiple failure experiment; each node will fail and recover once")
59
ashuef3490b2015-02-17 11:01:04 -060060 parser.add_option("--no-cli", action="store_false", dest="isCliEnabled",
61 help="Run experiments and exit without showing the command line interface")
62
63 (options, arg) = parser.parse_args()
64
65 testbed = options.testbed
66 pingall = options.pingall
67 ctime = options.ctime
68 hr = options.hr
69 faces = options.faces
70 failure = options.failure
Vince Lehmancb20c542015-05-12 14:04:47 -050071 isMultipleFailure = options.isMultipleFailure
ashuef3490b2015-02-17 11:01:04 -060072 isCliEnabled = options.isCliEnabled
73
74 if ctime is None:
75 ctime = 60
76
77 if isCliEnabled is None:
78 isCliEnabled = True
79
80 if len(arg) == 0 or len(arg) > 2:
81 file = ''
82 else:
83 file = arg[0]
84
Vince Lehmancb20c542015-05-12 14:04:47 -050085 return file, testbed, pingall, ctime, hr, faces, failure, isMultipleFailure, isCliEnabled
ashuef3490b2015-02-17 11:01:04 -060086
87class NdnTopo(Topo):
88 def __init__(self, conf_arq, **opts):
89 Topo.__init__(self, **opts)
90
91 global hosts_conf
92 global links_conf
93 hosts_conf = parse_hosts(conf_arq)
94 links_conf = parse_links(conf_arq)
95
96 self.isTCLink = False
97 self.isLimited = False
98
99 for host in hosts_conf:
100 if host.cpu != None and self.isLimited != True:
101 self.isLimited = True
102 self.addHost(host.name, app=host.app, fib=host.uri_tuples,cpu=host.cpu,cores=host.cores,cache=host.cache)
103
104 for link in links_conf:
105 if len(link.linkDict) == 0:
106 self.addLink(link.h1, link.h2)
107 else:
108 self.addLink(link.h1, link.h2, **link.linkDict)
109 self.isTCLink = True
110
111 info('Parse of ' + conf_arq + ' done.\n')
112
Vince Lehmancb20c542015-05-12 14:04:47 -0500113def 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 -0600114 "Create a network based on template_file"
115
Ashlesh Gawande20f70762015-06-17 15:18:19 -0500116 install_dir='/usr/local/etc/mini-ndn/'
117
ashuef3490b2015-02-17 11:01:04 -0600118 if template_file == '':
Ashlesh Gawande20f70762015-06-17 15:18:19 -0500119 template_file = install_dir + 'default-topology.conf'
120
121 if testbed:
122 template_file = install_dir + 'minindn.testbed.conf'
ashuef3490b2015-02-17 11:01:04 -0600123
124 if os.path.exists(template_file) == False:
Ashlesh Gawande20f70762015-06-17 15:18:19 -0500125 info('No template file given and default template file cannot be found. Exiting...\n')
ashuef3490b2015-02-17 11:01:04 -0600126 quit()
Ashlesh Gawande20f70762015-06-17 15:18:19 -0500127
ashuef3490b2015-02-17 11:01:04 -0600128 topo = NdnTopo(template_file)
129
130 t = datetime.datetime.now()
131
132 if topo.isTCLink == True and topo.isLimited == True:
133 net = Mininet(topo,host=CpuLimitedNdnHost,link=TCLink)
134 elif topo.isTCLink == True and topo.isLimited == False:
135 net = Mininet(topo,host=NdnHost,link=TCLink)
136 elif topo.isTCLink == False and topo.isLimited == True:
137 net = Mininet(topo,host=CpuLimitedNdnHost)
138 else:
139 net = Mininet(topo,host=NdnHost)
140
141 t2 = datetime.datetime.now()
142
143 delta = t2 - t
144
145 info('Setup time: ' + str(delta.seconds) + '\n')
146
147 net.start()
148
ashu2ad32e22015-05-29 13:37:40 -0500149 # Giving proper IPs to intf so neighbor nodes can communicate
150 # This is one way of giving connectivity, another way could be
151 # to insert a switch between each pair of neighbors
152 ndnNetBase = "1.0.0.0"
153 interfaces = []
154 for host in net.hosts:
155 for intf in host.intfList():
156 link = intf.link
157 node1, node2 = link.intf1.node, link.intf2.node
158 if link.intf1 not in interfaces and link.intf2 not in interfaces:
159 interfaces.append(link.intf1)
160 interfaces.append(link.intf2)
161 node1.setIP(ipStr(ipParse(ndnNetBase) + 1) + '/30', intf=link.intf1)
162 node2.setIP(ipStr(ipParse(ndnNetBase) + 2) + '/30', intf=link.intf2)
163 ndnNetBase = ipStr(ipParse(ndnNetBase) + 4)
164
ashuef3490b2015-02-17 11:01:04 -0600165 nodes = "" # Used later to check prefix name in checkFIB
166
167 # NLSR initialization
168 for host in net.hosts:
169 nodes += str(host.name) + ","
170
171 conf = next(x for x in hosts_conf if x.name == host.name)
172 host.nlsrParameters = conf.nlsrParameters
173
174 if faces is not None:
175 host.nlsrParameters["max-faces-per-prefix"] = faces
176
177 if hr is True:
178 host.nlsrParameters["hyperbolic-state"] = "on"
179
180 # Generate NLSR configuration file
ashu2ad32e22015-05-29 13:37:40 -0500181 configGenerator = NlsrConfigGenerator(host)
ashuef3490b2015-02-17 11:01:04 -0600182 configGenerator.createConfigFile()
183
184 # Start NLSR
ashu34c3ee02015-03-25 14:41:14 -0500185 host.nlsr = Nlsr(host)
186 host.nlsr.start()
ashuef3490b2015-02-17 11:01:04 -0600187
188 nodes = nodes[0:-1]
189
Vince Lehmancb20c542015-05-12 14:04:47 -0500190 if isMultipleFailure is True:
191 test = MultipleFailureExperiment(net, nodes, ctime, Nfd.STRATEGY_BEST_ROUTE_V3)
192 test.start()
193 elif failure is True:
ashu34c3ee02015-03-25 14:41:14 -0500194 test = FailureExperiment(net, nodes, ctime, Nfd.STRATEGY_BEST_ROUTE_V3)
195 test.start()
ashuef3490b2015-02-17 11:01:04 -0600196 elif pingall is not None:
ashu34c3ee02015-03-25 14:41:14 -0500197 test = PingallExperiment(net, nodes, ctime, pingall, Nfd.STRATEGY_BEST_ROUTE_V3)
198 test.start()
ashuef3490b2015-02-17 11:01:04 -0600199
200 for host in net.hosts:
201 if 'app' in host.params:
202 if host.params['app'] != '_':
203 host.cmd(host.params['app'])
204
205 if isCliEnabled is True:
206 CLI(net)
207
208 net.stop()
209
210if __name__ == '__main__':
211 hosts_conf = []
212 links_conf = []
Vince Lehmancb20c542015-05-12 14:04:47 -0500213 template, testbed, pingall, ctime, hr, faces, failure, isMultipleFailure, isCliEnabled = parse_args()
ashuef3490b2015-02-17 11:01:04 -0600214
215 setLogLevel('info')
Vince Lehmancb20c542015-05-12 14:04:47 -0500216 execute(template, testbed, pingall, ctime, hr, faces, failure, isMultipleFailure, isCliEnabled)