Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
Carmelo Cascone | 977ae3f | 2016-06-23 19:28:28 -0700 | [diff] [blame] | 3 | import os |
| 4 | import sys |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 5 | import json |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 6 | import argparse |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 7 | from collections import OrderedDict |
Carmelo Cascone | 977ae3f | 2016-06-23 19:28:28 -0700 | [diff] [blame] | 8 | |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 9 | TEMP_NETCFG_FILE = '/tmp/bmv2-demo-cfg.json' |
| 10 | BASE_LONGITUDE = -115 |
| 11 | SWITCH_BASE_LATITUDE = 25 |
| 12 | HOST_BASE_LATITUDE = 28 |
| 13 | BASE_SHIFT = 8 |
| 14 | VLAN_NONE = -1 |
| 15 | DEFAULT_SW_BW = 50 |
| 16 | DEFAULT_HOST_BW = 25 |
| 17 | |
Carmelo Cascone | 977ae3f | 2016-06-23 19:28:28 -0700 | [diff] [blame] | 18 | if 'ONOS_ROOT' not in os.environ: |
| 19 | print "Environment var $ONOS_ROOT not set" |
| 20 | exit() |
| 21 | else: |
Carmelo Cascone | 12e4d8d | 2016-07-05 15:55:15 -0700 | [diff] [blame] | 22 | ONOS_ROOT = os.environ["ONOS_ROOT"] |
| 23 | sys.path.append(ONOS_ROOT + "/tools/dev/mininet") |
Devin Lim | 0d944e2 | 2017-06-23 15:17:53 -0700 | [diff] [blame] | 24 | if 'RUN_PACK_PATH' not in os.environ: |
| 25 | print "Environment var $RUN_PACK_PATH not set" |
| 26 | exit() |
| 27 | else: |
| 28 | RUN_PACK_PATH = os.environ["RUN_PACK_PATH"] |
Carmelo Cascone | 12e4d8d | 2016-07-05 15:55:15 -0700 | [diff] [blame] | 29 | |
| 30 | from onos import ONOSCluster, ONOSCLI |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 31 | from bmv2 import ONOSBmv2Switch, ONOSHost |
Carmelo Cascone | 977ae3f | 2016-06-23 19:28:28 -0700 | [diff] [blame] | 32 | |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 33 | from itertools import combinations |
| 34 | from time import sleep |
Carmelo Cascone | 12e4d8d | 2016-07-05 15:55:15 -0700 | [diff] [blame] | 35 | from subprocess import call |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 36 | |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 37 | from mininet.cli import CLI |
| 38 | from mininet.link import TCLink |
| 39 | from mininet.log import setLogLevel |
| 40 | from mininet.net import Mininet |
| 41 | from mininet.node import RemoteController, Host |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 42 | from mininet.topo import Topo |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 43 | |
Carmelo Cascone | 73f6b6d | 2017-08-24 13:17:55 +0200 | [diff] [blame] | 44 | |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 45 | def getCmdBg(cmd, logfile="/dev/null"): |
| 46 | return "{} > {} 2>&1 &".format(cmd, logfile) |
| 47 | |
| 48 | |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 49 | class ClosTopo(Topo): |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 50 | """2 stage Clos topology""" |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 51 | |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 52 | def __init__(self, args, **opts): |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 53 | # Initialize topology and default options |
| 54 | Topo.__init__(self, **opts) |
| 55 | |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 56 | bmv2SwitchIds = [] |
| 57 | for row in (1, 2): |
| 58 | for col in range(1, args.size + 1): |
| 59 | bmv2SwitchIds.append("s%d%d" % (row, col)) |
| 60 | |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 61 | bmv2Switches = {} |
| 62 | |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 63 | for switchId in bmv2SwitchIds: |
Carmelo Cascone | 73f6b6d | 2017-08-24 13:17:55 +0200 | [diff] [blame] | 64 | deviceId = int(switchId[1:]) |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 65 | # Use first number in device id to calculate latitude (row number), |
| 66 | # use second to calculate longitude (column number) |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 67 | latitude = SWITCH_BASE_LATITUDE + (deviceId // 10) * BASE_SHIFT |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 68 | longitude = BASE_LONGITUDE + (deviceId % 10) * BASE_SHIFT |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 69 | |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 70 | bmv2Switches[switchId] = self.addSwitch(switchId, |
| 71 | cls=ONOSBmv2Switch, |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 72 | loglevel=args.log_level, |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 73 | deviceId=deviceId, |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 74 | netcfg=True, |
| 75 | netcfgDelay=0.5, |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 76 | longitude=longitude, |
| 77 | latitude=latitude, |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 78 | pipeconfId=args.pipeconf_id) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 79 | |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 80 | for i in range(1, args.size + 1): |
| 81 | for j in range(1, args.size + 1): |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 82 | if i == j: |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 83 | self.addLink(bmv2Switches["s1%d" % i], |
| 84 | bmv2Switches["s2%d" % j], |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 85 | cls=TCLink, bw=DEFAULT_SW_BW) |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 86 | if args.with_imbalanced_striping: |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 87 | # 2 links |
| 88 | self.addLink(bmv2Switches["s1%d" % i], |
| 89 | bmv2Switches["s2%d" % j], |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 90 | cls=TCLink, bw=DEFAULT_SW_BW) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 91 | else: |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 92 | self.addLink(bmv2Switches["s1%d" % i], |
| 93 | bmv2Switches["s2%d" % j], |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 94 | cls=TCLink, bw=DEFAULT_SW_BW) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 95 | |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 96 | for hostId in range(1, args.size + 1): |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 97 | host = self.addHost("h%d" % hostId, |
| 98 | cls=DemoHost, |
| 99 | ip="10.0.0.%d/24" % hostId, |
| 100 | mac='00:00:00:00:00:%02x' % hostId) |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 101 | self.addLink(host, bmv2Switches["s1%d" % hostId], |
| 102 | cls=TCLink, bw=DEFAULT_HOST_BW) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 103 | |
| 104 | |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 105 | class DemoHost(ONOSHost): |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 106 | """Demo host""" |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 107 | |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 108 | def __init__(self, name, **params): |
| 109 | ONOSHost.__init__(self, name, **params) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 110 | self.exectoken = "/tmp/mn-exec-token-host-%s" % name |
| 111 | self.cmd("touch %s" % self.exectoken) |
| 112 | |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 113 | def startPingBg(self, h): |
| 114 | self.cmd(self.getInfiniteCmdBg("ping -i0.5 %s" % h.IP())) |
| 115 | self.cmd(self.getInfiniteCmdBg("arping -w5000000 %s" % h.IP())) |
| 116 | |
| 117 | def startIperfServer(self): |
Carmelo Cascone | 6e85404 | 2017-09-11 21:37:53 +0200 | [diff] [blame] | 118 | self.cmd(self.getInfiniteCmdBg("iperf -s -u")) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 119 | |
| 120 | def startIperfClient(self, h, flowBw="512k", numFlows=5, duration=5): |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 121 | iperfCmd = "iperf -c{} -u -b{} -P{} -t{}".format( |
| 122 | h.IP(), flowBw, numFlows, duration) |
| 123 | self.cmd(self.getInfiniteCmdBg(iperfCmd, delay=0)) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 124 | |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 125 | def stop(self, **kwargs): |
Carmelo Cascone | 6e85404 | 2017-09-11 21:37:53 +0200 | [diff] [blame] | 126 | self.cmd("killall iperf") |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 127 | self.cmd("killall ping") |
| 128 | self.cmd("killall arping") |
| 129 | |
| 130 | def describe(self): |
| 131 | print "**********" |
| 132 | print self.name |
| 133 | print "default interface: %s\t%s\t%s" % ( |
| 134 | self.defaultIntf().name, |
| 135 | self.defaultIntf().IP(), |
| 136 | self.defaultIntf().MAC() |
| 137 | ) |
| 138 | print "**********" |
| 139 | |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 140 | def getInfiniteCmdBg(self, cmd, logfile="/dev/null", delay=1): |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 141 | return "(while [ -e {} ]; " \ |
| 142 | "do {}; " \ |
| 143 | "sleep {}; " \ |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 144 | "done;) > {} 2>&1 &".format(self.exectoken, cmd, delay, logfile) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 145 | |
Carmelo Cascone | 73f6b6d | 2017-08-24 13:17:55 +0200 | [diff] [blame] | 146 | |
| 147 | def generateNetcfg(onosIp, net, args): |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 148 | netcfg = OrderedDict() |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 149 | |
| 150 | netcfg['hosts'] = {} |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 151 | netcfg['devices'] = {} |
| 152 | netcfg['links'] = {} |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 153 | |
| 154 | if args.full_netcfg: |
| 155 | # Device configs |
| 156 | for sw in net.switches: |
| 157 | srcIp = sw.getSourceIp(onosIp) |
| 158 | netcfg['devices'][sw.onosDeviceId] = sw.getDeviceConfig(srcIp) |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 159 | |
| 160 | hostLocations = {} |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 161 | for link in net.links: |
| 162 | switchPort = link.intf1.name.split('-') |
Carmelo Cascone | 73f6b6d | 2017-08-24 13:17:55 +0200 | [diff] [blame] | 163 | sw1Name = switchPort[0] # s11 |
| 164 | port1Name = switchPort[1] # eth0 |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 165 | port1 = port1Name[3:] |
| 166 | switchPort = link.intf2.name.split('-') |
| 167 | sw2Name = switchPort[0] |
| 168 | port2Name = switchPort[1] |
| 169 | port2 = port2Name[3:] |
| 170 | sw1 = net[sw1Name] |
| 171 | sw2 = net[sw2Name] |
| 172 | if isinstance(sw1, Host): |
| 173 | # record host location and ignore it |
| 174 | # e.g. {'h1': 'device:bmv2:11'} |
| 175 | hostLocations[sw1.name] = '%s/%s' % (sw2.onosDeviceId, port2) |
| 176 | continue |
| 177 | |
| 178 | if isinstance(sw2, Host): |
| 179 | # record host location and ignore it |
| 180 | # e.g. {'h1': 'device:bmv2:11'} |
| 181 | hostLocations[sw2.name] = '%s/%s' % (sw1.onosDeviceId, port1) |
| 182 | continue |
| 183 | |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 184 | if args.full_netcfg: |
| 185 | # Link configs |
| 186 | for linkId in ('%s/%s-%s/%s' % (sw1.onosDeviceId, port1, |
| 187 | sw2.onosDeviceId, port2), |
| 188 | '%s/%s-%s/%s' % (sw2.onosDeviceId, port2, |
| 189 | sw1.onosDeviceId, port1)): |
| 190 | netcfg['links'][linkId] = { |
| 191 | 'basic': { |
| 192 | 'type': 'DIRECT', |
| 193 | 'bandwidth': DEFAULT_SW_BW |
| 194 | } |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 195 | } |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 196 | |
| 197 | # Host configs |
| 198 | longitude = BASE_LONGITUDE |
| 199 | for host in net.hosts: |
| 200 | longitude = longitude + BASE_SHIFT |
| 201 | hostDefaultIntf = host.defaultIntf() |
| 202 | hostMac = host.MAC(hostDefaultIntf) |
| 203 | hostIp = host.IP(hostDefaultIntf) |
| 204 | hostId = '%s/%d' % (hostMac, VLAN_NONE) |
| 205 | location = hostLocations[host.name] |
| 206 | |
| 207 | # use host Id to generate host location |
| 208 | hostConfig = { |
| 209 | 'basic': { |
| 210 | 'locations': [location], |
| 211 | 'ips': [hostIp], |
| 212 | 'name': host.name, |
| 213 | 'latitude': HOST_BASE_LATITUDE, |
| 214 | 'longitude': longitude |
| 215 | } |
| 216 | } |
| 217 | netcfg['hosts'][hostId] = hostConfig |
| 218 | |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 219 | if args.full_netcfg: |
| 220 | netcfg["apps"] = { |
| 221 | "org.onosproject.core": { |
| 222 | "core": { |
| 223 | "linkDiscoveryMode": "STRICT" |
| 224 | } |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 225 | } |
| 226 | } |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 227 | |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 228 | print "Writing network config to %s" % TEMP_NETCFG_FILE |
| 229 | with open(TEMP_NETCFG_FILE, 'w') as tempFile: |
Carmelo Cascone | 73f6b6d | 2017-08-24 13:17:55 +0200 | [diff] [blame] | 230 | json.dump(netcfg, tempFile, indent=4) |
| 231 | |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 232 | |
| 233 | def main(args): |
Carmelo Cascone | 12e4d8d | 2016-07-05 15:55:15 -0700 | [diff] [blame] | 234 | if not args.onos_ip: |
| 235 | controller = ONOSCluster('c0', 3) |
| 236 | onosIp = controller.nodes()[0].IP() |
| 237 | else: |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 238 | controller = RemoteController('c0', ip=args.onos_ip) |
Carmelo Cascone | 12e4d8d | 2016-07-05 15:55:15 -0700 | [diff] [blame] | 239 | onosIp = args.onos_ip |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 240 | |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 241 | topo = ClosTopo(args) |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 242 | |
Carmelo Cascone | 12e4d8d | 2016-07-05 15:55:15 -0700 | [diff] [blame] | 243 | net = Mininet(topo=topo, build=False, controller=[controller]) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 244 | |
| 245 | net.build() |
| 246 | net.start() |
| 247 | |
Carmelo Cascone | 12e4d8d | 2016-07-05 15:55:15 -0700 | [diff] [blame] | 248 | print "Network started" |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 249 | |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 250 | # Always generate background pings. |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 251 | sleep(3) |
| 252 | for (h1, h2) in combinations(net.hosts, 2): |
| 253 | h1.startPingBg(h2) |
| 254 | h2.startPingBg(h1) |
| 255 | |
Carmelo Cascone | 12e4d8d | 2016-07-05 15:55:15 -0700 | [diff] [blame] | 256 | print "Background ping started" |
| 257 | |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 258 | for h in net.hosts: |
| 259 | h.startIperfServer() |
| 260 | |
Carmelo Cascone | 12e4d8d | 2016-07-05 15:55:15 -0700 | [diff] [blame] | 261 | print "Iperf servers started" |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 262 | |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 263 | if args.bg_traffic: |
| 264 | sleep(4) |
| 265 | print "Starting iperf clients..." |
| 266 | net.hosts[0].startIperfClient(net.hosts[-1], flowBw="400k", |
| 267 | numFlows=50, duration=10) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 268 | |
Carmelo Cascone | 73f6b6d | 2017-08-24 13:17:55 +0200 | [diff] [blame] | 269 | generateNetcfg(onosIp, net, args) |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 270 | |
Carmelo Cascone | 6e85404 | 2017-09-11 21:37:53 +0200 | [diff] [blame] | 271 | if args.netcfg_sleep > 0: |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 272 | print "Waiting %d seconds before pushing config to ONOS..." \ |
| 273 | % args.netcfg_sleep |
Carmelo Cascone | 6e85404 | 2017-09-11 21:37:53 +0200 | [diff] [blame] | 274 | sleep(args.netcfg_sleep) |
| 275 | |
| 276 | print "Pushing config to ONOS..." |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 277 | call(("%s/onos-netcfg" % RUN_PACK_PATH, onosIp, TEMP_NETCFG_FILE)) |
Carmelo Cascone | 12e4d8d | 2016-07-05 15:55:15 -0700 | [diff] [blame] | 278 | |
| 279 | if not args.onos_ip: |
| 280 | ONOSCLI(net) |
| 281 | else: |
| 282 | CLI(net) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 283 | |
| 284 | net.stop() |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 285 | call(("rm", "-f", TEMP_NETCFG_FILE)) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 286 | |
| 287 | |
| 288 | if __name__ == '__main__': |
Carmelo Cascone | 12e4d8d | 2016-07-05 15:55:15 -0700 | [diff] [blame] | 289 | parser = argparse.ArgumentParser( |
| 290 | description='BMv2 mininet demo script (2-stage Clos topology)') |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 291 | parser.add_argument('--onos-ip', help='ONOS-BMv2 controller IP address', |
Carmelo Cascone | 12e4d8d | 2016-07-05 15:55:15 -0700 | [diff] [blame] | 292 | type=str, action="store", required=False) |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 293 | parser.add_argument('--size', help='Number of leaf/spine switches', |
| 294 | type=int, action="store", required=False, default=2) |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 295 | parser.add_argument('--with-imbalanced-striping', |
| 296 | help='Topology with imbalanced striping', |
| 297 | type=bool, action="store", required=False, |
| 298 | default=False) |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 299 | parser.add_argument('--pipeconf-id', help='Pipeconf ID for switches', |
| 300 | type=str, action="store", required=False, default='') |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 301 | parser.add_argument('--netcfg-sleep', |
| 302 | help='Seconds to wait before pushing config to ONOS', |
Carmelo Cascone | 6e85404 | 2017-09-11 21:37:53 +0200 | [diff] [blame] | 303 | type=int, action="store", required=False, default=5) |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 304 | parser.add_argument('--log-level', help='BMv2 log level', |
| 305 | type=str, action="store", required=False, |
| 306 | default='warn') |
| 307 | parser.add_argument('--full-netcfg', |
| 308 | help='Generate full netcfg JSON with links and devices', |
| 309 | type=bool, action="store", required=False, |
| 310 | default=False) |
| 311 | parser.add_argument('--bg-traffic', |
| 312 | help='Starts background traffic', |
| 313 | type=bool, action="store", required=False, |
| 314 | default=False) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 315 | setLogLevel('info') |
Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame] | 316 | main(parser.parse_args()) |