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