Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 3 | # Copyright (C) 2015-2017, 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 |
| 63 | from mininet.log import setLogLevel, output, info |
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 | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 71 | from ndn.ndn_host import NdnHost, CpuLimitedNdnHost, RemoteNdnHost |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 72 | from ndn.conf_parser import parse_hosts, parse_switches, parse_links |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 73 | from ndn.remote_ndn_link import RemoteNdnLink, RemoteGRENdnLink |
| 74 | from ndn.placer import GuidedPlacer, PopulatePlacement |
Ashlesh Gawande | 95789cc | 2017-02-27 12:38:04 -0600 | [diff] [blame] | 75 | from ndn.util import ssh, scp, MiniNDNCLI |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 76 | |
| 77 | import os.path, time |
Yucheng Zhang | 14aa596 | 2016-04-05 17:10:15 -0500 | [diff] [blame] | 78 | import shutil |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 79 | import argparse |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 80 | import datetime |
ashu | 01b62f7 | 2015-03-12 15:16:11 -0500 | [diff] [blame] | 81 | from os.path import expanduser |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 82 | import sys |
Ashlesh Gawande | 3807c1b | 2016-08-05 16:27:02 -0500 | [diff] [blame] | 83 | import signal |
Yucheng Zhang | 14aa596 | 2016-04-05 17:10:15 -0500 | [diff] [blame] | 84 | from subprocess import call |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 85 | import glob |
| 86 | from functools import partial |
| 87 | import re |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 88 | |
| 89 | from ndn.nlsr import Nlsr, NlsrConfigGenerator |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 90 | from ndn.nfd import Nfd |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 91 | |
Ashlesh Gawande | da475f0 | 2017-03-01 17:20:58 -0600 | [diff] [blame] | 92 | VERSION_NUMBER = "0.3.0" |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 93 | INSTALL_DIR='/usr/local/etc/mini-ndn/' |
Vince Lehman | e9f116d | 2015-07-15 10:40:21 -0500 | [diff] [blame] | 94 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 95 | class PrintExperimentNames(argparse.Action): |
| 96 | def __init__(self, option_strings, dest, nargs=0, help=None): |
| 97 | 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] | 98 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 99 | def __call__(self, parser, namespace, values, option_string=None): |
| 100 | experimentNames = ExperimentManager.getExperimentNames() |
Ashlesh Gawande | 501d4d6 | 2017-10-25 13:12:11 -0500 | [diff] [blame] | 101 | experimentArgs = ExperimentManager.getExperimentArgs() |
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 | print("Mini-NDN experiments:") |
| 104 | for experiment in experimentNames: |
Ashlesh Gawande | 501d4d6 | 2017-10-25 13:12:11 -0500 | [diff] [blame] | 105 | print(" {}".format(experiment)) |
| 106 | if experiment in experimentArgs: |
| 107 | print(" ({})".format(experimentArgs[experiment])) |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 108 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 109 | sys.exit(0) |
Vince Lehman | e9f116d | 2015-07-15 10:40:21 -0500 | [diff] [blame] | 110 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 111 | class ProgramOptions: |
| 112 | def __init__(self): |
| 113 | self.ctime = 60 |
| 114 | self.experimentName = None |
| 115 | self.nFaces = 3 |
| 116 | self.templateFile = "minindn.conf" |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 117 | self.routingType = "link-state" |
dmcoomes | ecf9c5a | 2017-10-11 10:17:46 -0500 | [diff] [blame] | 118 | self.isNlsrEnabled = True |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 119 | self.isCliEnabled = True |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame] | 120 | self.nlsrSecurity = False |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 121 | self.nPings = 300 |
| 122 | self.testbed = False |
dmcoomes | 80eeea1 | 2017-10-27 12:49:10 -0500 | [diff] [blame] | 123 | self.workDir = "/tmp/minindn" |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 124 | self.resultDir = None |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 125 | self.pctTraffic = 1.0 |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 126 | self.cluster = None |
| 127 | self.servers = None |
| 128 | self.guided = None |
| 129 | self.placer = None |
| 130 | self.tunnelType = None |
Ashlesh Gawande | 708fcca | 2017-06-23 14:04:12 -0500 | [diff] [blame] | 131 | self.faceType = "udp" |
Ashlesh Gawande | 501d4d6 | 2017-10-25 13:12:11 -0500 | [diff] [blame] | 132 | self.arbArgs = {} |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 133 | |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 134 | def createResultsDir(resultDir, faces, rType): |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 135 | if faces == 0: |
| 136 | faces = "all" |
| 137 | |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 138 | routingChoice = "/{}/".format(rType) |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 139 | |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 140 | resultDir = "{}/{}/faces-{}".format(resultDir, routingChoice, faces) |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 141 | resultDir = os.path.abspath(resultDir) |
| 142 | |
| 143 | if not os.path.isdir(resultDir): |
| 144 | os.makedirs(resultDir) |
| 145 | else: |
| 146 | print("Results directory (%s) already exists!" % resultDir) |
| 147 | sys.exit(1); |
| 148 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 149 | print("Results will be stored at: %s" % resultDir) |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 150 | return resultDir |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 151 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 152 | def parse_args(): |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 153 | parser = argparse.ArgumentParser(prog='minindn') |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 154 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 155 | # nargs='?' required here since optional argument |
| 156 | parser.add_argument('tempfile', nargs='?', default=INSTALL_DIR + 'default-topology.conf', |
| 157 | help="If no template_file is given, ndn_utils/default-topology.conf (given sample file) will be used.") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 158 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 159 | parser.add_argument("--ctime", type=int, default=60, |
| 160 | help="Specify convergence time for the topology (Default: 60 seconds)") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 161 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 162 | parser.add_argument("--experiment", |
| 163 | help="Runs the specified experiment") |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 164 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 165 | parser.add_argument("--faces", type=int, default=3, |
| 166 | help="Specify number of faces 0-60") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 167 | |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 168 | parser.add_argument("--routing", dest="routingType", default='link-state', choices=['link-state', 'hr', 'dry'], |
| 169 | help="""choices for routing are 'link-state' for link state, 'hr' for hyperbolic, and 'dry' |
| 170 | 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] | 171 | |
dmcoomes | ecf9c5a | 2017-10-11 10:17:46 -0500 | [diff] [blame] | 172 | parser.add_argument("--no-nlsr", action="store_false", dest="isNlsrEnabled", |
| 173 | help="Run mini-ndn without NLSR routing") |
| 174 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 175 | parser.add_argument("--list-experiments", action=PrintExperimentNames, |
| 176 | help="Lists the names of all available experiments") |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 177 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 178 | parser.add_argument("--no-cli", action="store_false", dest="isCliEnabled", |
| 179 | help="Run experiments and exit without showing the command line interface") |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 180 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 181 | parser.add_argument("--nPings", type=int, default=300, |
| 182 | help="Number of pings to perform between each node in the experiment") |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 183 | |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 184 | # store_true stores default value of False |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 185 | parser.add_argument("--nlsr-security", action="store_true", dest="nlsrSecurity", |
| 186 | help="Enables NLSR security") |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame] | 187 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 188 | parser.add_argument("-t", "--testbed", action="store_true", dest="testbed", |
| 189 | help="Instantiates a snapshot of the NDN Testbed irrespective of the tempfile provided") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 190 | |
dmcoomes | 80eeea1 | 2017-10-27 12:49:10 -0500 | [diff] [blame] | 191 | parser.add_argument("--work-dir", action="store", dest="workDir", default="/tmp/minindn", |
| 192 | help="Specify the working directory; default is /tmp/minindn") |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 193 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 194 | parser.add_argument("--result-dir", action="store", dest="resultDir", default=None, |
| 195 | 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] | 196 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 197 | parser.add_argument("--pct-traffic", dest="pctTraffic", type=float, default=1.0, |
| 198 | help="Specify the percentage of nodes each node should ping") |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 199 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 200 | parser.add_argument('--version', '-V', action='version', version='%(prog)s ' + VERSION_NUMBER, |
| 201 | help='Displays version information') |
Vince Lehman | e9f116d | 2015-07-15 10:40:21 -0500 | [diff] [blame] | 202 | |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 203 | parser.add_argument("--cluster", metavar='localhost,server2,...', |
| 204 | help="Run cluster edition") |
| 205 | |
| 206 | parser.add_argument("--placement", default='guided', |
| 207 | choices=['roundRobin', 'guided']) |
| 208 | |
| 209 | parser.add_argument("--place-list", dest="placeList", |
| 210 | help="""Provide corresponding number of nodes (comma separated) to put on |
| 211 | each node respectively of --cluster when guided placement is used""") |
| 212 | |
| 213 | parser.add_argument("--tunnel-type", dest="tunnelType", default='ssh', |
| 214 | choices=['ssh', 'gre']) |
| 215 | |
Ashlesh Gawande | 708fcca | 2017-06-23 14:04:12 -0500 | [diff] [blame] | 216 | parser.add_argument("--face-type", dest='faceType', default='udp', choices=['udp', 'tcp']) |
| 217 | |
Ashlesh Gawande | 501d4d6 | 2017-10-25 13:12:11 -0500 | [diff] [blame] | 218 | args, unknownArgs = parser.parse_known_args() |
| 219 | |
| 220 | unknownArgsList = [] |
| 221 | for arg in unknownArgs: |
| 222 | if arg.startswith(("--")): |
| 223 | parser.add_argument(arg) |
| 224 | unknownArgsList.append(arg.split("--")[1]) |
| 225 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 226 | args = parser.parse_args() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 227 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 228 | options = ProgramOptions() |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 229 | options.templateFile = args.tempfile |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 230 | options.ctime = args.ctime |
| 231 | options.experimentName = args.experiment |
| 232 | options.nFaces = args.faces |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 233 | options.routingType = args.routingType |
dmcoomes | ecf9c5a | 2017-10-11 10:17:46 -0500 | [diff] [blame] | 234 | options.isNlsrEnabled = args.isNlsrEnabled |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 235 | options.isCliEnabled = args.isCliEnabled |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame] | 236 | options.nlsrSecurity = args.nlsrSecurity |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 237 | options.nPings = args.nPings |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame] | 238 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 239 | options.testbed = args.testbed |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 240 | options.workDir = args.workDir |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 241 | options.resultDir = args.resultDir |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 242 | options.pctTraffic = args.pctTraffic |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 243 | options.cluster = args.cluster |
| 244 | options.placement = args.placement |
| 245 | options.tunnelType = args.tunnelType |
| 246 | options.placeList = args.placeList |
Ashlesh Gawande | 708fcca | 2017-06-23 14:04:12 -0500 | [diff] [blame] | 247 | options.faceType = args.faceType |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 248 | |
Ashlesh Gawande | 501d4d6 | 2017-10-25 13:12:11 -0500 | [diff] [blame] | 249 | for k in args.__dict__: |
| 250 | if k in unknownArgsList: |
| 251 | options.arbArgs[k] = args.__dict__[k] |
| 252 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 253 | if options.experimentName is not None and options.experimentName not in ExperimentManager.getExperimentNames(): |
| 254 | print("No experiment named %s" % options.experimentName) |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 255 | sys.exit(1) |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 256 | |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 257 | if options.experimentName is not None and options.resultDir is None: |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 258 | print("No results folder specified; experiment results will remain in the working directory") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 259 | |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 260 | if options.cluster is not None: |
| 261 | servers = options.cluster.split(',') |
| 262 | for server in servers: |
| 263 | ClusterCleanup.add(server) |
| 264 | options.servers = servers |
| 265 | |
| 266 | if options.placement == "roundRobin": |
| 267 | options.placement = RoundRobinPlacer |
| 268 | elif options.placement == "guided": |
| 269 | if options.placeList is None or not re.match("^[0-9,]+$", options.placeList): |
| 270 | print("Please specify correctly how many nodes you want to place on each node!") |
| 271 | sys.exit(1) |
| 272 | else: |
| 273 | try: |
| 274 | options.placeList = map(int, options.placeList.split(",")) |
| 275 | except ValueError: |
| 276 | print("Please specify the nodes correctly, no comma at the beginning/end!") |
| 277 | sys.exit(1) |
| 278 | |
| 279 | PopulatePlacement(options.placeList) |
| 280 | options.placement = GuidedPlacer |
| 281 | |
| 282 | if options.tunnelType == "ssh": |
| 283 | options.tunnelType = RemoteNdnLink |
| 284 | else: |
| 285 | options.tunnelType = RemoteGRENdnLink |
| 286 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 287 | return options |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 288 | |
| 289 | class NdnTopo(Topo): |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 290 | def __init__(self, conf_arq, workDir, **opts): |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 291 | Topo.__init__(self, **opts) |
| 292 | |
| 293 | global hosts_conf |
| 294 | global links_conf |
| 295 | hosts_conf = parse_hosts(conf_arq) |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 296 | switches_conf = parse_switches(conf_arq) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 297 | links_conf = parse_links(conf_arq) |
| 298 | |
| 299 | self.isTCLink = False |
| 300 | self.isLimited = False |
| 301 | |
| 302 | for host in hosts_conf: |
| 303 | if host.cpu != None and self.isLimited != True: |
| 304 | self.isLimited = True |
dmcoomes | 74da84c | 2017-11-07 16:09:23 -0600 | [diff] [blame] | 305 | self.addHost(host.name, app=host.app, params=host.uri_tuples, cpu=host.cpu, |
| 306 | cores=host.cores,cache=host.cache, workdir=workDir) |
| 307 | if (options.routingType != 'link-state' and (host.params.get('radius') is None |
| 308 | or host.params.get('angle') is None)): |
| 309 | info('Hyperbolic coordinates in topology file are either missing or misconfigured.\n' \ |
| 310 | 'Check that each node has one radius value and one or two angle value(s).\n') |
| 311 | sys.exit(1) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 312 | |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 313 | for switch in switches_conf: |
| 314 | self.addSwitch(switch.name) |
| 315 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 316 | for link in links_conf: |
| 317 | if len(link.linkDict) == 0: |
| 318 | self.addLink(link.h1, link.h2) |
| 319 | else: |
| 320 | self.addLink(link.h1, link.h2, **link.linkDict) |
| 321 | self.isTCLink = True |
| 322 | |
| 323 | info('Parse of ' + conf_arq + ' done.\n') |
| 324 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 325 | def execute(options): |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 326 | "Create a network based on template_file" |
| 327 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 328 | if options.testbed: |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 329 | options.templateFile = INSTALL_DIR + 'minindn.testbed.conf' |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 330 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 331 | if os.path.exists(options.templateFile) == False: |
| 332 | info('Template file cannot be found. Exiting...\n') |
| 333 | sys.exit(1) |
Ashlesh Gawande | 20f7076 | 2015-06-17 15:18:19 -0500 | [diff] [blame] | 334 | |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 335 | if options.cluster is not None and options.placement == GuidedPlacer: |
| 336 | num_nodes = 0 |
| 337 | with open(options.templateFile, 'r') as topo: |
| 338 | for line in topo: |
| 339 | if ': _' in line: |
| 340 | num_nodes += 1 |
| 341 | |
| 342 | if sum(options.placeList) != num_nodes: |
| 343 | print("Placement list sum is not equal to number of nodes!") |
| 344 | sys.exit(1) |
| 345 | |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 346 | # Copy nfd.conf to remote hosts - this assumes that NDN versions across |
| 347 | # the cluster are at least compatible if not the same |
| 348 | if options.cluster is not None: |
| 349 | for server in options.servers: |
| 350 | if server != "localhost": |
| 351 | login = "mininet@%s" % server |
| 352 | src = nfdConfFile |
| 353 | dst = "%s:/tmp/nfd.conf" % (login) |
| 354 | scp(src, dst) |
| 355 | ssh(login, "sudo cp /tmp/nfd.conf %s" % src) |
| 356 | |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 357 | if options.resultDir is not None: |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 358 | options.resultDir = createResultsDir(options.resultDir, options.nFaces, options.routingType) |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 359 | |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 360 | topo = NdnTopo(options.templateFile, options.workDir) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 361 | |
| 362 | t = datetime.datetime.now() |
| 363 | |
| 364 | if topo.isTCLink == True and topo.isLimited == True: |
| 365 | net = Mininet(topo,host=CpuLimitedNdnHost,link=TCLink) |
| 366 | elif topo.isTCLink == True and topo.isLimited == False: |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 367 | if options.cluster is not None: |
| 368 | mn = partial(MininetCluster, servers=options.servers, placement=options.placement) |
| 369 | net = mn(topo=topo, host=RemoteNdnHost, link=options.tunnelType) |
| 370 | else: |
| 371 | net = Mininet(topo, host=NdnHost, link=TCLink) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 372 | elif topo.isTCLink == False and topo.isLimited == True: |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 373 | net = Mininet(topo, host=CpuLimitedNdnHost) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 374 | else: |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 375 | net = Mininet(topo, host=NdnHost) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 376 | |
| 377 | t2 = datetime.datetime.now() |
| 378 | |
| 379 | delta = t2 - t |
| 380 | |
| 381 | info('Setup time: ' + str(delta.seconds) + '\n') |
| 382 | |
| 383 | net.start() |
| 384 | |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 385 | # Giving proper IPs to intf so neighbor nodes can communicate |
| 386 | # This is one way of giving connectivity, another way could be |
| 387 | # to insert a switch between each pair of neighbors |
| 388 | ndnNetBase = "1.0.0.0" |
| 389 | interfaces = [] |
| 390 | for host in net.hosts: |
| 391 | for intf in host.intfList(): |
| 392 | link = intf.link |
| 393 | node1, node2 = link.intf1.node, link.intf2.node |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 394 | |
| 395 | if node1 in net.switches or node2 in net.switches: |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 396 | continue |
| 397 | |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 398 | if link.intf1 not in interfaces and link.intf2 not in interfaces: |
| 399 | interfaces.append(link.intf1) |
| 400 | interfaces.append(link.intf2) |
| 401 | node1.setIP(ipStr(ipParse(ndnNetBase) + 1) + '/30', intf=link.intf1) |
| 402 | node2.setIP(ipStr(ipParse(ndnNetBase) + 2) + '/30', intf=link.intf2) |
| 403 | ndnNetBase = ipStr(ipParse(ndnNetBase) + 4) |
| 404 | |
dmcoomes | ecf9c5a | 2017-10-11 10:17:46 -0500 | [diff] [blame] | 405 | if options.isNlsrEnabled is True: |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame] | 406 | |
dmcoomes | ecf9c5a | 2017-10-11 10:17:46 -0500 | [diff] [blame] | 407 | # NLSR Security |
| 408 | if options.nlsrSecurity is True: |
| 409 | Nlsr.createKeysAndCertificates(net, options.workDir) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 410 | |
dmcoomes | ecf9c5a | 2017-10-11 10:17:46 -0500 | [diff] [blame] | 411 | # NLSR initialization |
| 412 | for host in net.hosts: |
| 413 | conf = next(x for x in hosts_conf if x.name == host.name) |
| 414 | host.nlsrParameters = conf.nlsrParameters |
| 415 | |
| 416 | if options.nFaces is not None: |
| 417 | host.nlsrParameters["max-faces-per-prefix"] = options.nFaces |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 418 | |
dmcoomes | 2ef39c0 | 2017-10-20 14:06:26 -0500 | [diff] [blame] | 419 | if options.routingType == 'dry': |
| 420 | host.nlsrParameters["hyperbolic-state"] = "dry-run" |
dmcoomes | 7adc7f7 | 2017-10-06 12:01:28 -0500 | [diff] [blame] | 421 | |
dmcoomes | 2ef39c0 | 2017-10-20 14:06:26 -0500 | [diff] [blame] | 422 | elif options.routingType == 'hr': |
| 423 | host.nlsrParameters["hyperbolic-state"] = "on" |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 424 | |
dmcoomes | ecf9c5a | 2017-10-11 10:17:46 -0500 | [diff] [blame] | 425 | # Generate NLSR configuration file |
| 426 | configGenerator = NlsrConfigGenerator(host, options.nlsrSecurity, options.faceType) |
| 427 | configGenerator.createConfigFile() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 428 | |
dmcoomes | ecf9c5a | 2017-10-11 10:17:46 -0500 | [diff] [blame] | 429 | # Start NLSR |
| 430 | host.nlsr = Nlsr(host, configGenerator.neighborIPs, options.faceType) |
| 431 | host.nlsr.start() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 432 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 433 | for host in net.hosts: |
| 434 | if 'app' in host.params: |
Ashlesh Gawande | 557cb84 | 2015-07-01 15:39:44 -0500 | [diff] [blame] | 435 | if host.params['app'] != '': |
| 436 | app = host.params['app'] |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 437 | print("Starting " + app + " on node " + host.name) |
Ashlesh Gawande | 557cb84 | 2015-07-01 15:39:44 -0500 | [diff] [blame] | 438 | print(host.cmd(app)) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 439 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 440 | # Load experiment |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 441 | experimentName = options.experimentName |
| 442 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 443 | if experimentName is not None: |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 444 | print("Loading experiment: %s" % experimentName) |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 445 | |
| 446 | experimentArgs = { |
| 447 | "net": net, |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 448 | "ctime": options.ctime, |
| 449 | "nPings": options.nPings, |
Ashlesh Gawande | b07ada8 | 2016-08-05 14:29:17 -0500 | [diff] [blame] | 450 | "strategy": Nfd.STRATEGY_BEST_ROUTE, |
Ashlesh Gawande | 6a075c2 | 2017-08-03 15:15:49 -0500 | [diff] [blame] | 451 | "pctTraffic": options.pctTraffic, |
Ashlesh Gawande | 501d4d6 | 2017-10-25 13:12:11 -0500 | [diff] [blame] | 452 | "nlsrSecurity": options.nlsrSecurity, |
| 453 | "workDir": options.workDir, |
| 454 | "arbArgs" : options.arbArgs |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | experiment = ExperimentManager.create(experimentName, experimentArgs) |
| 458 | |
| 459 | if experiment is not None: |
| 460 | experiment.start() |
| 461 | else: |
Ashlesh Gawande | 044611d | 2016-12-21 14:24:49 -0600 | [diff] [blame] | 462 | print("ERROR: Experiment '%s' does not exist" % experimentName) |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 463 | return |
| 464 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 465 | if options.isCliEnabled is True: |
Ashlesh Gawande | 95789cc | 2017-02-27 12:38:04 -0600 | [diff] [blame] | 466 | MiniNDNCLI(net) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 467 | |
| 468 | net.stop() |
| 469 | |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 470 | if options.resultDir is not None: |
| 471 | print("Moving results to %s" % options.resultDir) |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 472 | for file in glob.glob('%s/*' % options.workDir): |
| 473 | shutil.move(file, options.resultDir) |
| 474 | if options.cluster is not None: |
| 475 | for server in options.servers: |
| 476 | if server != "localhost": |
| 477 | login = "mininet@%s" % server |
| 478 | src = "%s:%s/*" % (login, options.workDir) |
| 479 | dst = options.resultDir |
| 480 | scp(src, dst) |
| 481 | print("Please clean work directories of other machines before running the cluster again") |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 482 | |
Ashlesh Gawande | 3807c1b | 2016-08-05 16:27:02 -0500 | [diff] [blame] | 483 | def signal_handler(signal, frame): |
| 484 | print('Cleaning up...') |
| 485 | call(["nfd-stop"]) |
| 486 | call(["sudo", "mn", "--clean"]) |
| 487 | sys.exit(1) |
| 488 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 489 | if __name__ == '__main__': |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 490 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 491 | hosts_conf = [] |
| 492 | links_conf = [] |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 493 | |
Ashlesh Gawande | 2763f19 | 2017-10-25 15:48:39 -0500 | [diff] [blame] | 494 | signal.signal(signal.SIGQUIT, signal_handler) |
Ashlesh Gawande | 3807c1b | 2016-08-05 16:27:02 -0500 | [diff] [blame] | 495 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 496 | options = parse_args() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 497 | |
| 498 | setLogLevel('info') |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 499 | execute(options) |