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