andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 4 | This driver enters the onos> prompt to issue commands. |
| 5 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 6 | Please follow the coding style demonstrated by existing |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 7 | functions and document properly. |
| 8 | |
| 9 | If you are a contributor to the driver, please |
| 10 | list your email here for future contact: |
| 11 | |
| 12 | jhall@onlab.us |
| 13 | andrew@onlab.us |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 14 | shreya@onlab.us |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 15 | |
| 16 | OCT 13 2014 |
| 17 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 18 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 19 | import sys |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 20 | import pexpect |
| 21 | import re |
| 22 | import traceback |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 23 | sys.path.append( "../" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 24 | from drivers.common.clidriver import CLI |
| 25 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 26 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 27 | class OnosCliDriver( CLI ): |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 28 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 29 | def __init__( self ): |
| 30 | """ |
| 31 | Initialize client |
| 32 | """ |
| 33 | super( CLI, self ).__init__() |
| 34 | |
| 35 | def connect( self, **connectargs ): |
| 36 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 37 | Creates ssh handle for ONOS cli. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 38 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 39 | try: |
| 40 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 41 | vars( self )[ key ] = connectargs[ key ] |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 42 | self.home = "~/ONOS" |
| 43 | for key in self.options: |
| 44 | if key == "home": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 45 | self.home = self.options[ 'home' ] |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 46 | break |
| 47 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 48 | self.name = self.options[ 'name' ] |
| 49 | self.handle = super( OnosCliDriver, self ).connect( |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 50 | user_name=self.user_name, |
| 51 | ip_address=self.ip_address, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 52 | port=self.port, |
| 53 | pwd=self.pwd, |
| 54 | home=self.home ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 55 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 56 | self.handle.sendline( "cd " + self.home ) |
| 57 | self.handle.expect( "\$" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 58 | if self.handle: |
| 59 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 60 | else: |
| 61 | main.log.info( "NO ONOS HANDLE" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 62 | return main.FALSE |
| 63 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 64 | main.log.error( self.name + ": EOF exception found" ) |
| 65 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 66 | main.cleanup() |
| 67 | main.exit() |
| 68 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 69 | main.log.info( self.name + ":::::::::::::::::::::::" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 70 | main.log.error( traceback.print_exc() ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 71 | main.log.info( ":::::::::::::::::::::::" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 72 | main.cleanup() |
| 73 | main.exit() |
| 74 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 75 | def disconnect( self ): |
| 76 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 77 | Called when Test is complete to disconnect the ONOS handle. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 78 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 79 | response = '' |
| 80 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 81 | self.handle.sendline( "" ) |
| 82 | i = self.handle.expect( [ "onos>", "\$" ] ) |
Jon Hall | 7e5b917 | 2014-10-22 12:32:47 -0400 | [diff] [blame] | 83 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 84 | self.handle.sendline( "system:shutdown" ) |
| 85 | self.handle.expect( "Confirm" ) |
| 86 | self.handle.sendline( "yes" ) |
| 87 | self.handle.expect( "\$" ) |
| 88 | self.handle.sendline( "" ) |
| 89 | self.handle.expect( "\$" ) |
| 90 | self.handle.sendline( "exit" ) |
| 91 | self.handle.expect( "closed" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 92 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 93 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 94 | main.log.error( self.name + ": EOF exception found" ) |
| 95 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 96 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 97 | main.log.error( self.name + ": Connection failed to the host" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 98 | response = main.FALSE |
| 99 | return response |
| 100 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 101 | def logout( self ): |
| 102 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 103 | Sends 'logout' command to ONOS cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 104 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 105 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 106 | self.handle.sendline( "" ) |
| 107 | i = self.handle.expect( [ |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 108 | "onos>", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 109 | "\$" ], timeout=10 ) |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 110 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 111 | self.handle.sendline( "logout" ) |
| 112 | self.handle.expect( "\$" ) |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 113 | elif i == 1: |
| 114 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 115 | |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 116 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 117 | main.log.error( self.name + ": eof exception found" ) |
| 118 | main.log.error( self.name + ": " + |
| 119 | self.handle.before ) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 120 | main.cleanup() |
| 121 | main.exit() |
| 122 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 123 | main.log.info( self.name + " ::::::" ) |
| 124 | main.log.error( traceback.print_exc() ) |
| 125 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 126 | main.cleanup() |
| 127 | main.exit() |
| 128 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 129 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 130 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 131 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 132 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 133 | Before issuing any cli commands, set the environment variable first. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 134 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 135 | try: |
| 136 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 137 | main.log.error( "Must define cellname" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 138 | main.cleanup() |
| 139 | main.exit() |
| 140 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 141 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 142 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 143 | # Note that this variable name is subject to change |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 144 | # and that this driver will have to change accordingly |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 145 | self.handle.expect( "ONOS_CELL=" + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 146 | handleBefore = self.handle.before |
| 147 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 148 | # Get the rest of the handle |
| 149 | self.handle.sendline( "" ) |
| 150 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 151 | handleMore = self.handle.before |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 152 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 153 | main.log.info( "Cell call returned: " + handleBefore + |
| 154 | handleAfter + handleMore ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 155 | |
| 156 | return main.TRUE |
| 157 | |
| 158 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 159 | main.log.error( self.name + ": eof exception found" ) |
| 160 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 161 | main.cleanup() |
| 162 | main.exit() |
| 163 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 164 | main.log.info( self.name + " ::::::" ) |
| 165 | main.log.error( traceback.print_exc() ) |
| 166 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 167 | main.cleanup() |
| 168 | main.exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 169 | |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame^] | 170 | def startOnosCli( self, ONOSIp, karafTimeout="", |
| 171 | commandlineTimeout=10, onosStartTimeout=60 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 172 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 173 | karafTimeout is an optional arugument. karafTimeout value passed |
| 174 | by user would be used to set the current karaf shell idle timeout. |
| 175 | Note that when ever this property is modified the shell will exit and |
Hari Krishna | d7b9c20 | 2015-01-05 10:38:14 -0800 | [diff] [blame] | 176 | the subsequent login would reflect new idle timeout. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 177 | Below is an example to start a session with 60 seconds idle timeout |
| 178 | ( input value is in milliseconds ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 179 | |
Hari Krishna | 25d42f7 | 2015-01-05 15:08:28 -0800 | [diff] [blame] | 180 | tValue = "60000" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 181 | main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 182 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 183 | Note: karafTimeout is left as str so that this could be read |
| 184 | and passed to startOnosCli from PARAMS file as str. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 185 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 186 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 187 | self.handle.sendline( "" ) |
| 188 | x = self.handle.expect( [ |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame^] | 189 | "\$", "onos>" ], commandlineTimeout) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 190 | |
| 191 | if x == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 192 | main.log.info( "ONOS cli is already running" ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 193 | return main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 194 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 195 | # Wait for onos start ( -w ) and enter onos cli |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 196 | self.handle.sendline( "onos -w " + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 197 | i = self.handle.expect( [ |
| 198 | "onos>", |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame^] | 199 | pexpect.TIMEOUT ], onosStartTimeout ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 200 | |
| 201 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 202 | main.log.info( str( ONOSIp ) + " CLI Started successfully" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 203 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 204 | self.handle.sendline( |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 205 | "config:property-set -p org.apache.karaf.shell\ |
| 206 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 207 | karafTimeout ) |
| 208 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 209 | self.handle.sendline( "onos -w " + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 210 | self.handle.expect( "onos>" ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 211 | return main.TRUE |
| 212 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 213 | # If failed, send ctrl+c to process and try again |
| 214 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 215 | self.handle.send( "\x03" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 216 | self.handle.sendline( "onos -w " + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 217 | i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ], |
| 218 | timeout=30 ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 219 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 220 | main.log.info( str( ONOSIp ) + " CLI Started " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 221 | "successfully after retry attempt" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 222 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 223 | self.handle.sendline( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 224 | "config:property-set -p org.apache.karaf.shell\ |
| 225 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 226 | karafTimeout ) |
| 227 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 228 | self.handle.sendline( "onos -w " + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 229 | self.handle.expect( "onos>" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 230 | return main.TRUE |
| 231 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 232 | main.log.error( "Connection to CLI " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 233 | str( ONOSIp ) + " timeout" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 234 | return main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 235 | |
| 236 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 237 | main.log.error( self.name + ": EOF exception found" ) |
| 238 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 239 | main.cleanup() |
| 240 | main.exit() |
| 241 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 242 | main.log.info( self.name + " ::::::" ) |
| 243 | main.log.error( traceback.print_exc() ) |
| 244 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 245 | main.cleanup() |
| 246 | main.exit() |
| 247 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 248 | def sendline( self, cmdStr ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 249 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 250 | Send a completely user specified string to |
| 251 | the onos> prompt. Use this function if you have |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 252 | a very specific command to send. |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 253 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 254 | Warning: There are no sanity checking to commands |
| 255 | sent using this method. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 256 | """ |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 257 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 258 | self.handle.sendline( "" ) |
| 259 | self.handle.expect( "onos>" ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 260 | |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 261 | self.handle.sendline( "log:log \"Sending CLI command: '" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 262 | + cmdStr + "'\"" ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 263 | self.handle.expect( "onos>" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 264 | self.handle.sendline( cmdStr ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 265 | self.handle.expect( "onos>" ) |
Jon Hall | aea67aa | 2015-01-23 13:30:57 -0800 | [diff] [blame] | 266 | main.log.info( "Command '" + str( cmdStr ) + "' sent to " |
| 267 | + self.name + "." ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 268 | |
| 269 | handle = self.handle.before |
Jon Hall | 7bdfc12 | 2015-01-23 11:45:32 -0800 | [diff] [blame] | 270 | # Remove control strings from output |
| 271 | ansiEscape = re.compile( r'\x1b[^m]*m' ) |
| 272 | handle = ansiEscape.sub( '', handle ) |
Jon Hall | 44225f8 | 2015-01-23 13:45:14 -0800 | [diff] [blame] | 273 | #Remove extra return chars that get added |
Jon Hall | aea67aa | 2015-01-23 13:30:57 -0800 | [diff] [blame] | 274 | handle = re.sub( r"\s\r", "", handle ) |
| 275 | handle = handle.strip() |
Jon Hall | 7bdfc12 | 2015-01-23 11:45:32 -0800 | [diff] [blame] | 276 | # parse for just the output, remove the cmd from handle |
| 277 | output = handle.split( cmdStr, 1 )[1] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 278 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 279 | |
Jon Hall | 7bdfc12 | 2015-01-23 11:45:32 -0800 | [diff] [blame] | 280 | return output |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 281 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 282 | main.log.error( self.name + ": EOF exception found" ) |
| 283 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 284 | main.cleanup() |
| 285 | main.exit() |
| 286 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 287 | main.log.info( self.name + " ::::::" ) |
| 288 | main.log.error( traceback.print_exc() ) |
| 289 | main.log.info( self.name + " ::::::" ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 290 | main.cleanup() |
| 291 | main.exit() |
| 292 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 293 | # IMPORTANT NOTE: |
| 294 | # For all cli commands, naming convention should match |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 295 | # the cli command changing 'a:b' with 'aB'. |
| 296 | # Ex ) onos:topology > onosTopology |
| 297 | # onos:links > onosLinks |
| 298 | # feature:list > featureList |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 299 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 300 | def addNode( self, nodeId, ONOSIp, tcpPort="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 301 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 302 | Adds a new cluster node by ID and address information. |
| 303 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 304 | * nodeId |
| 305 | * ONOSIp |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 306 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 307 | * tcpPort |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 308 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 309 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 310 | cmdStr = "add-node " + str( nodeId ) + " " +\ |
| 311 | str( ONOSIp ) + " " + str( tcpPort ) |
| 312 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 313 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 314 | main.log.error( "Error in adding node" ) |
| 315 | main.log.error( handle ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 316 | return main.FALSE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 317 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 318 | main.log.info( "Node " + str( ONOSIp ) + " added" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 319 | return main.TRUE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 320 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 321 | main.log.error( self.name + ": EOF exception found" ) |
| 322 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 323 | main.cleanup() |
| 324 | main.exit() |
| 325 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 326 | main.log.info( self.name + " ::::::" ) |
| 327 | main.log.error( traceback.print_exc() ) |
| 328 | main.log.info( self.name + " ::::::" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 329 | main.cleanup() |
| 330 | main.exit() |
| 331 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 332 | def removeNode( self, nodeId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 333 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 334 | Removes a cluster by ID |
| 335 | Issues command: 'remove-node [<node-id>]' |
| 336 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 337 | * nodeId |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 338 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 339 | try: |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 340 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 341 | cmdStr = "remove-node " + str( nodeId ) |
| 342 | self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 343 | # TODO: add error checking. Does ONOS give any errors? |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 344 | |
| 345 | return main.TRUE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 346 | |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 347 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 348 | main.log.error( self.name + ": EOF exception found" ) |
| 349 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 350 | main.cleanup() |
| 351 | main.exit() |
| 352 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 353 | main.log.info( self.name + " ::::::" ) |
| 354 | main.log.error( traceback.print_exc() ) |
| 355 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 356 | main.cleanup() |
| 357 | main.exit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 358 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 359 | def nodes( self ): |
| 360 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 361 | List the nodes currently visible |
| 362 | Issues command: 'nodes' |
| 363 | Returns: entire handle of list of nodes |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 364 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 365 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 366 | cmdStr = "nodes" |
| 367 | handle = self.sendline( cmdStr ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 368 | return handle |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 369 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 370 | main.log.error( self.name + ": EOF exception found" ) |
| 371 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 372 | main.cleanup() |
| 373 | main.exit() |
| 374 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 375 | main.log.info( self.name + " ::::::" ) |
| 376 | main.log.error( traceback.print_exc() ) |
| 377 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 378 | main.cleanup() |
| 379 | main.exit() |
| 380 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 381 | def topology( self ): |
| 382 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 383 | Shows the current state of the topology |
| 384 | by issusing command: 'onos> onos:topology' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 385 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 386 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 387 | # either onos:topology or 'topology' will work in CLI |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 388 | cmdStr = "onos:topology" |
| 389 | handle = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 390 | main.log.info( "onos:topology returned: " + str( handle ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 391 | return handle |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 392 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 393 | main.log.error( self.name + ": EOF exception found" ) |
| 394 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 395 | main.cleanup() |
| 396 | main.exit() |
| 397 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 398 | main.log.info( self.name + " ::::::" ) |
| 399 | main.log.error( traceback.print_exc() ) |
| 400 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 401 | main.cleanup() |
| 402 | main.exit() |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 403 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 404 | def featureInstall( self, featureStr ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 405 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 406 | Installs a specified feature |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 407 | by issuing command: 'onos> feature:install <feature_str>' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 408 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 409 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 410 | cmdStr = "feature:install " + str( featureStr ) |
| 411 | self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 412 | # TODO: Check for possible error responses from karaf |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 413 | return main.TRUE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 414 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 415 | main.log.error( self.name + ": EOF exception found" ) |
| 416 | main.log.error( self.name + ": " + self.handle.before ) |
| 417 | main.log.report( "Failed to install feature" ) |
| 418 | main.log.report( "Exiting test" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 419 | main.cleanup() |
| 420 | main.exit() |
| 421 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 422 | main.log.info( self.name + " ::::::" ) |
| 423 | main.log.error( traceback.print_exc() ) |
| 424 | main.log.report( "Failed to install feature" ) |
| 425 | main.log.report( "Exiting test" ) |
| 426 | main.log.info( self.name + " ::::::" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 427 | main.cleanup() |
| 428 | main.exit() |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 429 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 430 | def featureUninstall( self, featureStr ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 431 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 432 | Uninstalls a specified feature |
| 433 | by issuing command: 'onos> feature:uninstall <feature_str>' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 434 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 435 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 436 | cmdStr = "feature:uninstall " + str( featureStr ) |
| 437 | self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 438 | # TODO: Check for possible error responses from karaf |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 439 | return main.TRUE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 440 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 441 | main.log.error( self.name + ": EOF exception found" ) |
| 442 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 443 | main.cleanup() |
| 444 | main.exit() |
| 445 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 446 | main.log.info( self.name + " ::::::" ) |
| 447 | main.log.error( traceback.print_exc() ) |
| 448 | main.log.info( self.name + " ::::::" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 449 | main.cleanup() |
| 450 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 451 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 452 | def devices( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 453 | """ |
Jon Hall | 7b02d95 | 2014-10-17 20:14:54 -0400 | [diff] [blame] | 454 | Lists all infrastructure devices or switches |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 455 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 456 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 457 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 458 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 459 | if jsonFormat: |
| 460 | cmdStr = "devices -j" |
| 461 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 462 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 463 | handle variable here contains some ANSI escape color code |
| 464 | sequences at the end which are invisible in the print command |
| 465 | output. To make that escape sequence visible, use repr() |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 466 | function. The repr( handle ) output when printed shows the |
| 467 | ANSI escape sequences. In json.loads( somestring ), this |
| 468 | somestring variable is actually repr( somestring ) and |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 469 | json.loads would fail with the escape sequence. So we take off |
| 470 | that escape sequence using: |
| 471 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 472 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 473 | handle1 = ansiEscape.sub( '', handle ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 474 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 475 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 476 | handle1 = ansiEscape.sub( '', handle ) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 477 | return handle1 |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 478 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 479 | cmdStr = "devices" |
| 480 | handle = self.sendline( cmdStr ) |
Jon Hall | cd70729 | 2014-10-17 19:06:17 -0400 | [diff] [blame] | 481 | return handle |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 482 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 483 | main.log.error( self.name + ": EOF exception found" ) |
| 484 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 485 | main.cleanup() |
| 486 | main.exit() |
| 487 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 488 | main.log.info( self.name + " ::::::" ) |
| 489 | main.log.error( traceback.print_exc() ) |
| 490 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 491 | main.cleanup() |
| 492 | main.exit() |
| 493 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 494 | def balanceMasters( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 495 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 496 | This balances the devices across all controllers |
| 497 | by issuing command: 'onos> onos:balance-masters' |
| 498 | If required this could be extended to return devices balanced output. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 499 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 500 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 501 | cmdStr = "onos:balance-masters" |
| 502 | self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 503 | # TODO: Check for error responses from ONOS |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 504 | return main.TRUE |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 505 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 506 | main.log.error( self.name + ": EOF exception found" ) |
| 507 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 508 | main.cleanup() |
| 509 | main.exit() |
| 510 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 511 | main.log.info( self.name + " ::::::" ) |
| 512 | main.log.error( traceback.print_exc() ) |
| 513 | main.log.info( self.name + " ::::::" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 514 | main.cleanup() |
| 515 | main.exit() |
| 516 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 517 | def links( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 518 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 519 | Lists all core links |
| 520 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 521 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 522 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 523 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 524 | if jsonFormat: |
| 525 | cmdStr = "links -j" |
| 526 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 527 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 528 | handle variable here contains some ANSI escape color code |
| 529 | sequences at the end which are invisible in the print command |
| 530 | output. To make that escape sequence visible, use repr() |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 531 | function. The repr( handle ) output when printed shows the ANSI |
| 532 | escape sequences. In json.loads( somestring ), this somestring |
| 533 | variable is actually repr( somestring ) and json.loads would |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 534 | fail with the escape sequence. So we take off that escape |
| 535 | sequence using: |
| 536 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 537 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 538 | handle1 = ansiEscape.sub( '', handle ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 539 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 540 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 541 | handle1 = ansiEscape.sub( '', handle ) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 542 | return handle1 |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 543 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 544 | cmdStr = "links" |
| 545 | handle = self.sendline( cmdStr ) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 546 | return handle |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 547 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 548 | main.log.error( self.name + ": EOF exception found" ) |
| 549 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 550 | main.cleanup() |
| 551 | main.exit() |
| 552 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 553 | main.log.info( self.name + " ::::::" ) |
| 554 | main.log.error( traceback.print_exc() ) |
| 555 | main.log.info( self.name + " ::::::" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 556 | main.cleanup() |
| 557 | main.exit() |
| 558 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 559 | def ports( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 560 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 561 | Lists all ports |
| 562 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 563 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 564 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 565 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 566 | if jsonFormat: |
| 567 | cmdStr = "ports -j" |
| 568 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 569 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 570 | handle variable here contains some ANSI escape color code |
| 571 | sequences at the end which are invisible in the print command |
| 572 | output. To make that escape sequence visible, use repr() |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 573 | function. The repr( handle ) output when printed shows the ANSI |
| 574 | escape sequences. In json.loads( somestring ), this somestring |
| 575 | variable is actually repr( somestring ) and json.loads would |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 576 | fail with the escape sequence. So we take off that escape |
| 577 | sequence using the following commads: |
| 578 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 579 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 580 | handle1 = ansiEscape.sub( '', handle ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 581 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 582 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 583 | handle1 = ansiEscape.sub( '', handle ) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 584 | return handle1 |
| 585 | |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 586 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 587 | cmdStr = "ports" |
| 588 | handle = self.sendline( cmdStr ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 589 | return handle |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 590 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 591 | main.log.error( self.name + ": EOF exception found" ) |
| 592 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 593 | main.cleanup() |
| 594 | main.exit() |
| 595 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 596 | main.log.info( self.name + " ::::::" ) |
| 597 | main.log.error( traceback.print_exc() ) |
| 598 | main.log.info( self.name + " ::::::" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 599 | main.cleanup() |
| 600 | main.exit() |
| 601 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 602 | def roles( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 603 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 604 | Lists all devices and the controllers with roles assigned to them |
| 605 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 606 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 607 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 608 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 609 | if jsonFormat: |
| 610 | cmdStr = "roles -j" |
| 611 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 612 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 613 | handle variable here contains some ANSI escape color code |
| 614 | sequences at the end which are invisible in the print command |
| 615 | output. To make that escape sequence visible, use repr() |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 616 | function. The repr( handle ) output when printed shows the ANSI |
| 617 | escape sequences. In json.loads( somestring ), this somestring |
| 618 | variable is actually repr( somestring ) and json.loads would |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 619 | fail with the escape sequence. |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 620 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 621 | So we take off that escape sequence using the following |
| 622 | commads: |
| 623 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 624 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 625 | handle1 = ansiEscape.sub( '', handle ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 626 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 627 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 628 | handle1 = ansiEscape.sub( '', handle ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 629 | return handle1 |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 630 | |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 631 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 632 | cmdStr = "roles" |
| 633 | handle = self.sendline( cmdStr ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 634 | return handle |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 635 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 636 | main.log.error( self.name + ": EOF exception found" ) |
| 637 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 638 | main.cleanup() |
| 639 | main.exit() |
| 640 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 641 | main.log.info( self.name + " ::::::" ) |
| 642 | main.log.error( traceback.print_exc() ) |
| 643 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 644 | main.cleanup() |
| 645 | main.exit() |
| 646 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 647 | def getRole( self, deviceId ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 648 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 649 | Given the a string containing the json representation of the "roles" |
| 650 | cli command and a partial or whole device id, returns a json object |
| 651 | containing the roles output for the first device whose id contains |
| 652 | "device_id" |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 653 | |
| 654 | Returns: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 655 | A dict of the role assignments for the given device or |
| 656 | None if no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 657 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 658 | try: |
| 659 | import json |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 660 | if deviceId is None: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 661 | return None |
| 662 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 663 | rawRoles = self.roles() |
| 664 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 665 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 666 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 667 | # print device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 668 | if str( deviceId ) in device[ 'id' ]: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 669 | return device |
| 670 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 671 | |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 672 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 673 | main.log.error( self.name + ": EOF exception found" ) |
| 674 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 675 | main.cleanup() |
| 676 | main.exit() |
| 677 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 678 | main.log.info( self.name + " ::::::" ) |
| 679 | main.log.error( traceback.print_exc() ) |
| 680 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 681 | main.cleanup() |
| 682 | main.exit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 683 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 684 | def rolesNotNull( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 685 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 686 | Iterates through each device and checks if there is a master assigned |
| 687 | Returns: main.TRUE if each device has a master |
| 688 | main.FALSE any device has no master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 689 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 690 | try: |
| 691 | import json |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 692 | rawRoles = self.roles() |
| 693 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 694 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 695 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 696 | # print device |
| 697 | if device[ 'master' ] == "none": |
| 698 | main.log.warn( "Device has no master: " + str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 699 | return main.FALSE |
| 700 | return main.TRUE |
| 701 | |
| 702 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 703 | main.log.error( self.name + ": EOF exception found" ) |
| 704 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 705 | main.cleanup() |
| 706 | main.exit() |
| 707 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 708 | main.log.info( self.name + " ::::::" ) |
| 709 | main.log.error( traceback.print_exc() ) |
| 710 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 711 | main.cleanup() |
| 712 | main.exit() |
| 713 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 714 | def paths( self, srcId, dstId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 715 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 716 | Returns string of paths, and the cost. |
| 717 | Issues command: onos:paths <src> <dst> |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 718 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 719 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 720 | cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId ) |
| 721 | handle = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 722 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 723 | main.log.error( "Error in getting paths" ) |
| 724 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 725 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 726 | path = handle.split( ";" )[ 0 ] |
| 727 | cost = handle.split( ";" )[ 1 ] |
| 728 | return ( path, cost ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 729 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 730 | main.log.error( self.name + ": EOF exception found" ) |
| 731 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 732 | main.cleanup() |
| 733 | main.exit() |
| 734 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 735 | main.log.info( self.name + " ::::::" ) |
| 736 | main.log.error( traceback.print_exc() ) |
| 737 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 738 | main.cleanup() |
| 739 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 740 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 741 | def hosts( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 742 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 743 | Lists all discovered hosts |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 744 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 745 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 746 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 747 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 748 | if jsonFormat: |
| 749 | cmdStr = "hosts -j" |
| 750 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 751 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 752 | handle variable here contains some ANSI escape color code |
| 753 | sequences at the end which are invisible in the print command |
| 754 | output. To make that escape sequence visible, use repr() |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 755 | function. The repr( handle ) output when printed shows the ANSI |
| 756 | escape sequences. In json.loads( somestring ), this somestring |
| 757 | variable is actually repr( somestring ) and json.loads would |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 758 | fail with the escape sequence. So we take off that escape |
| 759 | sequence using: |
| 760 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 761 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 762 | handle1 = ansiEscape.sub( '', handle ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 763 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 764 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 765 | handle1 = ansiEscape.sub( '', handle ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 766 | return handle1 |
| 767 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 768 | cmdStr = "hosts" |
| 769 | handle = self.sendline( cmdStr ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 770 | return handle |
| 771 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 772 | main.log.error( self.name + ": EOF exception found" ) |
| 773 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 774 | main.cleanup() |
| 775 | main.exit() |
| 776 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 777 | main.log.info( self.name + " ::::::" ) |
| 778 | main.log.error( traceback.print_exc() ) |
| 779 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 780 | main.cleanup() |
| 781 | main.exit() |
| 782 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 783 | def getHost( self, mac ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 784 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 785 | Return the first host from the hosts api whose 'id' contains 'mac' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 786 | |
| 787 | Note: mac must be a colon seperated mac address, but could be a |
| 788 | partial mac address |
| 789 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 790 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 791 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 792 | import json |
| 793 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 794 | if mac is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 795 | return None |
| 796 | else: |
| 797 | mac = mac |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 798 | rawHosts = self.hosts() |
| 799 | hostsJson = json.loads( rawHosts ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 800 | # search json for the host with mac then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 801 | for host in hostsJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 802 | # print "%s in %s?" % ( mac, host[ 'id' ] ) |
| 803 | if mac in host[ 'id' ]: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 804 | return host |
| 805 | return None |
| 806 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 807 | main.log.error( self.name + ": EOF exception found" ) |
| 808 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 809 | main.cleanup() |
| 810 | main.exit() |
| 811 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 812 | main.log.info( self.name + " ::::::" ) |
| 813 | main.log.error( traceback.print_exc() ) |
| 814 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 815 | main.cleanup() |
| 816 | main.exit() |
| 817 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 818 | def getHostsId( self, hostList ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 819 | """ |
| 820 | Obtain list of hosts |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 821 | Issues command: 'onos> hosts' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 822 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 823 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 824 | * hostList: List of hosts obtained by Mininet |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 825 | IMPORTANT: |
| 826 | This function assumes that you started your |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 827 | topology with the option '--mac'. |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 828 | Furthermore, it assumes that value of VLAN is '-1' |
| 829 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 830 | Converts mininet hosts ( h1, h2, h3... ) into |
| 831 | ONOS format ( 00:00:00:00:00:01/-1 , ... ) |
| 832 | """ |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 833 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 834 | onosHostList = [] |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 835 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 836 | for host in hostList: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 837 | host = host.replace( "h", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 838 | hostHex = hex( int( host ) ).zfill( 12 ) |
| 839 | hostHex = str( hostHex ).replace( 'x', '0' ) |
| 840 | i = iter( str( hostHex ) ) |
| 841 | hostHex = ":".join( a + b for a, b in zip( i, i ) ) |
| 842 | hostHex = hostHex + "/-1" |
| 843 | onosHostList.append( hostHex ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 844 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 845 | return onosHostList |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 846 | |
| 847 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 848 | main.log.error( self.name + ": EOF exception found" ) |
| 849 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 850 | main.cleanup() |
| 851 | main.exit() |
| 852 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 853 | main.log.info( self.name + " ::::::" ) |
| 854 | main.log.error( traceback.print_exc() ) |
| 855 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 856 | main.cleanup() |
| 857 | main.exit() |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 858 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 859 | def addHostIntent( self, hostIdOne, hostIdTwo ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 860 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 861 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 862 | * hostIdOne: ONOS host id for host1 |
| 863 | * hostIdTwo: ONOS host id for host2 |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 864 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 865 | Adds a host-to-host intent ( bidrectional ) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 866 | specifying the two hosts. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 867 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 868 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 869 | cmdStr = "add-host-intent " + str( hostIdOne ) +\ |
| 870 | " " + str( hostIdTwo ) |
| 871 | handle = self.sendline( cmdStr ) |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 872 | if re.search( "Error", handle ): |
| 873 | main.log.error( "Error in adding Host intent" ) |
| 874 | return handle |
| 875 | else: |
| 876 | main.log.info( "Host intent installed between " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 877 | str( hostIdOne ) + " and " + str( hostIdTwo ) ) |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 878 | return main.TRUE |
| 879 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 880 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 881 | main.log.error( self.name + ": EOF exception found" ) |
| 882 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 883 | main.cleanup() |
| 884 | main.exit() |
| 885 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 886 | main.log.info( self.name + " ::::::" ) |
| 887 | main.log.error( traceback.print_exc() ) |
| 888 | main.log.info( self.name + " ::::::" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 889 | main.cleanup() |
| 890 | main.exit() |
| 891 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 892 | def addOpticalIntent( self, ingressDevice, egressDevice ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 893 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 894 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 895 | * ingressDevice: device id of ingress device |
| 896 | * egressDevice: device id of egress device |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 897 | Optional: |
| 898 | TODO: Still needs to be implemented via dev side |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 899 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 900 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 901 | cmdStr = "add-optical-intent " + str( ingressDevice ) +\ |
| 902 | " " + str( egressDevice ) |
| 903 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 904 | # If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 905 | if re.search( "Error", handle ): |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 906 | return handle |
| 907 | else: |
| 908 | return main.TRUE |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 909 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 910 | main.log.error( self.name + ": EOF exception found" ) |
| 911 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 912 | main.cleanup() |
| 913 | main.exit() |
| 914 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 915 | main.log.info( self.name + " ::::::" ) |
| 916 | main.log.error( traceback.print_exc() ) |
| 917 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 918 | main.cleanup() |
| 919 | main.exit() |
| 920 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 921 | def addPointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 922 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 923 | ingressDevice, |
| 924 | egressDevice, |
| 925 | portIngress="", |
| 926 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 927 | ethType="", |
| 928 | ethSrc="", |
| 929 | ethDst="", |
| 930 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 931 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 932 | ipProto="", |
| 933 | ipSrc="", |
| 934 | ipDst="", |
| 935 | tcpSrc="", |
| 936 | tcpDst="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 937 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 938 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 939 | * ingressDevice: device id of ingress device |
| 940 | * egressDevice: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 941 | Optional: |
| 942 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 943 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 944 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 945 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 946 | * lambdaAlloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 947 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 948 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 949 | * ipSrc: specify ip source address |
| 950 | * ipDst: specify ip destination address |
| 951 | * tcpSrc: specify tcp source port |
| 952 | * tcpDst: specify tcp destination port |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 953 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 954 | Adds a point-to-point intent ( uni-directional ) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 955 | specifying device id's and optional fields |
| 956 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 957 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 958 | options developers provide for point-to-point |
| 959 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 960 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 961 | try: |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 962 | cmd = "" |
| 963 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 964 | # If there are no optional arguments |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 965 | if not ethType and not ethSrc and not ethDst\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 966 | and not bandwidth and not lambdaAlloc \ |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 967 | and not ipProto and not ipSrc and not ipDst \ |
| 968 | and not tcpSrc and not tcpDst: |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 969 | cmd = "add-point-intent" |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 970 | |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 971 | else: |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 972 | cmd = "add-point-intent" |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 973 | |
andrewonlab | 0c0a677 | 2014-10-22 12:31:18 -0400 | [diff] [blame] | 974 | if ethType: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 975 | cmd += " --ethType " + str( ethType ) |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 976 | if ethSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 977 | cmd += " --ethSrc " + str( ethSrc ) |
| 978 | if ethDst: |
| 979 | cmd += " --ethDst " + str( ethDst ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 980 | if bandwidth: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 981 | cmd += " --bandwidth " + str( bandwidth ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 982 | if lambdaAlloc: |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 983 | cmd += " --lambda " |
| 984 | if ipProto: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 985 | cmd += " --ipProto " + str( ipProto ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 986 | if ipSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 987 | cmd += " --ipSrc " + str( ipSrc ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 988 | if ipDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 989 | cmd += " --ipDst " + str( ipDst ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 990 | if tcpSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 991 | cmd += " --tcpSrc " + str( tcpSrc ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 992 | if tcpDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 993 | cmd += " --tcpDst " + str( tcpDst ) |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 994 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 995 | # Check whether the user appended the port |
| 996 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 997 | if "/" in ingressDevice: |
| 998 | cmd += " " + str( ingressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 999 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1000 | if not portIngress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1001 | main.log.error( "You must specify " + |
| 1002 | "the ingress port" ) |
| 1003 | # TODO: perhaps more meaningful return |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1004 | return main.FALSE |
| 1005 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1006 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1007 | str( ingressDevice ) + "/" +\ |
| 1008 | str( portIngress ) + " " |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1009 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1010 | if "/" in egressDevice: |
| 1011 | cmd += " " + str( egressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1012 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1013 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1014 | main.log.error( "You must specify " + |
| 1015 | "the egress port" ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1016 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1017 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1018 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1019 | str( egressDevice ) + "/" +\ |
| 1020 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1021 | |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1022 | handle = self.sendline( cmd ) |
| 1023 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1024 | main.log.error( "Error in adding point-to-point intent" ) |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 1025 | return main.FALSE |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1026 | else: |
| 1027 | return main.TRUE |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1028 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1029 | main.log.error( self.name + ": EOF exception found" ) |
| 1030 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1031 | main.cleanup() |
| 1032 | main.exit() |
| 1033 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1034 | main.log.info( self.name + " ::::::" ) |
| 1035 | main.log.error( traceback.print_exc() ) |
| 1036 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1037 | main.cleanup() |
| 1038 | main.exit() |
| 1039 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1040 | def addMultipointToSinglepointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1041 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1042 | ingressDevice1, |
| 1043 | ingressDevice2, |
| 1044 | egressDevice, |
| 1045 | portIngress="", |
| 1046 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1047 | ethType="", |
| 1048 | ethSrc="", |
| 1049 | ethDst="", |
| 1050 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1051 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1052 | ipProto="", |
| 1053 | ipSrc="", |
| 1054 | ipDst="", |
| 1055 | tcpSrc="", |
| 1056 | tcpDst="", |
| 1057 | setEthSrc="", |
| 1058 | setEthDst="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1059 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1060 | Note: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1061 | This function assumes that there would be 2 ingress devices and |
| 1062 | one egress device. For more number of ingress devices, this |
| 1063 | function needs to be modified |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1064 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1065 | * ingressDevice1: device id of ingress device1 |
| 1066 | * ingressDevice2: device id of ingress device2 |
| 1067 | * egressDevice: device id of egress device |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1068 | Optional: |
| 1069 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1070 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1071 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1072 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1073 | * lambdaAlloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1074 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1075 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1076 | * ipSrc: specify ip source address |
| 1077 | * ipDst: specify ip destination address |
| 1078 | * tcpSrc: specify tcp source port |
| 1079 | * tcpDst: specify tcp destination port |
| 1080 | * setEthSrc: action to Rewrite Source MAC Address |
| 1081 | * setEthDst: action to Rewrite Destination MAC Address |
| 1082 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1083 | Adds a multipoint-to-singlepoint intent ( uni-directional ) by |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1084 | specifying device id's and optional fields |
| 1085 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1086 | NOTE: This function may change depending on the |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1087 | options developers provide for multipointpoint-to-singlepoint |
| 1088 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1089 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1090 | try: |
| 1091 | cmd = "" |
| 1092 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1093 | # If there are no optional arguments |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1094 | if not ethType and not ethSrc and not ethDst\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1095 | and not bandwidth and not lambdaAlloc\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1096 | and not ipProto and not ipSrc and not ipDst\ |
| 1097 | and not tcpSrc and not tcpDst and not setEthSrc\ |
| 1098 | and not setEthDst: |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1099 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1100 | |
| 1101 | else: |
| 1102 | cmd = "add-multi-to-single-intent" |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1103 | |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1104 | if ethType: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1105 | cmd += " --ethType " + str( ethType ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1106 | if ethSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1107 | cmd += " --ethSrc " + str( ethSrc ) |
| 1108 | if ethDst: |
| 1109 | cmd += " --ethDst " + str( ethDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1110 | if bandwidth: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1111 | cmd += " --bandwidth " + str( bandwidth ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1112 | if lambdaAlloc: |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1113 | cmd += " --lambda " |
| 1114 | if ipProto: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1115 | cmd += " --ipProto " + str( ipProto ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1116 | if ipSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1117 | cmd += " --ipSrc " + str( ipSrc ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1118 | if ipDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1119 | cmd += " --ipDst " + str( ipDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1120 | if tcpSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1121 | cmd += " --tcpSrc " + str( tcpSrc ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1122 | if tcpDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1123 | cmd += " --tcpDst " + str( tcpDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1124 | if setEthSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1125 | cmd += " --setEthSrc " + str( setEthSrc ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1126 | if setEthDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1127 | cmd += " --setEthDst " + str( setEthDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1128 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1129 | # Check whether the user appended the port |
| 1130 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1131 | if "/" in ingressDevice1: |
| 1132 | cmd += " " + str( ingressDevice1 ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1133 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1134 | if not portIngress1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1135 | main.log.error( "You must specify " + |
| 1136 | "the ingress port1" ) |
| 1137 | # TODO: perhaps more meaningful return |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1138 | return main.FALSE |
| 1139 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1140 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1141 | str( ingressDevice1 ) + "/" +\ |
| 1142 | str( portIngress1 ) + " " |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1143 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1144 | if "/" in ingressDevice2: |
| 1145 | cmd += " " + str( ingressDevice2 ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1146 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1147 | if not portIngress2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1148 | main.log.error( "You must specify " + |
| 1149 | "the ingress port2" ) |
| 1150 | # TODO: perhaps more meaningful return |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1151 | return main.FALSE |
| 1152 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1153 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1154 | str( ingressDevice2 ) + "/" +\ |
| 1155 | str( portIngress2 ) + " " |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1156 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1157 | if "/" in egressDevice: |
| 1158 | cmd += " " + str( egressDevice ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1159 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1160 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1161 | main.log.error( "You must specify " + |
| 1162 | "the egress port" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1163 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1164 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1165 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1166 | str( egressDevice ) + "/" +\ |
| 1167 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1168 | print "cmd= ", cmd |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1169 | handle = self.sendline( cmd ) |
| 1170 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1171 | main.log.error( "Error in adding point-to-point intent" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1172 | return self.handle |
| 1173 | else: |
| 1174 | return main.TRUE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1175 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1176 | main.log.error( self.name + ": EOF exception found" ) |
| 1177 | main.log.error( self.name + ": " + self.handle.before ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1178 | main.cleanup() |
| 1179 | main.exit() |
| 1180 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1181 | main.log.info( self.name + " ::::::" ) |
| 1182 | main.log.error( traceback.print_exc() ) |
| 1183 | main.log.info( self.name + " ::::::" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1184 | main.cleanup() |
| 1185 | main.exit() |
| 1186 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1187 | def removeIntent( self, intentId ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1188 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1189 | Remove intent for specified intent id |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1190 | |
| 1191 | Returns: |
| 1192 | main.False on error and |
| 1193 | cli output otherwise |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1194 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1195 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1196 | cmdStr = "remove-intent " + str( intentId ) |
| 1197 | handle = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1198 | if re.search( "Error", handle ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1199 | main.log.error( "Error in removing intent" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1200 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1201 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1202 | # TODO: Should this be main.TRUE |
| 1203 | return handle |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1204 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1205 | main.log.error( self.name + ": EOF exception found" ) |
| 1206 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1207 | main.cleanup() |
| 1208 | main.exit() |
| 1209 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1210 | main.log.info( self.name + " ::::::" ) |
| 1211 | main.log.error( traceback.print_exc() ) |
| 1212 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1213 | main.cleanup() |
| 1214 | main.exit() |
| 1215 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1216 | def routes( self, jsonFormat=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1217 | """ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1218 | NOTE: This method should be used after installing application: |
| 1219 | onos-app-sdnip |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1220 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1221 | * jsonFormat: enable output formatting in json |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1222 | Description: |
| 1223 | Obtain all routes in the system |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1224 | """ |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1225 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1226 | if jsonFormat: |
| 1227 | cmdStr = "routes -j" |
| 1228 | handleTmp = self.sendline( cmdStr ) |
| 1229 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1230 | handle = ansiEscape.sub( '', handleTmp ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1231 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1232 | cmdStr = "routes" |
| 1233 | handle = self.sendline( cmdStr ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1234 | return handle |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1235 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1236 | main.log.error( self.name + ": EOF exception found" ) |
| 1237 | main.log.error( self.name + ": " + self.handle.before ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1238 | main.cleanup() |
| 1239 | main.exit() |
| 1240 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1241 | main.log.info( self.name + " ::::::" ) |
| 1242 | main.log.error( traceback.print_exc() ) |
| 1243 | main.log.info( self.name + " ::::::" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1244 | main.cleanup() |
| 1245 | main.exit() |
| 1246 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1247 | def intents( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1248 | """ |
andrewonlab | 377693f | 2014-10-21 16:00:30 -0400 | [diff] [blame] | 1249 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1250 | * jsonFormat: enable output formatting in json |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1251 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1252 | Obtain intents currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1253 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1254 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1255 | if jsonFormat: |
| 1256 | cmdStr = "intents -j" |
| 1257 | handle = self.sendline( cmdStr ) |
| 1258 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1259 | handle = ansiEscape.sub( '', handle ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1260 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1261 | cmdStr = "intents" |
| 1262 | handle = self.sendline( cmdStr ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1263 | return handle |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1264 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1265 | main.log.error( self.name + ": EOF exception found" ) |
| 1266 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1267 | main.cleanup() |
| 1268 | main.exit() |
| 1269 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1270 | main.log.info( self.name + " ::::::" ) |
| 1271 | main.log.error( traceback.print_exc() ) |
| 1272 | main.log.info( self.name + " ::::::" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1273 | main.cleanup() |
| 1274 | main.exit() |
| 1275 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1276 | def flows( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1277 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1278 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1279 | * jsonFormat: enable output formatting in json |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1280 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1281 | Obtain flows currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1282 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1283 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1284 | if jsonFormat: |
| 1285 | cmdStr = "flows -j" |
| 1286 | handle = self.sendline( cmdStr ) |
| 1287 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1288 | handle = ansiEscape.sub( '', handle ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1289 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1290 | cmdStr = "flows" |
| 1291 | handle = self.sendline( cmdStr ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1292 | if re.search( "Error\sexecuting\scommand:", handle ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1293 | main.log.error( self.name + ".flows() response: " + |
| 1294 | str( handle ) ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1295 | return handle |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1296 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1297 | main.log.error( self.name + ": EOF exception found" ) |
| 1298 | main.log.error( self.name + ": " + self.handle.before ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1299 | main.cleanup() |
| 1300 | main.exit() |
| 1301 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1302 | main.log.info( self.name + " ::::::" ) |
| 1303 | main.log.error( traceback.print_exc() ) |
| 1304 | main.log.info( self.name + " ::::::" ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1305 | main.cleanup() |
| 1306 | main.exit() |
| 1307 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1308 | def pushTestIntents( self, dpidSrc, dpidDst, numIntents, |
| 1309 | numMult="", appId="", report=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1310 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1311 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1312 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1313 | a specific point-to-point intent definition |
| 1314 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1315 | * dpidSrc: specify source dpid |
| 1316 | * dpidDst: specify destination dpid |
| 1317 | * numIntents: specify number of intents to push |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1318 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1319 | * numMult: number multiplier for multiplying |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1320 | the number of intents specified |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1321 | * appId: specify the application id init to further |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1322 | modularize the intents |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1323 | * report: default True, returns latency information |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1324 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1325 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1326 | cmd = "push-test-intents " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1327 | str( dpidSrc ) + " " + str( dpidDst ) + " " +\ |
| 1328 | str( numIntents ) |
| 1329 | if numMult: |
| 1330 | cmd += " " + str( numMult ) |
| 1331 | # If app id is specified, then numMult |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1332 | # must exist because of the way this command |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1333 | if appId: |
| 1334 | cmd += " " + str( appId ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1335 | handle = self.sendline( cmd ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1336 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1337 | handle = ansiEscape.sub( '', handle ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1338 | if report: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1339 | latResult = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1340 | main.log.info( handle ) |
| 1341 | # Split result by newline |
| 1342 | newline = handle.split( "\r\r\n" ) |
| 1343 | # Ignore the first object of list, which is empty |
| 1344 | newline = newline[ 1: ] |
| 1345 | # Some sloppy parsing method to get the latency |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1346 | for result in newline: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1347 | result = result.split( ": " ) |
| 1348 | # Append the first result of second parse |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1349 | latResult.append( result[ 1 ].split( " " )[ 0 ] ) |
| 1350 | main.log.info( latResult ) |
| 1351 | return latResult |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1352 | else: |
| 1353 | return main.TRUE |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1354 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1355 | main.log.error( self.name + ": EOF exception found" ) |
| 1356 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1357 | main.cleanup() |
| 1358 | main.exit() |
| 1359 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1360 | main.log.info( self.name + " ::::::" ) |
| 1361 | main.log.error( traceback.print_exc() ) |
| 1362 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1363 | main.cleanup() |
| 1364 | main.exit() |
| 1365 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1366 | def intentsEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1367 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1368 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1369 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1370 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1371 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1372 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1373 | if jsonFormat: |
| 1374 | cmdStr = "intents-events-metrics -j" |
| 1375 | handle = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1376 | # Some color thing that we want to escape |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1377 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1378 | handle = ansiEscape.sub( '', handle ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1379 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1380 | cmdStr = "intents-events-metrics" |
| 1381 | handle = self.sendline( cmdStr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1382 | return handle |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1383 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1384 | main.log.error( self.name + ": EOF exception found" ) |
| 1385 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1386 | main.cleanup() |
| 1387 | main.exit() |
| 1388 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1389 | main.log.info( self.name + " ::::::" ) |
| 1390 | main.log.error( traceback.print_exc() ) |
| 1391 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1392 | main.cleanup() |
| 1393 | main.exit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1394 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1395 | def topologyEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1396 | """ |
| 1397 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1398 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1399 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1400 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1401 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1402 | if jsonFormat: |
| 1403 | cmdStr = "topology-events-metrics -j" |
| 1404 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1405 | # Some color thing that we want to escape |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1406 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1407 | handle = ansiEscape.sub( '', handle ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1408 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1409 | cmdStr = "topology-events-metrics" |
| 1410 | handle = self.sendline( cmdStr ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1411 | return handle |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1412 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1413 | main.log.error( self.name + ": EOF exception found" ) |
| 1414 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1415 | main.cleanup() |
| 1416 | main.exit() |
| 1417 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1418 | main.log.info( self.name + " ::::::" ) |
| 1419 | main.log.error( traceback.print_exc() ) |
| 1420 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1421 | main.cleanup() |
| 1422 | main.exit() |
| 1423 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1424 | # Wrapper functions **************** |
| 1425 | # Wrapper functions use existing driver |
| 1426 | # functions and extends their use case. |
| 1427 | # For example, we may use the output of |
| 1428 | # a normal driver function, and parse it |
| 1429 | # using a wrapper function |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 1430 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1431 | def getAllIntentsId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1432 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1433 | Description: |
| 1434 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1435 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1436 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1437 | # Obtain output of intents function |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1438 | intentsStr = self.intents() |
| 1439 | allIntentList = [] |
| 1440 | intentIdList = [] |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1441 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1442 | # Parse the intents output for ID's |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1443 | intentsList = [ s.strip() for s in intentsStr.splitlines() ] |
| 1444 | for intents in intentsList: |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1445 | if "onos>" in intents: |
| 1446 | continue |
| 1447 | elif "intents" in intents: |
| 1448 | continue |
| 1449 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1450 | lineList = intents.split( " " ) |
| 1451 | allIntentList.append( lineList[ 0 ] ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1452 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1453 | allIntentList = allIntentList[ 1:-2 ] |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1454 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1455 | for intents in allIntentList: |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1456 | if not intents: |
| 1457 | continue |
| 1458 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1459 | intentIdList.append( intents ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1460 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1461 | return intentIdList |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1462 | |
| 1463 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1464 | main.log.error( self.name + ": EOF exception found" ) |
| 1465 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1466 | main.cleanup() |
| 1467 | main.exit() |
| 1468 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1469 | main.log.info( self.name + " ::::::" ) |
| 1470 | main.log.error( traceback.print_exc() ) |
| 1471 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1472 | main.cleanup() |
| 1473 | main.exit() |
| 1474 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1475 | def getAllDevicesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1476 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1477 | Use 'devices' function to obtain list of all devices |
| 1478 | and parse the result to obtain a list of all device |
| 1479 | id's. Returns this list. Returns empty list if no |
| 1480 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1481 | List is ordered sequentially |
| 1482 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1483 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1484 | device id, and wish to execute other commands using |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1485 | the ids. By obtaining the list of device ids on the fly, |
| 1486 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1487 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1488 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1489 | # Call devices and store result string |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1490 | devicesStr = self.devices( jsonFormat=False ) |
| 1491 | idList = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1492 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1493 | if not devicesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1494 | main.log.info( "There are no devices to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1495 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1496 | |
| 1497 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1498 | deviceList = devicesStr.split( "," ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1499 | # Get temporary list of all arguments with string 'id=' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1500 | tempList = [ dev for dev in deviceList if "id=" in dev ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1501 | # Split list further into arguments before and after string |
| 1502 | # 'id='. Get the latter portion ( the actual device id ) and |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1503 | # append to idList |
| 1504 | for arg in tempList: |
| 1505 | idList.append( arg.split( "id=" )[ 1 ] ) |
| 1506 | return idList |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1507 | |
| 1508 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1509 | main.log.error( self.name + ": EOF exception found" ) |
| 1510 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1511 | main.cleanup() |
| 1512 | main.exit() |
| 1513 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1514 | main.log.info( self.name + " ::::::" ) |
| 1515 | main.log.error( traceback.print_exc() ) |
| 1516 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1517 | main.cleanup() |
| 1518 | main.exit() |
| 1519 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1520 | def getAllNodesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1521 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1522 | Uses 'nodes' function to obtain list of all nodes |
| 1523 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1524 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1525 | Returns: |
| 1526 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1527 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1528 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1529 | nodesStr = self.nodes() |
| 1530 | idList = [] |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1531 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1532 | if not nodesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1533 | main.log.info( "There are no nodes to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1534 | return idList |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1535 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1536 | # Sample nodesStr output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1537 | # id=local, address=127.0.0.1:9876, state=ACTIVE * |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1538 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1539 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1540 | nodesList = nodesStr.split( "," ) |
| 1541 | tempList = [ node for node in nodesList if "id=" in node ] |
| 1542 | for arg in tempList: |
| 1543 | idList.append( arg.split( "id=" )[ 1 ] ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1544 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1545 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1546 | |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1547 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1548 | main.log.error( self.name + ": EOF exception found" ) |
| 1549 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1550 | main.cleanup() |
| 1551 | main.exit() |
| 1552 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1553 | main.log.info( self.name + " ::::::" ) |
| 1554 | main.log.error( traceback.print_exc() ) |
| 1555 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1556 | main.cleanup() |
| 1557 | main.exit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1558 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1559 | def getDevice( self, dpid=None ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1560 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1561 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 1562 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1563 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1564 | import json |
| 1565 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1566 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1567 | return None |
| 1568 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1569 | dpid = dpid.replace( ':', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1570 | rawDevices = self.devices() |
| 1571 | devicesJson = json.loads( rawDevices ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1572 | # search json for the device with dpid then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1573 | for device in devicesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1574 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 1575 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1576 | return device |
| 1577 | return None |
| 1578 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1579 | main.log.error( self.name + ": EOF exception found" ) |
| 1580 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1581 | main.cleanup() |
| 1582 | main.exit() |
| 1583 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1584 | main.log.info( self.name + " ::::::" ) |
| 1585 | main.log.error( traceback.print_exc() ) |
| 1586 | main.log.info( self.name + " ::::::" ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1587 | main.cleanup() |
| 1588 | main.exit() |
| 1589 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1590 | def checkStatus( self, ip, numoswitch, numolink, logLevel="info" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1591 | """ |
| 1592 | Checks the number of swithes & links that ONOS sees against the |
| 1593 | supplied values. By default this will report to main.log, but the |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1594 | log level can be specifid. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1595 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1596 | Params: ip = ip used for the onos cli |
| 1597 | numoswitch = expected number of switches |
| 1598 | numlink = expected number of links |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1599 | logLevel = level to log to. Currently accepts |
| 1600 | 'info', 'warn' and 'report' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1601 | |
| 1602 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1603 | logLevel can |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1604 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1605 | Returns: main.TRUE if the number of switchs and links are correct, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1606 | main.FALSE if the numer of switches and links is incorrect, |
| 1607 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1608 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1609 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1610 | topology = self.getTopology( ip ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1611 | if topology == {}: |
| 1612 | return main.ERROR |
| 1613 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1614 | # Is the number of switches is what we expected |
| 1615 | devices = topology.get( 'devices', False ) |
| 1616 | links = topology.get( 'links', False ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1617 | if devices == False or links == False: |
| 1618 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1619 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1620 | # Is the number of links is what we expected |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1621 | linkCheck = ( int( links ) == int( numolink ) ) |
| 1622 | if ( switchCheck and linkCheck ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1623 | # We expected the correct numbers |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1624 | output = output + "The number of links and switches match "\ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1625 | + "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1626 | result = main.TRUE |
| 1627 | else: |
| 1628 | output = output + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1629 | "The number of links and switches does not matc\ |
| 1630 | h what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1631 | result = main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1632 | output = output + "\n ONOS sees %i devices (%i expected) \ |
| 1633 | and %i links (%i expected)" % ( |
| 1634 | int( devices ), int( numoswitch ), int( links ), |
| 1635 | int( numolink ) ) |
| 1636 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1637 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1638 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1639 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1640 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1641 | main.log.info( output ) |
| 1642 | return result |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1643 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1644 | main.log.error( self.name + ": EOF exception found" ) |
| 1645 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1646 | main.cleanup() |
| 1647 | main.exit() |
| 1648 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1649 | main.log.info( self.name + " ::::::" ) |
| 1650 | main.log.error( traceback.print_exc() ) |
| 1651 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1652 | main.cleanup() |
| 1653 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1654 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1655 | def deviceRole( self, deviceId, onosNode, role="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1656 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1657 | Calls the device-role cli command. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1658 | deviceId must be the id of a device as seen in the onos devices command |
| 1659 | onosNode is the ip of one of the onos nodes in the cluster |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1660 | role must be either master, standby, or none |
| 1661 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1662 | Returns: |
| 1663 | main.TRUE or main.FALSE based on argument verification and |
| 1664 | main.ERROR if command returns and error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1665 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1666 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1667 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1668 | role.lower() == "none": |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1669 | cmdStr = "device-role " +\ |
| 1670 | str( deviceId ) + " " +\ |
| 1671 | str( onosNode ) + " " +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1672 | str( role ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1673 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1674 | if re.search( "Error", handle ): |
| 1675 | # end color output to escape any colours |
| 1676 | # from the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1677 | main.log.error( self.name + ": " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1678 | handle + '\033[0m' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1679 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1680 | return main.TRUE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1681 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1682 | main.log.error( "Invalid 'role' given to device_role(). " + |
| 1683 | "Value was '" + str(role) + "'." ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1684 | return main.FALSE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1685 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1686 | main.log.error( self.name + ": EOF exception found" ) |
| 1687 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1688 | main.cleanup() |
| 1689 | main.exit() |
| 1690 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1691 | main.log.info( self.name + " ::::::" ) |
| 1692 | main.log.error( traceback.print_exc() ) |
| 1693 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1694 | main.cleanup() |
| 1695 | main.exit() |
| 1696 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1697 | def clusters( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1698 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1699 | Lists all clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1700 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1701 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1702 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1703 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1704 | if jsonFormat: |
| 1705 | cmdStr = "clusters -j" |
| 1706 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1707 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1708 | handle variable here contains some ANSI escape color code |
| 1709 | sequences at the end which are invisible in the print command |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1710 | output. To make that escape sequence visible, use repr() |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1711 | function. The repr( handle ) output when printed shows the ANSI |
| 1712 | escape sequences. In json.loads( somestring ), this somestring |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1713 | variable is actually repr( somestring ) and json.loads would |
| 1714 | fail with the escape sequence. So we take off that escape |
| 1715 | sequence using: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1716 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1717 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1718 | handle1 = ansiEscape.sub( '', handle ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1719 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1720 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1721 | handle1 = ansiEscape.sub( '', handle ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1722 | return handle1 |
| 1723 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1724 | cmdStr = "clusters" |
| 1725 | handle = self.sendline( cmdStr ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1726 | return handle |
| 1727 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1728 | main.log.error( self.name + ": EOF exception found" ) |
| 1729 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1730 | main.cleanup() |
| 1731 | main.exit() |
| 1732 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1733 | main.log.info( self.name + " ::::::" ) |
| 1734 | main.log.error( traceback.print_exc() ) |
| 1735 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1736 | main.cleanup() |
| 1737 | main.exit() |
| 1738 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1739 | def electionTestLeader( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1740 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1741 | CLI command to get the current leader for the Election test application |
| 1742 | NOTE: Requires installation of the onos-app-election feature |
| 1743 | Returns: Node IP of the leader if one exists |
| 1744 | None if none exists |
| 1745 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1746 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1747 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1748 | cmdStr = "election-test-leader" |
| 1749 | response = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1750 | # Leader |
| 1751 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1752 | "app\sis\s(?P<node>.+)\." |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1753 | nodeSearch = re.search( leaderPattern, response ) |
| 1754 | if nodeSearch: |
| 1755 | node = nodeSearch.group( 'node' ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1756 | main.log.info( "Election-test-leader on " + str( self.name ) + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1757 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1758 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1759 | # no leader |
| 1760 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1761 | "the\sElection\sapp" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1762 | nullSearch = re.search( nullPattern, response ) |
| 1763 | if nullSearch: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1764 | main.log.info( "Election-test-leader found no leader on " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1765 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1766 | return None |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1767 | # error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1768 | errorPattern = "Command\snot\sfound" |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1769 | if re.search( errorPattern, response ): |
| 1770 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1771 | # TODO: Should this be main.ERROR? |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1772 | return main.FALSE |
| 1773 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1774 | main.log.error( "Error in election_test_leader: " + |
| 1775 | "unexpected response" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1776 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1777 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1778 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1779 | main.log.error( self.name + ": EOF exception found" ) |
| 1780 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1781 | main.cleanup() |
| 1782 | main.exit() |
| 1783 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1784 | main.log.info( self.name + " ::::::" ) |
| 1785 | main.log.error( traceback.print_exc() ) |
| 1786 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1787 | main.cleanup() |
| 1788 | main.exit() |
| 1789 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1790 | def electionTestRun( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1791 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1792 | CLI command to run for leadership of the Election test application. |
| 1793 | NOTE: Requires installation of the onos-app-election feature |
| 1794 | Returns: Main.TRUE on success |
| 1795 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1796 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1797 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1798 | cmdStr = "election-test-run" |
| 1799 | response = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1800 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1801 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1802 | "Election\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1803 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1804 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1805 | main.log.info( self.name + " entering leadership elections " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1806 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1807 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1808 | # error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1809 | errorPattern = "Command\snot\sfound" |
| 1810 | if re.search( errorPattern, response ): |
| 1811 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1812 | return main.FALSE |
| 1813 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1814 | main.log.error( "Error in election_test_run: " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1815 | "unexpected response" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1816 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1817 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1818 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1819 | main.log.error( self.name + ": EOF exception found" ) |
| 1820 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1821 | main.cleanup() |
| 1822 | main.exit() |
| 1823 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1824 | main.log.info( self.name + " ::::::" ) |
| 1825 | main.log.error( traceback.print_exc() ) |
| 1826 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1827 | main.cleanup() |
| 1828 | main.exit() |
| 1829 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1830 | def electionTestWithdraw( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1831 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1832 | * CLI command to withdraw the local node from leadership election for |
| 1833 | * the Election test application. |
| 1834 | #NOTE: Requires installation of the onos-app-election feature |
| 1835 | Returns: Main.TRUE on success |
| 1836 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1837 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1838 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1839 | cmdStr = "election-test-withdraw" |
| 1840 | response = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1841 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1842 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1843 | "\sthe\sElection\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1844 | if re.search( successPattern, response ): |
| 1845 | main.log.info( self.name + " withdrawing from leadership " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1846 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1847 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1848 | # error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1849 | errorPattern = "Command\snot\sfound" |
| 1850 | if re.search( errorPattern, response ): |
| 1851 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1852 | return main.FALSE |
| 1853 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1854 | main.log.error( "Error in election_test_withdraw: " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1855 | "unexpected response" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1856 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1857 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1858 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1859 | main.log.error( self.name + ": EOF exception found" ) |
| 1860 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1861 | main.cleanup() |
| 1862 | main.exit() |
| 1863 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1864 | main.log.info( self.name + " ::::::" ) |
| 1865 | main.log.error( traceback.print_exc() ) |
| 1866 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1867 | main.cleanup() |
| 1868 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1869 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1870 | def getDevicePortsEnabledCount( self, dpid ): |
| 1871 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1872 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1873 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1874 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1875 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1876 | cmdStr = "onos:ports -e " + dpid + " | wc -l" |
| 1877 | output = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1878 | if re.search( "No such device", output ): |
| 1879 | main.log.error( "Error in getting ports" ) |
| 1880 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1881 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1882 | return output |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1883 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1884 | main.log.error( self.name + ": EOF exception found" ) |
| 1885 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1886 | main.cleanup() |
| 1887 | main.exit() |
| 1888 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1889 | main.log.info( self.name + " ::::::" ) |
| 1890 | main.log.error( traceback.print_exc() ) |
| 1891 | main.log.info( self.name + " ::::::" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1892 | main.cleanup() |
| 1893 | main.exit() |
| 1894 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1895 | def getDeviceLinksActiveCount( self, dpid ): |
| 1896 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1897 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1898 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1899 | try: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1900 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1901 | cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
| 1902 | output = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1903 | if re.search( "No such device", output ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1904 | main.log.error( "Error in getting ports " ) |
| 1905 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1906 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1907 | return output |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1908 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1909 | main.log.error( self.name + ": EOF exception found" ) |
| 1910 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1911 | main.cleanup() |
| 1912 | main.exit() |
| 1913 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1914 | main.log.info( self.name + " ::::::" ) |
| 1915 | main.log.error( traceback.print_exc() ) |
| 1916 | main.log.info( self.name + " ::::::" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1917 | main.cleanup() |
| 1918 | main.exit() |
| 1919 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1920 | def getAllIntentIds( self ): |
| 1921 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1922 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1923 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1924 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1925 | cmdStr = "onos:intents | grep id=" |
| 1926 | output = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1927 | if re.search( "Error", output ): |
| 1928 | main.log.error( "Error in getting ports" ) |
| 1929 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1930 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1931 | return output |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1932 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1933 | main.log.error( self.name + ": EOF exception found" ) |
| 1934 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1935 | main.cleanup() |
| 1936 | main.exit() |
| 1937 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1938 | main.log.info( self.name + " ::::::" ) |
| 1939 | main.log.error( traceback.print_exc() ) |
| 1940 | main.log.info( self.name + " ::::::" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1941 | main.cleanup() |
| 1942 | main.exit() |