Ashlesh Gawande | 6651a74 | 2019-01-03 18:13:06 -0600 | [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.nfdc import Nfdc |
| 26 | |
| 27 | import time |
| 28 | import sys |
| 29 | |
| 30 | class PSyncFull(Experiment): |
| 31 | |
| 32 | def __init__(self, args): |
| 33 | Experiment.__init__(self, args) |
| 34 | self.syncPrefix = "/sync" |
| 35 | self.numUserPrefixesPerNode = 2 |
| 36 | self.maxUpdatesPerUserPrefixPerNode = 3 |
| 37 | |
| 38 | def registerRouteToAllNeighbors(self, host): |
| 39 | for node in self.net.hosts: |
| 40 | for neighbor in node.connectionsTo(host): |
| 41 | ip = node.IP(neighbor[0]) |
| 42 | Nfdc.createFace(host, ip) |
| 43 | Nfdc.registerRoute(host, self.syncPrefix, ip) |
| 44 | |
| 45 | def start(self): |
| 46 | for host in self.net.hosts: |
| 47 | Nfdc.setStrategy(host, self.syncPrefix, "multicast") |
| 48 | self.registerRouteToAllNeighbors(host) |
| 49 | |
| 50 | print("Starting psync-full-sync on all the nodes") |
| 51 | for host in self.net.hosts: |
| 52 | host.cmd("export NDN_LOG=examples.FullSyncApp=INFO") |
| 53 | host.cmd("psync-full-sync {} {} {} {} &> psync.logs &" |
| 54 | .format(self.syncPrefix, host.name, self.numUserPrefixesPerNode, |
| 55 | self.maxUpdatesPerUserPrefixPerNode)) |
| 56 | |
| 57 | print("Sleeping 5 minutes for convergence") |
| 58 | # Estimated time for 4 node default topology |
| 59 | time.sleep(300) |
| 60 | |
| 61 | totalUpdates = int(host.cmd("grep -r Update {}/*/psync.logs | wc -l" |
| 62 | .format(self.options.workDir))) |
| 63 | |
| 64 | expectedUpdates = (self.maxUpdatesPerUserPrefixPerNode * |
| 65 | len(self.net.hosts) * (len(self.net.hosts) - 1) * |
| 66 | self.numUserPrefixesPerNode) |
| 67 | |
| 68 | if totalUpdates == expectedUpdates: |
| 69 | print("PSync full sync has successfully converged.") |
| 70 | else: |
| 71 | print("PSync full sync convergence was not successful. Exiting...") |
| 72 | self.net.stop() |
| 73 | sys.exit(1) |
| 74 | |
| 75 | Experiment.register("psync-full", PSyncFull) |