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