Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 1 | import os |
Carmelo Cascone | 977ae3f | 2016-06-23 19:28:28 -0700 | [diff] [blame] | 2 | import socket |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 3 | import re |
| 4 | import json |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 5 | import threading |
Brian O'Connor | 71167f9 | 2017-06-16 14:55:00 -0700 | [diff] [blame] | 6 | import urllib2 |
Carmelo Cascone | 977ae3f | 2016-06-23 19:28:28 -0700 | [diff] [blame] | 7 | |
Carmelo Cascone | 46d360b | 2017-08-29 20:20:32 +0200 | [diff] [blame] | 8 | import time |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 9 | from contextlib import closing |
Carmelo Cascone | 46d360b | 2017-08-29 20:20:32 +0200 | [diff] [blame] | 10 | |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 11 | from mininet.log import info, warn, error |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 12 | from mininet.node import Switch, Host |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 13 | |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 14 | if 'ONOS_ROOT' not in os.environ: |
| 15 | error("ERROR: environment var $ONOS_ROOT not set") |
| 16 | exit() |
| 17 | |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 18 | SIMPLE_SWITCH_GRPC = 'simple_switch_grpc' |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 19 | ONOS_ROOT = os.environ["ONOS_ROOT"] |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 20 | PKT_BYTES_TO_DUMP = 80 |
Carmelo Cascone | 46d360b | 2017-08-29 20:20:32 +0200 | [diff] [blame] | 21 | VALGRIND_PREFIX = 'valgrind --leak-check=yes' |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 22 | SWITCH_START_TIMEOUT = 5 # seconds |
| 23 | BMV2_LOG_LINES = 5 |
| 24 | |
Carmelo Cascone | 46d360b | 2017-08-29 20:20:32 +0200 | [diff] [blame] | 25 | |
| 26 | def parseBoolean(value): |
| 27 | if value in ['1', 1, 'true', 'True']: |
| 28 | return True |
| 29 | else: |
| 30 | return False |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 31 | |
| 32 | |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 33 | def pickUnusedPort(): |
| 34 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 35 | s.bind(('localhost', 0)) |
| 36 | addr, port = s.getsockname() |
| 37 | s.close() |
| 38 | return port |
| 39 | |
| 40 | |
| 41 | def writeToFile(path, value): |
| 42 | with open(path, "w") as f: |
| 43 | f.write(str(value)) |
| 44 | |
| 45 | |
| 46 | def watchDog(sw): |
| 47 | while True: |
| 48 | if sw.stopped: |
| 49 | return |
| 50 | with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s: |
| 51 | if s.connect_ex(('127.0.0.1', sw.grpcPort)) == 0: |
| 52 | time.sleep(1) |
| 53 | else: |
| 54 | warn("\n*** WARN: BMv2 instance %s (%s) died!\n" |
| 55 | % (sw.deviceId, sw.name)) |
| 56 | sw.printBmv2Log() |
| 57 | print ("-" * 80) + "\n" |
| 58 | return |
| 59 | |
| 60 | |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 61 | class ONOSHost(Host): |
| 62 | def __init__(self, name, inNamespace=True, **params): |
| 63 | Host.__init__(self, name, inNamespace=inNamespace, **params) |
| 64 | |
| 65 | def config(self, **params): |
| 66 | r = super(Host, self).config(**params) |
| 67 | for off in ["rx", "tx", "sg"]: |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 68 | cmd = "/sbin/ethtool --offload %s %s off" \ |
Carmelo Cascone | 6ec8f8f | 2017-11-22 14:27:06 -0800 | [diff] [blame] | 69 | % (self.defaultIntf(), off) |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 70 | self.cmd(cmd) |
| 71 | # disable IPv6 |
| 72 | self.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1") |
| 73 | self.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1") |
| 74 | self.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1") |
| 75 | return r |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 76 | |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 77 | |
| 78 | class ONOSBmv2Switch(Switch): |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 79 | """BMv2 software switch with gRPC server""" |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 80 | |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 81 | deviceId = 0 |
| 82 | |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 83 | def __init__(self, name, json=None, debugger=False, loglevel="warn", |
Carmelo Cascone | eaa8b1d | 2018-04-11 14:12:17 -0700 | [diff] [blame] | 84 | elogger=False, grpcport=None, cpuport=255, |
| 85 | thriftport=None, netcfg=True, dryrun=False, pipeconf="", |
| 86 | pktdump=False, valgrind=False, gnmi=False, |
| 87 | portcfg=True, **kwargs): |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 88 | Switch.__init__(self, name, **kwargs) |
Carmelo Cascone | eaa8b1d | 2018-04-11 14:12:17 -0700 | [diff] [blame] | 89 | self.grpcPort = pickUnusedPort() if not grpcport else grpcport |
| 90 | self.thriftPort = pickUnusedPort() if not thriftport else thriftport |
Carmelo Cascone | 75e9799 | 2017-06-05 02:32:47 -0400 | [diff] [blame] | 91 | if self.dpid: |
| 92 | self.deviceId = int(self.dpid, 0 if 'x' in self.dpid else 16) |
Carmelo Cascone | 977ae3f | 2016-06-23 19:28:28 -0700 | [diff] [blame] | 93 | else: |
Carmelo Cascone | 75e9799 | 2017-06-05 02:32:47 -0400 | [diff] [blame] | 94 | self.deviceId = ONOSBmv2Switch.deviceId |
| 95 | ONOSBmv2Switch.deviceId += 1 |
Carmelo Cascone | eaa8b1d | 2018-04-11 14:12:17 -0700 | [diff] [blame] | 96 | self.cpuPort = cpuport |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 97 | self.json = json |
Carmelo Cascone | 46d360b | 2017-08-29 20:20:32 +0200 | [diff] [blame] | 98 | self.debugger = parseBoolean(debugger) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 99 | self.loglevel = loglevel |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 100 | # Important: Mininet removes all /tmp/*.log files in case of exceptions. |
| 101 | # We want to be able to see the bmv2 log if anything goes wrong, hence |
| 102 | # avoid the .log extension. |
| 103 | self.logfile = '/tmp/bmv2-%d-log' % self.deviceId |
Carmelo Cascone | 46d360b | 2017-08-29 20:20:32 +0200 | [diff] [blame] | 104 | self.elogger = parseBoolean(elogger) |
| 105 | self.pktdump = parseBoolean(pktdump) |
Carmelo Cascone | 46d360b | 2017-08-29 20:20:32 +0200 | [diff] [blame] | 106 | self.netcfg = parseBoolean(netcfg) |
| 107 | self.dryrun = parseBoolean(dryrun) |
| 108 | self.valgrind = parseBoolean(valgrind) |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 109 | self.netcfgfile = '/tmp/bmv2-%d-netcfg.json' % self.deviceId |
Carmelo Cascone | eaa8b1d | 2018-04-11 14:12:17 -0700 | [diff] [blame] | 110 | self.pipeconfId = pipeconf |
| 111 | self.injectPorts = parseBoolean(portcfg) |
| 112 | self.withGnmi = parseBoolean(gnmi) |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 113 | self.longitude = kwargs['longitude'] if 'longitude' in kwargs else None |
| 114 | self.latitude = kwargs['latitude'] if 'latitude' in kwargs else None |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 115 | self.onosDeviceId = "device:bmv2:%d" % self.deviceId |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 116 | self.logfd = None |
| 117 | self.bmv2popen = None |
| 118 | self.stopped = False |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 119 | |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 120 | # Remove files from previous executions |
| 121 | self.cleanupTmpFiles() |
| 122 | |
| 123 | writeToFile("/tmp/bmv2-%d-grpc-port" % self.deviceId, self.grpcPort) |
| 124 | writeToFile("/tmp/bmv2-%d-thrift-port" % self.deviceId, self.thriftPort) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 125 | |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 126 | def getSourceIp(self, dstIP): |
| 127 | """ |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 128 | Queries the Linux routing table to get the source IP that can talk with |
| 129 | dstIP, and vice versa. |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 130 | """ |
| 131 | ipRouteOut = self.cmd('ip route get %s' % dstIP) |
| 132 | r = re.search(r"src (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", ipRouteOut) |
| 133 | return r.group(1) if r else None |
| 134 | |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 135 | def getDeviceConfig(self, srcIP): |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 136 | |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 137 | basicCfg = { |
| 138 | "driver": "bmv2" |
| 139 | } |
| 140 | |
| 141 | if self.longitude and self.latitude: |
| 142 | basicCfg["longitude"] = self.longitude |
| 143 | basicCfg["latitude"] = self.latitude |
| 144 | |
| 145 | cfgData = { |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 146 | "generalprovider": { |
| 147 | "p4runtime": { |
| 148 | "ip": srcIP, |
| 149 | "port": self.grpcPort, |
| 150 | "deviceId": self.deviceId, |
| 151 | "deviceKeyId": "p4runtime:%s" % self.onosDeviceId |
| 152 | } |
| 153 | }, |
| 154 | "piPipeconf": { |
| 155 | "piPipeconfId": self.pipeconfId |
| 156 | }, |
Andrea Campanella | bf9e5ce | 2017-12-06 14:26:36 +0100 | [diff] [blame] | 157 | "basic": basicCfg |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Carmelo Cascone | 4f985cd | 2018-02-11 17:36:42 -0800 | [diff] [blame] | 160 | if self.withGnmi: |
| 161 | cfgData["generalprovider"]["gnmi"] = { |
| 162 | "ip": srcIP, |
| 163 | "port": self.grpcPort |
| 164 | } |
| 165 | |
| 166 | if self.injectPorts: |
Andrea Campanella | bf9e5ce | 2017-12-06 14:26:36 +0100 | [diff] [blame] | 167 | portData = {} |
| 168 | portId = 1 |
| 169 | for intfName in self.intfNames(): |
| 170 | if intfName == 'lo': |
| 171 | continue |
| 172 | portData[str(portId)] = { |
| 173 | "number": portId, |
| 174 | "name": intfName, |
| 175 | "enabled": True, |
| 176 | "removed": False, |
| 177 | "type": "copper", |
| 178 | "speed": 10000 |
| 179 | } |
| 180 | portId += 1 |
| 181 | |
| 182 | cfgData['ports'] = portData |
| 183 | |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 184 | return cfgData |
| 185 | |
| 186 | def doOnosNetcfg(self, controllerIP): |
| 187 | """ |
| 188 | Notifies ONOS about the new device via Netcfg. |
| 189 | """ |
| 190 | srcIP = self.getSourceIp(controllerIP) |
| 191 | if not srcIP: |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 192 | warn("*** WARN: unable to get switch IP address, won't do netcfg\n") |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 193 | return |
| 194 | |
Carmelo Cascone | a11279b | 2017-06-22 04:30:08 -0400 | [diff] [blame] | 195 | cfgData = { |
| 196 | "devices": { |
Yi Tseng | 7875cb7 | 2017-08-08 10:15:58 -0700 | [diff] [blame] | 197 | self.onosDeviceId: self.getDeviceConfig(srcIP) |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 198 | } |
Carmelo Cascone | a11279b | 2017-06-22 04:30:08 -0400 | [diff] [blame] | 199 | } |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 200 | with open(self.netcfgfile, 'w') as fp: |
| 201 | json.dump(cfgData, fp, indent=4) |
Carmelo Cascone | 46d360b | 2017-08-29 20:20:32 +0200 | [diff] [blame] | 202 | |
| 203 | if not self.netcfg: |
| 204 | # Do not push config to ONOS. |
| 205 | return |
| 206 | |
Brian O'Connor | 71167f9 | 2017-06-16 14:55:00 -0700 | [diff] [blame] | 207 | # Build netcfg URL |
| 208 | url = 'http://%s:8181/onos/v1/network/configuration/' % controllerIP |
| 209 | # Instantiate password manager for HTTP auth |
| 210 | pm = urllib2.HTTPPasswordMgrWithDefaultRealm() |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 211 | pm.add_password(None, url, |
| 212 | os.environ['ONOS_WEB_USER'], |
| 213 | os.environ['ONOS_WEB_PASS']) |
| 214 | urllib2.install_opener(urllib2.build_opener( |
| 215 | urllib2.HTTPBasicAuthHandler(pm))) |
Brian O'Connor | 71167f9 | 2017-06-16 14:55:00 -0700 | [diff] [blame] | 216 | # Push config data to controller |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 217 | req = urllib2.Request(url, json.dumps(cfgData), |
| 218 | {'Content-Type': 'application/json'}) |
Carmelo Cascone | a11279b | 2017-06-22 04:30:08 -0400 | [diff] [blame] | 219 | try: |
| 220 | f = urllib2.urlopen(req) |
| 221 | print f.read() |
| 222 | f.close() |
| 223 | except urllib2.URLError as e: |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 224 | warn("*** WARN: unable to push config to ONOS (%s)\n" % e.reason) |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 225 | |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 226 | def start(self, controllers): |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 227 | bmv2Args = [SIMPLE_SWITCH_GRPC] + self.grpcTargetArgs() |
| 228 | if self.valgrind: |
| 229 | bmv2Args = VALGRIND_PREFIX.split() + bmv2Args |
| 230 | |
| 231 | cmdString = " ".join(bmv2Args) |
| 232 | |
| 233 | if self.dryrun: |
| 234 | info("\n*** DRY RUN (not executing bmv2)") |
| 235 | |
| 236 | info("\nStarting BMv2 target: %s\n" % cmdString) |
| 237 | |
| 238 | try: |
| 239 | if not self.dryrun: |
| 240 | # Start the switch |
| 241 | self.logfd = open(self.logfile, "w") |
| 242 | self.bmv2popen = self.popen(cmdString, |
| 243 | stdout=self.logfd, |
| 244 | stderr=self.logfd) |
| 245 | self.waitBmv2Start() |
| 246 | # We want to be notified if BMv2 dies... |
| 247 | threading.Thread(target=watchDog, args=[self]).start() |
| 248 | |
| 249 | self.doOnosNetcfg(self.controllerIp(controllers)) |
| 250 | except Exception as ex: |
| 251 | self.killBmv2() |
| 252 | self.printBmv2Log() |
| 253 | raise ex |
| 254 | |
| 255 | def grpcTargetArgs(self): |
| 256 | args = ['--device-id %s' % str(self.deviceId)] |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 257 | for port, intf in self.intfs.items(): |
| 258 | if not intf.IP(): |
| 259 | args.append('-i %d@%s' % (port, intf.name)) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 260 | if self.elogger: |
| 261 | nanomsg = 'ipc:///tmp/bmv2-%d-log.ipc' % self.deviceId |
| 262 | args.append('--nanolog %s' % nanomsg) |
| 263 | if self.debugger: |
| 264 | args.append('--debugger') |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 265 | args.append('--log-console') |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 266 | if self.pktdump: |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 267 | args.append('--pcap --dump-packet-data %s' % PKT_BYTES_TO_DUMP) |
Carmelo Cascone | 9e6621f | 2017-06-27 16:06:33 -0400 | [diff] [blame] | 268 | args.append('-L%s' % self.loglevel) |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 269 | args.append('--thrift-port %s' % self.thriftPort) |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 270 | if not self.json: |
| 271 | args.append('--no-p4') |
| 272 | else: |
| 273 | args.append(self.json) |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 274 | # gRPC target-specific options |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 275 | args.append('--') |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 276 | args.append('--cpu-port %s' % self.cpuPort) |
| 277 | args.append('--grpc-server-addr 0.0.0.0:%s' % self.grpcPort) |
| 278 | return args |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 279 | |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 280 | def waitBmv2Start(self): |
| 281 | # Wait for switch to open gRPC port, before sending ONOS the netcfg. |
| 282 | # Include time-out just in case something hangs. |
| 283 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 284 | endtime = time.time() + SWITCH_START_TIMEOUT |
| 285 | while True: |
| 286 | result = sock.connect_ex(('127.0.0.1', self.grpcPort)) |
| 287 | if result == 0: |
| 288 | # The port is open. Let's go! (Close socket first) |
| 289 | sock.close() |
| 290 | break |
| 291 | # Port is not open yet. If there is time, we wait a bit. |
| 292 | if endtime > time.time(): |
| 293 | time.sleep(0.2) |
| 294 | else: |
| 295 | # Time's up. |
| 296 | raise Exception("Switch did not start before timeout") |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 297 | |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 298 | def printBmv2Log(self): |
| 299 | if os.path.isfile(self.logfile): |
| 300 | print "-" * 80 |
| 301 | print "BMv2 %d log (from %s):" % (self.deviceId, self.logfile) |
| 302 | with open(self.logfile, 'r') as f: |
| 303 | lines = f.readlines() |
| 304 | if len(lines) > BMV2_LOG_LINES: |
| 305 | print "..." |
| 306 | for line in lines[-BMV2_LOG_LINES:]: |
| 307 | print line.rstrip() |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 308 | |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 309 | @staticmethod |
| 310 | def controllerIp(controllers): |
| 311 | try: |
| 312 | # onos.py |
Carmelo Cascone | 46d360b | 2017-08-29 20:20:32 +0200 | [diff] [blame] | 313 | clist = controllers[0].nodes() |
| 314 | except AttributeError: |
| 315 | clist = controllers |
| 316 | assert len(clist) > 0 |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 317 | return clist[0].IP() |
Keesjan Karsten | 8539f08 | 2018-01-04 17:03:31 +0100 | [diff] [blame] | 318 | |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 319 | def killBmv2(self, log=False): |
| 320 | if self.bmv2popen is not None: |
| 321 | self.bmv2popen.kill() |
| 322 | if self.logfd is not None: |
| 323 | if log: |
| 324 | self.logfd.write("*** PROCESS TERMINATED BY MININET ***\n") |
| 325 | self.logfd.close() |
Keesjan Karsten | 8539f08 | 2018-01-04 17:03:31 +0100 | [diff] [blame] | 326 | |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 327 | def cleanupTmpFiles(self): |
| 328 | self.cmd("rm -f /tmp/bmv2-%d-*" % self.deviceId) |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 329 | |
| 330 | def stop(self, deleteIntfs=True): |
| 331 | """Terminate switch.""" |
Carmelo Cascone | f11513d | 2018-01-16 00:31:14 -0800 | [diff] [blame] | 332 | self.stopped = True |
| 333 | self.killBmv2(log=True) |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 334 | Switch.stop(self, deleteIntfs) |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 335 | |
| 336 | |
Carmelo Cascone | b752427 | 2017-06-05 16:53:13 -0400 | [diff] [blame] | 337 | # Exports for bin/mn |
Carmelo Cascone | 785fada | 2016-06-16 18:34:16 -0700 | [diff] [blame] | 338 | switches = {'onosbmv2': ONOSBmv2Switch} |
Carmelo Cascone | 3443325 | 2017-08-25 20:27:18 +0200 | [diff] [blame] | 339 | hosts = {'onoshost': ONOSHost} |