You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 2 | Copyright 2016 Open Networking Foundation (ONF) |
| 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
| 21 | |
| 22 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 23 | This file contains classes for CHOTestMonkey that are related to network event |
| 24 | Author: you@onlab.us |
| 25 | """ |
| 26 | from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event |
| 27 | from tests.CHOTestMonkey.dependencies.elements.NetworkElement import NetworkElement, Device, Host, Link |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 28 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 29 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 30 | class LinkEvent( Event ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 31 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 32 | def __init__( self ): |
| 33 | Event.__init__( self ) |
| 34 | self.linkA = None |
| 35 | self.linkB = None |
| 36 | |
| 37 | def startLinkEvent( self ): |
| 38 | return EventStates().PASS |
| 39 | |
| 40 | def startEvent( self, args ): |
| 41 | """ |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 42 | args are the names of the two link ends, e.g. [ 's1', 's2' ] |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 43 | """ |
| 44 | with self.eventLock: |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 45 | #main.log.info( "%s - starting event" % ( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 46 | if len( args ) < 2: |
| 47 | main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) ) |
| 48 | return EventStates().ABORT |
| 49 | elif len( args ) > 2: |
| 50 | main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) ) |
| 51 | return EventStates().ABORT |
| 52 | if args[ 0 ] == 'random' or args[ 1 ] == 'random': |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 53 | if self.typeIndex == EventType().NETWORK_LINK_DOWN: |
You Wang | 221db32 | 2016-06-03 15:45:52 -0700 | [diff] [blame] | 54 | with main.mininetLock: |
| 55 | linkRandom = main.Mininet1.getLinkRandom() |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 56 | if linkRandom is None: |
You Wang | 221db32 | 2016-06-03 15:45:52 -0700 | [diff] [blame] | 57 | main.log.warn( "No link available, aborting event" ) |
| 58 | return EventStates().ABORT |
| 59 | args[ 0 ] = linkRandom[ 0 ] |
| 60 | args[ 1 ] = linkRandom[ 1 ] |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 61 | elif self.typeIndex == EventType().NETWORK_LINK_UP: |
You Wang | 221db32 | 2016-06-03 15:45:52 -0700 | [diff] [blame] | 62 | import random |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 63 | with main.variableLock: |
| 64 | downLinks = [] |
| 65 | for link in main.links: |
| 66 | if link.isDown(): |
| 67 | downLinks.append( link ) |
| 68 | if len( downLinks ) == 0: |
| 69 | main.log.warn( "None of the links are in 'down' state, aborting event" ) |
| 70 | return EventStates().ABORT |
| 71 | linkList = random.sample( downLinks, 1 ) |
| 72 | self.linkA = linkList[ 0 ] |
| 73 | self.linkB = linkList[ 0 ].backwardLink |
| 74 | elif args[ 0 ] == args[ 1 ]: |
| 75 | main.log.warn( "%s - invalid arguments: %s" % ( self.typeString, args ) ) |
| 76 | return EventStates().ABORT |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 77 | if self.linkA is None or self.linkB is None: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 78 | for link in main.links: |
| 79 | if link.deviceA.name == args[ 0 ] and link.deviceB.name == args[ 1 ]: |
| 80 | self.linkA = link |
| 81 | elif link.deviceA.name == args[ 1 ] and link.deviceB.name == args[ 0 ]: |
| 82 | self.linkB = link |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 83 | if self.linkA is not None and self.linkB is not None: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 84 | break |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 85 | if self.linkA is None or self.linkB is None: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 86 | main.log.warn( "Bidirectional link %s - %s does not exist: " % ( args[ 0 ], args[ 1 ] ) ) |
| 87 | return EventStates().ABORT |
| 88 | main.log.debug( "%s - %s" % ( self.typeString, self.linkA ) ) |
| 89 | return self.startLinkEvent() |
| 90 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 91 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 92 | class LinkDown( LinkEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 93 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 94 | """ |
| 95 | Generate a link down event giving the two ends of the link |
| 96 | """ |
| 97 | def __init__( self ): |
| 98 | LinkEvent.__init__( self ) |
| 99 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 100 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 101 | |
| 102 | def startLinkEvent( self ): |
| 103 | # TODO: do we need to handle a unidirectional link? |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 104 | assert self.linkA is not None and self.linkB is not None |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 105 | with main.variableLock: |
| 106 | if self.linkA.isDown() or self.linkB.isDown(): |
| 107 | main.log.warn( "Link Down - link already down" ) |
| 108 | return EventStates().ABORT |
| 109 | elif self.linkA.isRemoved() or self.linkB.isRemoved(): |
| 110 | main.log.warn( "Link Down - link has been removed" ) |
| 111 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 112 | main.log.info( "Event recorded: {} {} {} {}".format( self.typeIndex, self.typeString, self.linkA.deviceA.name, self.linkA.deviceB.name ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 113 | with main.mininetLock: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 114 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 115 | result = main.Mininet1.link( END1=self.linkA.deviceA.name, |
| 116 | END2=self.linkA.deviceB.name, |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 117 | OPTION="down" ) |
| 118 | """ |
You Wang | 221db32 | 2016-06-03 15:45:52 -0700 | [diff] [blame] | 119 | result = main.Mininet1.delLink( self.linkA.deviceA.name, |
| 120 | self.linkA.deviceB.name ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 121 | if not result: |
| 122 | main.log.warn( "%s - failed to bring down link" % ( self.typeString ) ) |
| 123 | return EventStates().FAIL |
| 124 | with main.variableLock: |
| 125 | self.linkA.bringDown() |
| 126 | self.linkB.bringDown() |
| 127 | return EventStates().PASS |
| 128 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 129 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 130 | class LinkUp( LinkEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 131 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 132 | """ |
| 133 | Generate a link up event giving the two ends of the link |
| 134 | """ |
| 135 | def __init__( self ): |
| 136 | LinkEvent.__init__( self ) |
| 137 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 138 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 139 | |
| 140 | def startLinkEvent( self ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 141 | assert self.linkA is not None and self.linkB is not None |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 142 | with main.variableLock: |
| 143 | if self.linkA.isUp() or self.linkB.isUp(): |
| 144 | main.log.warn( "Link Up - link already up" ) |
| 145 | return EventStates().ABORT |
| 146 | if self.linkA.isRemoved() or self.linkB.isRemoved(): |
| 147 | main.log.warn( "Link Up - link has been removed" ) |
| 148 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 149 | main.log.info( "Event recorded: {} {} {} {}".format( self.typeIndex, self.typeString, self.linkA.deviceA.name, self.linkA.deviceB.name ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 150 | with main.mininetLock: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 151 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 152 | result = main.Mininet1.link( END1=self.linkA.deviceA.name, |
| 153 | END2=self.linkA.deviceB.name, |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 154 | OPTION="up" ) |
| 155 | """ |
You Wang | 221db32 | 2016-06-03 15:45:52 -0700 | [diff] [blame] | 156 | result = main.Mininet1.addLink( self.linkA.deviceA.name, |
| 157 | self.linkA.deviceB.name ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 158 | if not result: |
| 159 | main.log.warn( "%s - failed to bring up link" % ( self.typeString ) ) |
| 160 | return EventStates().FAIL |
| 161 | with main.variableLock: |
| 162 | self.linkA.bringUp() |
| 163 | self.linkB.bringUp() |
| 164 | return EventStates().PASS |
| 165 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 166 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 167 | class DeviceEvent( Event ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 168 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 169 | def __init__( self ): |
| 170 | Event.__init__( self ) |
| 171 | self.device = None |
| 172 | |
| 173 | def startDeviceEvent( self ): |
| 174 | return EventStates().PASS |
| 175 | |
| 176 | def startEvent( self, args ): |
| 177 | """ |
| 178 | args are the names of the device, e.g. 's1' |
| 179 | """ |
| 180 | with self.eventLock: |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 181 | #main.log.info( "%s - starting event" % ( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 182 | if len( args ) < 1: |
| 183 | main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) ) |
| 184 | return EventStates().ABORT |
| 185 | elif len( args ) > 1: |
| 186 | main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) ) |
| 187 | return EventStates().ABORT |
| 188 | if args[ 0 ] == 'random': |
| 189 | import random |
| 190 | if self.typeIndex == EventType().NETWORK_DEVICE_DOWN: |
You Wang | 221db32 | 2016-06-03 15:45:52 -0700 | [diff] [blame] | 191 | with main.mininetLock: |
| 192 | switchRandom = main.Mininet1.getSwitchRandom() |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 193 | if switchRandom is None: |
You Wang | 221db32 | 2016-06-03 15:45:52 -0700 | [diff] [blame] | 194 | main.log.warn( "No switch available, aborting event" ) |
| 195 | return EventStates().ABORT |
| 196 | args[ 0 ] = switchRandom |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 197 | elif self.typeIndex == EventType().NETWORK_DEVICE_UP: |
| 198 | with main.variableLock: |
| 199 | removedDevices = [] |
| 200 | for device in main.devices: |
| 201 | if device.isRemoved(): |
| 202 | removedDevices.append( device ) |
| 203 | if len( removedDevices ) == 0: |
| 204 | main.log.warn( "None of the devices are removed, aborting event" ) |
| 205 | return EventStates().ABORT |
| 206 | deviceList = random.sample( removedDevices, 1 ) |
| 207 | self.device = deviceList[ 0 ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 208 | if self.device is None: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 209 | for device in main.devices: |
| 210 | if device.name == args[ 0 ]: |
| 211 | self.device = device |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 212 | if self.device is None: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 213 | main.log.warn( "Device %s does not exist: " % ( args[ 0 ] ) ) |
| 214 | return EventStates().ABORT |
| 215 | main.log.debug( "%s - %s" % ( self.typeString, self.device ) ) |
| 216 | return self.startDeviceEvent() |
| 217 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 218 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 219 | class DeviceDown( DeviceEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 220 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 221 | """ |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 222 | Generate a device down event ( which actually removes this device for now ) giving its name |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 223 | """ |
| 224 | def __init__( self ): |
| 225 | DeviceEvent.__init__( self ) |
| 226 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 227 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 228 | |
| 229 | def startDeviceEvent( self ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 230 | assert self.device is not None |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 231 | with main.variableLock: |
| 232 | if self.device.isRemoved(): |
| 233 | main.log.warn( "Device Down - device has been removed" ) |
| 234 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 235 | main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.device.name ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 236 | with main.mininetLock: |
| 237 | result = main.Mininet1.delSwitch( self.device.name ) |
| 238 | if not result: |
| 239 | main.log.warn( "%s - failed to bring down device" % ( self.typeString ) ) |
| 240 | return EventStates().FAIL |
| 241 | with main.variableLock: |
| 242 | self.device.setRemoved() |
| 243 | for link in self.device.outgoingLinks: |
| 244 | link.setRemoved() |
| 245 | link.backwardLink.setRemoved() |
| 246 | for host in self.device.hosts: |
| 247 | host.setRemoved() |
You Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 248 | for intent in main.intents: |
| 249 | if intent.deviceA == self.device or intent.deviceB == self.device: |
| 250 | intent.setFailed() |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 251 | return EventStates().PASS |
| 252 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 253 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 254 | class DeviceUp( DeviceEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 255 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 256 | """ |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 257 | Generate a device up event ( which re-adds this device in case the device is removed ) giving its name |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 258 | """ |
| 259 | def __init__( self ): |
| 260 | DeviceEvent.__init__( self ) |
| 261 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 262 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 263 | |
| 264 | def startDeviceEvent( self ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 265 | assert self.device is not None |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 266 | with main.variableLock: |
| 267 | if self.device.isUp(): |
| 268 | main.log.warn( "Device Up - device already up" ) |
| 269 | return EventStates().ABORT |
| 270 | # Re-add the device |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 271 | main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.device.name ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 272 | with main.mininetLock: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 273 | result = main.Mininet1.addSwitch( self.device.name, dpid=self.device.dpid[ 3: ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 274 | if not result: |
| 275 | main.log.warn( "%s - failed to re-add device" % ( self.typeString ) ) |
| 276 | return EventStates().FAIL |
| 277 | with main.variableLock: |
| 278 | self.device.bringUp() |
| 279 | # Re-add links |
| 280 | # We add host-device links first since we did the same in mininet topology file |
| 281 | # TODO: a more rubust way is to add links according to the port info of the device |
| 282 | for host in self.device.hosts: |
| 283 | # Add host-device link |
| 284 | with main.mininetLock: |
| 285 | result = main.Mininet1.addLink( self.device.name, host.name ) |
| 286 | if not result: |
| 287 | main.log.warn( "%s - failed to re-connect host %s to device" % ( self.typeString, host.name ) ) |
| 288 | return EventStates().FAIL |
| 289 | for link in self.device.outgoingLinks: |
| 290 | neighbor = link.deviceB |
| 291 | # Skip bringing up any link that connecting this device to a removed neighbor |
| 292 | if neighbor.isRemoved(): |
| 293 | continue |
| 294 | with main.mininetLock: |
| 295 | result = main.Mininet1.addLink( self.device.name, neighbor.name ) |
| 296 | if not result: |
| 297 | main.log.warn( "%s - failed to re-add link to %s" % ( self.typeString, neighbor.name ) ) |
| 298 | return EventStates().FAIL |
| 299 | with main.variableLock: |
| 300 | link.bringUp() |
| 301 | link.backwardLink.bringUp() |
You Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 302 | for intent in main.intents: |
| 303 | if intent.isFailed(): |
| 304 | if intent.deviceA == self.device and intent.deviceB.isUp() or\ |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 305 | intent.deviceB == self.device and intent.deviceA.isUp(): |
You Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 306 | intent.setInstalled() |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 307 | # Re-assign mastership for the device |
| 308 | with main.mininetLock: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 309 | ips = main.Cluster.getIps() |
| 310 | main.Mininet1.assignSwController( sw=self.device.name, ip=ips ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 311 | # Re-discover hosts |
| 312 | for host in self.device.hosts: |
| 313 | correspondent = None |
| 314 | for h in main.hosts: |
| 315 | if h.isUp() and h != host: |
| 316 | correspondent = h |
| 317 | break |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 318 | if correspondent is None: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 319 | with main.mininetLock: |
| 320 | main.Mininet1.pingall() |
| 321 | if main.enableIPv6: |
| 322 | main.Mininet1.pingall( protocol="IPv6" ) |
| 323 | else: |
| 324 | ipv4Addr = None |
| 325 | ipv6Addr = None |
| 326 | for ipAddress in correspondent.ipAddresses: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 327 | if ipAddress.startswith( str( main.params[ 'TEST' ][ 'ipv6Prefix' ] ) ) and ipv6Addr is None: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 328 | ipv6Addr = ipAddress |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 329 | elif ipAddress.startswith( str( main.params[ 'TEST' ][ 'ipv4Prefix' ] ) ) and ipv4Addr is None: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 330 | ipv4Addr = ipAddress |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 331 | assert ipv4Addr is not None |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 332 | host.handle.pingHostSetAlternative( [ ipv4Addr ], 1 ) |
| 333 | if main.enableIPv6: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 334 | assert ipv6Addr is not None |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 335 | host.handle.pingHostSetAlternative( [ ipv6Addr ], 1, True ) |
| 336 | with main.variableLock: |
| 337 | host.bringUp() |
| 338 | return EventStates().PASS |