awlane | 2672471 | 2024-07-05 16:18:27 -0500 | [diff] [blame^] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
| 3 | # Copyright (C) 2015-2024, 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 | |
| 24 | from subprocess import PIPE |
| 25 | from time import sleep |
| 26 | |
| 27 | from mininet.log import setLogLevel, info, debug |
| 28 | from mininet.topo import Topo |
| 29 | |
| 30 | from minindn.minindn import Minindn |
| 31 | from minindn.apps.app_manager import AppManager |
| 32 | from minindn.util import MiniNDNCLI, getPopen |
| 33 | from minindn.apps.nfd import Nfd |
| 34 | from minindn.helpers.nfdc import Nfdc, NfdcBatch |
| 35 | |
| 36 | PREFIX = "/example" |
| 37 | |
| 38 | def printOutput(output): |
| 39 | _out = output.decode("utf-8").split("\n") |
| 40 | for _line in _out: |
| 41 | info(_line + "\n") |
| 42 | |
| 43 | def run(): |
| 44 | Minindn.cleanUp() |
| 45 | Minindn.verifyDependencies() |
| 46 | |
| 47 | # Topology can be created/modified using Mininet topo object |
| 48 | topo = Topo() |
| 49 | info("Setup\n") |
| 50 | # add hosts |
| 51 | a = topo.addHost('a') |
| 52 | b = topo.addHost('b') |
| 53 | c = topo.addHost('c') |
| 54 | |
| 55 | # add links |
| 56 | topo.addLink(a, b, delay='10ms', bw=10) # bw = bandwidth |
| 57 | topo.addLink(b, c, delay='10ms', bw=10) |
| 58 | topo.addLink(a, c, delay='10ms', bw=10) |
| 59 | |
| 60 | ndn = Minindn(topo=topo) |
| 61 | ndn.start() |
| 62 | |
| 63 | # configure and start nfd on each node |
| 64 | info("Configuring NFD\n") |
| 65 | AppManager(ndn, ndn.net.hosts, Nfd, logLevel="DEBUG") |
| 66 | |
| 67 | info("Setting up routes and strategies...\n") |
| 68 | links = {"a": ["b", "c"], "b": ["c"]} |
| 69 | for first in links: |
| 70 | for second in links[first]: |
| 71 | host1 = ndn.net[first] |
| 72 | host2 = ndn.net[second] |
| 73 | interface = host2.connectionsTo(host1)[0][0] |
| 74 | interface_ip = interface.IP() |
| 75 | # Nfdc.createFace(host1, interface_ip) |
| 76 | Nfdc.createFace(host1, interface_ip) |
| 77 | Nfdc.registerRoute(host1, PREFIX, interface_ip, cost=0) |
| 78 | Nfdc.setStrategy(host1, PREFIX, Nfdc.STRATEGY_ASF) |
| 79 | info(ndn.net["a"].cmd("nfdc face list")) |
| 80 | info(ndn.net["a"].cmd("nfdc fib list")) |
| 81 | info(ndn.net["a"].cmd("nfdc strategy show /example")) |
| 82 | |
| 83 | # Start ping server |
| 84 | info("Starting pings...\n") |
| 85 | pingserver_log = open(f"{ndn.workDir}/c/ndnpingserver.log", "w") |
| 86 | getPopen(ndn.net["c"], f"ndnpingserver {PREFIX}", stdout=pingserver_log, |
| 87 | stderr=pingserver_log) |
| 88 | |
| 89 | # start ping client |
| 90 | ping1 = getPopen(ndn.net["a"], f"ndnping {PREFIX} -c 5", stdout=PIPE, stderr=PIPE) |
| 91 | ping1.wait() |
| 92 | printOutput(ping1.stdout.read()) |
| 93 | |
| 94 | info("Bringing down routes and strategies...\n") |
| 95 | links = {"a": ["b", "c"], "b": ["c"]} |
| 96 | for first in links: |
| 97 | for second in links[first]: |
| 98 | host1 = ndn.net[first] |
| 99 | host2 = ndn.net[second] |
| 100 | interface = host2.connectionsTo(host1)[0][0] |
| 101 | interface_ip = interface.IP() |
| 102 | Nfdc.unregisterRoute(host1, PREFIX, interface_ip) |
| 103 | Nfdc.destroyFace(host1, interface_ip) |
| 104 | Nfdc.unsetStrategy(host1, PREFIX) |
| 105 | info(ndn.net["a"].cmd("nfdc face list")) |
| 106 | info(ndn.net["a"].cmd("nfdc fib list")) |
| 107 | info(ndn.net["a"].cmd("nfdc strategy show /example")) |
| 108 | |
| 109 | ping2 = getPopen(ndn.net["a"], f"ndnping {PREFIX} -c 5", stdout=PIPE, stderr=PIPE) |
| 110 | ping2.wait() |
| 111 | printOutput(ping2.stdout.read()) |
| 112 | |
| 113 | info("\nExperiment Completed!\n") |
| 114 | # MiniNDNCLI(ndn.net) |
| 115 | ndn.stop() |
| 116 | |
| 117 | if __name__ == '__main__': |
| 118 | setLogLevel("info") |
| 119 | run() |