Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
Alexander Lane | 9944cf5 | 2018-05-17 12:16:50 -0500 | [diff] [blame] | 3 | # Copyright (C) 2015-2018, The University of Memphis, |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame] | 4 | # Arizona Board of Regents, |
| 5 | # Regents of the University of California. |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 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 | # This file incorporates work covered by the following copyright and |
| 25 | # permission notice: |
| 26 | # |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 27 | # Mininet 2.3.0d1 License |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 28 | # |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 29 | # Copyright (c) 2013-2016 Open Networking Laboratory |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 30 | # Copyright (c) 2009-2012 Bob Lantz and The Board of Trustees of |
| 31 | # The Leland Stanford Junior University |
| 32 | # |
| 33 | # Original authors: Bob Lantz and Brandon Heller |
| 34 | # |
| 35 | # We are making Mininet available for public use and benefit with the |
| 36 | # expectation that others will use, modify and enhance the Software and |
| 37 | # contribute those enhancements back to the community. However, since we |
| 38 | # would like to make the Software available for broadest use, with as few |
| 39 | # restrictions as possible permission is hereby granted, free of charge, to |
| 40 | # any person obtaining a copy of this Software to deal in the Software |
| 41 | # under the copyrights without restriction, including without limitation |
| 42 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 43 | # and/or sell copies of the Software, and to permit persons to whom the |
| 44 | # Software is furnished to do so, subject to the following conditions: |
| 45 | # |
| 46 | # The above copyright notice and this permission notice shall be included |
| 47 | # in all copies or substantial portions of the Software. |
| 48 | # |
| 49 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 50 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 51 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 52 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 53 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 54 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 55 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 56 | # |
| 57 | # The name and trademarks of copyright holder(s) may NOT be used in |
| 58 | # advertising or publicity pertaining to the Software or any derivatives |
| 59 | # without specific, written prior permission. |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 60 | |
| 61 | from mininet.topo import Topo |
| 62 | from mininet.net import Mininet |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 63 | from mininet.log import setLogLevel, output, info, error, warn |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 64 | from mininet.link import TCLink |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 65 | from mininet.util import ipStr, ipParse |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 66 | |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 67 | from mininet.examples.cluster import MininetCluster, RoundRobinPlacer, ClusterCleanup |
| 68 | from mininet.examples.clustercli import ClusterCLI |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 69 | |
| 70 | from ndn import ExperimentManager |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 71 | from ndn.experiments.experiment import Experiment |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 72 | from ndn.ndn_host import NdnHost, CpuLimitedNdnHost, RemoteNdnHost |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 73 | from ndn.conf_parser import parse_hosts, parse_switches, parse_links |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 74 | from ndn.remote_ndn_link import RemoteNdnLink, RemoteGRENdnLink |
| 75 | from ndn.placer import GuidedPlacer, PopulatePlacement |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 76 | from ndn.nfd import Nfd |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 77 | from ndn.util import ssh, scp, MiniNDNCLI, ProgramOptions |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 78 | |
| 79 | import os.path, time |
Yucheng Zhang | 14aa596 | 2016-04-05 17:10:15 -0500 | [diff] [blame] | 80 | import shutil |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 81 | import argparse |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 82 | import datetime |
ashu | 01b62f7 | 2015-03-12 15:16:11 -0500 | [diff] [blame] | 83 | from os.path import expanduser |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 84 | import sys |
Ashlesh Gawande | 3807c1b | 2016-08-05 16:27:02 -0500 | [diff] [blame] | 85 | import signal |
Yucheng Zhang | 14aa596 | 2016-04-05 17:10:15 -0500 | [diff] [blame] | 86 | from subprocess import call |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 87 | import glob |
| 88 | from functools import partial |
| 89 | import re |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 90 | |
Ashlesh Gawande | 212cb82 | 2017-02-07 10:42:13 -0600 | [diff] [blame] | 91 | try: |
| 92 | import argcomplete |
| 93 | except ImportError: |
| 94 | pass |
| 95 | |
Ashlesh Gawande | 670ff15 | 2018-06-08 12:26:39 -0500 | [diff] [blame] | 96 | VERSION_NUMBER = "0.4.0" |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 97 | INSTALL_DIR='/usr/local/etc/mini-ndn/' |
Vince Lehman | e9f116d | 2015-07-15 10:40:21 -0500 | [diff] [blame] | 98 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 99 | class PrintExperimentNames(argparse.Action): |
| 100 | def __init__(self, option_strings, dest, nargs=0, help=None): |
| 101 | super(PrintExperimentNames, self).__init__(option_strings=option_strings, dest=dest, nargs=nargs, help=help) |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 102 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 103 | def __call__(self, parser, namespace, values, option_string=None): |
| 104 | experimentNames = ExperimentManager.getExperimentNames() |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 105 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 106 | print("Mini-NDN experiments:") |
| 107 | for experiment in experimentNames: |
Ashlesh Gawande | 501d4d6 | 2017-10-25 13:12:11 -0500 | [diff] [blame] | 108 | print(" {}".format(experiment)) |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 109 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 110 | sys.exit(0) |
Vince Lehman | e9f116d | 2015-07-15 10:40:21 -0500 | [diff] [blame] | 111 | |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 112 | def createResultsDir(resultDir, faces, rType): |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 113 | if faces == 0: |
| 114 | faces = "all" |
| 115 | |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 116 | routingChoice = "/{}/".format(rType) |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 117 | |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 118 | resultDir = "{}/{}/faces-{}".format(resultDir, routingChoice, faces) |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 119 | resultDir = os.path.abspath(resultDir) |
| 120 | |
| 121 | if not os.path.isdir(resultDir): |
| 122 | os.makedirs(resultDir) |
| 123 | else: |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 124 | warn("Results directory ({}) already exists!".format(resultDir)) |
Ashlesh Gawande | 212cb82 | 2017-02-07 10:42:13 -0600 | [diff] [blame] | 125 | sys.exit(1) |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 126 | |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 127 | info("Results will be stored at: {}".format(resultDir)) |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 128 | return resultDir |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 129 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 130 | def parse_args(): |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 131 | parser = argparse.ArgumentParser(prog='minindn') |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 132 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 133 | # nargs='?' required here since optional argument |
| 134 | parser.add_argument('tempfile', nargs='?', default=INSTALL_DIR + 'default-topology.conf', |
Ashlesh Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 135 | help="If no template_file is given, topologies/default-topology.conf (given sample file) will be used.") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 136 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 137 | parser.add_argument("--ctime", type=int, default=60, |
| 138 | help="Specify convergence time for the topology (Default: 60 seconds)") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 139 | |
Ashlesh Gawande | 212cb82 | 2017-02-07 10:42:13 -0600 | [diff] [blame] | 140 | parser.add_argument("--experiment", choices=[experiment for experiment in ExperimentManager.getExperimentNames()], |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 141 | help="Runs the specified experiment") |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 142 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 143 | parser.add_argument("--faces", type=int, default=3, |
Ashlesh Gawande | 212cb82 | 2017-02-07 10:42:13 -0600 | [diff] [blame] | 144 | help="Specify number of max faces per prefix for NLSR 0-60") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 145 | |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 146 | parser.add_argument("--routing", dest="routingType", default='link-state', choices=['link-state', 'hr', 'dry'], |
| 147 | help="""choices for routing are 'link-state' for link state, 'hr' for hyperbolic, and 'dry' |
| 148 | to test hyperbolic routing and compare with link state. Default is link-state.""") |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 149 | |
dmcoomes | ecf9c5a | 2017-10-11 10:17:46 -0500 | [diff] [blame] | 150 | parser.add_argument("--no-nlsr", action="store_false", dest="isNlsrEnabled", |
| 151 | help="Run mini-ndn without NLSR routing") |
| 152 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 153 | parser.add_argument("--list-experiments", action=PrintExperimentNames, |
| 154 | help="Lists the names of all available experiments") |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 155 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 156 | parser.add_argument("--no-cli", action="store_false", dest="isCliEnabled", |
| 157 | help="Run experiments and exit without showing the command line interface") |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 158 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 159 | parser.add_argument("--nPings", type=int, default=300, |
| 160 | help="Number of pings to perform between each node in the experiment") |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 161 | |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 162 | # store_true stores default value of False |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 163 | parser.add_argument("--nlsr-security", action="store_true", dest="nlsrSecurity", |
| 164 | help="Enables NLSR security") |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame] | 165 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 166 | parser.add_argument("-t", "--testbed", action="store_true", dest="testbed", |
| 167 | help="Instantiates a snapshot of the NDN Testbed irrespective of the tempfile provided") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 168 | |
dmcoomes | 80eeea1 | 2017-10-27 12:49:10 -0500 | [diff] [blame] | 169 | parser.add_argument("--work-dir", action="store", dest="workDir", default="/tmp/minindn", |
| 170 | help="Specify the working directory; default is /tmp/minindn") |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 171 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 172 | parser.add_argument("--result-dir", action="store", dest="resultDir", default=None, |
| 173 | help="Specify the full path destination folder where experiment results will be moved") |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 174 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 175 | parser.add_argument("--pct-traffic", dest="pctTraffic", type=float, default=1.0, |
| 176 | help="Specify the percentage of nodes each node should ping") |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 177 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 178 | parser.add_argument('--version', '-V', action='version', version='%(prog)s ' + VERSION_NUMBER, |
| 179 | help='Displays version information') |
Vince Lehman | e9f116d | 2015-07-15 10:40:21 -0500 | [diff] [blame] | 180 | |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 181 | parser.add_argument("--cluster", metavar='localhost,server2,...', |
| 182 | help="Run cluster edition") |
| 183 | |
| 184 | parser.add_argument("--placement", default='guided', |
| 185 | choices=['roundRobin', 'guided']) |
| 186 | |
| 187 | parser.add_argument("--place-list", dest="placeList", |
| 188 | help="""Provide corresponding number of nodes (comma separated) to put on |
| 189 | each node respectively of --cluster when guided placement is used""") |
| 190 | |
| 191 | parser.add_argument("--tunnel-type", dest="tunnelType", default='ssh', |
| 192 | choices=['ssh', 'gre']) |
| 193 | |
Ashlesh Gawande | 708fcca | 2017-06-23 14:04:12 -0500 | [diff] [blame] | 194 | parser.add_argument("--face-type", dest='faceType', default='udp', choices=['udp', 'tcp']) |
| 195 | |
Ashlesh Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 196 | parser.add_argument("--cs-size", dest='csSize', type=int, default=65536, |
| 197 | help="Set CS size in NFD's conf file") |
| 198 | |
Alexander Lane | 1bc9b47 | 2018-05-16 15:07:16 -0500 | [diff] [blame] | 199 | ExperimentManager.addExperimentArgs(parser) |
| 200 | |
Ashlesh Gawande | 212cb82 | 2017-02-07 10:42:13 -0600 | [diff] [blame] | 201 | if "argcomplete" in sys.modules: |
| 202 | argcomplete.autocomplete(parser) |
| 203 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 204 | args = parser.parse_args() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 205 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 206 | options = ProgramOptions() |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 207 | options.templateFile = args.tempfile |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 208 | options.ctime = args.ctime |
| 209 | options.experimentName = args.experiment |
| 210 | options.nFaces = args.faces |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 211 | options.routingType = args.routingType |
dmcoomes | ecf9c5a | 2017-10-11 10:17:46 -0500 | [diff] [blame] | 212 | options.isNlsrEnabled = args.isNlsrEnabled |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 213 | options.isCliEnabled = args.isCliEnabled |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame] | 214 | options.nlsrSecurity = args.nlsrSecurity |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 215 | options.nPings = args.nPings |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame] | 216 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 217 | options.testbed = args.testbed |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 218 | options.workDir = args.workDir |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 219 | options.resultDir = args.resultDir |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 220 | options.pctTraffic = args.pctTraffic |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 221 | options.cluster = args.cluster |
| 222 | options.placement = args.placement |
| 223 | options.tunnelType = args.tunnelType |
| 224 | options.placeList = args.placeList |
Ashlesh Gawande | 708fcca | 2017-06-23 14:04:12 -0500 | [diff] [blame] | 225 | options.faceType = args.faceType |
Ashlesh Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 226 | options.csSize = args.csSize |
Alexander Lane | 1bc9b47 | 2018-05-16 15:07:16 -0500 | [diff] [blame] | 227 | options.arguments = args |
Ashlesh Gawande | 501d4d6 | 2017-10-25 13:12:11 -0500 | [diff] [blame] | 228 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 229 | if options.experimentName is not None and options.experimentName not in ExperimentManager.getExperimentNames(): |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 230 | error("No experiment named {}".format(options.experimentName)) |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 231 | sys.exit(1) |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 232 | |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 233 | if options.experimentName is not None and options.resultDir is None: |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 234 | warn("No results folder specified; experiment results will remain in the working directory") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 235 | |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 236 | if options.cluster is not None: |
| 237 | servers = options.cluster.split(',') |
| 238 | for server in servers: |
| 239 | ClusterCleanup.add(server) |
| 240 | options.servers = servers |
| 241 | |
| 242 | if options.placement == "roundRobin": |
| 243 | options.placement = RoundRobinPlacer |
| 244 | elif options.placement == "guided": |
| 245 | if options.placeList is None or not re.match("^[0-9,]+$", options.placeList): |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 246 | error("Please specify correctly how many nodes you want to place on each node!") |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 247 | sys.exit(1) |
| 248 | else: |
| 249 | try: |
| 250 | options.placeList = map(int, options.placeList.split(",")) |
| 251 | except ValueError: |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 252 | error("Please specify the nodes correctly, no comma at the beginning/end!") |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 253 | sys.exit(1) |
| 254 | |
| 255 | PopulatePlacement(options.placeList) |
| 256 | options.placement = GuidedPlacer |
| 257 | |
| 258 | if options.tunnelType == "ssh": |
| 259 | options.tunnelType = RemoteNdnLink |
| 260 | else: |
| 261 | options.tunnelType = RemoteGRENdnLink |
| 262 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 263 | return options |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 264 | |
| 265 | class NdnTopo(Topo): |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 266 | def __init__(self, conf_arq, workDir, **opts): |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 267 | Topo.__init__(self, **opts) |
| 268 | |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 269 | self.hosts_conf = parse_hosts(conf_arq) |
| 270 | self.switches_conf = parse_switches(conf_arq) |
| 271 | self.links_conf = parse_links(conf_arq) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 272 | |
| 273 | self.isTCLink = False |
| 274 | self.isLimited = False |
| 275 | |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 276 | for host in self.hosts_conf: |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 277 | if host.cpu != None and self.isLimited != True: |
| 278 | self.isLimited = True |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 279 | self.addHost(host.name, app=host.app, params=host.params, cpu=host.cpu, |
dmcoomes | 74da84c | 2017-11-07 16:09:23 -0600 | [diff] [blame] | 280 | cores=host.cores,cache=host.cache, workdir=workDir) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 281 | |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 282 | for switch in self.switches_conf: |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 283 | self.addSwitch(switch.name) |
| 284 | |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 285 | for link in self.links_conf: |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 286 | if len(link.linkDict) == 0: |
| 287 | self.addLink(link.h1, link.h2) |
| 288 | else: |
| 289 | self.addLink(link.h1, link.h2, **link.linkDict) |
| 290 | self.isTCLink = True |
| 291 | |
| 292 | info('Parse of ' + conf_arq + ' done.\n') |
| 293 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 294 | def execute(options): |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 295 | "Create a network based on template_file" |
| 296 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 297 | if options.testbed: |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 298 | options.templateFile = INSTALL_DIR + 'minindn.testbed.conf' |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 299 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 300 | if os.path.exists(options.templateFile) == False: |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 301 | error('Template file cannot be found. Exiting...\n') |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 302 | sys.exit(1) |
Ashlesh Gawande | 20f7076 | 2015-06-17 15:18:19 -0500 | [diff] [blame] | 303 | |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 304 | if options.cluster is not None and options.placement == GuidedPlacer: |
| 305 | num_nodes = 0 |
| 306 | with open(options.templateFile, 'r') as topo: |
| 307 | for line in topo: |
| 308 | if ': _' in line: |
| 309 | num_nodes += 1 |
| 310 | |
| 311 | if sum(options.placeList) != num_nodes: |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 312 | error("Placement list sum is not equal to number of nodes!") |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 313 | sys.exit(1) |
| 314 | |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 315 | # Copy nfd.conf to remote hosts - this assumes that NDN versions across |
| 316 | # the cluster are at least compatible if not the same |
| 317 | if options.cluster is not None: |
| 318 | for server in options.servers: |
| 319 | if server != "localhost": |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 320 | login = "mininet@{}".format(server) |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 321 | src = nfdConfFile |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 322 | dst = "{}:/tmp/nfd.conf".format(login) |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 323 | scp(src, dst) |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 324 | ssh(login, "sudo cp /tmp/nfd.conf {}".format(src)) |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 325 | |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 326 | if options.resultDir is not None: |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 327 | options.resultDir = createResultsDir(options.resultDir, options.nFaces, options.routingType) |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 328 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 329 | topo = NdnTopo(options.templateFile, options.workDir) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 330 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 331 | if topo.isTCLink == True and topo.isLimited == True: |
| 332 | net = Mininet(topo,host=CpuLimitedNdnHost,link=TCLink) |
| 333 | elif topo.isTCLink == True and topo.isLimited == False: |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 334 | if options.cluster is not None: |
| 335 | mn = partial(MininetCluster, servers=options.servers, placement=options.placement) |
| 336 | net = mn(topo=topo, host=RemoteNdnHost, link=options.tunnelType) |
| 337 | else: |
| 338 | net = Mininet(topo, host=NdnHost, link=TCLink) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 339 | elif topo.isTCLink == False and topo.isLimited == True: |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 340 | net = Mininet(topo, host=CpuLimitedNdnHost) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 341 | else: |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 342 | net = Mininet(topo, host=NdnHost) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 343 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 344 | net.start() |
| 345 | |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 346 | # Giving proper IPs to intf so neighbor nodes can communicate |
| 347 | # This is one way of giving connectivity, another way could be |
| 348 | # to insert a switch between each pair of neighbors |
| 349 | ndnNetBase = "1.0.0.0" |
| 350 | interfaces = [] |
| 351 | for host in net.hosts: |
| 352 | for intf in host.intfList(): |
| 353 | link = intf.link |
| 354 | node1, node2 = link.intf1.node, link.intf2.node |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 355 | |
| 356 | if node1 in net.switches or node2 in net.switches: |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 357 | continue |
| 358 | |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 359 | if link.intf1 not in interfaces and link.intf2 not in interfaces: |
| 360 | interfaces.append(link.intf1) |
| 361 | interfaces.append(link.intf2) |
| 362 | node1.setIP(ipStr(ipParse(ndnNetBase) + 1) + '/30', intf=link.intf1) |
| 363 | node2.setIP(ipStr(ipParse(ndnNetBase) + 2) + '/30', intf=link.intf2) |
| 364 | ndnNetBase = ipStr(ipParse(ndnNetBase) + 4) |
| 365 | |
Ashlesh Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 366 | time.sleep(2) |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 367 | |
Ashlesh Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 368 | info('Starting NFD on nodes\n') |
| 369 | for host in net.hosts: |
| 370 | host.nfd = Nfd(host, options.csSize) |
| 371 | host.nfd.start() |
| 372 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 373 | for host in net.hosts: |
| 374 | if 'app' in host.params: |
Ashlesh Gawande | 557cb84 | 2015-07-01 15:39:44 -0500 | [diff] [blame] | 375 | if host.params['app'] != '': |
| 376 | app = host.params['app'] |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 377 | info("Starting {} on node {}".format(app, host.name)) |
| 378 | info(host.cmd(app)) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 379 | |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 380 | # Determine if each host is running NFD |
Alexander Lane | 052aabb | 2018-05-14 14:48:29 -0500 | [diff] [blame] | 381 | for host in net.hosts: |
| 382 | nfdStatus = host.cmd("ps -g -U root | grep 'nfd --config {}/[n]fd.conf'".format(host.homeFolder)) |
Alexander Lane | 052aabb | 2018-05-14 14:48:29 -0500 | [diff] [blame] | 383 | if not host.nfd.isRunning or not nfdStatus: |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 384 | error("NFD on host {} is not running. Printing log file and exiting...".format(host.name)) |
| 385 | info(host.cmd("tail {}/nfd.log".format(host.homeFolder))) |
Alexander Lane | 052aabb | 2018-05-14 14:48:29 -0500 | [diff] [blame] | 386 | net.stop() |
| 387 | sys.exit(1) |
| 388 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 389 | # Load experiment |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 390 | experimentName = options.experimentName |
| 391 | |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 392 | experimentArgs = { |
| 393 | "net": net, |
| 394 | "options": options |
| 395 | } |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 396 | |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 397 | if experimentName is not None: |
| 398 | info("Loading experiment: {}".format(experimentName)) |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 399 | |
| 400 | experiment = ExperimentManager.create(experimentName, experimentArgs) |
| 401 | |
| 402 | if experiment is not None: |
| 403 | experiment.start() |
| 404 | else: |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 405 | error("Experiment '{}' does not exist".format(experimentName)) |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 406 | return |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 407 | else: |
| 408 | experiment = Experiment(experimentArgs) |
| 409 | if options.isNlsrEnabled: |
| 410 | experiment.startNlsr(checkConvergence = False) |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 411 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 412 | if options.isCliEnabled is True: |
Ashlesh Gawande | 95789cc | 2017-02-27 12:38:04 -0600 | [diff] [blame] | 413 | MiniNDNCLI(net) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 414 | |
| 415 | net.stop() |
| 416 | |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 417 | if options.resultDir is not None: |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 418 | info("Moving results to {}".format(options.resultDir)) |
| 419 | for file in glob.glob('{}/*'.format(options.workDir)): |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 420 | shutil.move(file, options.resultDir) |
| 421 | if options.cluster is not None: |
| 422 | for server in options.servers: |
| 423 | if server != "localhost": |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 424 | login = "mininet@{}".format(server) |
| 425 | src = "{}:{}/*".format(login, options.workDir) |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 426 | dst = options.resultDir |
| 427 | scp(src, dst) |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 428 | info("Please clean work directories of other machines before running the cluster again") |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 429 | |
Ashlesh Gawande | 3807c1b | 2016-08-05 16:27:02 -0500 | [diff] [blame] | 430 | def signal_handler(signal, frame): |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 431 | info('Cleaning up...') |
Ashlesh Gawande | 3807c1b | 2016-08-05 16:27:02 -0500 | [diff] [blame] | 432 | call(["nfd-stop"]) |
| 433 | call(["sudo", "mn", "--clean"]) |
| 434 | sys.exit(1) |
| 435 | |
Alexander Lane | 052aabb | 2018-05-14 14:48:29 -0500 | [diff] [blame] | 436 | def verify_dependencies(): |
| 437 | "Prevent MiniNDN from running without necessary dependencies" |
| 438 | dependencies = ["nfd", "nlsr", "infoedit", "ndnping", "ndnpingserver"] |
| 439 | devnull = open("/dev/null", "w") |
| 440 | # Checks that each program is in the system path |
| 441 | for program in dependencies: |
| 442 | if call(["which", program], stdout=devnull): |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 443 | error("{} is missing from the system path! Exiting...".format(program)) |
Alexander Lane | 052aabb | 2018-05-14 14:48:29 -0500 | [diff] [blame] | 444 | sys.exit(1) |
| 445 | devnull.close() |
| 446 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 447 | if __name__ == '__main__': |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 448 | |
Ashlesh Gawande | 2763f19 | 2017-10-25 15:48:39 -0500 | [diff] [blame] | 449 | signal.signal(signal.SIGQUIT, signal_handler) |
Ashlesh Gawande | 3807c1b | 2016-08-05 16:27:02 -0500 | [diff] [blame] | 450 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 451 | options = parse_args() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 452 | |
| 453 | setLogLevel('info') |
Alexander Lane | 052aabb | 2018-05-14 14:48:29 -0500 | [diff] [blame] | 454 | verify_dependencies() |
Alexander Lane | e842cc2 | 2018-05-14 11:37:43 -0500 | [diff] [blame] | 455 | |
Alexander Lane | e842cc2 | 2018-05-14 11:37:43 -0500 | [diff] [blame] | 456 | try: |
| 457 | execute(options) |
| 458 | except Exception as e: |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame^] | 459 | error("{}".format(e)) |
Alexander Lane | e842cc2 | 2018-05-14 11:37:43 -0500 | [diff] [blame] | 460 | call(["nfd-stop"]) |
| 461 | call(["sudo", "mn", "--clean"]) |
Ashlesh Gawande | 670ff15 | 2018-06-08 12:26:39 -0500 | [diff] [blame] | 462 | sys.exit(1) |