Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
Saurab Dulal | 576a419 | 2020-08-25 00:55:22 -0500 | [diff] [blame^] | 3 | # Copyright (C) 2015-2020, The University of Memphis, |
Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 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 | import argparse |
| 25 | import sys |
| 26 | |
| 27 | from mininet.log import setLogLevel, info |
| 28 | from mininet.topo import Topo |
| 29 | |
| 30 | from minindn.minindn import Minindn |
| 31 | from minindn.util import MiniNDNCLI |
| 32 | from minindn.apps.app_manager import AppManager |
| 33 | from minindn.apps.nfd import Nfd |
| 34 | from minindn.helpers.ndn_routing_helper import NdnRoutingHelper |
| 35 | |
| 36 | if __name__ == '__main__': |
| 37 | setLogLevel('info') |
| 38 | |
| 39 | Minindn.cleanUp() |
| 40 | Minindn.verifyDependencies() |
| 41 | |
| 42 | parser = argparse.ArgumentParser() |
| 43 | parser.add_argument('--face-type', dest='faceType', default='udp', choices=['udp', 'tcp']) |
| 44 | parser.add_argument('--routing', dest='routingType', default='link-state', |
| 45 | choices=['link-state', 'hr', 'dry'], |
| 46 | help='''Choose routing type, dry = link-state is used |
| 47 | but hr is calculated for comparision.''') |
| 48 | |
| 49 | ''' |
| 50 | Experiment run with default topology, test cases won't work with other topologies |
| 51 | # With calculateNPossibleRoutes, |
| 52 | 10 # routing = hr, N = All, from A, 3 routes needs to added to NFD. |
| 53 | a +++++++ b # a - b -- cost 10 |
| 54 | + + # a - c -- cost 10 |
| 55 | 10 + + 10 # a - d -- cost 20 |
| 56 | + + # Same goes for B being a source. |
| 57 | c d # |
| 58 | ''' |
| 59 | topo = Topo() |
| 60 | a = topo.addHost('a') |
| 61 | b = topo.addHost('b') |
| 62 | c = topo.addHost('c') |
| 63 | d = topo.addHost('d') |
| 64 | topo.addLink(a, b, delay='10ms') |
| 65 | topo.addLink(a, c, delay='10ms') |
| 66 | topo.addLink(b, d, delay='10ms') |
| 67 | |
| 68 | ndn = Minindn(parser=parser, topo=topo) |
| 69 | |
| 70 | ndn.start() |
| 71 | |
| 72 | info('Starting NFD on nodes\n') |
| 73 | nfds = AppManager(ndn, ndn.net.hosts, Nfd) |
| 74 | |
| 75 | info('Adding static routes to NFD\n') |
| 76 | grh = NdnRoutingHelper(ndn.net, ndn.args.faceType, ndn.args.routingType) |
| 77 | # For all host, pass ndn.net.hosts or a list, [ndn.net['a'], ..] or [ndn.net.hosts[0],.] |
| 78 | grh.addOrigin([ndn.net['a']], ["/abc"]) |
| 79 | grh.calculateNPossibleRoutes() |
| 80 | |
| 81 | ''' |
| 82 | prefix "/abc" is advertise from node A, it should be reachable from all other nodes. |
| 83 | ''' |
| 84 | routesFromA = ndn.net['a'].cmd("nfdc route | grep -v '/localhost/nfd'") |
| 85 | if '/ndn/b-site/b' not in routesFromA or \ |
| 86 | '/ndn/c-site/c' not in routesFromA or \ |
| 87 | '/ndn/d-site/d' not in routesFromA: |
| 88 | info("Route addition failed\n") |
| 89 | |
| 90 | routesToPrefix = ndn.net['b'].cmd("nfdc fib | grep '/abc'") |
| 91 | if '/abc' not in routesToPrefix: |
| 92 | info("Missing route to advertised prefix, Route addition failed\n") |
| 93 | ndn.net.stop() |
| 94 | sys.exit(1) |
| 95 | |
| 96 | info('Route addition to NFD completed\n') |
| 97 | |
| 98 | MiniNDNCLI(ndn.net) |
| 99 | |
| 100 | ndn.stop() |