admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 2 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 3 | Created on 26-Oct-2012 |
| 4 | |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 5 | author: Anil Kumar ( anilkumar.s@paxterrasolutions.com ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 6 | |
| 7 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 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. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 12 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 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. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 17 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 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/>. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 20 | |
| 21 | |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 22 | MininetCliDriver is the basic driver which will handle the Mininet functions |
| 23 | |
Jon Hall | 272a4db | 2015-01-12 17:43:48 -0800 | [diff] [blame] | 24 | Some functions rely on STS module. To install this, |
| 25 | git clone https://github.com/jhall11/sts.git |
| 26 | |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 27 | Some functions rely on a modified version of Mininet. These functions |
| 28 | should all be noted in the comments. To get this MN version run these commands |
| 29 | from within your Mininet folder: |
Jon Hall | 272a4db | 2015-01-12 17:43:48 -0800 | [diff] [blame] | 30 | git remote add jhall11 https://github.com/jhall11/mininet.git |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 31 | git fetch jhall11 |
Jon Hall | 272a4db | 2015-01-12 17:43:48 -0800 | [diff] [blame] | 32 | git checkout -b dynamic_topo remotes/jhall11/dynamic_topo |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 33 | git pull |
| 34 | |
Jon Hall | 272a4db | 2015-01-12 17:43:48 -0800 | [diff] [blame] | 35 | |
| 36 | Note that you may need to run 'sudo make develop' if your mnexec.c file |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 37 | changed when switching branches.""" |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 38 | import traceback |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 39 | import pexpect |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 40 | import re |
| 41 | import sys |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 42 | sys.path.append( "../" ) |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 43 | from math import pow |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 44 | from drivers.common.cli.emulatordriver import Emulator |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 45 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 46 | |
| 47 | class MininetCliDriver( Emulator ): |
| 48 | |
| 49 | """ |
| 50 | MininetCliDriver is the basic driver which will handle |
| 51 | the Mininet functions""" |
| 52 | def __init__( self ): |
| 53 | super( Emulator, self ).__init__() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 54 | self.handle = self |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 55 | self.wrapped = sys.modules[ __name__ ] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 56 | self.flag = 0 |
| 57 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 58 | def connect( self, **connectargs ): |
| 59 | """ |
| 60 | Here the main is the TestON instance after creating |
| 61 | all the log handles.""" |
kelvin-onlab | a0ce322 | 2015-01-27 17:25:15 -0800 | [diff] [blame^] | 62 | try: |
| 63 | for key in connectargs: |
| 64 | vars( self )[ key ] = connectargs[ key ] |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 65 | |
kelvin-onlab | a0ce322 | 2015-01-27 17:25:15 -0800 | [diff] [blame^] | 66 | self.name = self.options[ 'name' ] |
| 67 | self.handle = super( |
| 68 | MininetCliDriver, |
| 69 | self ).connect( |
| 70 | user_name=self.user_name, |
| 71 | ip_address=self.ip_address, |
| 72 | port=None, |
| 73 | pwd=self.pwd ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 74 | |
kelvin-onlab | a0ce322 | 2015-01-27 17:25:15 -0800 | [diff] [blame^] | 75 | self.sshHandle = self.handle |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 76 | |
kelvin-onlab | a0ce322 | 2015-01-27 17:25:15 -0800 | [diff] [blame^] | 77 | if self.handle: |
| 78 | main.log.info("Connection successful to the host " + |
| 79 | self.user_name + |
| 80 | "@" + |
| 81 | self.ip_address ) |
| 82 | return main.TRUE |
| 83 | else: |
| 84 | main.log.error( "Connection failed to the host " + |
| 85 | self.user_name + |
| 86 | "@" + |
| 87 | self.ip_address ) |
| 88 | msin.log.error( "Failed to connect to the Mininet CLI" ) |
| 89 | return main.FALSE |
| 90 | except pexpect.EOF: |
| 91 | main.log.error( self.name + ": EOF exception found" ) |
| 92 | main.log.error( self.name + ": " + self.handle.before ) |
| 93 | main.cleanup() |
| 94 | main.exit() |
| 95 | except: |
| 96 | main.log.info( self.name + ":::::::::::::::::::::::" ) |
| 97 | main.log.error( traceback.print_exc() ) |
| 98 | main.log.info( ":::::::::::::::::::::::" ) |
| 99 | main.cleanup() |
| 100 | main.exit() |
| 101 | |
| 102 | |
| 103 | """ |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 104 | if self.handle: |
| 105 | main.log.info( |
| 106 | self.name + |
| 107 | ": Clearing any residual state or processes" ) |
| 108 | self.handle.sendline( "sudo mn -c" ) |
| 109 | i = self.handle.expect( [ 'password\sfor\s', |
| 110 | 'Cleanup\scomplete', |
| 111 | pexpect.EOF, |
| 112 | pexpect.TIMEOUT ], |
| 113 | 120 ) |
| 114 | if i == 0: |
| 115 | main.log.info( self.name + ": Sending sudo password" ) |
| 116 | self.handle.sendline( self.pwd ) |
| 117 | i = self.handle.expect( [ '%s:' % ( self.user ), |
| 118 | '\$', |
| 119 | pexpect.EOF, |
| 120 | pexpect.TIMEOUT ], |
| 121 | 120 ) |
| 122 | if i == 1: |
| 123 | main.log.info( self.name + ": Clean" ) |
| 124 | elif i == 2: |
| 125 | main.log.error( self.name + ": Connection terminated" ) |
| 126 | elif i == 3: # timeout |
| 127 | main.log.error( |
| 128 | self.name + |
| 129 | ": Something while cleaning MN took too long... " ) |
kelvin-onlab | a0ce322 | 2015-01-27 17:25:15 -0800 | [diff] [blame^] | 130 | """ |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 131 | |
kelvin-onlab | a0ce322 | 2015-01-27 17:25:15 -0800 | [diff] [blame^] | 132 | def startNet( self, topoFile = None, args = None ): |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 133 | |
kelvin-onlab | a0ce322 | 2015-01-27 17:25:15 -0800 | [diff] [blame^] | 134 | self.name = self.options[ 'name' ] |
| 135 | if self.handle: |
| 136 | main.log.info( |
| 137 | self.name + |
| 138 | ": Clearing any residual state or processes" ) |
| 139 | self.handle.sendline( "sudo mn -c" ) |
| 140 | i = self.handle.expect( [ 'password\sfor\s', |
| 141 | 'Cleanup\scomplete', |
| 142 | pexpect.EOF, |
| 143 | pexpect.TIMEOUT ], |
| 144 | 120 ) |
| 145 | if i == 0: |
| 146 | main.log.info( self.name + ": Sending sudo password" ) |
| 147 | self.handle.sendline( self.pwd ) |
| 148 | i = self.handle.expect( [ '%s:' % ( self.user ), |
| 149 | '\$', |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 150 | pexpect.EOF, |
| 151 | pexpect.TIMEOUT ], |
kelvin-onlab | a0ce322 | 2015-01-27 17:25:15 -0800 | [diff] [blame^] | 152 | 120 ) |
| 153 | if i == 1: |
| 154 | main.log.info( self.name + ": Clean" ) |
| 155 | elif i == 2: |
| 156 | main.log.error( self.name + ": Connection terminated" ) |
| 157 | elif i == 3: # timeout |
| 158 | main.log.error( |
| 159 | self.name + |
| 160 | ": Something while cleaning MN took too long... " ) |
| 161 | if topoFile == None and args == None: |
| 162 | main.log.info( self.name + ": building fresh mininet" ) |
| 163 | # for reactive/PARP enabled tests |
| 164 | cmdString = "sudo mn " + self.options[ 'arg1' ] +\ |
| 165 | " " + self.options[ 'arg2' ] +\ |
| 166 | " --mac --controller " +\ |
| 167 | self.options[ 'controller' ] + " " +\ |
| 168 | self.options[ 'arg3' ] |
| 169 | |
| 170 | argList = self.options[ 'arg1' ].split( "," ) |
| 171 | global topoArgList |
| 172 | topoArgList = argList[ 0 ].split( " " ) |
| 173 | argList = map( int, argList[ 1: ] ) |
| 174 | topoArgList = topoArgList[ 1: ] + argList |
| 175 | |
| 176 | self.handle.sendline( cmdString ) |
| 177 | self.handle.expect( [ "sudo mn", |
| 178 | pexpect.EOF, |
| 179 | pexpect.TIMEOUT ] ) |
| 180 | while True: |
| 181 | i = self.handle.expect( [ 'mininet>', |
| 182 | '\*\*\*', |
| 183 | 'Exception', |
| 184 | pexpect.EOF, |
| 185 | pexpect.TIMEOUT ], |
| 186 | 300 ) |
| 187 | if i == 0: |
| 188 | main.log.info( self.name + ": mininet built" ) |
| 189 | return main.TRUE |
| 190 | if i == 1: |
| 191 | self.handle.expect( |
| 192 | [ "\n", pexpect.EOF, pexpect.TIMEOUT ] ) |
| 193 | main.log.info( self.handle.before ) |
| 194 | elif i == 2: |
| 195 | main.log.error( |
| 196 | self.name + |
| 197 | ": Launching mininet failed..." ) |
| 198 | return main.FALSE |
| 199 | elif i == 3: |
| 200 | main.log.error( self.name + ": Connection timeout" ) |
| 201 | return main.FALSE |
| 202 | elif i == 4: # timeout |
| 203 | main.log.error( |
| 204 | self.name + |
| 205 | ": Something took too long... " ) |
| 206 | return main.FALSE |
| 207 | return main.TRUE |
| 208 | else: |
| 209 | self.handle.sendline('sudo ' + topoFile + ' ' + args) |
| 210 | self.handle.sendline('') |
| 211 | i = 1 |
| 212 | i = self.handle.expect( [ 'mininet>', |
| 213 | pexpect.EOF , |
| 214 | pexpect.TIMEOUT ], |
| 215 | timeout = 2) |
| 216 | self.handle.expect('mininet>') |
| 217 | main.log.info(self.name + ": Network started") |
| 218 | return main.TRUE |
| 219 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 220 | else: # if no handle |
| 221 | main.log.error( |
| 222 | self.name + |
| 223 | ": Connection failed to the host " + |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 224 | self.user_name + |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 225 | "@" + |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 226 | self.ip_address ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 227 | main.log.error( self.name + ": Failed to connect to the Mininet" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 228 | return main.FALSE |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 229 | |
kelvin-onlab | fccaafa | 2015-01-20 13:50:44 -0800 | [diff] [blame] | 230 | def numSwitchesNlinks( self, topoType, depth, fanout ): |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 231 | if topoType == 'tree': |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 232 | # In tree topology, if fanout arg is not given, by default it is 2 |
| 233 | if fanout is None: |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 234 | fanout = 2 |
| 235 | k = 0 |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 236 | count = 0 |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 237 | while( k <= depth - 1 ): |
| 238 | count = count + pow( fanout, k ) |
| 239 | k = k + 1 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 240 | numSwitches = count |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 241 | while( k <= depth - 2 ): |
| 242 | # depth-2 gives you only core links and not considering |
| 243 | # edge links as seen by ONOS. If all the links including |
| 244 | # edge links are required, do depth-1 |
| 245 | count = count + pow( fanout, k ) |
| 246 | k = k + 1 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 247 | numLinks = count * fanout |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 248 | # print "num_switches for %s(%d,%d) = %d and links=%d" %( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 249 | # topoType,depth,fanout,numSwitches,numLinks ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 250 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 251 | elif topoType == 'linear': |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 252 | # In linear topology, if fanout or numHostsPerSw is not given, |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 253 | # by default it is 1 |
| 254 | if fanout is None: |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 255 | fanout = 1 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 256 | numSwitches = depth |
| 257 | numHostsPerSw = fanout |
| 258 | totalNumHosts = numSwitches * numHostsPerSw |
| 259 | numLinks = totalNumHosts + ( numSwitches - 1 ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 260 | print "num_switches for %s(%d,%d) = %d and links=%d" %\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 261 | ( topoType, depth, fanout, numSwitches, numLinks ) |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 262 | topoDict = {} |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 263 | topoDict = { |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 264 | "num_switches": int( numSwitches ), |
| 265 | "num_corelinks": int( numLinks ) } |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 266 | return topoDict |
| 267 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 268 | def calculateSwAndLinks( self ): |
| 269 | topoDict = self.numSwitchesN_links( *topoArgList ) |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 270 | return topoDict |
| 271 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 272 | def pingall( self, timeout=300 ): |
| 273 | """ |
| 274 | Verifies the reachability of the hosts using pingall command. |
| 275 | Optional parameter timeout allows you to specify how long to |
| 276 | wait for pingall to complete |
| 277 | Returns: |
| 278 | main.TRUE if pingall completes with no pings dropped |
| 279 | otherwise main.FALSE""" |
| 280 | if self.handle: |
| 281 | main.log.info( |
| 282 | self.name + |
| 283 | ": Checking reachabilty to the hosts using pingall" ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 284 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 285 | response = self.execute( |
| 286 | cmd="pingall", |
| 287 | prompt="mininet>", |
| 288 | timeout=int( timeout ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 289 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 290 | main.log.error( self.name + ": EOF exception found" ) |
| 291 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 292 | main.cleanup() |
| 293 | main.exit() |
| 294 | except pexpect.TIMEOUT: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 295 | # We may not want to kill the test if pexpect times out |
| 296 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 297 | main.log.error( self.name + |
| 298 | ": " + |
| 299 | str( self.handle.before ) ) |
| 300 | # NOTE: mininet's pingall rounds, so we will check the number of |
| 301 | # passed and number of failed |
| 302 | pattern = "Results\:\s0\%\sdropped\s\(" +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 303 | "(?P<passed>[\d]+)/(?P=passed)" |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 304 | if re.search( pattern, response ): |
| 305 | main.log.info( self.name + ": All hosts are reachable" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 306 | return main.TRUE |
| 307 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 308 | main.log.error( self.name + ": Unable to reach all the hosts" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 309 | main.log.info( "Pingall output: " + str( response ) ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 310 | # NOTE: Send ctrl-c to make sure pingall is done |
| 311 | self.handle.send( "\x03" ) |
| 312 | self.handle.expect( "Interrupt" ) |
| 313 | self.handle.expect( "mininet>" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 314 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 315 | else: |
| 316 | main.log.error( self.name + ": Connection failed to the host" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 317 | main.cleanup() |
| 318 | main.exit() |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 319 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 320 | def fpingHost( self, **pingParams ): |
| 321 | """ |
| 322 | Uses the fping package for faster pinging... |
| 323 | *requires fping to be installed on machine running mininet""" |
kelvin-onlab | 7d0c967 | 2015-01-20 15:56:22 -0800 | [diff] [blame] | 324 | args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 325 | command = args[ "SRC" ] + \ |
| 326 | " fping -i 100 -t 20 -C 1 -q " + args[ "TARGET" ] |
| 327 | self.handle.sendline( command ) |
| 328 | self.handle.expect( |
| 329 | [ args[ "TARGET" ], pexpect.EOF, pexpect.TIMEOUT ] ) |
| 330 | self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] ) |
| 331 | response = self.handle.before |
| 332 | if re.search( ":\s-", response ): |
| 333 | main.log.info( self.name + ": Ping fail" ) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 334 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 335 | elif re.search( ":\s\d{1,2}\.\d\d", response ): |
| 336 | main.log.info( self.name + ": Ping good!" ) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 337 | return main.TRUE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 338 | main.log.info( self.name + ": Install fping on mininet machine... " ) |
| 339 | main.log.info( self.name + ": \n---\n" + response ) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 340 | return main.FALSE |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 341 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 342 | def pingHost( self, **pingParams ): |
| 343 | """ |
| 344 | Ping from one mininet host to another |
| 345 | Currently the only supported Params: SRC and TARGET""" |
kelvin-onlab | 7d0c967 | 2015-01-20 15:56:22 -0800 | [diff] [blame] | 346 | args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 347 | command = args[ "SRC" ] + " ping " + \ |
| 348 | args[ "TARGET" ] + " -c 1 -i 1 -W 8" |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 349 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 350 | main.log.warn( "Sending: " + command ) |
| 351 | self.handle.sendline( command ) |
| 352 | i = self.handle.expect( [ command, pexpect.TIMEOUT ] ) |
Jon Hall | 6e18c7b | 2014-04-23 16:26:33 -0700 | [diff] [blame] | 353 | if i == 1: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 354 | main.log.error( |
| 355 | self.name + |
| 356 | ": timeout when waiting for response from mininet" ) |
| 357 | main.log.error( "response: " + str( self.handle.before ) ) |
| 358 | i = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ] ) |
Jon Hall | 6e18c7b | 2014-04-23 16:26:33 -0700 | [diff] [blame] | 359 | if i == 1: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 360 | main.log.error( |
| 361 | self.name + |
| 362 | ": timeout when waiting for response from mininet" ) |
| 363 | main.log.error( "response: " + str( self.handle.before ) ) |
Jon Hall | 6e18c7b | 2014-04-23 16:26:33 -0700 | [diff] [blame] | 364 | response = self.handle.before |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 365 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 366 | main.log.error( self.name + ": EOF exception found" ) |
| 367 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 368 | main.cleanup() |
| 369 | main.exit() |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 370 | main.log.info( self.name + ": Ping Response: " + response ) |
| 371 | if re.search( ',\s0\%\spacket\sloss', response ): |
| 372 | main.log.info( self.name + ": no packets lost, host is reachable" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 373 | main.lastResult = main.TRUE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 374 | return main.TRUE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 375 | else: |
| 376 | main.log.error( |
| 377 | self.name + |
| 378 | ": PACKET LOST, HOST IS NOT REACHABLE" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 379 | main.lastResult = main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 380 | return main.FALSE |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 381 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 382 | def checkIP( self, host ): |
| 383 | """ |
| 384 | Verifies the host's ip configured or not.""" |
| 385 | if self.handle: |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 386 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 387 | response = self.execute( |
| 388 | cmd=host + |
| 389 | " ifconfig", |
| 390 | prompt="mininet>", |
| 391 | timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 392 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 393 | main.log.error( self.name + ": EOF exception found" ) |
| 394 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 395 | main.cleanup() |
| 396 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 397 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 398 | pattern = "inet\s(addr|Mask):([0-1]{1}[0-9]{1,2}|" +\ |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 399 | "2[0-4][0-9]|25[0-5]|[0-9]{1,2}).([0-1]{1}" +\ |
| 400 | "[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2})." +\ |
| 401 | "([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|" +\ |
| 402 | "[0-9]{1,2}).([0-1]{1}[0-9]{1,2}|2[0-4]" +\ |
| 403 | "[0-9]|25[0-5]|[0-9]{1,2})" |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 404 | # pattern = "inet addr:10.0.0.6" |
| 405 | if re.search( pattern, response ): |
| 406 | main.log.info( self.name + ": Host Ip configured properly" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 407 | return main.TRUE |
| 408 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 409 | main.log.error( self.name + ": Host IP not found" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 410 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 411 | else: |
| 412 | main.log.error( self.name + ": Connection failed to the host" ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 413 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 414 | def verifySSH( self, **connectargs ): |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 415 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 416 | response = self.execute( |
| 417 | cmd="h1 /usr/sbin/sshd -D&", |
| 418 | prompt="mininet>", |
| 419 | timeout=10 ) |
| 420 | response = self.execute( |
| 421 | cmd="h4 /usr/sbin/sshd -D&", |
| 422 | prompt="mininet>", |
| 423 | timeout=10 ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 424 | for key in connectargs: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 425 | vars( self )[ key ] = connectargs[ key ] |
| 426 | response = self.execute( |
| 427 | cmd="xterm h1 h4 ", |
| 428 | prompt="mininet>", |
| 429 | timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 430 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 431 | main.log.error( self.name + ": EOF exception found" ) |
| 432 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 433 | main.cleanup() |
| 434 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 435 | import time |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 436 | time.sleep( 20 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 437 | if self.flag == 0: |
| 438 | self.flag = 1 |
| 439 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 440 | else: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 441 | return main.TRUE |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 442 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 443 | def changeIP( self, host, intf, newIP, newNetmask ): |
| 444 | """ |
| 445 | Changes the ip address of a host on the fly |
| 446 | Ex: h2 ifconfig h2-eth0 10.0.1.2 netmask 255.255.255.0""" |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 447 | if self.handle: |
| 448 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 449 | cmd = host + " ifconfig " + intf + " " + \ |
| 450 | newIP + " " + 'netmask' + " " + newNetmask |
| 451 | self.handle.sendline( cmd ) |
| 452 | self.handle.expect( "mininet>" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 453 | response = self.handle.before |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 454 | main.log.info( "response = " + response ) |
| 455 | main.log.info( |
| 456 | "Ip of host " + |
| 457 | host + |
| 458 | " changed to new IP " + |
| 459 | newIP ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 460 | return main.TRUE |
| 461 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 462 | main.log.error( self.name + ": EOF exception found" ) |
| 463 | main.log.error( self.name + ": " + self.handle.before ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 464 | return main.FALSE |
| 465 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 466 | def changeDefaultGateway( self, host, newGW ): |
| 467 | """ |
| 468 | Changes the default gateway of a host |
| 469 | Ex: h1 route add default gw 10.0.1.2""" |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 470 | if self.handle: |
| 471 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 472 | cmd = host + " route add default gw " + newGW |
| 473 | self.handle.sendline( cmd ) |
| 474 | self.handle.expect( "mininet>" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 475 | response = self.handle.before |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 476 | main.log.info( "response = " + response ) |
| 477 | main.log.info( |
| 478 | "Default gateway of host " + |
| 479 | host + |
| 480 | " changed to " + |
| 481 | newGW ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 482 | return main.TRUE |
| 483 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 484 | main.log.error( self.name + ": EOF exception found" ) |
| 485 | main.log.error( self.name + ": " + self.handle.before ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 486 | return main.FALSE |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 487 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 488 | def addStaticMACAddress( self, host, GW, macaddr ): |
| 489 | """ |
| 490 | Changes the mac address of a geateway host""" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 491 | if self.handle: |
| 492 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 493 | # h1 arp -s 10.0.1.254 00:00:00:00:11:11 |
| 494 | cmd = host + " arp -s " + GW + " " + macaddr |
| 495 | self.handle.sendline( cmd ) |
| 496 | self.handle.expect( "mininet>" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 497 | response = self.handle.before |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 498 | main.log.info( "response = " + response ) |
| 499 | main.log.info( |
| 500 | "Mac adrress of gateway " + |
| 501 | GW + |
| 502 | " changed to " + |
| 503 | macaddr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 504 | return main.TRUE |
| 505 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 506 | main.log.error( self.name + ": EOF exception found" ) |
| 507 | main.log.error( self.name + ": " + self.handle.before ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 508 | return main.FALSE |
| 509 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 510 | def verifyStaticGWandMAC( self, host ): |
| 511 | """ |
| 512 | Verify if the static gateway and mac address assignment""" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 513 | if self.handle: |
| 514 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 515 | # h1 arp -an |
| 516 | cmd = host + " arp -an " |
| 517 | self.handle.sendline( cmd ) |
| 518 | self.handle.expect( "mininet>" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 519 | response = self.handle.before |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 520 | main.log.info( host + " arp -an = " + response ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 521 | return main.TRUE |
| 522 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 523 | main.log.error( self.name + ": EOF exception found" ) |
| 524 | main.log.error( self.name + ": " + self.handle.before ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 525 | return main.FALSE |
| 526 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 527 | def getMacAddress( self, host ): |
| 528 | """ |
| 529 | Verifies the host's ip configured or not.""" |
| 530 | if self.handle: |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 531 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 532 | response = self.execute( |
| 533 | cmd=host + |
| 534 | " ifconfig", |
| 535 | prompt="mininet>", |
| 536 | timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 537 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 538 | main.log.error( self.name + ": EOF exception found" ) |
| 539 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 540 | main.cleanup() |
| 541 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 542 | |
Ahmed El-Hassany | f720e20 | 2014-04-04 16:11:36 -0700 | [diff] [blame] | 543 | pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 544 | macAddressSearch = re.search( pattern, response, re.I ) |
| 545 | macAddress = macAddressSearch.group().split( " " )[ 1 ] |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 546 | main.log.info( |
| 547 | self.name + |
| 548 | ": Mac-Address of Host " + |
| 549 | host + |
| 550 | " is " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 551 | macAddress ) |
| 552 | return macAddress |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 553 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 554 | main.log.error( self.name + ": Connection failed to the host" ) |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 555 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 556 | def getInterfaceMACAddress( self, host, interface ): |
| 557 | """ |
| 558 | Return the IP address of the interface on the given host""" |
| 559 | if self.handle: |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 560 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 561 | response = self.execute( cmd=host + " ifconfig " + interface, |
| 562 | prompt="mininet>", timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 563 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 564 | main.log.error( self.name + ": EOF exception found" ) |
| 565 | main.log.error( self.name + ": " + self.handle.before ) |
| 566 | main.cleanup() |
| 567 | main.exit() |
| 568 | |
| 569 | pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 570 | macAddressSearch = re.search( pattern, response, re.I ) |
| 571 | if macAddressSearch is None: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 572 | main.log.info( "No mac address found in %s" % response ) |
| 573 | return main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 574 | macAddress = macAddressSearch.group().split( " " )[ 1 ] |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 575 | main.log.info( |
| 576 | "Mac-Address of " + |
| 577 | host + |
| 578 | ":" + |
| 579 | interface + |
| 580 | " is " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 581 | macAddress ) |
| 582 | return macAddress |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 583 | else: |
| 584 | main.log.error( "Connection failed to the host" ) |
| 585 | |
| 586 | def getIPAddress( self, host ): |
| 587 | """ |
| 588 | Verifies the host's ip configured or not.""" |
| 589 | if self.handle: |
| 590 | try: |
| 591 | response = self.execute( |
| 592 | cmd=host + |
| 593 | " ifconfig", |
| 594 | prompt="mininet>", |
| 595 | timeout=10 ) |
| 596 | except pexpect.EOF: |
| 597 | main.log.error( self.name + ": EOF exception found" ) |
| 598 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 599 | main.cleanup() |
| 600 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 601 | |
| 602 | pattern = "inet\saddr:(\d+\.\d+\.\d+\.\d+)" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 603 | ipAddressSearch = re.search( pattern, response ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 604 | main.log.info( |
| 605 | self.name + |
| 606 | ": IP-Address of Host " + |
| 607 | host + |
| 608 | " is " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 609 | ipAddressSearch.group( 1 ) ) |
| 610 | return ipAddressSearch.group( 1 ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 611 | else: |
| 612 | main.log.error( self.name + ": Connection failed to the host" ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 613 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 614 | def getSwitchDPID( self, switch ): |
| 615 | """ |
| 616 | return the datapath ID of the switch""" |
| 617 | if self.handle: |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 618 | cmd = "py %s.dpid" % switch |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 619 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 620 | response = self.execute( |
| 621 | cmd=cmd, |
| 622 | prompt="mininet>", |
| 623 | timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 624 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 625 | main.log.error( self.name + ": EOF exception found" ) |
| 626 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 627 | main.cleanup() |
| 628 | main.exit() |
Jon Hall | 28bf54b | 2014-12-17 16:25:44 -0800 | [diff] [blame] | 629 | pattern = r'^(?P<dpid>\w)+' |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 630 | result = re.search( pattern, response, re.MULTILINE ) |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 631 | if result is None: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 632 | main.log.info( |
| 633 | "Couldn't find DPID for switch %s, found: %s" % |
| 634 | ( switch, response ) ) |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 635 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 636 | return str( result.group( 0 ) ).lower() |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 637 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 638 | main.log.error( "Connection failed to the host" ) |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 639 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 640 | def getDPID( self, switch ): |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 641 | if self.handle: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 642 | self.handle.sendline( "" ) |
| 643 | self.expect( "mininet>" ) |
| 644 | cmd = "py %s.dpid" % switch |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 645 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 646 | response = self.execute( |
| 647 | cmd=cmd, |
| 648 | prompt="mininet>", |
| 649 | timeout=10 ) |
| 650 | self.handle.expect( "mininet>" ) |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 651 | response = self.handle.before |
| 652 | return response |
| 653 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 654 | main.log.error( self.name + ": EOF exception found" ) |
| 655 | main.log.error( self.name + ": " + self.handle.before ) |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 656 | main.cleanup() |
| 657 | main.exit() |
| 658 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 659 | def getInterfaces( self, node ): |
| 660 | """ |
| 661 | return information dict about interfaces connected to the node""" |
| 662 | if self.handle: |
| 663 | cmd = 'py "\\n".join(["name=%s,mac=%s,ip=%s,enabled=%s"' +\ |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 664 | ' % (i.name, i.MAC(), i.IP(), i.isUp())' |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 665 | cmd += ' for i in %s.intfs.values()])' % node |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 666 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 667 | response = self.execute( |
| 668 | cmd=cmd, |
| 669 | prompt="mininet>", |
| 670 | timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 671 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 672 | main.log.error( self.name + ": EOF exception found" ) |
| 673 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 674 | main.cleanup() |
| 675 | main.exit() |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 676 | return response |
| 677 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 678 | main.log.error( "Connection failed to the node" ) |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 679 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 680 | def dump( self ): |
| 681 | main.log.info( self.name + ": Dump node info" ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 682 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 683 | response = self.execute( |
| 684 | cmd='dump', |
| 685 | prompt='mininet>', |
| 686 | timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 687 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 688 | main.log.error( self.name + ": EOF exception found" ) |
| 689 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 690 | main.cleanup() |
| 691 | main.exit() |
Ahmed El-Hassany | d1f7170 | 2014-04-04 16:12:45 -0700 | [diff] [blame] | 692 | return response |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 693 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 694 | def intfs( self ): |
| 695 | main.log.info( self.name + ": List interfaces" ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 696 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 697 | response = self.execute( |
| 698 | cmd='intfs', |
| 699 | prompt='mininet>', |
| 700 | timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 701 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 702 | main.log.error( self.name + ": EOF exception found" ) |
| 703 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 704 | main.cleanup() |
| 705 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 706 | return response |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 707 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 708 | def net( self ): |
| 709 | main.log.info( self.name + ": List network connections" ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 710 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 711 | response = self.execute( cmd='net', prompt='mininet>', timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 712 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 713 | main.log.error( self.name + ": EOF exception found" ) |
| 714 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 715 | main.cleanup() |
| 716 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 717 | return response |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 718 | |
| 719 | def iperf( self, host1, host2 ): |
| 720 | main.log.info( |
| 721 | self.name + |
| 722 | ": Simple iperf TCP test between two hosts" ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 723 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 724 | cmd1 = 'iperf ' + host1 + " " + host2 |
| 725 | self.handle.sendline( cmd1 ) |
| 726 | self.handle.expect( "mininet>" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 727 | response = self.handle.before |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 728 | if re.search( 'Results:', response ): |
| 729 | main.log.info( self.name + ": iperf test succssful" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 730 | return main.TRUE |
| 731 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 732 | main.log.error( self.name + ": iperf test failed" ) |
| 733 | return main.FALSE |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 734 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 735 | main.log.error( self.name + ": EOF exception found" ) |
| 736 | main.log.error( self.name + ": " + self.handle.before ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 737 | main.cleanup() |
| 738 | main.exit() |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 739 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 740 | def iperfudp( self ): |
| 741 | main.log.info( |
| 742 | self.name + |
| 743 | ": Simple iperf TCP test between two " + |
| 744 | "(optionally specified) hosts" ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 745 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 746 | response = self.execute( |
| 747 | cmd='iperfudp', |
| 748 | prompt='mininet>', |
| 749 | timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 750 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 751 | main.log.error( self.name + ": EOF exception found" ) |
| 752 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 753 | main.cleanup() |
| 754 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 755 | return response |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 756 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 757 | def nodes( self ): |
| 758 | main.log.info( self.name + ": List all nodes." ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 759 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 760 | response = self.execute( |
| 761 | cmd='nodes', |
| 762 | prompt='mininet>', |
| 763 | timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 764 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 765 | main.log.error( self.name + ": EOF exception found" ) |
| 766 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 767 | main.cleanup() |
| 768 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 769 | return response |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 770 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 771 | def pingpair( self ): |
| 772 | main.log.info( self.name + ": Ping between first two hosts" ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 773 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 774 | response = self.execute( |
| 775 | cmd='pingpair', |
| 776 | prompt='mininet>', |
| 777 | timeout=20 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 778 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 779 | main.log.error( self.name + ": EOF exception found" ) |
| 780 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 781 | main.cleanup() |
| 782 | main.exit() |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 783 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 784 | if re.search( ',\s0\%\spacket\sloss', response ): |
| 785 | main.log.info( self.name + ": Ping between two hosts SUCCESSFUL" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 786 | main.lastResult = main.TRUE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 787 | return main.TRUE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 788 | else: |
| 789 | main.log.error( self.name + ": PACKET LOST, HOSTS NOT REACHABLE" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 790 | main.lastResult = main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 791 | return main.FALSE |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 792 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 793 | def link( self, **linkargs ): |
| 794 | """ |
| 795 | Bring link( s ) between two nodes up or down""" |
kelvin-onlab | 7d0c967 | 2015-01-20 15:56:22 -0800 | [diff] [blame] | 796 | args = utilities.parse_args( [ "END1", "END2", "OPTION" ], **linkargs ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 797 | end1 = args[ "END1" ] if args[ "END1" ] is not None else "" |
| 798 | end2 = args[ "END2" ] if args[ "END2" ] is not None else "" |
| 799 | option = args[ "OPTION" ] if args[ "OPTION" ] is not None else "" |
| 800 | main.log.info( |
| 801 | "Bring link between '" + |
| 802 | end1 + |
| 803 | "' and '" + |
| 804 | end2 + |
| 805 | "' '" + |
| 806 | option + |
| 807 | "'" ) |
| 808 | command = "link " + \ |
| 809 | str( end1 ) + " " + str( end2 ) + " " + str( option ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 810 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 811 | self.handle.sendline( command ) |
| 812 | self.handle.expect( "mininet>" ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 813 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 814 | main.log.error( self.name + ": EOF exception found" ) |
| 815 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 816 | main.cleanup() |
| 817 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 818 | return main.TRUE |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 819 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 820 | def yank( self, **yankargs ): |
| 821 | """ |
| 822 | yank a mininet switch interface to a host""" |
| 823 | main.log.info( 'Yank the switch interface attached to a host' ) |
kelvin-onlab | 7d0c967 | 2015-01-20 15:56:22 -0800 | [diff] [blame] | 824 | args = utilities.parse_args( [ "SW", "INTF" ], **yankargs ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 825 | sw = args[ "SW" ] if args[ "SW" ] is not None else "" |
| 826 | intf = args[ "INTF" ] if args[ "INTF" ] is not None else "" |
| 827 | command = "py " + str( sw ) + '.detach("' + str(intf) + '")' |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 828 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 829 | response = self.execute( |
| 830 | cmd=command, |
| 831 | prompt="mininet>", |
| 832 | timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 833 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 834 | main.log.error( self.name + ": EOF exception found" ) |
| 835 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 836 | main.cleanup() |
| 837 | main.exit() |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 838 | return main.TRUE |
| 839 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 840 | def plug( self, **plugargs ): |
| 841 | """ |
| 842 | plug the yanked mininet switch interface to a switch""" |
| 843 | main.log.info( 'Plug the switch interface attached to a switch' ) |
kelvin-onlab | 7d0c967 | 2015-01-20 15:56:22 -0800 | [diff] [blame] | 844 | args = utilities.parse_args( [ "SW", "INTF" ], **plugargs ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 845 | sw = args[ "SW" ] if args[ "SW" ] is not None else "" |
| 846 | intf = args[ "INTF" ] if args[ "INTF" ] is not None else "" |
| 847 | command = "py " + str( sw ) + '.attach("' + str(intf) + '")' |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 848 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 849 | response = self.execute( |
| 850 | cmd=command, |
| 851 | prompt="mininet>", |
| 852 | timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 853 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 854 | main.log.error( self.name + ": EOF exception found" ) |
| 855 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 856 | main.cleanup() |
| 857 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 858 | return main.TRUE |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 859 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 860 | def dpctl( self, **dpctlargs ): |
| 861 | """ |
| 862 | Run dpctl command on all switches.""" |
| 863 | main.log.info( 'Run dpctl command on all switches' ) |
kelvin-onlab | 7d0c967 | 2015-01-20 15:56:22 -0800 | [diff] [blame] | 864 | args = utilities.parse_args( [ "CMD", "ARGS" ], **dpctlargs ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 865 | cmd = args[ "CMD" ] if args[ "CMD" ] is not None else "" |
| 866 | cmdargs = args[ "ARGS" ] if args[ "ARGS" ] is not None else "" |
| 867 | command = "dpctl " + cmd + " " + str( cmdargs ) |
| 868 | try: |
| 869 | response = self.execute( |
| 870 | cmd=command, |
| 871 | prompt="mininet>", |
| 872 | timeout=10 ) |
| 873 | except pexpect.EOF: |
| 874 | main.log.error( self.name + ": EOF exception found" ) |
| 875 | main.log.error( self.name + ": " + self.handle.before ) |
| 876 | main.cleanup() |
| 877 | main.exit() |
| 878 | return main.TRUE |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 879 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 880 | def getVersion( self ): |
| 881 | fileInput = path + '/lib/Mininet/INSTALL' |
| 882 | version = super( Mininet, self ).getVersion() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 883 | pattern = 'Mininet\s\w\.\w\.\w\w*' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 884 | for line in open( fileInput, 'r' ).readlines(): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 885 | result = re.match( pattern, line ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 886 | if result: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 887 | version = result.group( 0 ) |
Jon Hall | ec3c21e | 2014-11-10 22:22:37 -0500 | [diff] [blame] | 888 | return version |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 889 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 890 | def getSwController( self, sw ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 891 | """ |
Jon Hall | ec3c21e | 2014-11-10 22:22:37 -0500 | [diff] [blame] | 892 | Parameters: |
| 893 | sw: The name of an OVS switch. Example "s1" |
| 894 | Return: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 895 | The output of the command from the mininet cli |
| 896 | or main.FALSE on timeout""" |
| 897 | command = "sh ovs-vsctl get-controller " + str( sw ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 898 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 899 | response = self.execute( |
| 900 | cmd=command, |
| 901 | prompt="mininet>", |
| 902 | timeout=10 ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 903 | if response: |
Jon Hall | ec3c21e | 2014-11-10 22:22:37 -0500 | [diff] [blame] | 904 | return response |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 905 | else: |
| 906 | return main.FALSE |
| 907 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 908 | main.log.error( self.name + ": EOF exception found" ) |
| 909 | main.log.error( self.name + ": " + self.handle.before ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 910 | main.cleanup() |
| 911 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 912 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 913 | def assignSwController( self, **kwargs ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 914 | """ |
| 915 | count is only needed if there is more than 1 controller""" |
kelvin-onlab | 7d0c967 | 2015-01-20 15:56:22 -0800 | [diff] [blame] | 916 | args = utilities.parse_args( [ "COUNT" ], **kwargs ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 917 | count = args[ "COUNT" ] if args != {} else 1 |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 918 | |
| 919 | argstring = "SW" |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 920 | for j in range( count ): |
| 921 | argstring = argstring + ",IP" + \ |
| 922 | str( j + 1 ) + ",PORT" + str( j + 1 ) |
kelvin-onlab | 7d0c967 | 2015-01-20 15:56:22 -0800 | [diff] [blame] | 923 | args = utilities.parse_args( argstring.split( "," ), **kwargs ) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 924 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 925 | sw = args[ "SW" ] if args[ "SW" ] is not None else "" |
| 926 | ptcpA = int( args[ "PORT1" ] ) + \ |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 927 | int( sw ) if args[ "PORT1" ] is not None else "" |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 928 | ptcpB = "ptcp:" + str( ptcpA ) if ptcpA != "" else "" |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 929 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 930 | command = "sh ovs-vsctl set-controller s" + \ |
| 931 | str( sw ) + " " + ptcpB + " " |
| 932 | for j in range( count ): |
| 933 | i = j + 1 |
kelvin-onlab | 7d0c967 | 2015-01-20 15:56:22 -0800 | [diff] [blame] | 934 | args = utilities.parse_args( |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 935 | [ "IP" + str( i ), "PORT" + str( i ) ], **kwargs ) |
| 936 | ip = args[ |
| 937 | "IP" + |
| 938 | str( i ) ] if args[ |
| 939 | "IP" + |
| 940 | str( i ) ] is not None else "" |
| 941 | port = args[ |
| 942 | "PORT" + |
| 943 | str( i ) ] if args[ |
| 944 | "PORT" + |
| 945 | str( i ) ] is not None else "" |
| 946 | tcp = "tcp:" + str( ip ) + ":" + str( port ) + \ |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 947 | " " if ip != "" else "" |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 948 | command = command + tcp |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 949 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 950 | self.execute( cmd=command, prompt="mininet>", timeout=5 ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 951 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 952 | main.log.error( self.name + ": EOF exception found" ) |
| 953 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 954 | main.cleanup() |
| 955 | main.exit() |
| 956 | except: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 957 | main.log.info( self.name + ":" * 50 ) |
kelvin-onlab | 64b3371 | 2015-01-21 15:26:15 -0800 | [diff] [blame] | 958 | main.log.error( traceback.print_exc() ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 959 | main.log.info( ":" * 50 ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 960 | main.cleanup() |
| 961 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 962 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 963 | def deleteSwController( self, sw ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 964 | """ |
| 965 | Removes the controller target from sw""" |
| 966 | command = "sh ovs-vsctl del-controller " + str( sw ) |
Jon Hall | 0819fd9 | 2014-05-23 12:08:13 -0700 | [diff] [blame] | 967 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 968 | response = self.execute( |
| 969 | cmd=command, |
| 970 | prompt="mininet>", |
| 971 | timeout=10 ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 972 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 973 | main.log.error( self.name + ": EOF exception found" ) |
| 974 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 0819fd9 | 2014-05-23 12:08:13 -0700 | [diff] [blame] | 975 | main.cleanup() |
| 976 | main.exit() |
| 977 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 978 | main.log.info( response ) |
Jon Hall | 0819fd9 | 2014-05-23 12:08:13 -0700 | [diff] [blame] | 979 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 980 | def addSwitch( self, sw, **kwargs ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 981 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 982 | adds a switch to the mininet topology |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 983 | NOTE: This uses a custom mn function. MN repo should be on |
Jon Hall | 272a4db | 2015-01-12 17:43:48 -0800 | [diff] [blame] | 984 | dynamic_topo branch |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 985 | NOTE: cannot currently specify what type of switch |
| 986 | required params: |
| 987 | switchname = name of the new switch as a string |
| 988 | optional keyvalues: |
| 989 | dpid = "dpid" |
| 990 | returns: main.FASLE on an error, else main.TRUE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 991 | """ |
| 992 | dpid = kwargs.get( 'dpid', '' ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 993 | command = "addswitch " + str( sw ) + " " + str( dpid ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 994 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 995 | response = self.execute( |
| 996 | cmd=command, |
| 997 | prompt="mininet>", |
| 998 | timeout=10 ) |
| 999 | if re.search( "already exists!", response ): |
| 1000 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1001 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1002 | elif re.search( "Error", response ): |
| 1003 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1004 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1005 | elif re.search( "usage:", response ): |
| 1006 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1007 | return main.FALSE |
| 1008 | else: |
| 1009 | return main.TRUE |
| 1010 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1011 | main.log.error( self.name + ": EOF exception found" ) |
| 1012 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1013 | main.cleanup() |
| 1014 | main.exit() |
| 1015 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1016 | def delSwitch( self, sw ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1017 | """ |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 1018 | delete a switch from the mininet topology |
| 1019 | NOTE: This uses a custom mn function. MN repo should be on |
Jon Hall | 272a4db | 2015-01-12 17:43:48 -0800 | [diff] [blame] | 1020 | dynamic_topo branch |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 1021 | required params: |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1022 | switchname = name of the switch as a string |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 1023 | returns: main.FASLE on an error, else main.TRUE""" |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1024 | command = "delswitch " + str( sw ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1025 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1026 | response = self.execute( |
| 1027 | cmd=command, |
| 1028 | prompt="mininet>", |
| 1029 | timeout=10 ) |
| 1030 | if re.search( "no switch named", response ): |
| 1031 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1032 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1033 | elif re.search( "Error", response ): |
| 1034 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1035 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1036 | elif re.search( "usage:", response ): |
| 1037 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1038 | return main.FALSE |
| 1039 | else: |
| 1040 | return main.TRUE |
| 1041 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1042 | main.log.error( self.name + ": EOF exception found" ) |
| 1043 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1044 | main.cleanup() |
| 1045 | main.exit() |
| 1046 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1047 | def addLink( self, node1, node2 ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1048 | """ |
| 1049 | add a link to the mininet topology |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 1050 | NOTE: This uses a custom mn function. MN repo should be on |
Jon Hall | 272a4db | 2015-01-12 17:43:48 -0800 | [diff] [blame] | 1051 | dynamic_topo branch |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1052 | NOTE: cannot currently specify what type of link |
| 1053 | required params: |
| 1054 | node1 = the string node name of the first endpoint of the link |
| 1055 | node2 = the string node name of the second endpoint of the link |
| 1056 | returns: main.FASLE on an error, else main.TRUE""" |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1057 | command = "addlink " + str( node1 ) + " " + str( node2 ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1058 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1059 | response = self.execute( |
| 1060 | cmd=command, |
| 1061 | prompt="mininet>", |
| 1062 | timeout=10 ) |
| 1063 | if re.search( "doesnt exist!", response ): |
| 1064 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1065 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1066 | elif re.search( "Error", response ): |
| 1067 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1068 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1069 | elif re.search( "usage:", response ): |
| 1070 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1071 | return main.FALSE |
| 1072 | else: |
| 1073 | return main.TRUE |
| 1074 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1075 | main.log.error( self.name + ": EOF exception found" ) |
| 1076 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1077 | main.cleanup() |
| 1078 | main.exit() |
| 1079 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1080 | def delLink( self, node1, node2 ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1081 | """ |
| 1082 | delete a link from the mininet topology |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 1083 | NOTE: This uses a custom mn function. MN repo should be on |
Jon Hall | 272a4db | 2015-01-12 17:43:48 -0800 | [diff] [blame] | 1084 | dynamic_topo branch |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1085 | required params: |
| 1086 | node1 = the string node name of the first endpoint of the link |
| 1087 | node2 = the string node name of the second endpoint of the link |
| 1088 | returns: main.FASLE on an error, else main.TRUE""" |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1089 | command = "dellink " + str( node1 ) + " " + str( node2 ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1090 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1091 | response = self.execute( |
| 1092 | cmd=command, |
| 1093 | prompt="mininet>", |
| 1094 | timeout=10 ) |
| 1095 | if re.search( "no node named", response ): |
| 1096 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1097 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1098 | elif re.search( "Error", response ): |
| 1099 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1100 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1101 | elif re.search( "usage:", response ): |
| 1102 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1103 | return main.FALSE |
| 1104 | else: |
| 1105 | return main.TRUE |
| 1106 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1107 | main.log.error( self.name + ": EOF exception found" ) |
| 1108 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1109 | main.cleanup() |
| 1110 | main.exit() |
| 1111 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1112 | def addHost( self, hostname, **kwargs ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1113 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1114 | Add a host to the mininet topology |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 1115 | NOTE: This uses a custom mn function. MN repo should be on |
Jon Hall | 272a4db | 2015-01-12 17:43:48 -0800 | [diff] [blame] | 1116 | dynamic_topo branch |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1117 | NOTE: cannot currently specify what type of host |
| 1118 | required params: |
| 1119 | hostname = the string hostname |
| 1120 | optional key-value params |
| 1121 | switch = "switch name" |
| 1122 | returns: main.FASLE on an error, else main.TRUE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1123 | """ |
| 1124 | switch = kwargs.get( 'switch', '' ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1125 | command = "addhost " + str( hostname ) + " " + str( switch ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1126 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1127 | response = self.execute( |
| 1128 | cmd=command, |
| 1129 | prompt="mininet>", |
| 1130 | timeout=10 ) |
| 1131 | if re.search( "already exists!", response ): |
| 1132 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1133 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1134 | elif re.search( "doesnt exists!", response ): |
| 1135 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1136 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1137 | elif re.search( "Error", response ): |
| 1138 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1139 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1140 | elif re.search( "usage:", response ): |
| 1141 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1142 | return main.FALSE |
| 1143 | else: |
| 1144 | return main.TRUE |
| 1145 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1146 | main.log.error( self.name + ": EOF exception found" ) |
| 1147 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1148 | main.cleanup() |
| 1149 | main.exit() |
| 1150 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1151 | def delHost( self, hostname ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1152 | """ |
| 1153 | delete a host from the mininet topology |
Jon Hall | be6dfc4 | 2015-01-12 17:37:25 -0800 | [diff] [blame] | 1154 | NOTE: This uses a custom mn function. MN repo should be on |
Jon Hall | 272a4db | 2015-01-12 17:43:48 -0800 | [diff] [blame] | 1155 | dynamic_topo branch |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1156 | NOTE: this uses a custom mn function |
| 1157 | required params: |
| 1158 | hostname = the string hostname |
| 1159 | returns: main.FASLE on an error, else main.TRUE""" |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1160 | command = "delhost " + str( hostname ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1161 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1162 | response = self.execute( |
| 1163 | cmd=command, |
| 1164 | prompt="mininet>", |
| 1165 | timeout=10 ) |
| 1166 | if re.search( "no host named", response ): |
| 1167 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1168 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1169 | elif re.search( "Error", response ): |
| 1170 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1171 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1172 | elif re.search( "usage:", response ): |
| 1173 | main.log.warn( response ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1174 | return main.FALSE |
| 1175 | else: |
| 1176 | return main.TRUE |
| 1177 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1178 | main.log.error( self.name + ": EOF exception found" ) |
| 1179 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1180 | main.cleanup() |
| 1181 | main.exit() |
Jon Hall | 0819fd9 | 2014-05-23 12:08:13 -0700 | [diff] [blame] | 1182 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1183 | def disconnect( self ): |
kelvin-onlab | a0ce322 | 2015-01-27 17:25:15 -0800 | [diff] [blame^] | 1184 | """ |
| 1185 | Called at the end of the test to disconnect the handle. |
| 1186 | """ |
| 1187 | self.handle.sendline('') |
| 1188 | i = 1 |
| 1189 | i = self.handle.expect( ['mininet>',pexpect.EOF,pexpect.TIMEOUT ], timeout = 2) |
| 1190 | if i == 0: |
| 1191 | self.stopNet() |
| 1192 | response = '' |
| 1193 | # print "Disconnecting Mininet" |
| 1194 | if self.handle: |
| 1195 | self.handle.sendline( "exit" ) |
| 1196 | self.handle.expect( "exit" ) |
| 1197 | self.handle.expect( "(.*)" ) |
| 1198 | main.log.info( "Mininet CLI is successfully disconnected" ) |
| 1199 | response = self.handle.before |
| 1200 | else: |
| 1201 | main.log.error( "Connection failed to the host" ) |
| 1202 | response = main.FALSE |
| 1203 | |
| 1204 | return response |
| 1205 | |
| 1206 | def stopNet( self ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1207 | main.log.info( self.name + ": Disconnecting mininet..." ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1208 | response = '' |
| 1209 | if self.handle: |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 1210 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1211 | response = self.execute( |
| 1212 | cmd="exit", |
| 1213 | prompt="(.*)", |
| 1214 | timeout=120 ) |
kelvin-onlab | a0ce322 | 2015-01-27 17:25:15 -0800 | [diff] [blame^] | 1215 | main.log.info( self.name + ": Disconnected") |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1216 | self.handle.sendline( "sudo mn -c" ) |
shahshreya | 328c2a7 | 2014-11-17 10:19:50 -0800 | [diff] [blame] | 1217 | response = main.TRUE |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 1218 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1219 | main.log.error( self.name + ": EOF exception found" ) |
| 1220 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 1221 | main.cleanup() |
| 1222 | main.exit() |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1223 | else: |
| 1224 | main.log.error( self.name + ": Connection failed to the host" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1225 | response = main.FALSE |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 1226 | return response |
| 1227 | |
kelvin-onlab | a0ce322 | 2015-01-27 17:25:15 -0800 | [diff] [blame^] | 1228 | |
| 1229 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1230 | def arping( self, src, dest, destmac ): |
| 1231 | self.handle.sendline( '' ) |
| 1232 | self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] ) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 1233 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1234 | self.handle.sendline( src + ' arping ' + dest ) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 1235 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1236 | self.handle.expect( [ destmac, pexpect.EOF, pexpect.TIMEOUT ] ) |
| 1237 | main.log.info( self.name + ": ARP successful" ) |
| 1238 | self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] ) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 1239 | return main.TRUE |
| 1240 | except: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1241 | main.log.warn( self.name + ": ARP FAILURE" ) |
| 1242 | self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] ) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 1243 | return main.FALSE |
| 1244 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1245 | def decToHex( self, num ): |
| 1246 | return hex( num ).split( 'x' )[ 1 ] |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 1247 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1248 | def getSwitchFlowCount( self, switch ): |
| 1249 | """ |
| 1250 | return the Flow Count of the switch""" |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1251 | if self.handle: |
| 1252 | cmd = "sh ovs-ofctl dump-aggregate %s" % switch |
| 1253 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1254 | response = self.execute( |
| 1255 | cmd=cmd, |
| 1256 | prompt="mininet>", |
| 1257 | timeout=10 ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1258 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1259 | main.log.error( self.name + ": EOF exception found" ) |
| 1260 | main.log.error( self.name + " " + self.handle.before ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1261 | main.cleanup() |
| 1262 | main.exit() |
| 1263 | pattern = "flow_count=(\d+)" |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1264 | result = re.search( pattern, response, re.MULTILINE ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1265 | if result is None: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1266 | main.log.info( |
| 1267 | "Couldn't find flows on switch %s, found: %s" % |
| 1268 | ( switch, response ) ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1269 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1270 | return result.group( 1 ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1271 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1272 | main.log.error( "Connection failed to the Mininet host" ) |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 1273 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1274 | def checkFlows( self, sw, dumpFormat=None ): |
| 1275 | if dumpFormat: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1276 | command = "sh ovs-ofctl -F " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1277 | dumpFormat + " dump-flows " + str( sw ) |
Ahmed El-Hassany | b6545eb | 2014-08-01 11:32:10 -0700 | [diff] [blame] | 1278 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1279 | command = "sh ovs-ofctl dump-flows " + str( sw ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1280 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1281 | response = self.execute( |
| 1282 | cmd=command, |
| 1283 | prompt="mininet>", |
| 1284 | timeout=10 ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1285 | return response |
| 1286 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1287 | main.log.error( self.name + ": EOF exception found" ) |
| 1288 | main.log.error( self.name + ": " + self.handle.before ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1289 | main.cleanup() |
| 1290 | main.exit() |
| 1291 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1292 | main.log.info( response ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1293 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1294 | def startTcpdump( self, filename, intf="eth0", port="port 6633" ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1295 | """ |
| 1296 | Runs tpdump on an intferface and saves the file |
| 1297 | intf can be specified, or the default eth0 is used""" |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1298 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1299 | self.handle.sendline( "" ) |
| 1300 | self.handle.expect( "mininet>" ) |
| 1301 | self.handle.sendline( |
| 1302 | "sh sudo tcpdump -n -i " + |
| 1303 | intf + |
| 1304 | " " + |
| 1305 | port + |
| 1306 | " -w " + |
| 1307 | filename.strip() + |
| 1308 | " &" ) |
| 1309 | self.handle.sendline( "" ) |
| 1310 | i = self.handle.expect( [ 'No\ssuch\device', |
| 1311 | 'listening\son', |
| 1312 | pexpect.TIMEOUT, |
| 1313 | "mininet>" ], |
| 1314 | timeout=10 ) |
| 1315 | main.log.warn( self.handle.before + self.handle.after ) |
| 1316 | self.handle.sendline( "" ) |
| 1317 | self.handle.expect( "mininet>" ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1318 | if i == 0: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1319 | main.log.error( |
| 1320 | self.name + |
| 1321 | ": tcpdump - No such device exists. " + |
| 1322 | "tcpdump attempted on: " + |
| 1323 | intf ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1324 | return main.FALSE |
| 1325 | elif i == 1: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1326 | main.log.info( self.name + ": tcpdump started on " + intf ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1327 | return main.TRUE |
| 1328 | elif i == 2: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1329 | main.log.error( |
| 1330 | self.name + |
| 1331 | ": tcpdump command timed out! Check interface name," + |
| 1332 | " given interface was: " + |
| 1333 | intf ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1334 | return main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1335 | elif i == 3: |
| 1336 | main.log.info( self.name + ": " + self.handle.before ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1337 | return main.TRUE |
| 1338 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1339 | main.log.error( self.name + ": tcpdump - unexpected response" ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1340 | return main.FALSE |
| 1341 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1342 | main.log.error( self.name + ": EOF exception found" ) |
| 1343 | main.log.error( self.name + ": " + self.handle.before ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1344 | main.cleanup() |
| 1345 | main.exit() |
| 1346 | except: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1347 | main.log.info( self.name + ":" * 50 ) |
kelvin-onlab | 64b3371 | 2015-01-21 15:26:15 -0800 | [diff] [blame] | 1348 | main.log.error( traceback.print_exc() ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 1349 | main.log.info( ":" * 50 ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1350 | main.cleanup() |
| 1351 | main.exit() |
| 1352 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1353 | def stopTcpdump( self ): |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1354 | "pkills tcpdump" |
| 1355 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1356 | self.handle.sendline( "sh sudo pkill tcpdump" ) |
| 1357 | self.handle.expect( "mininet>" ) |
| 1358 | self.handle.sendline( "" ) |
| 1359 | self.handle.expect( "mininet>" ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1360 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1361 | main.log.error( self.name + ": EOF exception found" ) |
| 1362 | main.log.error( self.name + ": " + self.handle.before ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1363 | main.cleanup() |
| 1364 | main.exit() |
| 1365 | except: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1366 | main.log.info( self.name + ":" * 50 ) |
kelvin-onlab | 64b3371 | 2015-01-21 15:26:15 -0800 | [diff] [blame] | 1367 | main.log.error( traceback.print_exc() ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 1368 | main.log.info( ":" * 50 ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1369 | main.cleanup() |
| 1370 | main.exit() |
| 1371 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1372 | def compareSwitches( self, topo, switchesJson ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1373 | """ |
| 1374 | Compare mn and onos switches |
| 1375 | topo: sts TestONTopology object |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1376 | switchesJson: parsed json object from the onos devices api |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1377 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1378 | This uses the sts TestONTopology object""" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1379 | # main.log.debug( "Switches_json string: ", switchesJson ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1380 | output = { "switches": [] } |
| 1381 | # iterate through the MN topology and pull out switches and and port |
| 1382 | # info |
| 1383 | for switch in topo.graph.switches: |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1384 | ports = [] |
| 1385 | for port in switch.ports.values(): |
kelvin-onlab | 652e1dd | 2015-01-20 17:01:39 -0800 | [diff] [blame] | 1386 | ports.append( { 'of_port': port.port_no, |
| 1387 | 'mac': str( port.hw_addr ).replace( '\'', |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1388 | '' ), |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1389 | 'name': port.name } ) |
| 1390 | output[ 'switches' ].append( { |
| 1391 | "name": switch.name, |
| 1392 | "dpid": str( switch.dpid ).zfill( 16 ), |
| 1393 | "ports": ports } ) |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1394 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1395 | # print "mn" |
| 1396 | # print json.dumps( output, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1397 | # sortKeys=True, |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1398 | # indent=4, |
| 1399 | # separators=( ',', ': ' ) ) |
| 1400 | # print "onos" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1401 | # print json.dumps( switchesJson, |
| 1402 | # sortKeys=True, |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1403 | # indent=4, |
| 1404 | # separators=( ',', ': ' ) ) |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1405 | |
| 1406 | # created sorted list of dpid's in MN and ONOS for comparison |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1407 | mnDPIDs = [] |
| 1408 | for switch in output[ 'switches' ]: |
| 1409 | mnDPIDs.append( switch[ 'dpid' ].lower() ) |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1410 | mnDPIDs.sort() |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1411 | # print "List of Mininet switch DPID's" |
| 1412 | # print mnDPIDs |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1413 | if switchesJson == "": # if rest call fails |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1414 | main.log.error( |
| 1415 | self.name + |
| 1416 | ".compare_switches(): Empty JSON object given from ONOS" ) |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1417 | return main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1418 | onos = switchesJson |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1419 | onosDPIDs = [] |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1420 | for switch in onos: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1421 | if switch[ 'available' ]: |
| 1422 | onosDPIDs.append( |
| 1423 | switch[ 'id' ].replace( |
| 1424 | ":", |
| 1425 | '' ).replace( |
| 1426 | "of", |
| 1427 | '' ).lower() ) |
| 1428 | # else: |
| 1429 | # print "Switch is unavailable:" |
| 1430 | # print switch |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1431 | onosDPIDs.sort() |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1432 | # print "List of ONOS switch DPID's" |
| 1433 | # print onosDPIDs |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1434 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1435 | if mnDPIDs != onosDPIDs: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1436 | switchResults = main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1437 | main.log.report( "Switches in MN but not in ONOS:" ) |
| 1438 | list1 = [ switch for switch in mnDPIDs if switch not in onosDPIDs ] |
| 1439 | main.log.report( str( list1 ) ) |
| 1440 | main.log.report( "Switches in ONOS but not in MN:" ) |
| 1441 | list2 = [ switch for switch in onosDPIDs if switch not in mnDPIDs ] |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 1442 | main.log.report( str( list2 ) ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1443 | else: # list of dpid's match in onos and mn |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1444 | switchResults = main.TRUE |
| 1445 | return switchResults |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1446 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1447 | def comparePorts( self, topo, portsJson ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1448 | """ |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1449 | Compare mn and onos ports |
| 1450 | topo: sts TestONTopology object |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1451 | portsJson: parsed json object from the onos ports api |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1452 | |
Jon Hall | fbc828e | 2015-01-06 17:30:19 -0800 | [diff] [blame] | 1453 | Dependencies: |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1454 | 1. This uses the sts TestONTopology object |
| 1455 | 2. numpy - "sudo pip install numpy" |
| 1456 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1457 | """ |
| 1458 | # FIXME: this does not look for extra ports in ONOS, only checks that |
| 1459 | # ONOS has what is in MN |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1460 | from numpy import uint64 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1461 | portsResults = main.TRUE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1462 | output = { "switches": [] } |
| 1463 | # iterate through the MN topology and pull out switches and and port |
| 1464 | # info |
| 1465 | for switch in topo.graph.switches: |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1466 | ports = [] |
| 1467 | for port in switch.ports.values(): |
kelvin-onlab | 652e1dd | 2015-01-20 17:01:39 -0800 | [diff] [blame] | 1468 | # print port.hw_addr.toStr( separator='' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1469 | tmpPort = {} |
kelvin-onlab | 652e1dd | 2015-01-20 17:01:39 -0800 | [diff] [blame] | 1470 | tmpPort[ 'of_port' ] = port.port_no |
| 1471 | tmpPort[ 'mac' ] = str( port.hw_addr ).replace( '\'', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1472 | tmpPort[ 'name' ] = port.name |
| 1473 | tmpPort[ 'enabled' ] = port.enabled |
Jon Hall | 39f29df | 2014-11-04 19:30:21 -0500 | [diff] [blame] | 1474 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1475 | ports.append( tmpPort ) |
| 1476 | tmpSwitch = {} |
| 1477 | tmpSwitch[ 'name' ] = switch.name |
| 1478 | tmpSwitch[ 'dpid' ] = str( switch.dpid ).zfill( 16 ) |
| 1479 | tmpSwitch[ 'ports' ] = ports |
Jon Hall | 39f29df | 2014-11-04 19:30:21 -0500 | [diff] [blame] | 1480 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1481 | output[ 'switches' ].append( tmpSwitch ) |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1482 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1483 | # PORTS |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1484 | for mnSwitch in output[ 'switches' ]: |
| 1485 | mnPorts = [] |
| 1486 | onosPorts = [] |
| 1487 | switchResult = main.TRUE |
| 1488 | for port in mnSwitch[ 'ports' ]: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1489 | if port[ 'enabled' ]: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1490 | mnPorts.append( port[ 'of_port' ] ) |
| 1491 | for onosSwitch in portsJson: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1492 | # print "Iterating through a new switch as seen by ONOS" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1493 | # print onosSwitch |
| 1494 | if onosSwitch[ 'device' ][ 'available' ]: |
| 1495 | if onosSwitch[ 'device' ][ 'id' ].replace( |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1496 | ':', |
| 1497 | '' ).replace( |
| 1498 | "of", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1499 | '' ) == mnSwitch[ 'dpid' ]: |
| 1500 | for port in onosSwitch[ 'ports' ]: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1501 | if port[ 'isEnabled' ]: |
| 1502 | if port[ 'port' ] == 'local': |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1503 | # onosPorts.append( 'local' ) |
| 1504 | onosPorts.append( long( uint64( -2 ) ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1505 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1506 | onosPorts.append( int( port[ 'port' ] ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1507 | break |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1508 | mnPorts.sort( key=float ) |
| 1509 | onosPorts.sort( key=float ) |
| 1510 | # print "\nPorts for Switch %s:" % ( mnSwitch[ 'name' ] ) |
| 1511 | # print "\tmn_ports[] = ", mnPorts |
| 1512 | # print "\tonos_ports[] = ", onosPorts |
| 1513 | mnPortsLog = mnPorts |
| 1514 | onosPortsLog = onosPorts |
| 1515 | mnPorts = [ x for x in mnPorts ] |
| 1516 | onosPorts = [ x for x in onosPorts ] |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1517 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1518 | # TODO: handle other reserved port numbers besides LOCAL |
| 1519 | # NOTE: Reserved ports |
| 1520 | # Local port: -2 in Openflow, ONOS shows 'local', we store as |
| 1521 | # long( uint64( -2 ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1522 | for mnPort in mnPortsLog: |
| 1523 | if mnPort in onosPorts: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1524 | # don't set results to true here as this is just one of |
| 1525 | # many checks and it might override a failure |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1526 | mnPorts.remove( mnPort ) |
| 1527 | onosPorts.remove( mnPort ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1528 | # NOTE: OVS reports this as down since there is no link |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1529 | # So ignoring these for now |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1530 | # TODO: Come up with a better way of handling these |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1531 | if 65534 in mnPorts: |
| 1532 | mnPorts.remove( 65534 ) |
| 1533 | if long( uint64( -2 ) ) in onosPorts: |
| 1534 | onosPorts.remove( long( uint64( -2 ) ) ) |
| 1535 | if len( mnPorts ): # the ports of this switch don't match |
| 1536 | switchResult = main.FALSE |
| 1537 | main.log.warn( "Ports in MN but not ONOS: " + str( mnPorts ) ) |
| 1538 | if len( onosPorts ): # the ports of this switch don't match |
| 1539 | switchResult = main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1540 | main.log.warn( |
| 1541 | "Ports in ONOS but not MN: " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1542 | str( onosPorts ) ) |
| 1543 | if switchResult == main.FALSE: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1544 | main.log.report( |
| 1545 | "The list of ports for switch %s(%s) does not match:" % |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1546 | ( mnSwitch[ 'name' ], mnSwitch[ 'dpid' ] ) ) |
| 1547 | main.log.warn( "mn_ports[] = " + str( mnPortsLog ) ) |
| 1548 | main.log.warn( "onos_ports[] = " + str( onosPortsLog ) ) |
| 1549 | portsResults = portsResults and switchResult |
| 1550 | return portsResults |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1551 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1552 | def compareLinks( self, topo, linksJson ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1553 | """ |
| 1554 | Compare mn and onos links |
| 1555 | topo: sts TestONTopology object |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1556 | linksJson: parsed json object from the onos links api |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1557 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1558 | This uses the sts TestONTopology object""" |
| 1559 | # FIXME: this does not look for extra links in ONOS, only checks that |
| 1560 | # ONOS has what is in MN |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1561 | linkResults = main.TRUE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1562 | output = { "switches": [] } |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1563 | onos = linksJson |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1564 | # iterate through the MN topology and pull out switches and and port |
| 1565 | # info |
| 1566 | for switch in topo.graph.switches: |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1567 | # print "Iterating though switches as seen by Mininet" |
| 1568 | # print switch |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1569 | ports = [] |
| 1570 | for port in switch.ports.values(): |
kelvin-onlab | 652e1dd | 2015-01-20 17:01:39 -0800 | [diff] [blame] | 1571 | # print port.hw_addr.toStr( separator='' ) |
| 1572 | ports.append( { 'of_port': port.port_no, |
| 1573 | 'mac': str( port.hw_addr ).replace( '\'', |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1574 | '' ), |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1575 | 'name': port.name } ) |
| 1576 | output[ 'switches' ].append( { |
| 1577 | "name": switch.name, |
| 1578 | "dpid": str( switch.dpid ).zfill( 16 ), |
| 1579 | "ports": ports } ) |
| 1580 | # LINKS |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1581 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1582 | mnLinks = [ |
kelvin-onlab | 9592d13 | 2015-01-20 17:18:02 -0800 | [diff] [blame] | 1583 | link for link in topo.patch_panel.network_links if ( |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1584 | link.port1.enabled and link.port2.enabled ) ] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1585 | if 2 * len( mnLinks ) == len( onos ): |
| 1586 | linkResults = main.TRUE |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1587 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1588 | linkResults = main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1589 | main.log.report( |
| 1590 | "Mininet has %i bidirectional links and " + |
| 1591 | "ONOS has %i unidirectional links" % |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1592 | ( len( mnLinks ), len( onos ) ) ) |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1593 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1594 | # iterate through MN links and check if an ONOS link exists in |
| 1595 | # both directions |
| 1596 | # NOTE: Will currently only show mn links as down if they are |
| 1597 | # cut through STS. We can either do everything through STS or |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1598 | # wait for upNetworkLinks and downNetworkLinks to be |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1599 | # fully implemented. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1600 | for link in mnLinks: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1601 | # print "Link: %s" % link |
| 1602 | # TODO: Find a more efficient search method |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1603 | node1 = None |
| 1604 | port1 = None |
| 1605 | node2 = None |
| 1606 | port2 = None |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1607 | firstDir = main.FALSE |
| 1608 | secondDir = main.FALSE |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1609 | for switch in output[ 'switches' ]: |
| 1610 | # print "Switch: %s" % switch[ 'name' ] |
| 1611 | if switch[ 'name' ] == link.node1.name: |
| 1612 | node1 = switch[ 'dpid' ] |
| 1613 | for port in switch[ 'ports' ]: |
| 1614 | if str( port[ 'name' ] ) == str( link.port1 ): |
| 1615 | port1 = port[ 'of_port' ] |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1616 | if node1 is not None and node2 is not None: |
| 1617 | break |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1618 | if switch[ 'name' ] == link.node2.name: |
| 1619 | node2 = switch[ 'dpid' ] |
| 1620 | for port in switch[ 'ports' ]: |
| 1621 | if str( port[ 'name' ] ) == str( link.port2 ): |
| 1622 | port2 = port[ 'of_port' ] |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1623 | if node1 is not None and node2 is not None: |
| 1624 | break |
| 1625 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1626 | for onosLink in onos: |
| 1627 | onosNode1 = onosLink[ 'src' ][ 'device' ].replace( |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1628 | ":", |
| 1629 | '' ).replace( |
| 1630 | "of", |
| 1631 | '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1632 | onosNode2 = onosLink[ 'dst' ][ 'device' ].replace( |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1633 | ":", |
| 1634 | '' ).replace( |
| 1635 | "of", |
| 1636 | '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1637 | onosPort1 = onosLink[ 'src' ][ 'port' ] |
| 1638 | onosPort2 = onosLink[ 'dst' ][ 'port' ] |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1639 | |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1640 | # check onos link from node1 to node2 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1641 | if str( onosNode1 ) == str( node1 ) and str( |
| 1642 | onosNode2 ) == str( node2 ): |
| 1643 | if int( onosPort1 ) == int( port1 ) and int( |
| 1644 | onosPort2 ) == int( port2 ): |
| 1645 | firstDir = main.TRUE |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1646 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1647 | main.log.warn( |
| 1648 | 'The port numbers do not match for ' + |
| 1649 | str( link ) + |
| 1650 | ' between ONOS and MN. When cheking ONOS for ' + |
| 1651 | 'link %s/%s -> %s/%s' % |
| 1652 | ( node1, |
| 1653 | port1, |
| 1654 | node2, |
| 1655 | port2 ) + |
| 1656 | ' ONOS has the values %s/%s -> %s/%s' % |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1657 | ( onosNode1, |
| 1658 | onosPort1, |
| 1659 | onosNode2, |
| 1660 | onosPort2 ) ) |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1661 | |
| 1662 | # check onos link from node2 to node1 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1663 | elif ( str( onosNode1 ) == str( node2 ) and |
| 1664 | str( onosNode2 ) == str( node1 ) ): |
| 1665 | if ( int( onosPort1 ) == int( port2 ) |
| 1666 | and int( onosPort2 ) == int( port1 ) ): |
| 1667 | secondDir = main.TRUE |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1668 | else: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1669 | main.log.warn( |
| 1670 | 'The port numbers do not match for ' + |
| 1671 | str( link ) + |
| 1672 | ' between ONOS and MN. When cheking ONOS for ' + |
| 1673 | 'link %s/%s -> %s/%s' % |
| 1674 | ( node2, |
| 1675 | port2, |
| 1676 | node1, |
| 1677 | port1 ) + |
| 1678 | ' ONOS has the values %s/%s -> %s/%s' % |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1679 | ( onosNode2, |
| 1680 | onosPort2, |
| 1681 | onosNode1, |
| 1682 | onosPort1 ) ) |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1683 | else: # this is not the link you're looking for |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1684 | pass |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1685 | if not firstDir: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1686 | main.log.report( |
| 1687 | 'ONOS does not have the link %s/%s -> %s/%s' % |
| 1688 | ( node1, port1, node2, port2 ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1689 | if not secondDir: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1690 | main.log.report( |
| 1691 | 'ONOS does not have the link %s/%s -> %s/%s' % |
| 1692 | ( node2, port2, node1, port1 ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1693 | linkResults = linkResults and firstDir and secondDir |
| 1694 | return linkResults |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1695 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1696 | def getHosts( self ): |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1697 | """ |
| 1698 | Returns a list of all hosts |
| 1699 | Don't ask questions just use it""" |
| 1700 | self.handle.sendline( "" ) |
| 1701 | self.handle.expect( "mininet>" ) |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1702 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1703 | self.handle.sendline( "py [ host.name for host in net.hosts ]" ) |
| 1704 | self.handle.expect( "mininet>" ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1705 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1706 | handlePy = self.handle.before |
| 1707 | handlePy = handlePy.split( "]\r\n", 1 )[ 1 ] |
| 1708 | handlePy = handlePy.rstrip() |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1709 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1710 | self.handle.sendline( "" ) |
| 1711 | self.handle.expect( "mininet>" ) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1712 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1713 | hostStr = handlePy.replace( "]", "" ) |
| 1714 | hostStr = hostStr.replace( "'", "" ) |
| 1715 | hostStr = hostStr.replace( "[", "" ) |
| 1716 | hostList = hostStr.split( "," ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1717 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1718 | return hostList |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1719 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1720 | def update( self ): |
| 1721 | """ |
| 1722 | updates the port address and status information for |
| 1723 | each port in mn""" |
| 1724 | # TODO: Add error checking. currently the mininet command has no output |
| 1725 | main.log.info( "Updateing MN port information" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1726 | try: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1727 | self.handle.sendline( "" ) |
| 1728 | self.handle.expect( "mininet>" ) |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1729 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1730 | self.handle.sendline( "update" ) |
| 1731 | self.handle.expect( "update" ) |
| 1732 | self.handle.expect( "mininet>" ) |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1733 | |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1734 | self.handle.sendline( "" ) |
| 1735 | self.handle.expect( "mininet>" ) |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1736 | |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1737 | return main.TRUE |
| 1738 | except pexpect.EOF: |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1739 | main.log.error( self.name + ": EOF exception found" ) |
| 1740 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1741 | main.cleanup() |
| 1742 | main.exit() |
| 1743 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1744 | if __name__ != "__main__": |
| 1745 | import sys |
Jon Hall | 7eb3840 | 2015-01-08 17:19:54 -0800 | [diff] [blame] | 1746 | sys.modules[ __name__ ] = MininetCliDriver() |