dulalsaurab | 2085544 | 2021-05-21 20:37:03 +0000 | [diff] [blame] | 1 | # -*- 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 | |
| 24 | from subprocess import PIPE |
| 25 | |
| 26 | from mininet.log import setLogLevel, info |
| 27 | from mininet.topo import Topo |
| 28 | |
| 29 | from minindn.minindn import Minindn |
| 30 | from minindn.apps.app_manager import AppManager |
| 31 | from minindn.util import MiniNDNCLI, getPopen |
| 32 | from minindn.apps.nfd import Nfd |
| 33 | from minindn.helpers.nfdc import Nfdc |
| 34 | |
| 35 | PREFIX = "/example" |
| 36 | |
| 37 | def printOutput(output): |
| 38 | _out = output.decode("utf-8").split("\n") |
| 39 | for _line in _out: |
| 40 | info(_line + "\n") |
| 41 | |
| 42 | def run(): |
| 43 | Minindn.cleanUp() |
| 44 | Minindn.verifyDependencies() |
| 45 | |
| 46 | # Topology can be created/modified using Mininet topo object |
| 47 | topo = Topo() |
| 48 | info("Setup\n") |
| 49 | # add hosts |
| 50 | a = topo.addHost('a') |
| 51 | b = topo.addHost('b') |
| 52 | c = topo.addHost('c') |
| 53 | |
| 54 | # add links |
| 55 | topo.addLink(a, b, delay='10ms', bw=10) # bw = bandwidth |
| 56 | topo.addLink(b, c, delay='10ms', bw=10) |
| 57 | |
| 58 | ndn = Minindn(topo=topo) |
| 59 | ndn.start() |
| 60 | |
| 61 | # configure and start nfd on each node |
| 62 | info("Configuring NFD\n") |
| 63 | AppManager(ndn, ndn.net.hosts, Nfd, logLevel="DEBUG") |
| 64 | |
| 65 | """ |
| 66 | There are multiple ways of setting up routes in Mini-NDN |
| 67 | refer: https://minindn.memphis.edu/experiment.html#routing-options |
| 68 | It can also be set manually as follows. The important bit to note here |
| 69 | is the use of the Nfdc command |
| 70 | """ |
| 71 | links = {"a":["b"], "b":["c"]} |
| 72 | for first in links: |
| 73 | for second in links[first]: |
| 74 | host1 = ndn.net[first] |
| 75 | host2 = ndn.net[second] |
| 76 | interface = host2.connectionsTo(host1)[0][0] |
| 77 | interface_ip = interface.IP() |
| 78 | Nfdc.createFace(host1, interface_ip) |
| 79 | Nfdc.registerRoute(host1, PREFIX, interface_ip, cost=0) |
| 80 | |
| 81 | # Start ping server |
| 82 | info("Starting pings...\n") |
awlane | a169f57 | 2022-04-08 17:21:29 -0500 | [diff] [blame] | 83 | pingserver_log = open("{}/c/ndnpingserver.log".format(ndn.workDir), "w") |
dulalsaurab | 2085544 | 2021-05-21 20:37:03 +0000 | [diff] [blame] | 84 | getPopen(ndn.net["c"], "ndnpingserver {}".format(PREFIX), stdout=pingserver_log,\ |
| 85 | stderr=pingserver_log) |
| 86 | |
| 87 | # start ping client |
| 88 | ping1 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE) |
| 89 | ping1.wait() |
| 90 | printOutput(ping1.stdout.read()) |
| 91 | |
| 92 | interface = ndn.net["b"].connectionsTo(ndn.net["a"])[0][0] |
| 93 | info("Failing link\n") # failing link by setting link loss to 100% |
| 94 | interface.config(delay="10ms", bw=10, loss=100) |
| 95 | info ("\n starting ping2 client \n") |
| 96 | |
| 97 | ping2 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE) |
| 98 | ping2.wait() |
| 99 | printOutput(ping2.stdout.read()) |
| 100 | |
| 101 | interface.config(delay="10ms", bw=10, loss=0) # bringing back the link |
| 102 | |
| 103 | info("\nExperiment Completed!\n") |
| 104 | MiniNDNCLI(ndn.net) |
| 105 | ndn.stop() |
| 106 | |
| 107 | if __name__ == '__main__': |
| 108 | setLogLevel("info") |
| 109 | run() |