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