blob: 0589441055000d969998c25ecee64818deb508fd [file] [log] [blame]
awlane21acd052024-06-13 21:12:51 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
3# Copyright (C) 2015-2021, The University of Memphis,
4# Arizona Board of Regents,
5# Regents of the University of California.
6#
7# This file is part of Mini-NDN.
8# See AUTHORS.md for a complete list of Mini-NDN authors and contributors.
9#
10# Mini-NDN is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# Mini-NDN is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with Mini-NDN, e.g., in COPYING.md file.
22# If not, see <http://www.gnu.org/licenses/>.
23
24from subprocess import PIPE
25from time import sleep
26
27from mininet.log import setLogLevel, info, debug
28from mininet.topo import Topo
29
30from minindn.minindn import Minindn
31from minindn.apps.app_manager import AppManager
32from minindn.util import MiniNDNCLI, getPopen
33from minindn.apps.nfd import Nfd
34from minindn.apps.nlsr import Nlsr
35from minindn.helpers.experiment import Experiment
36from minindn.helpers.nfdc import Nfdc
37from minindn.helpers.ndn_routing_helper import NdnRoutingHelper
38
39PREFIX = "/example"
40
41def printOutput(output):
42 _out = output.decode("utf-8").split("\n")
43 for _line in _out:
44 info(_line + "\n")
45
46def udp_run():
47 Minindn.cleanUp()
48 Minindn.verifyDependencies()
49
50 # Topology can be created/modified using Mininet topo object
51 topo = Topo()
52 info("Setup\n")
53 # add hosts
54 a = topo.addHost('a')
55 b = topo.addHost('b')
56 c = topo.addHost('c')
57
58 # add links
59 topo.addLink(a, b, delay='10ms', bw=10) # bw = bandwidth
60 topo.addLink(b, c, delay='10ms', bw=10)
61 topo.addLink(a, c, delay='10ms', bw=10)
62
63 ndn = Minindn(topo=topo)
64 ndn.start()
65
66 # configure and start nfd on each node
67 info("Configuring NFD\n")
68 AppManager(ndn, ndn.net.hosts, Nfd, logLevel="DEBUG")
69
70 """
71 There are multiple ways of setting up routes in Mini-NDN
72 refer: https://minindn.memphis.edu/experiment.html#routing-options
73 It can also be set manually as follows. The important bit to note here
74 is the use of the Nfdc command
75 """
76 links = {"a":["b", "c"], "b":["c"]}
77 nfdc_batches = dict()
78 for first in links:
79 for second in links[first]:
80 host1 = ndn.net[first]
81 host2 = ndn.net[second]
82 interface = host2.connectionsTo(host1)[0][0]
83 interface_ip = interface.IP()
84 Nfdc.createFace(host1, interface_ip)
85 Nfdc.registerRoute(host1, PREFIX, interface_ip, cost=0)
86 Nfdc.setStrategy(host1, PREFIX, Nfdc.STRATEGY_ASF)
87 sleep(1)
88 debug(ndn.net["a"].cmd("nfdc face list"))
89 debug(ndn.net["a"].cmd("nfdc fib list"))
90 debug(ndn.net["a"].cmd("nfdc strategy show /example"))
91
92 # Start ping server
93 info("Starting pings...\n")
94 pingserver_log = open("{}/c/ndnpingserver.log".format(ndn.workDir), "w")
95 getPopen(ndn.net["c"], "ndnpingserver {}".format(PREFIX), stdout=pingserver_log,\
96 stderr=pingserver_log)
97
98 # start ping client
99 ping1 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
100 ping1.wait()
101 printOutput(ping1.stdout.read())
102
103 links = {"a":["b", "c"], "b":["c"]}
104 for first in links:
105 for second in links[first]:
106 host1 = ndn.net[first]
107 host2 = ndn.net[second]
108 interface = host2.connectionsTo(host1)[0][0]
109 interface_ip = interface.IP()
110 Nfdc.unregisterRoute(host1, PREFIX, interface_ip)
111 Nfdc.destroyFace(host1, interface_ip)
112 Nfdc.unsetStrategy(host1, PREFIX)
113 sleep(1)
114 debug(ndn.net["a"].cmd("nfdc face list"))
115 debug(ndn.net["a"].cmd("nfdc fib list"))
116 debug(ndn.net["a"].cmd("nfdc strategy show /example"))
117
118 ping2 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
119 ping2.wait()
120 printOutput(ping2.stdout.read())
121
122 info("\nExperiment Completed!\n")
123 # MiniNDNCLI(ndn.net)
124 ndn.stop()
125
126def eth_run():
127 Minindn.cleanUp()
128 Minindn.verifyDependencies()
129
130 # Topology can be created/modified using Mininet topo object
131 topo = Topo()
132 info("Setup\n")
133 # add hosts
134 a = topo.addHost('a')
135 b = topo.addHost('b')
136 c = topo.addHost('c')
137
138 # add links
139 topo.addLink(a, b, delay='10ms', bw=10) # bw = bandwidth
140 topo.addLink(b, c, delay='10ms', bw=10)
141 topo.addLink(a, c, delay='10ms', bw=10)
142
143 ndn = Minindn(topo=topo)
144 ndn.start()
145
146 # configure and start nfd on each node
147 info("Configuring NFD\n")
148 AppManager(ndn, ndn.net.hosts, Nfd, logLevel="DEBUG")
149
150 """
151 There are multiple ways of setting up routes in Mini-NDN
152 refer: https://minindn.memphis.edu/experiment.html#routing-options
153 It can also be set manually as follows. The important bit to note here
154 is the use of the Nfdc command
155 """
156 links = {"a":["b", "c"], "b":["c"]}
157 nfdc_batches = dict()
158 for first in links:
159 for second in links[first]:
160 host1 = ndn.net[first]
161 host2 = ndn.net[second]
162 sender_interface = host1.connectionsTo(host2)[0][0]
163 interface = host2.connectionsTo(host1)[0][0]
164 interface_addr = interface.MAC()
165 Nfdc.createFace(host1, interface_addr, protocol=Nfdc.PROTOCOL_ETHER, localInterface=sender_interface)
166 Nfdc.registerRoute(host1, PREFIX, interface_addr, cost=0, protocol=Nfdc.PROTOCOL_ETHER)
167 Nfdc.setStrategy(host1, PREFIX, Nfdc.STRATEGY_ASF)
168 sleep(1)
169 debug(ndn.net["a"].cmd("nfdc face list"))
170 debug(ndn.net["a"].cmd("nfdc fib list"))
171 debug(ndn.net["a"].cmd("nfdc strategy show /example"))
172
173 # Start ping server
174 info("Starting pings...\n")
175 pingserver_log = open("{}/c/ndnpingserver.log".format(ndn.workDir), "w")
176 getPopen(ndn.net["c"], "ndnpingserver {}".format(PREFIX), stdout=pingserver_log,\
177 stderr=pingserver_log)
178
179 # start ping client
180 ping1 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
181 ping1.wait()
182 printOutput(ping1.stdout.read())
183
184 links = {"a":["b", "c"], "b":["c"]}
185 for first in links:
186 for second in links[first]:
187 host1 = ndn.net[first]
188 host2 = ndn.net[second]
189 interface = host2.connectionsTo(host1)[0][0]
190 interface_addr = interface.MAC()
191 Nfdc.unregisterRoute(host1, PREFIX, interface_addr, protocol=Nfdc.PROTOCOL_ETHER)
192 Nfdc.destroyFace(host1, interface_addr, protocol=Nfdc.PROTOCOL_ETHER)
193 Nfdc.unsetStrategy(host1, PREFIX)
194 sleep(1)
195 debug(ndn.net["a"].cmd("nfdc face list"))
196 debug(ndn.net["a"].cmd("nfdc fib list"))
197 debug(ndn.net["a"].cmd("nfdc strategy show /example"))
198
199 ping2 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
200 ping2.wait()
201 printOutput(ping2.stdout.read())
202
203 info("\nExperiment Completed!\n")
204 # MiniNDNCLI(ndn.net)
205 ndn.stop()
206
207def udp_nlsr_run():
208 Minindn.cleanUp()
209 Minindn.verifyDependencies()
210
211 # Topology can be created/modified using Mininet topo object
212 topo = Topo()
213 info("Setup\n")
214 # add hosts
215 a = topo.addHost('a')
216 b = topo.addHost('b')
217 c = topo.addHost('c')
218
219 # add links
220 topo.addLink(a, b, delay='10ms', bw=10) # bw = bandwidth
221 topo.addLink(b, c, delay='10ms', bw=10)
222 topo.addLink(a, c, delay='10ms', bw=10)
223
224 ndn = Minindn(topo=topo)
225 ndn.start()
226
227 nfds = AppManager(ndn, ndn.net.hosts, Nfd)
228 nlsrs = AppManager(ndn, ndn.net.hosts, Nlsr, faceType=Nfdc.PROTOCOL_UDP,
229 logLevel='ndn.*=TRACE:nlsr.*=TRACE')
230
231 Experiment.checkConvergence(ndn, ndn.net.hosts, 60, quit=False)
232
233 Experiment.setupPing(ndn.net.hosts, Nfdc.STRATEGY_BEST_ROUTE)
234 Experiment.startPctPings(ndn.net, 60)
235
236 sleep(70)
237
238 ndn.stop()
239
240def eth_nlsr_run():
241 Minindn.cleanUp()
242 Minindn.verifyDependencies()
243
244 # Topology can be created/modified using Mininet topo object
245 topo = Topo()
246 info("Setup\n")
247 # add hosts
248 a = topo.addHost('a')
249 b = topo.addHost('b')
250 c = topo.addHost('c')
251
252 # add links
253 topo.addLink(a, b, delay='10ms', bw=10) # bw = bandwidth
254 topo.addLink(b, c, delay='10ms', bw=10)
255 topo.addLink(a, c, delay='10ms', bw=10)
256
257 ndn = Minindn(topo=topo)
258 ndn.start()
259
260 nfds = AppManager(ndn, ndn.net.hosts, Nfd)
261 nlsrs = AppManager(ndn, ndn.net.hosts, Nlsr, faceType=Nfdc.PROTOCOL_ETHER,
262 logLevel='ndn.*=TRACE:nlsr.*=TRACE')
263
264 Experiment.checkConvergence(ndn, ndn.net.hosts, 60, quit=False)
265
266 Experiment.setupPing(ndn.net.hosts, Nfdc.STRATEGY_BEST_ROUTE)
267 Experiment.startPctPings(ndn.net, 60)
268
269 sleep(70)
270
271 ndn.stop()
272
273def udp_static_run():
274 Minindn.cleanUp()
275 Minindn.verifyDependencies()
276
277 # Topology can be created/modified using Mininet topo object
278 topo = Topo()
279 info("Setup\n")
280 # add hosts
281 a = topo.addHost('a')
282 b = topo.addHost('b')
283 c = topo.addHost('c')
284
285 # add links
286 topo.addLink(a, b, delay='10ms', bw=10) # bw = bandwidth
287 topo.addLink(b, c, delay='10ms', bw=10)
288 topo.addLink(a, c, delay='10ms', bw=10)
289
290 ndn = Minindn(topo=topo)
291 ndn.start()
292
293 nfds = AppManager(ndn, ndn.net.hosts, Nfd)
294 info('Adding static routes to NFD\n')
295 grh = NdnRoutingHelper(ndn.net, Nfdc.PROTOCOL_UDP)
296 # For all host, pass ndn.net.hosts or a list, [ndn.net['a'], ..] or [ndn.net.hosts[0],.]
297 grh.addOrigin([ndn.net['c']], ["/example"])
298 grh.calculateNPossibleRoutes()
299
300 '''
301 prefix "/abc" is advertise from node A, it should be reachable from all other nodes.
302 '''
303 routesFromA = ndn.net['a'].cmd("nfdc route | grep -v '/localhost/nfd'")
304 if '/ndn/b-site/b' not in routesFromA or '/ndn/c-site/c' not in routesFromA:
305 info("Route addition failed\n")
306
307 routesToPrefix = ndn.net['b'].cmd("nfdc fib | grep '/example'")
308 if '/example' not in routesToPrefix:
309 info("Missing route to advertised prefix, Route addition failed\n")
310 ndn.net.stop()
311
312 info('Route addition to NFD completed succesfully\n')
313
314 debug(ndn.net["a"].cmd("nfdc face list"))
315 debug(ndn.net["a"].cmd("nfdc fib list"))
316 debug(ndn.net["a"].cmd("nfdc strategy show /example"))
317
318 # Start ping server
319 info("Starting pings...\n")
320 pingserver_log = open("{}/c/ndnpingserver.log".format(ndn.workDir), "w")
321 getPopen(ndn.net["c"], "ndnpingserver {}".format(PREFIX), stdout=pingserver_log,\
322 stderr=pingserver_log)
323
324 # start ping client
325 ping1 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
326 ping1.wait()
327 printOutput(ping1.stdout.read())
328
329 ndn.stop()
330
331def eth_static_run():
332 Minindn.cleanUp()
333 Minindn.verifyDependencies()
334
335 # Topology can be created/modified using Mininet topo object
336 topo = Topo()
337 info("Setup\n")
338 # add hosts
339 a = topo.addHost('a')
340 b = topo.addHost('b')
341 c = topo.addHost('c')
342
343 # add links
344 topo.addLink(a, b, delay='10ms', bw=10) # bw = bandwidth
345 topo.addLink(b, c, delay='10ms', bw=10)
346 topo.addLink(a, c, delay='10ms', bw=10)
347
348 ndn = Minindn(topo=topo)
349 ndn.start()
350
351 nfds = AppManager(ndn, ndn.net.hosts, Nfd)
352 info('Adding static routes to NFD\n')
353 grh = NdnRoutingHelper(ndn.net, Nfdc.PROTOCOL_ETHER)
354 # For all host, pass ndn.net.hosts or a list, [ndn.net['a'], ..] or [ndn.net.hosts[0],.]
355 grh.addOrigin([ndn.net['c']], ["/example"])
356 grh.calculateNPossibleRoutes()
357
358 '''
359 prefix "/abc" is advertise from node A, it should be reachable from all other nodes.
360 '''
361 routesFromA = ndn.net['a'].cmd("nfdc route | grep -v '/localhost/nfd'")
362 if '/ndn/b-site/b' not in routesFromA or '/ndn/c-site/c' not in routesFromA:
363 info("Route addition failed\n")
364
365 routesToPrefix = ndn.net['b'].cmd("nfdc fib | grep '/example'")
366 if '/example' not in routesToPrefix:
367 info("Missing route to advertised prefix, Route addition failed\n")
368 ndn.net.stop()
369
370 info('Route addition to NFD completed succesfully\n')
371
372 debug(ndn.net["a"].cmd("nfdc face list"))
373 debug(ndn.net["a"].cmd("nfdc fib list"))
374 debug(ndn.net["a"].cmd("nfdc strategy show /example"))
375
376 # Start ping server
377 info("Starting pings...\n")
378 pingserver_log = open("{}/c/ndnpingserver.log".format(ndn.workDir), "w")
379 getPopen(ndn.net["c"], "ndnpingserver {}".format(PREFIX), stdout=pingserver_log,\
380 stderr=pingserver_log)
381
382 # start ping client
383 ping1 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
384 ping1.wait()
385 printOutput(ping1.stdout.read())
386
387 ndn.stop()
388
389if __name__ == '__main__':
390 setLogLevel("debug")
391 udp_run()
392 eth_run()
393 udp_nlsr_run()
394 eth_nlsr_run()
395 udp_static_run()
396 eth_static_run()