Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
dulalsaurab | 2085544 | 2021-05-21 20:37:03 +0000 | [diff] [blame] | 3 | # Copyright (C) 2015-2021, 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 time |
dulalsaurab | 2085544 | 2021-05-21 20:37:03 +0000 | [diff] [blame] | 25 | import sys |
Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 26 | |
| 27 | from mininet.log import setLogLevel, info |
| 28 | |
| 29 | from minindn.minindn import Minindn |
| 30 | from minindn.util import MiniNDNCLI |
| 31 | from minindn.apps.app_manager import AppManager |
| 32 | from minindn.apps.nfd import Nfd |
| 33 | from minindn.apps.nlsr import Nlsr |
| 34 | from minindn.helpers.experiment import Experiment |
| 35 | |
| 36 | from nlsr_common import getParser |
| 37 | |
| 38 | if __name__ == '__main__': |
| 39 | setLogLevel('info') |
| 40 | |
| 41 | ndn = Minindn(parser=getParser()) |
| 42 | args = ndn.args |
| 43 | |
| 44 | ndn.start() |
| 45 | |
| 46 | nfds = AppManager(ndn, ndn.net.hosts, Nfd) |
| 47 | nlsrs = AppManager(ndn, ndn.net.hosts, Nlsr, sync=args.sync, |
| 48 | security=args.security, faceType=args.faceType, |
| 49 | nFaces=args.faces, routingType=args.routingType) |
| 50 | |
| 51 | Experiment.checkConvergence(ndn, ndn.net.hosts, args.ctime, quit=True) |
| 52 | |
| 53 | firstNode = ndn.net.hosts[0] |
| 54 | |
| 55 | if args.security: |
| 56 | firstNode.cmd('ndnsec-set-default /ndn/{}-site/%C1.Operator/op'.format(firstNode.name)) |
| 57 | |
| 58 | info('Testing advertise\n') |
| 59 | firstNode.cmd('nlsrc advertise /testPrefix') |
| 60 | time.sleep(30) |
| 61 | |
| 62 | for host in ndn.net.hosts: |
| 63 | if host.name != firstNode.name: |
| 64 | if (int(host.cmd('nfdc fib | grep testPrefix | wc -l')) != 1 or |
| 65 | int(host.cmd('nlsrc status | grep testPrefix | wc -l')) != 1): |
| 66 | info('Advertise test failed\n') |
| 67 | ndn.stop() |
| 68 | sys.exit(1) |
| 69 | |
| 70 | info('Testing withdraw\n') |
| 71 | firstNode.cmd('nlsrc withdraw /testPrefix') |
| 72 | time.sleep(30) |
| 73 | |
| 74 | for host in ndn.net.hosts: |
| 75 | if host.name != firstNode.name: |
| 76 | if (int(host.cmd('nfdc fib | grep testPrefix | wc -l')) != 0 or |
| 77 | int(host.cmd('nlsrc status | grep testPrefix | wc -l')) != 0): |
| 78 | info('Withdraw test failed\n') |
| 79 | ndn.stop() |
| 80 | sys.exit(1) |
| 81 | |
| 82 | if args.isCliEnabled: |
| 83 | MiniNDNCLI(ndn.net) |
| 84 | |
| 85 | ndn.stop() |