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