Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [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 | import time |
| 25 | import sys |
| 26 | |
| 27 | from mininet.log import setLogLevel, info |
| 28 | |
| 29 | from minindn.minindn import Minindn |
| 30 | from minindn.apps.app_manager import AppManager |
| 31 | from minindn.apps.nfd import Nfd |
| 32 | from minindn.helpers.nfdc import Nfdc |
| 33 | |
| 34 | def registerRouteToAllNeighbors(ndn, host, syncPrefix): |
| 35 | for node in ndn.net.hosts: |
| 36 | for neighbor in node.connectionsTo(host): |
| 37 | ip = node.IP(neighbor[0]) |
Alex Lane | 1d3c0a8 | 2021-07-22 17:28:16 -0500 | [diff] [blame] | 38 | faceID = Nfdc.createFace(host, ip) |
| 39 | Nfdc.registerRoute(host, syncPrefix, faceID) |
Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 40 | |
| 41 | if __name__ == '__main__': |
| 42 | setLogLevel('info') |
| 43 | |
| 44 | ndn = Minindn() |
| 45 | args = ndn.args |
| 46 | |
| 47 | ndn.start() |
| 48 | |
| 49 | nfds = AppManager(ndn, ndn.net.hosts, Nfd) |
| 50 | |
| 51 | syncPrefix = "/sync" |
| 52 | numUserPrefixesPerNode = 2 |
| 53 | maxUpdatesPerUserPrefixPerNode = 3 |
| 54 | |
| 55 | for host in ndn.net.hosts: |
| 56 | Nfdc.setStrategy(host, syncPrefix, Nfdc.STRATEGY_MULTICAST) |
| 57 | registerRouteToAllNeighbors(ndn, host, syncPrefix) |
| 58 | |
| 59 | info('Starting psync-full-sync on all the nodes\n') |
| 60 | for host in ndn.net.hosts: |
| 61 | host.cmd('export NDN_LOG=examples.FullSyncApp=INFO') |
| 62 | host.cmd('psync-full-sync {} {} {} {} &> psync.logs &' |
| 63 | .format(syncPrefix, host.name, numUserPrefixesPerNode, |
| 64 | maxUpdatesPerUserPrefixPerNode)) |
| 65 | |
| 66 | info('Sleeping 5 minutes for convergence\n') |
| 67 | # Estimated time for 4 node default topology |
| 68 | time.sleep(300) |
| 69 | |
| 70 | totalUpdates = int(host.cmd('grep -r Update {}/*/psync.logs | wc -l' |
awlane | a169f57 | 2022-04-08 17:21:29 -0500 | [diff] [blame] | 71 | .format(ndn.workDir))) |
Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 72 | |
| 73 | expectedUpdates = (maxUpdatesPerUserPrefixPerNode * |
| 74 | len(ndn.net.hosts) * (len(ndn.net.hosts) - 1) * numUserPrefixesPerNode) |
| 75 | |
| 76 | if totalUpdates == expectedUpdates: |
| 77 | info('PSync full sync has successfully converged.\n') |
| 78 | else: |
| 79 | info('PSync full sync convergence was not successful. Exiting...\n') |
| 80 | ndn.stop() |
| 81 | sys.exit(1) |