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