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