Saurab Dulal | 8ae870a | 2018-07-31 05:17:49 +0000 | [diff] [blame^] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
| 3 | # Copyright (C) 2015-2019, 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 ndn.experiments.experiment import Experiment |
| 25 | from ndn.apps.ndn_global_routing_helper import GlobalRoutingHelper |
| 26 | |
| 27 | from mininet.log import info |
| 28 | |
| 29 | class RoutingHelperExp(Experiment): |
| 30 | |
| 31 | def __init__(self, args): |
| 32 | Experiment.__init__(self, args) |
| 33 | |
| 34 | def start(self): |
| 35 | """ |
| 36 | Compute and add routes to NFD |
| 37 | """ |
| 38 | info('Adding static routes to NFD\n') |
| 39 | grh = GlobalRoutingHelper(self.net, self.options.faceType, self.options.routingType) |
| 40 | # For all host, pass self.net.hosts or a list, [self.net['a'], ..] or [self.net.hosts[0],.] |
| 41 | grh.addOrigin([self.net['a']], ["/abc"]) |
| 42 | grh.calculateNPossibleRoutes() |
| 43 | |
| 44 | ''' |
| 45 | Experiment run with default topology, test cases won't work with other topologies |
| 46 | # With calculateNPossibleRoutes, |
| 47 | 10 # routing = hr, N = All, from A, 3 routes needs to added to NFD. |
| 48 | A +++++++ B # A - B -- cost 10 |
| 49 | + + # A - C -- cost 10 |
| 50 | 10 + + 10 # A - D -- cost 20 |
| 51 | + + # Same goes for B being a source. |
| 52 | C D # |
| 53 | |
| 54 | prefix "/abc" is advertise from node A, it should be reachable from all other nodes. |
| 55 | |
| 56 | ''' |
| 57 | if self.options.routingType == "link-state": |
| 58 | # This test only for link-state. Similar test can be done for hyperbolic routing. |
| 59 | routesFromA = self.net['a'].cmd("nfdc route | grep -v '/localhost/nfd'") |
| 60 | if '/ndn/b-site/b' not in routesFromA or \ |
| 61 | '/ndn/c-site/c' not in routesFromA or \ |
| 62 | '/ndn/d-site/d' not in routesFromA: |
| 63 | info("Route addition failed\n") |
| 64 | exit(-1) |
| 65 | |
| 66 | routesToPrefix = self.net['b'].cmd("nfdc fib | grep '/abc'") |
| 67 | if '/abc' not in routesToPrefix: |
| 68 | info("Missing route to advertised prefix, Route addition failed\n") |
| 69 | exit(-1) |
| 70 | |
| 71 | info('Route addition to NFD completed\n') |
| 72 | |
| 73 | Experiment.register("centralize-routing", RoutingHelperExp) |