blob: 57650aeb6936a37259a32dcaaae27c9fc081bc18 [file] [log] [blame]
andrewonlab95ce8322014-10-13 14:12:04 -04001#!/usr/bin/env python
2
kelvin8ec71442015-01-15 16:57:00 -08003"""
andrewonlab95ce8322014-10-13 14:12:04 -04004This driver enters the onos> prompt to issue commands.
5
kelvin8ec71442015-01-15 16:57:00 -08006Please follow the coding style demonstrated by existing
andrewonlab95ce8322014-10-13 14:12:04 -04007functions and document properly.
8
9If you are a contributor to the driver, please
10list your email here for future contact:
11
12jhall@onlab.us
13andrew@onlab.us
Jon Halle8217482014-10-17 13:49:14 -040014shreya@onlab.us
andrewonlab95ce8322014-10-13 14:12:04 -040015
16OCT 13 2014
17
kelvin8ec71442015-01-15 16:57:00 -080018"""
andrewonlab95ce8322014-10-13 14:12:04 -040019import sys
andrewonlab95ce8322014-10-13 14:12:04 -040020import pexpect
21import re
22import traceback
kelvin8ec71442015-01-15 16:57:00 -080023sys.path.append( "../" )
andrewonlab95ce8322014-10-13 14:12:04 -040024from drivers.common.clidriver import CLI
25
andrewonlab95ce8322014-10-13 14:12:04 -040026
kelvin8ec71442015-01-15 16:57:00 -080027class OnosCliDriver( CLI ):
andrewonlab95ce8322014-10-13 14:12:04 -040028
kelvin8ec71442015-01-15 16:57:00 -080029 def __init__( self ):
30 """
31 Initialize client
32 """
33 super( CLI, self ).__init__()
34
35 def connect( self, **connectargs ):
36 """
andrewonlab95ce8322014-10-13 14:12:04 -040037 Creates ssh handle for ONOS cli.
kelvin8ec71442015-01-15 16:57:00 -080038 """
andrewonlab95ce8322014-10-13 14:12:04 -040039 try:
40 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080041 vars( self )[ key ] = connectargs[ key ]
andrewonlab95ce8322014-10-13 14:12:04 -040042 self.home = "~/ONOS"
43 for key in self.options:
44 if key == "home":
kelvin8ec71442015-01-15 16:57:00 -080045 self.home = self.options[ 'home' ]
andrewonlab95ce8322014-10-13 14:12:04 -040046 break
kelvin-onlabd6634ac2015-01-29 14:23:10 -080047 if self.home == None or self.home == "":
48 self.home = "~/ONOS"
49
kelvin8ec71442015-01-15 16:57:00 -080050 self.name = self.options[ 'name' ]
51 self.handle = super( OnosCliDriver, self ).connect(
kelvin-onlab08679eb2015-01-21 16:11:48 -080052 user_name=self.user_name,
53 ip_address=self.ip_address,
kelvin-onlab898a6c62015-01-16 14:13:53 -080054 port=self.port,
55 pwd=self.pwd,
56 home=self.home )
andrewonlab95ce8322014-10-13 14:12:04 -040057
kelvin8ec71442015-01-15 16:57:00 -080058 self.handle.sendline( "cd " + self.home )
59 self.handle.expect( "\$" )
andrewonlab95ce8322014-10-13 14:12:04 -040060 if self.handle:
61 return self.handle
kelvin8ec71442015-01-15 16:57:00 -080062 else:
63 main.log.info( "NO ONOS HANDLE" )
andrewonlab95ce8322014-10-13 14:12:04 -040064 return main.FALSE
65 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080066 main.log.error( self.name + ": EOF exception found" )
67 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -040068 main.cleanup()
69 main.exit()
70 except:
kelvin8ec71442015-01-15 16:57:00 -080071 main.log.info( self.name + ":::::::::::::::::::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -040072 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -080073 main.log.info( ":::::::::::::::::::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -040074 main.cleanup()
75 main.exit()
76
kelvin8ec71442015-01-15 16:57:00 -080077 def disconnect( self ):
78 """
andrewonlab95ce8322014-10-13 14:12:04 -040079 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -080080 """
andrewonlab95ce8322014-10-13 14:12:04 -040081 response = ''
82 try:
kelvin8ec71442015-01-15 16:57:00 -080083 self.handle.sendline( "" )
84 i = self.handle.expect( [ "onos>", "\$" ] )
Jon Hall7e5b9172014-10-22 12:32:47 -040085 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -080086 self.handle.sendline( "system:shutdown" )
87 self.handle.expect( "Confirm" )
88 self.handle.sendline( "yes" )
89 self.handle.expect( "\$" )
90 self.handle.sendline( "" )
91 self.handle.expect( "\$" )
92 self.handle.sendline( "exit" )
93 self.handle.expect( "closed" )
andrewonlabc2d05aa2014-10-13 16:51:10 -040094
andrewonlab95ce8322014-10-13 14:12:04 -040095 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080096 main.log.error( self.name + ": EOF exception found" )
97 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -040098 except:
kelvin8ec71442015-01-15 16:57:00 -080099 main.log.error( self.name + ": Connection failed to the host" )
andrewonlab95ce8322014-10-13 14:12:04 -0400100 response = main.FALSE
101 return response
102
kelvin8ec71442015-01-15 16:57:00 -0800103 def logout( self ):
104 """
andrewonlab38d2b4a2014-11-13 16:28:47 -0500105 Sends 'logout' command to ONOS cli
kelvin8ec71442015-01-15 16:57:00 -0800106 """
andrewonlab38d2b4a2014-11-13 16:28:47 -0500107 try:
kelvin8ec71442015-01-15 16:57:00 -0800108 self.handle.sendline( "" )
109 i = self.handle.expect( [
andrewonlab9627f432014-11-14 12:45:10 -0500110 "onos>",
kelvin8ec71442015-01-15 16:57:00 -0800111 "\$" ], timeout=10 )
andrewonlab9627f432014-11-14 12:45:10 -0500112 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800113 self.handle.sendline( "logout" )
114 self.handle.expect( "\$" )
andrewonlab9627f432014-11-14 12:45:10 -0500115 elif i == 1:
116 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800117
andrewonlab38d2b4a2014-11-13 16:28:47 -0500118 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800119 main.log.error( self.name + ": eof exception found" )
120 main.log.error( self.name + ": " +
121 self.handle.before )
andrewonlab38d2b4a2014-11-13 16:28:47 -0500122 main.cleanup()
123 main.exit()
124 except:
kelvin8ec71442015-01-15 16:57:00 -0800125 main.log.info( self.name + " ::::::" )
126 main.log.error( traceback.print_exc() )
127 main.log.info( self.name + " ::::::" )
andrewonlab38d2b4a2014-11-13 16:28:47 -0500128 main.cleanup()
129 main.exit()
130
kelvin-onlabd3b64892015-01-20 13:26:24 -0800131 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800132 """
andrewonlab95ce8322014-10-13 14:12:04 -0400133 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800134
andrewonlab95ce8322014-10-13 14:12:04 -0400135 Before issuing any cli commands, set the environment variable first.
kelvin8ec71442015-01-15 16:57:00 -0800136 """
andrewonlab95ce8322014-10-13 14:12:04 -0400137 try:
138 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800139 main.log.error( "Must define cellname" )
andrewonlab95ce8322014-10-13 14:12:04 -0400140 main.cleanup()
141 main.exit()
142 else:
kelvin8ec71442015-01-15 16:57:00 -0800143 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800144 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800145 # Note that this variable name is subject to change
andrewonlab95ce8322014-10-13 14:12:04 -0400146 # and that this driver will have to change accordingly
kelvin8ec71442015-01-15 16:57:00 -0800147 self.handle.expect( "ONOS_CELL=" + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800148 handleBefore = self.handle.before
149 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800150 # Get the rest of the handle
151 self.handle.sendline( "" )
152 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800153 handleMore = self.handle.before
andrewonlab95ce8322014-10-13 14:12:04 -0400154
kelvin-onlabd3b64892015-01-20 13:26:24 -0800155 main.log.info( "Cell call returned: " + handleBefore +
156 handleAfter + handleMore )
andrewonlab95ce8322014-10-13 14:12:04 -0400157
158 return main.TRUE
159
160 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800161 main.log.error( self.name + ": eof exception found" )
162 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400163 main.cleanup()
164 main.exit()
165 except:
kelvin8ec71442015-01-15 16:57:00 -0800166 main.log.info( self.name + " ::::::" )
167 main.log.error( traceback.print_exc() )
168 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -0400169 main.cleanup()
170 main.exit()
kelvin8ec71442015-01-15 16:57:00 -0800171
kelvin-onlabd3b64892015-01-20 13:26:24 -0800172 def startOnosCli( self, ONOSIp, karafTimeout="" ):
kelvin8ec71442015-01-15 16:57:00 -0800173 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800174 karafTimeout is an optional arugument. karafTimeout value passed
175 by user would be used to set the current karaf shell idle timeout.
176 Note that when ever this property is modified the shell will exit and
Hari Krishnad7b9c202015-01-05 10:38:14 -0800177 the subsequent login would reflect new idle timeout.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800178 Below is an example to start a session with 60 seconds idle timeout
179 ( input value is in milliseconds ):
kelvin8ec71442015-01-15 16:57:00 -0800180
Hari Krishna25d42f72015-01-05 15:08:28 -0800181 tValue = "60000"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800182 main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue )
kelvin8ec71442015-01-15 16:57:00 -0800183
kelvin-onlabd3b64892015-01-20 13:26:24 -0800184 Note: karafTimeout is left as str so that this could be read
185 and passed to startOnosCli from PARAMS file as str.
kelvin8ec71442015-01-15 16:57:00 -0800186 """
andrewonlab95ce8322014-10-13 14:12:04 -0400187 try:
kelvin8ec71442015-01-15 16:57:00 -0800188 self.handle.sendline( "" )
189 x = self.handle.expect( [
190 "\$", "onos>" ], timeout=10 )
andrewonlab48829f62014-11-17 13:49:01 -0500191
192 if x == 1:
kelvin8ec71442015-01-15 16:57:00 -0800193 main.log.info( "ONOS cli is already running" )
andrewonlab48829f62014-11-17 13:49:01 -0500194 return main.TRUE
andrewonlab95ce8322014-10-13 14:12:04 -0400195
kelvin8ec71442015-01-15 16:57:00 -0800196 # Wait for onos start ( -w ) and enter onos cli
kelvin-onlabd3b64892015-01-20 13:26:24 -0800197 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800198 i = self.handle.expect( [
199 "onos>",
kelvin-onlab898a6c62015-01-16 14:13:53 -0800200 pexpect.TIMEOUT ], timeout=60 )
andrewonlab2a7ea9b2014-10-24 12:21:05 -0400201
202 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800203 main.log.info( str( ONOSIp ) + " CLI Started successfully" )
Hari Krishnae36ef212015-01-04 14:09:13 -0800204 if karafTimeout:
kelvin8ec71442015-01-15 16:57:00 -0800205 self.handle.sendline(
Hari Krishnaac4e1782015-01-26 12:09:12 -0800206 "config:property-set -p org.apache.karaf.shell\
207 sshIdleTimeout " +
kelvin8ec71442015-01-15 16:57:00 -0800208 karafTimeout )
209 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800210 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800211 self.handle.expect( "onos>" )
andrewonlab2a7ea9b2014-10-24 12:21:05 -0400212 return main.TRUE
213 else:
kelvin8ec71442015-01-15 16:57:00 -0800214 # If failed, send ctrl+c to process and try again
215 main.log.info( "Starting CLI failed. Retrying..." )
216 self.handle.send( "\x03" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800217 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800218 i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ],
219 timeout=30 )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400220 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800221 main.log.info( str( ONOSIp ) + " CLI Started " +
kelvin8ec71442015-01-15 16:57:00 -0800222 "successfully after retry attempt" )
Hari Krishnae36ef212015-01-04 14:09:13 -0800223 if karafTimeout:
kelvin8ec71442015-01-15 16:57:00 -0800224 self.handle.sendline(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800225 "config:property-set -p org.apache.karaf.shell\
226 sshIdleTimeout " +
kelvin8ec71442015-01-15 16:57:00 -0800227 karafTimeout )
228 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800229 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800230 self.handle.expect( "onos>" )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400231 return main.TRUE
232 else:
kelvin8ec71442015-01-15 16:57:00 -0800233 main.log.error( "Connection to CLI " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800234 str( ONOSIp ) + " timeout" )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400235 return main.FALSE
andrewonlab95ce8322014-10-13 14:12:04 -0400236
237 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800238 main.log.error( self.name + ": EOF exception found" )
239 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400240 main.cleanup()
241 main.exit()
242 except:
kelvin8ec71442015-01-15 16:57:00 -0800243 main.log.info( self.name + " ::::::" )
244 main.log.error( traceback.print_exc() )
245 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -0400246 main.cleanup()
247 main.exit()
248
kelvin-onlabd3b64892015-01-20 13:26:24 -0800249 def sendline( self, cmdStr ):
kelvin8ec71442015-01-15 16:57:00 -0800250 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800251 Send a completely user specified string to
252 the onos> prompt. Use this function if you have
andrewonlaba18f6bf2014-10-13 19:31:54 -0400253 a very specific command to send.
Jon Halle3f39ff2015-01-13 11:50:53 -0800254
andrewonlaba18f6bf2014-10-13 19:31:54 -0400255 Warning: There are no sanity checking to commands
256 sent using this method.
kelvin8ec71442015-01-15 16:57:00 -0800257 """
andrewonlaba18f6bf2014-10-13 19:31:54 -0400258 try:
kelvin8ec71442015-01-15 16:57:00 -0800259 self.handle.sendline( "" )
260 self.handle.expect( "onos>" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400261
kelvin-onlab898a6c62015-01-16 14:13:53 -0800262 self.handle.sendline( "log:log \"Sending CLI command: '"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800263 + cmdStr + "'\"" )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800264 self.handle.expect( "onos>" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800265 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -0800266 self.handle.expect( "onos>" )
Jon Hallaea67aa2015-01-23 13:30:57 -0800267 main.log.info( "Command '" + str( cmdStr ) + "' sent to "
268 + self.name + "." )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400269
270 handle = self.handle.before
Jon Hall7bdfc122015-01-23 11:45:32 -0800271 # Remove control strings from output
272 ansiEscape = re.compile( r'\x1b[^m]*m' )
273 handle = ansiEscape.sub( '', handle )
Jon Hall44225f82015-01-23 13:45:14 -0800274 #Remove extra return chars that get added
Jon Hallaea67aa2015-01-23 13:30:57 -0800275 handle = re.sub( r"\s\r", "", handle )
276 handle = handle.strip()
Jon Hall7bdfc122015-01-23 11:45:32 -0800277 # parse for just the output, remove the cmd from handle
278 output = handle.split( cmdStr, 1 )[1]
kelvin8ec71442015-01-15 16:57:00 -0800279
andrewonlaba18f6bf2014-10-13 19:31:54 -0400280
Jon Hall7bdfc122015-01-23 11:45:32 -0800281 return output
andrewonlaba18f6bf2014-10-13 19:31:54 -0400282 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800283 main.log.error( self.name + ": EOF exception found" )
284 main.log.error( self.name + ": " + self.handle.before )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400285 main.cleanup()
286 main.exit()
287 except:
kelvin8ec71442015-01-15 16:57:00 -0800288 main.log.info( self.name + " ::::::" )
289 main.log.error( traceback.print_exc() )
290 main.log.info( self.name + " ::::::" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400291 main.cleanup()
292 main.exit()
293
kelvin8ec71442015-01-15 16:57:00 -0800294 # IMPORTANT NOTE:
295 # For all cli commands, naming convention should match
kelvin-onlabd3b64892015-01-20 13:26:24 -0800296 # the cli command changing 'a:b' with 'aB'.
297 # Ex ) onos:topology > onosTopology
298 # onos:links > onosLinks
299 # feature:list > featureList
Jon Halle3f39ff2015-01-13 11:50:53 -0800300
kelvin-onlabd3b64892015-01-20 13:26:24 -0800301 def addNode( self, nodeId, ONOSIp, tcpPort="" ):
kelvin8ec71442015-01-15 16:57:00 -0800302 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400303 Adds a new cluster node by ID and address information.
304 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800305 * nodeId
306 * ONOSIp
andrewonlabc2d05aa2014-10-13 16:51:10 -0400307 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800308 * tcpPort
kelvin8ec71442015-01-15 16:57:00 -0800309 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400310 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800311 cmdStr = "add-node " + str( nodeId ) + " " +\
312 str( ONOSIp ) + " " + str( tcpPort )
313 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800314 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -0800315 main.log.error( "Error in adding node" )
316 main.log.error( handle )
Jon Halle3f39ff2015-01-13 11:50:53 -0800317 return main.FALSE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400318 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800319 main.log.info( "Node " + str( ONOSIp ) + " added" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400320 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400321 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800322 main.log.error( self.name + ": EOF exception found" )
323 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400324 main.cleanup()
325 main.exit()
326 except:
kelvin8ec71442015-01-15 16:57:00 -0800327 main.log.info( self.name + " ::::::" )
328 main.log.error( traceback.print_exc() )
329 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400330 main.cleanup()
331 main.exit()
332
kelvin-onlabd3b64892015-01-20 13:26:24 -0800333 def removeNode( self, nodeId ):
kelvin8ec71442015-01-15 16:57:00 -0800334 """
andrewonlab86dc3082014-10-13 18:18:38 -0400335 Removes a cluster by ID
336 Issues command: 'remove-node [<node-id>]'
337 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800338 * nodeId
kelvin8ec71442015-01-15 16:57:00 -0800339 """
andrewonlab86dc3082014-10-13 18:18:38 -0400340 try:
andrewonlab86dc3082014-10-13 18:18:38 -0400341
kelvin-onlabd3b64892015-01-20 13:26:24 -0800342 cmdStr = "remove-node " + str( nodeId )
343 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800344 # TODO: add error checking. Does ONOS give any errors?
andrewonlab86dc3082014-10-13 18:18:38 -0400345
346 return main.TRUE
Jon Halle3f39ff2015-01-13 11:50:53 -0800347
andrewonlab86dc3082014-10-13 18:18:38 -0400348 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800349 main.log.error( self.name + ": EOF exception found" )
350 main.log.error( self.name + ": " + self.handle.before )
andrewonlab86dc3082014-10-13 18:18:38 -0400351 main.cleanup()
352 main.exit()
353 except:
kelvin8ec71442015-01-15 16:57:00 -0800354 main.log.info( self.name + " ::::::" )
355 main.log.error( traceback.print_exc() )
356 main.log.info( self.name + " ::::::" )
andrewonlab86dc3082014-10-13 18:18:38 -0400357 main.cleanup()
358 main.exit()
andrewonlabc2d05aa2014-10-13 16:51:10 -0400359
kelvin8ec71442015-01-15 16:57:00 -0800360 def nodes( self ):
361 """
andrewonlab7c211572014-10-15 16:45:20 -0400362 List the nodes currently visible
363 Issues command: 'nodes'
364 Returns: entire handle of list of nodes
kelvin8ec71442015-01-15 16:57:00 -0800365 """
andrewonlab7c211572014-10-15 16:45:20 -0400366 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800367 cmdStr = "nodes"
368 handle = self.sendline( cmdStr )
andrewonlab7c211572014-10-15 16:45:20 -0400369 return handle
andrewonlab7c211572014-10-15 16:45:20 -0400370 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800371 main.log.error( self.name + ": EOF exception found" )
372 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -0400373 main.cleanup()
374 main.exit()
375 except:
kelvin8ec71442015-01-15 16:57:00 -0800376 main.log.info( self.name + " ::::::" )
377 main.log.error( traceback.print_exc() )
378 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -0400379 main.cleanup()
380 main.exit()
381
kelvin8ec71442015-01-15 16:57:00 -0800382 def topology( self ):
383 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400384 Shows the current state of the topology
385 by issusing command: 'onos> onos:topology'
kelvin8ec71442015-01-15 16:57:00 -0800386 """
andrewonlab95ce8322014-10-13 14:12:04 -0400387 try:
Jon Halle3f39ff2015-01-13 11:50:53 -0800388 # either onos:topology or 'topology' will work in CLI
kelvin-onlabd3b64892015-01-20 13:26:24 -0800389 cmdStr = "onos:topology"
390 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800391 main.log.info( "onos:topology returned: " + str( handle ) )
andrewonlab95ce8322014-10-13 14:12:04 -0400392 return handle
andrewonlab95ce8322014-10-13 14:12:04 -0400393 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800394 main.log.error( self.name + ": EOF exception found" )
395 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400396 main.cleanup()
397 main.exit()
398 except:
kelvin8ec71442015-01-15 16:57:00 -0800399 main.log.info( self.name + " ::::::" )
400 main.log.error( traceback.print_exc() )
401 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -0400402 main.cleanup()
403 main.exit()
Jon Halle3f39ff2015-01-13 11:50:53 -0800404
kelvin-onlabd3b64892015-01-20 13:26:24 -0800405 def featureInstall( self, featureStr ):
kelvin8ec71442015-01-15 16:57:00 -0800406 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800407 Installs a specified feature
andrewonlabc2d05aa2014-10-13 16:51:10 -0400408 by issuing command: 'onos> feature:install <feature_str>'
kelvin8ec71442015-01-15 16:57:00 -0800409 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400410 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800411 cmdStr = "feature:install " + str( featureStr )
412 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800413 # TODO: Check for possible error responses from karaf
andrewonlabc2d05aa2014-10-13 16:51:10 -0400414 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400415 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800416 main.log.error( self.name + ": EOF exception found" )
417 main.log.error( self.name + ": " + self.handle.before )
418 main.log.report( "Failed to install feature" )
419 main.log.report( "Exiting test" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400420 main.cleanup()
421 main.exit()
422 except:
kelvin8ec71442015-01-15 16:57:00 -0800423 main.log.info( self.name + " ::::::" )
424 main.log.error( traceback.print_exc() )
425 main.log.report( "Failed to install feature" )
426 main.log.report( "Exiting test" )
427 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400428 main.cleanup()
429 main.exit()
Jon Halle3f39ff2015-01-13 11:50:53 -0800430
kelvin-onlabd3b64892015-01-20 13:26:24 -0800431 def featureUninstall( self, featureStr ):
kelvin8ec71442015-01-15 16:57:00 -0800432 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400433 Uninstalls a specified feature
434 by issuing command: 'onos> feature:uninstall <feature_str>'
kelvin8ec71442015-01-15 16:57:00 -0800435 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400436 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800437 cmdStr = "feature:uninstall " + str( featureStr )
438 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800439 # TODO: Check for possible error responses from karaf
andrewonlabc2d05aa2014-10-13 16:51:10 -0400440 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400441 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800442 main.log.error( self.name + ": EOF exception found" )
443 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400444 main.cleanup()
445 main.exit()
446 except:
kelvin8ec71442015-01-15 16:57:00 -0800447 main.log.info( self.name + " ::::::" )
448 main.log.error( traceback.print_exc() )
449 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400450 main.cleanup()
451 main.exit()
Jon Hallffb386d2014-11-21 13:43:38 -0800452
kelvin-onlabd3b64892015-01-20 13:26:24 -0800453 def devices( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800454 """
Jon Hall7b02d952014-10-17 20:14:54 -0400455 Lists all infrastructure devices or switches
andrewonlab86dc3082014-10-13 18:18:38 -0400456 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800457 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800458 """
andrewonlab86dc3082014-10-13 18:18:38 -0400459 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800460 if jsonFormat:
461 cmdStr = "devices -j"
462 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800463 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800464 handle variable here contains some ANSI escape color code
465 sequences at the end which are invisible in the print command
466 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800467 function. The repr( handle ) output when printed shows the
468 ANSI escape sequences. In json.loads( somestring ), this
469 somestring variable is actually repr( somestring ) and
Jon Halle3f39ff2015-01-13 11:50:53 -0800470 json.loads would fail with the escape sequence. So we take off
471 that escape sequence using:
472
kelvin-onlabd3b64892015-01-20 13:26:24 -0800473 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
474 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800475 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800476 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
477 handle1 = ansiEscape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400478 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400479 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800480 cmdStr = "devices"
481 handle = self.sendline( cmdStr )
Jon Hallcd707292014-10-17 19:06:17 -0400482 return handle
andrewonlab7c211572014-10-15 16:45:20 -0400483 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800484 main.log.error( self.name + ": EOF exception found" )
485 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -0400486 main.cleanup()
487 main.exit()
488 except:
kelvin8ec71442015-01-15 16:57:00 -0800489 main.log.info( self.name + " ::::::" )
490 main.log.error( traceback.print_exc() )
491 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -0400492 main.cleanup()
493 main.exit()
494
kelvin-onlabd3b64892015-01-20 13:26:24 -0800495 def balanceMasters( self ):
kelvin8ec71442015-01-15 16:57:00 -0800496 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800497 This balances the devices across all controllers
498 by issuing command: 'onos> onos:balance-masters'
499 If required this could be extended to return devices balanced output.
kelvin8ec71442015-01-15 16:57:00 -0800500 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800501 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800502 cmdStr = "onos:balance-masters"
503 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800504 # TODO: Check for error responses from ONOS
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800505 return main.TRUE
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800506 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800507 main.log.error( self.name + ": EOF exception found" )
508 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800509 main.cleanup()
510 main.exit()
511 except:
kelvin8ec71442015-01-15 16:57:00 -0800512 main.log.info( self.name + " ::::::" )
513 main.log.error( traceback.print_exc() )
514 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800515 main.cleanup()
516 main.exit()
517
kelvin-onlabd3b64892015-01-20 13:26:24 -0800518 def links( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800519 """
Jon Halle8217482014-10-17 13:49:14 -0400520 Lists all core links
521 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800522 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800523 """
Jon Halle8217482014-10-17 13:49:14 -0400524 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800525 if jsonFormat:
526 cmdStr = "links -j"
527 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800528 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800529 handle variable here contains some ANSI escape color code
530 sequences at the end which are invisible in the print command
531 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800532 function. The repr( handle ) output when printed shows the ANSI
533 escape sequences. In json.loads( somestring ), this somestring
534 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800535 fail with the escape sequence. So we take off that escape
536 sequence using:
537
kelvin-onlabd3b64892015-01-20 13:26:24 -0800538 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
539 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800540 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800541 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
542 handle1 = ansiEscape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400543 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400544 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800545 cmdStr = "links"
546 handle = self.sendline( cmdStr )
Jon Halla001c392014-10-17 18:50:59 -0400547 return handle
Jon Halle8217482014-10-17 13:49:14 -0400548 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800549 main.log.error( self.name + ": EOF exception found" )
550 main.log.error( self.name + ": " + self.handle.before )
Jon Halle8217482014-10-17 13:49:14 -0400551 main.cleanup()
552 main.exit()
553 except:
kelvin8ec71442015-01-15 16:57:00 -0800554 main.log.info( self.name + " ::::::" )
555 main.log.error( traceback.print_exc() )
556 main.log.info( self.name + " ::::::" )
Jon Halle8217482014-10-17 13:49:14 -0400557 main.cleanup()
558 main.exit()
559
kelvin-onlabd3b64892015-01-20 13:26:24 -0800560 def ports( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800561 """
Jon Halle8217482014-10-17 13:49:14 -0400562 Lists all ports
563 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800564 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800565 """
Jon Halle8217482014-10-17 13:49:14 -0400566 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800567 if jsonFormat:
568 cmdStr = "ports -j"
569 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800570 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800571 handle variable here contains some ANSI escape color code
572 sequences at the end which are invisible in the print command
573 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800574 function. The repr( handle ) output when printed shows the ANSI
575 escape sequences. In json.loads( somestring ), this somestring
576 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800577 fail with the escape sequence. So we take off that escape
578 sequence using the following commads:
579
kelvin-onlabd3b64892015-01-20 13:26:24 -0800580 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
581 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800582 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800583 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
584 handle1 = ansiEscape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400585 return handle1
586
Jon Halle8217482014-10-17 13:49:14 -0400587 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800588 cmdStr = "ports"
589 handle = self.sendline( cmdStr )
Jon Hallffb386d2014-11-21 13:43:38 -0800590 return handle
Jon Halle8217482014-10-17 13:49:14 -0400591 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800592 main.log.error( self.name + ": EOF exception found" )
593 main.log.error( self.name + ": " + self.handle.before )
Jon Halle8217482014-10-17 13:49:14 -0400594 main.cleanup()
595 main.exit()
596 except:
kelvin8ec71442015-01-15 16:57:00 -0800597 main.log.info( self.name + " ::::::" )
598 main.log.error( traceback.print_exc() )
599 main.log.info( self.name + " ::::::" )
Jon Halle8217482014-10-17 13:49:14 -0400600 main.cleanup()
601 main.exit()
602
kelvin-onlabd3b64892015-01-20 13:26:24 -0800603 def roles( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800604 """
Jon Hall983a1702014-10-28 18:44:22 -0400605 Lists all devices and the controllers with roles assigned to them
606 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800607 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800608 """
andrewonlab7c211572014-10-15 16:45:20 -0400609 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800610 if jsonFormat:
611 cmdStr = "roles -j"
612 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800613 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800614 handle variable here contains some ANSI escape color code
615 sequences at the end which are invisible in the print command
616 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800617 function. The repr( handle ) output when printed shows the ANSI
618 escape sequences. In json.loads( somestring ), this somestring
619 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800620 fail with the escape sequence.
Jon Hallb1290e82014-11-18 16:17:48 -0500621
Jon Halle3f39ff2015-01-13 11:50:53 -0800622 So we take off that escape sequence using the following
623 commads:
624
kelvin-onlabd3b64892015-01-20 13:26:24 -0800625 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
626 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800627 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800628 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
629 handle1 = ansiEscape.sub( '', handle )
Jon Hall983a1702014-10-28 18:44:22 -0400630 return handle1
andrewonlab7c211572014-10-15 16:45:20 -0400631
andrewonlab7c211572014-10-15 16:45:20 -0400632 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800633 cmdStr = "roles"
634 handle = self.sendline( cmdStr )
Jon Hallffb386d2014-11-21 13:43:38 -0800635 return handle
Jon Hall983a1702014-10-28 18:44:22 -0400636 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800637 main.log.error( self.name + ": EOF exception found" )
638 main.log.error( self.name + ": " + self.handle.before )
Jon Hall983a1702014-10-28 18:44:22 -0400639 main.cleanup()
640 main.exit()
641 except:
kelvin8ec71442015-01-15 16:57:00 -0800642 main.log.info( self.name + " ::::::" )
643 main.log.error( traceback.print_exc() )
644 main.log.info( self.name + " ::::::" )
Jon Hall983a1702014-10-28 18:44:22 -0400645 main.cleanup()
646 main.exit()
647
kelvin-onlabd3b64892015-01-20 13:26:24 -0800648 def getRole( self, deviceId ):
kelvin-onlab898a6c62015-01-16 14:13:53 -0800649 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800650 Given the a string containing the json representation of the "roles"
651 cli command and a partial or whole device id, returns a json object
652 containing the roles output for the first device whose id contains
653 "device_id"
Jon Hall983a1702014-10-28 18:44:22 -0400654
655 Returns:
Jon Halle3f39ff2015-01-13 11:50:53 -0800656 A dict of the role assignments for the given device or
657 None if no match
kelvin8ec71442015-01-15 16:57:00 -0800658 """
Jon Hall983a1702014-10-28 18:44:22 -0400659 try:
660 import json
kelvin-onlabd3b64892015-01-20 13:26:24 -0800661 if deviceId is None:
Jon Hall983a1702014-10-28 18:44:22 -0400662 return None
663 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800664 rawRoles = self.roles()
665 rolesJson = json.loads( rawRoles )
kelvin8ec71442015-01-15 16:57:00 -0800666 # search json for the device with id then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800667 for device in rolesJson:
kelvin8ec71442015-01-15 16:57:00 -0800668 # print device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800669 if str( deviceId ) in device[ 'id' ]:
Jon Hall983a1702014-10-28 18:44:22 -0400670 return device
671 return None
andrewonlab7c211572014-10-15 16:45:20 -0400672
andrewonlab86dc3082014-10-13 18:18:38 -0400673 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800674 main.log.error( self.name + ": EOF exception found" )
675 main.log.error( self.name + ": " + self.handle.before )
andrewonlab86dc3082014-10-13 18:18:38 -0400676 main.cleanup()
677 main.exit()
678 except:
kelvin8ec71442015-01-15 16:57:00 -0800679 main.log.info( self.name + " ::::::" )
680 main.log.error( traceback.print_exc() )
681 main.log.info( self.name + " ::::::" )
andrewonlab86dc3082014-10-13 18:18:38 -0400682 main.cleanup()
683 main.exit()
Jon Hall94fd0472014-12-08 11:52:42 -0800684
kelvin-onlabd3b64892015-01-20 13:26:24 -0800685 def rolesNotNull( self ):
kelvin8ec71442015-01-15 16:57:00 -0800686 """
Jon Hall94fd0472014-12-08 11:52:42 -0800687 Iterates through each device and checks if there is a master assigned
688 Returns: main.TRUE if each device has a master
689 main.FALSE any device has no master
kelvin8ec71442015-01-15 16:57:00 -0800690 """
Jon Hall94fd0472014-12-08 11:52:42 -0800691 try:
692 import json
kelvin-onlabd3b64892015-01-20 13:26:24 -0800693 rawRoles = self.roles()
694 rolesJson = json.loads( rawRoles )
kelvin8ec71442015-01-15 16:57:00 -0800695 # search json for the device with id then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800696 for device in rolesJson:
kelvin8ec71442015-01-15 16:57:00 -0800697 # print device
698 if device[ 'master' ] == "none":
699 main.log.warn( "Device has no master: " + str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800700 return main.FALSE
701 return main.TRUE
702
703 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800704 main.log.error( self.name + ": EOF exception found" )
705 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -0800706 main.cleanup()
707 main.exit()
708 except:
kelvin8ec71442015-01-15 16:57:00 -0800709 main.log.info( self.name + " ::::::" )
710 main.log.error( traceback.print_exc() )
711 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -0800712 main.cleanup()
713 main.exit()
714
kelvin-onlabd3b64892015-01-20 13:26:24 -0800715 def paths( self, srcId, dstId ):
kelvin8ec71442015-01-15 16:57:00 -0800716 """
andrewonlab3e15ead2014-10-15 14:21:34 -0400717 Returns string of paths, and the cost.
718 Issues command: onos:paths <src> <dst>
kelvin8ec71442015-01-15 16:57:00 -0800719 """
andrewonlab3e15ead2014-10-15 14:21:34 -0400720 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800721 cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId )
722 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800723 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -0800724 main.log.error( "Error in getting paths" )
725 return ( handle, "Error" )
andrewonlab3e15ead2014-10-15 14:21:34 -0400726 else:
kelvin8ec71442015-01-15 16:57:00 -0800727 path = handle.split( ";" )[ 0 ]
728 cost = handle.split( ";" )[ 1 ]
729 return ( path, cost )
andrewonlab3e15ead2014-10-15 14:21:34 -0400730 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800731 main.log.error( self.name + ": EOF exception found" )
732 main.log.error( self.name + ": " + self.handle.before )
andrewonlab3e15ead2014-10-15 14:21:34 -0400733 main.cleanup()
734 main.exit()
735 except:
kelvin8ec71442015-01-15 16:57:00 -0800736 main.log.info( self.name + " ::::::" )
737 main.log.error( traceback.print_exc() )
738 main.log.info( self.name + " ::::::" )
andrewonlab3e15ead2014-10-15 14:21:34 -0400739 main.cleanup()
740 main.exit()
Jon Hallffb386d2014-11-21 13:43:38 -0800741
kelvin-onlabd3b64892015-01-20 13:26:24 -0800742 def hosts( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800743 """
Jon Hallffb386d2014-11-21 13:43:38 -0800744 Lists all discovered hosts
Jon Hall42db6dc2014-10-24 19:03:48 -0400745 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800746 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800747 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400748 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800749 if jsonFormat:
750 cmdStr = "hosts -j"
751 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800752 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800753 handle variable here contains some ANSI escape color code
754 sequences at the end which are invisible in the print command
755 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800756 function. The repr( handle ) output when printed shows the ANSI
757 escape sequences. In json.loads( somestring ), this somestring
758 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800759 fail with the escape sequence. So we take off that escape
760 sequence using:
761
kelvin-onlabd3b64892015-01-20 13:26:24 -0800762 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
763 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800764 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800765 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
766 handle1 = ansiEscape.sub( '', handle )
Jon Hall42db6dc2014-10-24 19:03:48 -0400767 return handle1
768 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800769 cmdStr = "hosts"
770 handle = self.sendline( cmdStr )
Jon Hall42db6dc2014-10-24 19:03:48 -0400771 return handle
772 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800773 main.log.error( self.name + ": EOF exception found" )
774 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -0400775 main.cleanup()
776 main.exit()
777 except:
kelvin8ec71442015-01-15 16:57:00 -0800778 main.log.info( self.name + " ::::::" )
779 main.log.error( traceback.print_exc() )
780 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -0400781 main.cleanup()
782 main.exit()
783
kelvin-onlabd3b64892015-01-20 13:26:24 -0800784 def getHost( self, mac ):
kelvin8ec71442015-01-15 16:57:00 -0800785 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400786 Return the first host from the hosts api whose 'id' contains 'mac'
Jon Halle3f39ff2015-01-13 11:50:53 -0800787
788 Note: mac must be a colon seperated mac address, but could be a
789 partial mac address
790
Jon Hall42db6dc2014-10-24 19:03:48 -0400791 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -0800792 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400793 import json
794 try:
kelvin8ec71442015-01-15 16:57:00 -0800795 if mac is None:
Jon Hall42db6dc2014-10-24 19:03:48 -0400796 return None
797 else:
798 mac = mac
kelvin-onlabd3b64892015-01-20 13:26:24 -0800799 rawHosts = self.hosts()
800 hostsJson = json.loads( rawHosts )
kelvin8ec71442015-01-15 16:57:00 -0800801 # search json for the host with mac then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800802 for host in hostsJson:
kelvin8ec71442015-01-15 16:57:00 -0800803 # print "%s in %s?" % ( mac, host[ 'id' ] )
804 if mac in host[ 'id' ]:
Jon Hall42db6dc2014-10-24 19:03:48 -0400805 return host
806 return None
807 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800808 main.log.error( self.name + ": EOF exception found" )
809 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -0400810 main.cleanup()
811 main.exit()
812 except:
kelvin8ec71442015-01-15 16:57:00 -0800813 main.log.info( self.name + " ::::::" )
814 main.log.error( traceback.print_exc() )
815 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -0400816 main.cleanup()
817 main.exit()
818
kelvin-onlabd3b64892015-01-20 13:26:24 -0800819 def getHostsId( self, hostList ):
kelvin8ec71442015-01-15 16:57:00 -0800820 """
821 Obtain list of hosts
andrewonlab3f0a4af2014-10-17 12:25:14 -0400822 Issues command: 'onos> hosts'
kelvin8ec71442015-01-15 16:57:00 -0800823
andrewonlab3f0a4af2014-10-17 12:25:14 -0400824 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800825 * hostList: List of hosts obtained by Mininet
andrewonlab3f0a4af2014-10-17 12:25:14 -0400826 IMPORTANT:
827 This function assumes that you started your
kelvin8ec71442015-01-15 16:57:00 -0800828 topology with the option '--mac'.
andrewonlab3f0a4af2014-10-17 12:25:14 -0400829 Furthermore, it assumes that value of VLAN is '-1'
830 Description:
kelvin8ec71442015-01-15 16:57:00 -0800831 Converts mininet hosts ( h1, h2, h3... ) into
832 ONOS format ( 00:00:00:00:00:01/-1 , ... )
833 """
andrewonlab3f0a4af2014-10-17 12:25:14 -0400834 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800835 onosHostList = []
andrewonlab3f0a4af2014-10-17 12:25:14 -0400836
kelvin-onlabd3b64892015-01-20 13:26:24 -0800837 for host in hostList:
kelvin8ec71442015-01-15 16:57:00 -0800838 host = host.replace( "h", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800839 hostHex = hex( int( host ) ).zfill( 12 )
840 hostHex = str( hostHex ).replace( 'x', '0' )
841 i = iter( str( hostHex ) )
842 hostHex = ":".join( a + b for a, b in zip( i, i ) )
843 hostHex = hostHex + "/-1"
844 onosHostList.append( hostHex )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400845
kelvin-onlabd3b64892015-01-20 13:26:24 -0800846 return onosHostList
andrewonlab3f0a4af2014-10-17 12:25:14 -0400847
848 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800849 main.log.error( self.name + ": EOF exception found" )
850 main.log.error( self.name + ": " + self.handle.before )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400851 main.cleanup()
852 main.exit()
853 except:
kelvin8ec71442015-01-15 16:57:00 -0800854 main.log.info( self.name + " ::::::" )
855 main.log.error( traceback.print_exc() )
856 main.log.info( self.name + " ::::::" )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400857 main.cleanup()
858 main.exit()
andrewonlab3e15ead2014-10-15 14:21:34 -0400859
kelvin-onlabd3b64892015-01-20 13:26:24 -0800860 def addHostIntent( self, hostIdOne, hostIdTwo ):
kelvin8ec71442015-01-15 16:57:00 -0800861 """
andrewonlabe6745342014-10-17 14:29:13 -0400862 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800863 * hostIdOne: ONOS host id for host1
864 * hostIdTwo: ONOS host id for host2
andrewonlabe6745342014-10-17 14:29:13 -0400865 Description:
kelvin8ec71442015-01-15 16:57:00 -0800866 Adds a host-to-host intent ( bidrectional ) by
Jon Hallb1290e82014-11-18 16:17:48 -0500867 specifying the two hosts.
kelvin8ec71442015-01-15 16:57:00 -0800868 """
andrewonlabe6745342014-10-17 14:29:13 -0400869 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800870 cmdStr = "add-host-intent " + str( hostIdOne ) +\
871 " " + str( hostIdTwo )
872 handle = self.sendline( cmdStr )
Hari Krishnaac4e1782015-01-26 12:09:12 -0800873 if re.search( "Error", handle ):
874 main.log.error( "Error in adding Host intent" )
875 return handle
876 else:
877 main.log.info( "Host intent installed between " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800878 str( hostIdOne ) + " and " + str( hostIdTwo ) )
Hari Krishnaac4e1782015-01-26 12:09:12 -0800879 return main.TRUE
880
andrewonlabe6745342014-10-17 14:29:13 -0400881 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800882 main.log.error( self.name + ": EOF exception found" )
883 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe6745342014-10-17 14:29:13 -0400884 main.cleanup()
885 main.exit()
886 except:
kelvin8ec71442015-01-15 16:57:00 -0800887 main.log.info( self.name + " ::::::" )
888 main.log.error( traceback.print_exc() )
889 main.log.info( self.name + " ::::::" )
andrewonlabe6745342014-10-17 14:29:13 -0400890 main.cleanup()
891 main.exit()
892
kelvin-onlabd3b64892015-01-20 13:26:24 -0800893 def addOpticalIntent( self, ingressDevice, egressDevice ):
kelvin8ec71442015-01-15 16:57:00 -0800894 """
andrewonlab7b31d232014-10-24 13:31:47 -0400895 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800896 * ingressDevice: device id of ingress device
897 * egressDevice: device id of egress device
andrewonlab7b31d232014-10-24 13:31:47 -0400898 Optional:
899 TODO: Still needs to be implemented via dev side
kelvin-onlab898a6c62015-01-16 14:13:53 -0800900 """
andrewonlab7b31d232014-10-24 13:31:47 -0400901 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800902 cmdStr = "add-optical-intent " + str( ingressDevice ) +\
903 " " + str( egressDevice )
904 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800905 # If error, return error message
Jon Halle3f39ff2015-01-13 11:50:53 -0800906 if re.search( "Error", handle ):
andrewonlab7b31d232014-10-24 13:31:47 -0400907 return handle
908 else:
909 return main.TRUE
andrewonlab7b31d232014-10-24 13:31:47 -0400910 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800911 main.log.error( self.name + ": EOF exception found" )
912 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7b31d232014-10-24 13:31:47 -0400913 main.cleanup()
914 main.exit()
915 except:
kelvin8ec71442015-01-15 16:57:00 -0800916 main.log.info( self.name + " ::::::" )
917 main.log.error( traceback.print_exc() )
918 main.log.info( self.name + " ::::::" )
andrewonlab7b31d232014-10-24 13:31:47 -0400919 main.cleanup()
920 main.exit()
921
kelvin-onlabd3b64892015-01-20 13:26:24 -0800922 def addPointIntent(
kelvin-onlab898a6c62015-01-16 14:13:53 -0800923 self,
kelvin-onlabd3b64892015-01-20 13:26:24 -0800924 ingressDevice,
925 egressDevice,
926 portIngress="",
927 portEgress="",
kelvin-onlab898a6c62015-01-16 14:13:53 -0800928 ethType="",
929 ethSrc="",
930 ethDst="",
931 bandwidth="",
kelvin-onlabd3b64892015-01-20 13:26:24 -0800932 lambdaAlloc=False,
kelvin-onlab898a6c62015-01-16 14:13:53 -0800933 ipProto="",
934 ipSrc="",
935 ipDst="",
936 tcpSrc="",
937 tcpDst="" ):
kelvin8ec71442015-01-15 16:57:00 -0800938 """
andrewonlab4dbb4d82014-10-17 18:22:31 -0400939 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800940 * ingressDevice: device id of ingress device
941 * egressDevice: device id of egress device
andrewonlab289e4b72014-10-21 21:24:18 -0400942 Optional:
943 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -0800944 * ethSrc: specify ethSrc ( i.e. src mac addr )
945 * ethDst: specify ethDst ( i.e. dst mac addr )
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500946 * bandwidth: specify bandwidth capacity of link
kelvin-onlabd3b64892015-01-20 13:26:24 -0800947 * lambdaAlloc: if True, intent will allocate lambda
andrewonlab40ccd8b2014-11-06 16:23:34 -0500948 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -0800949 * ipProto: specify ip protocol
andrewonlabf77e0cb2014-11-11 17:17:59 -0500950 * ipSrc: specify ip source address
951 * ipDst: specify ip destination address
952 * tcpSrc: specify tcp source port
953 * tcpDst: specify tcp destination port
andrewonlab4dbb4d82014-10-17 18:22:31 -0400954 Description:
kelvin8ec71442015-01-15 16:57:00 -0800955 Adds a point-to-point intent ( uni-directional ) by
andrewonlab289e4b72014-10-21 21:24:18 -0400956 specifying device id's and optional fields
957
Jon Halle3f39ff2015-01-13 11:50:53 -0800958 NOTE: This function may change depending on the
andrewonlab4dbb4d82014-10-17 18:22:31 -0400959 options developers provide for point-to-point
960 intent via cli
kelvin8ec71442015-01-15 16:57:00 -0800961 """
andrewonlab4dbb4d82014-10-17 18:22:31 -0400962 try:
andrewonlab289e4b72014-10-21 21:24:18 -0400963 cmd = ""
964
kelvin8ec71442015-01-15 16:57:00 -0800965 # If there are no optional arguments
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500966 if not ethType and not ethSrc and not ethDst\
kelvin-onlabd3b64892015-01-20 13:26:24 -0800967 and not bandwidth and not lambdaAlloc \
andrewonlabfa4ff502014-11-11 16:41:30 -0500968 and not ipProto and not ipSrc and not ipDst \
969 and not tcpSrc and not tcpDst:
andrewonlab36af3822014-11-18 17:48:18 -0500970 cmd = "add-point-intent"
andrewonlab36af3822014-11-18 17:48:18 -0500971
andrewonlab289e4b72014-10-21 21:24:18 -0400972 else:
andrewonlab36af3822014-11-18 17:48:18 -0500973 cmd = "add-point-intent"
Jon Halle3f39ff2015-01-13 11:50:53 -0800974
andrewonlab0c0a6772014-10-22 12:31:18 -0400975 if ethType:
kelvin8ec71442015-01-15 16:57:00 -0800976 cmd += " --ethType " + str( ethType )
andrewonlab289e4b72014-10-21 21:24:18 -0400977 if ethSrc:
kelvin8ec71442015-01-15 16:57:00 -0800978 cmd += " --ethSrc " + str( ethSrc )
979 if ethDst:
980 cmd += " --ethDst " + str( ethDst )
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500981 if bandwidth:
kelvin8ec71442015-01-15 16:57:00 -0800982 cmd += " --bandwidth " + str( bandwidth )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800983 if lambdaAlloc:
andrewonlabfa4ff502014-11-11 16:41:30 -0500984 cmd += " --lambda "
985 if ipProto:
kelvin8ec71442015-01-15 16:57:00 -0800986 cmd += " --ipProto " + str( ipProto )
andrewonlabfa4ff502014-11-11 16:41:30 -0500987 if ipSrc:
kelvin8ec71442015-01-15 16:57:00 -0800988 cmd += " --ipSrc " + str( ipSrc )
andrewonlabfa4ff502014-11-11 16:41:30 -0500989 if ipDst:
kelvin8ec71442015-01-15 16:57:00 -0800990 cmd += " --ipDst " + str( ipDst )
andrewonlabfa4ff502014-11-11 16:41:30 -0500991 if tcpSrc:
kelvin8ec71442015-01-15 16:57:00 -0800992 cmd += " --tcpSrc " + str( tcpSrc )
andrewonlabfa4ff502014-11-11 16:41:30 -0500993 if tcpDst:
kelvin8ec71442015-01-15 16:57:00 -0800994 cmd += " --tcpDst " + str( tcpDst )
andrewonlab289e4b72014-10-21 21:24:18 -0400995
kelvin8ec71442015-01-15 16:57:00 -0800996 # Check whether the user appended the port
997 # or provided it as an input
kelvin-onlabd3b64892015-01-20 13:26:24 -0800998 if "/" in ingressDevice:
999 cmd += " " + str( ingressDevice )
andrewonlab36af3822014-11-18 17:48:18 -05001000 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001001 if not portIngress:
kelvin8ec71442015-01-15 16:57:00 -08001002 main.log.error( "You must specify " +
1003 "the ingress port" )
1004 # TODO: perhaps more meaningful return
andrewonlab36af3822014-11-18 17:48:18 -05001005 return main.FALSE
1006
kelvin8ec71442015-01-15 16:57:00 -08001007 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001008 str( ingressDevice ) + "/" +\
1009 str( portIngress ) + " "
andrewonlab36af3822014-11-18 17:48:18 -05001010
kelvin-onlabd3b64892015-01-20 13:26:24 -08001011 if "/" in egressDevice:
1012 cmd += " " + str( egressDevice )
andrewonlab36af3822014-11-18 17:48:18 -05001013 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001014 if not portEgress:
kelvin8ec71442015-01-15 16:57:00 -08001015 main.log.error( "You must specify " +
1016 "the egress port" )
andrewonlab36af3822014-11-18 17:48:18 -05001017 return main.FALSE
Jon Halle3f39ff2015-01-13 11:50:53 -08001018
kelvin8ec71442015-01-15 16:57:00 -08001019 cmd += " " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001020 str( egressDevice ) + "/" +\
1021 str( portEgress )
kelvin8ec71442015-01-15 16:57:00 -08001022
kelvin-onlab898a6c62015-01-16 14:13:53 -08001023 handle = self.sendline( cmd )
1024 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -08001025 main.log.error( "Error in adding point-to-point intent" )
Jon Hall47a93fb2015-01-06 16:46:06 -08001026 return main.FALSE
andrewonlab4dbb4d82014-10-17 18:22:31 -04001027 else:
1028 return main.TRUE
andrewonlab4dbb4d82014-10-17 18:22:31 -04001029 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001030 main.log.error( self.name + ": EOF exception found" )
1031 main.log.error( self.name + ": " + self.handle.before )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001032 main.cleanup()
1033 main.exit()
1034 except:
kelvin8ec71442015-01-15 16:57:00 -08001035 main.log.info( self.name + " ::::::" )
1036 main.log.error( traceback.print_exc() )
1037 main.log.info( self.name + " ::::::" )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001038 main.cleanup()
1039 main.exit()
1040
kelvin-onlabd3b64892015-01-20 13:26:24 -08001041 def addMultipointToSinglepointIntent(
kelvin-onlab898a6c62015-01-16 14:13:53 -08001042 self,
kelvin-onlabd3b64892015-01-20 13:26:24 -08001043 ingressDevice1,
1044 ingressDevice2,
1045 egressDevice,
1046 portIngress="",
1047 portEgress="",
kelvin-onlab898a6c62015-01-16 14:13:53 -08001048 ethType="",
1049 ethSrc="",
1050 ethDst="",
1051 bandwidth="",
kelvin-onlabd3b64892015-01-20 13:26:24 -08001052 lambdaAlloc=False,
kelvin-onlab898a6c62015-01-16 14:13:53 -08001053 ipProto="",
1054 ipSrc="",
1055 ipDst="",
1056 tcpSrc="",
1057 tcpDst="",
1058 setEthSrc="",
1059 setEthDst="" ):
kelvin8ec71442015-01-15 16:57:00 -08001060 """
shahshreyad0c80432014-12-04 16:56:05 -08001061 Note:
Jon Halle3f39ff2015-01-13 11:50:53 -08001062 This function assumes that there would be 2 ingress devices and
1063 one egress device. For more number of ingress devices, this
1064 function needs to be modified
shahshreyad0c80432014-12-04 16:56:05 -08001065 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001066 * ingressDevice1: device id of ingress device1
1067 * ingressDevice2: device id of ingress device2
1068 * egressDevice: device id of egress device
shahshreyad0c80432014-12-04 16:56:05 -08001069 Optional:
1070 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -08001071 * ethSrc: specify ethSrc ( i.e. src mac addr )
1072 * ethDst: specify ethDst ( i.e. dst mac addr )
shahshreyad0c80432014-12-04 16:56:05 -08001073 * bandwidth: specify bandwidth capacity of link
kelvin-onlabd3b64892015-01-20 13:26:24 -08001074 * lambdaAlloc: if True, intent will allocate lambda
shahshreyad0c80432014-12-04 16:56:05 -08001075 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -08001076 * ipProto: specify ip protocol
shahshreyad0c80432014-12-04 16:56:05 -08001077 * ipSrc: specify ip source address
1078 * ipDst: specify ip destination address
1079 * tcpSrc: specify tcp source port
1080 * tcpDst: specify tcp destination port
1081 * setEthSrc: action to Rewrite Source MAC Address
1082 * setEthDst: action to Rewrite Destination MAC Address
1083 Description:
kelvin8ec71442015-01-15 16:57:00 -08001084 Adds a multipoint-to-singlepoint intent ( uni-directional ) by
shahshreyad0c80432014-12-04 16:56:05 -08001085 specifying device id's and optional fields
1086
Jon Halle3f39ff2015-01-13 11:50:53 -08001087 NOTE: This function may change depending on the
shahshreyad0c80432014-12-04 16:56:05 -08001088 options developers provide for multipointpoint-to-singlepoint
1089 intent via cli
kelvin8ec71442015-01-15 16:57:00 -08001090 """
shahshreyad0c80432014-12-04 16:56:05 -08001091 try:
1092 cmd = ""
1093
kelvin8ec71442015-01-15 16:57:00 -08001094 # If there are no optional arguments
shahshreyad0c80432014-12-04 16:56:05 -08001095 if not ethType and not ethSrc and not ethDst\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001096 and not bandwidth and not lambdaAlloc\
Jon Halle3f39ff2015-01-13 11:50:53 -08001097 and not ipProto and not ipSrc and not ipDst\
1098 and not tcpSrc and not tcpDst and not setEthSrc\
1099 and not setEthDst:
shahshreyad0c80432014-12-04 16:56:05 -08001100 cmd = "add-multi-to-single-intent"
shahshreyad0c80432014-12-04 16:56:05 -08001101
1102 else:
1103 cmd = "add-multi-to-single-intent"
Jon Halle3f39ff2015-01-13 11:50:53 -08001104
shahshreyad0c80432014-12-04 16:56:05 -08001105 if ethType:
kelvin8ec71442015-01-15 16:57:00 -08001106 cmd += " --ethType " + str( ethType )
shahshreyad0c80432014-12-04 16:56:05 -08001107 if ethSrc:
kelvin8ec71442015-01-15 16:57:00 -08001108 cmd += " --ethSrc " + str( ethSrc )
1109 if ethDst:
1110 cmd += " --ethDst " + str( ethDst )
shahshreyad0c80432014-12-04 16:56:05 -08001111 if bandwidth:
kelvin8ec71442015-01-15 16:57:00 -08001112 cmd += " --bandwidth " + str( bandwidth )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001113 if lambdaAlloc:
shahshreyad0c80432014-12-04 16:56:05 -08001114 cmd += " --lambda "
1115 if ipProto:
kelvin8ec71442015-01-15 16:57:00 -08001116 cmd += " --ipProto " + str( ipProto )
shahshreyad0c80432014-12-04 16:56:05 -08001117 if ipSrc:
kelvin8ec71442015-01-15 16:57:00 -08001118 cmd += " --ipSrc " + str( ipSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001119 if ipDst:
kelvin8ec71442015-01-15 16:57:00 -08001120 cmd += " --ipDst " + str( ipDst )
shahshreyad0c80432014-12-04 16:56:05 -08001121 if tcpSrc:
kelvin8ec71442015-01-15 16:57:00 -08001122 cmd += " --tcpSrc " + str( tcpSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001123 if tcpDst:
kelvin8ec71442015-01-15 16:57:00 -08001124 cmd += " --tcpDst " + str( tcpDst )
shahshreyad0c80432014-12-04 16:56:05 -08001125 if setEthSrc:
kelvin8ec71442015-01-15 16:57:00 -08001126 cmd += " --setEthSrc " + str( setEthSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001127 if setEthDst:
kelvin8ec71442015-01-15 16:57:00 -08001128 cmd += " --setEthDst " + str( setEthDst )
shahshreyad0c80432014-12-04 16:56:05 -08001129
kelvin8ec71442015-01-15 16:57:00 -08001130 # Check whether the user appended the port
1131 # or provided it as an input
kelvin-onlabd3b64892015-01-20 13:26:24 -08001132 if "/" in ingressDevice1:
1133 cmd += " " + str( ingressDevice1 )
shahshreyad0c80432014-12-04 16:56:05 -08001134 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001135 if not portIngress1:
kelvin8ec71442015-01-15 16:57:00 -08001136 main.log.error( "You must specify " +
1137 "the ingress port1" )
1138 # TODO: perhaps more meaningful return
shahshreyad0c80432014-12-04 16:56:05 -08001139 return main.FALSE
1140
kelvin8ec71442015-01-15 16:57:00 -08001141 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001142 str( ingressDevice1 ) + "/" +\
1143 str( portIngress1 ) + " "
shahshreyad0c80432014-12-04 16:56:05 -08001144
kelvin-onlabd3b64892015-01-20 13:26:24 -08001145 if "/" in ingressDevice2:
1146 cmd += " " + str( ingressDevice2 )
shahshreyad0c80432014-12-04 16:56:05 -08001147 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001148 if not portIngress2:
kelvin8ec71442015-01-15 16:57:00 -08001149 main.log.error( "You must specify " +
1150 "the ingress port2" )
1151 # TODO: perhaps more meaningful return
shahshreyad0c80432014-12-04 16:56:05 -08001152 return main.FALSE
1153
kelvin8ec71442015-01-15 16:57:00 -08001154 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001155 str( ingressDevice2 ) + "/" +\
1156 str( portIngress2 ) + " "
shahshreyad0c80432014-12-04 16:56:05 -08001157
kelvin-onlabd3b64892015-01-20 13:26:24 -08001158 if "/" in egressDevice:
1159 cmd += " " + str( egressDevice )
shahshreyad0c80432014-12-04 16:56:05 -08001160 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001161 if not portEgress:
kelvin8ec71442015-01-15 16:57:00 -08001162 main.log.error( "You must specify " +
1163 "the egress port" )
shahshreyad0c80432014-12-04 16:56:05 -08001164 return main.FALSE
Jon Halle3f39ff2015-01-13 11:50:53 -08001165
kelvin8ec71442015-01-15 16:57:00 -08001166 cmd += " " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001167 str( egressDevice ) + "/" +\
1168 str( portEgress )
kelvin8ec71442015-01-15 16:57:00 -08001169 print "cmd= ", cmd
kelvin-onlab898a6c62015-01-16 14:13:53 -08001170 handle = self.sendline( cmd )
1171 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -08001172 main.log.error( "Error in adding point-to-point intent" )
shahshreyad0c80432014-12-04 16:56:05 -08001173 return self.handle
1174 else:
1175 return main.TRUE
shahshreyad0c80432014-12-04 16:56:05 -08001176 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001177 main.log.error( self.name + ": EOF exception found" )
1178 main.log.error( self.name + ": " + self.handle.before )
shahshreyad0c80432014-12-04 16:56:05 -08001179 main.cleanup()
1180 main.exit()
1181 except:
kelvin8ec71442015-01-15 16:57:00 -08001182 main.log.info( self.name + " ::::::" )
1183 main.log.error( traceback.print_exc() )
1184 main.log.info( self.name + " ::::::" )
shahshreyad0c80432014-12-04 16:56:05 -08001185 main.cleanup()
1186 main.exit()
1187
kelvin-onlabd3b64892015-01-20 13:26:24 -08001188 def removeIntent( self, intentId ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001189 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001190 Remove intent for specified intent id
Jon Halle3f39ff2015-01-13 11:50:53 -08001191
1192 Returns:
1193 main.False on error and
1194 cli output otherwise
kelvin-onlab898a6c62015-01-16 14:13:53 -08001195 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001196 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001197 cmdStr = "remove-intent " + str( intentId )
1198 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001199 if re.search( "Error", handle ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001200 main.log.error( "Error in removing intent" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001201 return main.FALSE
andrewonlab9a50dfe2014-10-17 17:22:31 -04001202 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001203 # TODO: Should this be main.TRUE
1204 return handle
andrewonlab9a50dfe2014-10-17 17:22:31 -04001205 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001206 main.log.error( self.name + ": EOF exception found" )
1207 main.log.error( self.name + ": " + self.handle.before )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001208 main.cleanup()
1209 main.exit()
1210 except:
kelvin8ec71442015-01-15 16:57:00 -08001211 main.log.info( self.name + " ::::::" )
1212 main.log.error( traceback.print_exc() )
1213 main.log.info( self.name + " ::::::" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001214 main.cleanup()
1215 main.exit()
1216
kelvin-onlabd3b64892015-01-20 13:26:24 -08001217 def routes( self, jsonFormat=False ):
kelvin8ec71442015-01-15 16:57:00 -08001218 """
kelvin-onlab898a6c62015-01-16 14:13:53 -08001219 NOTE: This method should be used after installing application:
1220 onos-app-sdnip
pingping-lin8b306ac2014-11-17 18:13:51 -08001221 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001222 * jsonFormat: enable output formatting in json
pingping-lin8b306ac2014-11-17 18:13:51 -08001223 Description:
1224 Obtain all routes in the system
kelvin8ec71442015-01-15 16:57:00 -08001225 """
pingping-lin8b306ac2014-11-17 18:13:51 -08001226 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001227 if jsonFormat:
1228 cmdStr = "routes -j"
1229 handleTmp = self.sendline( cmdStr )
1230 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1231 handle = ansiEscape.sub( '', handleTmp )
pingping-lin8b306ac2014-11-17 18:13:51 -08001232 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001233 cmdStr = "routes"
1234 handle = self.sendline( cmdStr )
pingping-lin8b306ac2014-11-17 18:13:51 -08001235 return handle
pingping-lin8b306ac2014-11-17 18:13:51 -08001236 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001237 main.log.error( self.name + ": EOF exception found" )
1238 main.log.error( self.name + ": " + self.handle.before )
pingping-lin8b306ac2014-11-17 18:13:51 -08001239 main.cleanup()
1240 main.exit()
1241 except:
kelvin8ec71442015-01-15 16:57:00 -08001242 main.log.info( self.name + " ::::::" )
1243 main.log.error( traceback.print_exc() )
1244 main.log.info( self.name + " ::::::" )
pingping-lin8b306ac2014-11-17 18:13:51 -08001245 main.cleanup()
1246 main.exit()
1247
kelvin-onlabd3b64892015-01-20 13:26:24 -08001248 def intents( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001249 """
andrewonlab377693f2014-10-21 16:00:30 -04001250 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001251 * jsonFormat: enable output formatting in json
andrewonlabe6745342014-10-17 14:29:13 -04001252 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001253 Obtain intents currently installed
kelvin-onlab898a6c62015-01-16 14:13:53 -08001254 """
andrewonlabe6745342014-10-17 14:29:13 -04001255 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001256 if jsonFormat:
1257 cmdStr = "intents -j"
1258 handle = self.sendline( cmdStr )
1259 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1260 handle = ansiEscape.sub( '', handle )
kelvin8ec71442015-01-15 16:57:00 -08001261 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001262 cmdStr = "intents"
1263 handle = self.sendline( cmdStr )
andrewonlabe6745342014-10-17 14:29:13 -04001264 return handle
andrewonlabe6745342014-10-17 14:29:13 -04001265 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001266 main.log.error( self.name + ": EOF exception found" )
1267 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe6745342014-10-17 14:29:13 -04001268 main.cleanup()
1269 main.exit()
1270 except:
kelvin8ec71442015-01-15 16:57:00 -08001271 main.log.info( self.name + " ::::::" )
1272 main.log.error( traceback.print_exc() )
1273 main.log.info( self.name + " ::::::" )
andrewonlabe6745342014-10-17 14:29:13 -04001274 main.cleanup()
1275 main.exit()
1276
kelvin-onlabd3b64892015-01-20 13:26:24 -08001277 def flows( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001278 """
Shreya Shah0f01c812014-10-26 20:15:28 -04001279 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001280 * jsonFormat: enable output formatting in json
Shreya Shah0f01c812014-10-26 20:15:28 -04001281 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001282 Obtain flows currently installed
kelvin-onlab898a6c62015-01-16 14:13:53 -08001283 """
Shreya Shah0f01c812014-10-26 20:15:28 -04001284 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001285 if jsonFormat:
1286 cmdStr = "flows -j"
1287 handle = self.sendline( cmdStr )
1288 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1289 handle = ansiEscape.sub( '', handle )
Shreya Shah0f01c812014-10-26 20:15:28 -04001290 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001291 cmdStr = "flows"
1292 handle = self.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -08001293 if re.search( "Error\sexecuting\scommand:", handle ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001294 main.log.error( self.name + ".flows() response: " +
1295 str( handle ) )
Shreya Shah0f01c812014-10-26 20:15:28 -04001296 return handle
Shreya Shah0f01c812014-10-26 20:15:28 -04001297 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001298 main.log.error( self.name + ": EOF exception found" )
1299 main.log.error( self.name + ": " + self.handle.before )
Shreya Shah0f01c812014-10-26 20:15:28 -04001300 main.cleanup()
1301 main.exit()
1302 except:
kelvin8ec71442015-01-15 16:57:00 -08001303 main.log.info( self.name + " ::::::" )
1304 main.log.error( traceback.print_exc() )
1305 main.log.info( self.name + " ::::::" )
Shreya Shah0f01c812014-10-26 20:15:28 -04001306 main.cleanup()
1307 main.exit()
1308
kelvin-onlabd3b64892015-01-20 13:26:24 -08001309 def pushTestIntents( self, dpidSrc, dpidDst, numIntents,
1310 numMult="", appId="", report=True ):
kelvin8ec71442015-01-15 16:57:00 -08001311 """
andrewonlab87852b02014-11-19 18:44:19 -05001312 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001313 Push a number of intents in a batch format to
andrewonlab87852b02014-11-19 18:44:19 -05001314 a specific point-to-point intent definition
1315 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001316 * dpidSrc: specify source dpid
1317 * dpidDst: specify destination dpid
1318 * numIntents: specify number of intents to push
andrewonlab87852b02014-11-19 18:44:19 -05001319 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001320 * numMult: number multiplier for multiplying
andrewonlabb66dfa12014-12-02 15:51:10 -05001321 the number of intents specified
kelvin-onlabd3b64892015-01-20 13:26:24 -08001322 * appId: specify the application id init to further
andrewonlabb66dfa12014-12-02 15:51:10 -05001323 modularize the intents
andrewonlab87852b02014-11-19 18:44:19 -05001324 * report: default True, returns latency information
kelvin8ec71442015-01-15 16:57:00 -08001325 """
andrewonlab87852b02014-11-19 18:44:19 -05001326 try:
kelvin8ec71442015-01-15 16:57:00 -08001327 cmd = "push-test-intents " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001328 str( dpidSrc ) + " " + str( dpidDst ) + " " +\
1329 str( numIntents )
1330 if numMult:
1331 cmd += " " + str( numMult )
1332 # If app id is specified, then numMult
kelvin8ec71442015-01-15 16:57:00 -08001333 # must exist because of the way this command
kelvin-onlabd3b64892015-01-20 13:26:24 -08001334 if appId:
1335 cmd += " " + str( appId )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001336 handle = self.sendline( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001337 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1338 handle = ansiEscape.sub( '', handle )
andrewonlab87852b02014-11-19 18:44:19 -05001339 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001340 latResult = []
kelvin8ec71442015-01-15 16:57:00 -08001341 main.log.info( handle )
1342 # Split result by newline
1343 newline = handle.split( "\r\r\n" )
1344 # Ignore the first object of list, which is empty
1345 newline = newline[ 1: ]
1346 # Some sloppy parsing method to get the latency
andrewonlabb66dfa12014-12-02 15:51:10 -05001347 for result in newline:
kelvin8ec71442015-01-15 16:57:00 -08001348 result = result.split( ": " )
1349 # Append the first result of second parse
kelvin-onlabd3b64892015-01-20 13:26:24 -08001350 latResult.append( result[ 1 ].split( " " )[ 0 ] )
1351 main.log.info( latResult )
1352 return latResult
andrewonlab87852b02014-11-19 18:44:19 -05001353 else:
1354 return main.TRUE
andrewonlab87852b02014-11-19 18:44:19 -05001355 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001356 main.log.error( self.name + ": EOF exception found" )
1357 main.log.error( self.name + ": " + self.handle.before )
andrewonlab87852b02014-11-19 18:44:19 -05001358 main.cleanup()
1359 main.exit()
1360 except:
kelvin8ec71442015-01-15 16:57:00 -08001361 main.log.info( self.name + " ::::::" )
1362 main.log.error( traceback.print_exc() )
1363 main.log.info( self.name + " ::::::" )
andrewonlab87852b02014-11-19 18:44:19 -05001364 main.cleanup()
1365 main.exit()
1366
kelvin-onlabd3b64892015-01-20 13:26:24 -08001367 def intentsEventsMetrics( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001368 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001369 Description:Returns topology metrics
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001370 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001371 * jsonFormat: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08001372 """
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001373 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001374 if jsonFormat:
1375 cmdStr = "intents-events-metrics -j"
1376 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001377 # Some color thing that we want to escape
kelvin-onlabd3b64892015-01-20 13:26:24 -08001378 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1379 handle = ansiEscape.sub( '', handle )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001380 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001381 cmdStr = "intents-events-metrics"
1382 handle = self.sendline( cmdStr )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001383 return handle
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001384 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001385 main.log.error( self.name + ": EOF exception found" )
1386 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001387 main.cleanup()
1388 main.exit()
1389 except:
kelvin8ec71442015-01-15 16:57:00 -08001390 main.log.info( self.name + " ::::::" )
1391 main.log.error( traceback.print_exc() )
1392 main.log.info( self.name + " ::::::" )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001393 main.cleanup()
1394 main.exit()
Shreya Shah0f01c812014-10-26 20:15:28 -04001395
kelvin-onlabd3b64892015-01-20 13:26:24 -08001396 def topologyEventsMetrics( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001397 """
1398 Description:Returns topology metrics
andrewonlab867212a2014-10-22 20:13:38 -04001399 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001400 * jsonFormat: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08001401 """
andrewonlab867212a2014-10-22 20:13:38 -04001402 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001403 if jsonFormat:
1404 cmdStr = "topology-events-metrics -j"
1405 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001406 # Some color thing that we want to escape
kelvin-onlabd3b64892015-01-20 13:26:24 -08001407 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1408 handle = ansiEscape.sub( '', handle )
andrewonlab867212a2014-10-22 20:13:38 -04001409 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001410 cmdStr = "topology-events-metrics"
1411 handle = self.sendline( cmdStr )
andrewonlab867212a2014-10-22 20:13:38 -04001412 return handle
andrewonlab867212a2014-10-22 20:13:38 -04001413 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001414 main.log.error( self.name + ": EOF exception found" )
1415 main.log.error( self.name + ": " + self.handle.before )
andrewonlab867212a2014-10-22 20:13:38 -04001416 main.cleanup()
1417 main.exit()
1418 except:
kelvin8ec71442015-01-15 16:57:00 -08001419 main.log.info( self.name + " ::::::" )
1420 main.log.error( traceback.print_exc() )
1421 main.log.info( self.name + " ::::::" )
andrewonlab867212a2014-10-22 20:13:38 -04001422 main.cleanup()
1423 main.exit()
1424
kelvin8ec71442015-01-15 16:57:00 -08001425 # Wrapper functions ****************
1426 # Wrapper functions use existing driver
1427 # functions and extends their use case.
1428 # For example, we may use the output of
1429 # a normal driver function, and parse it
1430 # using a wrapper function
andrewonlabc2d05aa2014-10-13 16:51:10 -04001431
kelvin-onlabd3b64892015-01-20 13:26:24 -08001432 def getAllIntentsId( self ):
kelvin8ec71442015-01-15 16:57:00 -08001433 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001434 Description:
1435 Obtain all intent id's in a list
kelvin8ec71442015-01-15 16:57:00 -08001436 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001437 try:
kelvin8ec71442015-01-15 16:57:00 -08001438 # Obtain output of intents function
kelvin-onlabd3b64892015-01-20 13:26:24 -08001439 intentsStr = self.intents()
1440 allIntentList = []
1441 intentIdList = []
andrewonlab9a50dfe2014-10-17 17:22:31 -04001442
kelvin8ec71442015-01-15 16:57:00 -08001443 # Parse the intents output for ID's
kelvin-onlabd3b64892015-01-20 13:26:24 -08001444 intentsList = [ s.strip() for s in intentsStr.splitlines() ]
1445 for intents in intentsList:
andrewonlab9a50dfe2014-10-17 17:22:31 -04001446 if "onos>" in intents:
1447 continue
1448 elif "intents" in intents:
1449 continue
1450 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001451 lineList = intents.split( " " )
1452 allIntentList.append( lineList[ 0 ] )
kelvin8ec71442015-01-15 16:57:00 -08001453
kelvin-onlabd3b64892015-01-20 13:26:24 -08001454 allIntentList = allIntentList[ 1:-2 ]
andrewonlab9a50dfe2014-10-17 17:22:31 -04001455
kelvin-onlabd3b64892015-01-20 13:26:24 -08001456 for intents in allIntentList:
andrewonlab9a50dfe2014-10-17 17:22:31 -04001457 if not intents:
1458 continue
1459 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001460 intentIdList.append( intents )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001461
kelvin-onlabd3b64892015-01-20 13:26:24 -08001462 return intentIdList
andrewonlab9a50dfe2014-10-17 17:22:31 -04001463
1464 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001465 main.log.error( self.name + ": EOF exception found" )
1466 main.log.error( self.name + ": " + self.handle.before )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001467 main.cleanup()
1468 main.exit()
1469 except:
kelvin8ec71442015-01-15 16:57:00 -08001470 main.log.info( self.name + " ::::::" )
1471 main.log.error( traceback.print_exc() )
1472 main.log.info( self.name + " ::::::" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001473 main.cleanup()
1474 main.exit()
1475
kelvin-onlabd3b64892015-01-20 13:26:24 -08001476 def getAllDevicesId( self ):
kelvin8ec71442015-01-15 16:57:00 -08001477 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04001478 Use 'devices' function to obtain list of all devices
1479 and parse the result to obtain a list of all device
1480 id's. Returns this list. Returns empty list if no
1481 devices exist
kelvin8ec71442015-01-15 16:57:00 -08001482 List is ordered sequentially
1483
andrewonlab3e15ead2014-10-15 14:21:34 -04001484 This function may be useful if you are not sure of the
kelvin8ec71442015-01-15 16:57:00 -08001485 device id, and wish to execute other commands using
andrewonlab3e15ead2014-10-15 14:21:34 -04001486 the ids. By obtaining the list of device ids on the fly,
1487 you can iterate through the list to get mastership, etc.
kelvin8ec71442015-01-15 16:57:00 -08001488 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04001489 try:
kelvin8ec71442015-01-15 16:57:00 -08001490 # Call devices and store result string
kelvin-onlabd3b64892015-01-20 13:26:24 -08001491 devicesStr = self.devices( jsonFormat=False )
1492 idList = []
kelvin8ec71442015-01-15 16:57:00 -08001493
kelvin-onlabd3b64892015-01-20 13:26:24 -08001494 if not devicesStr:
kelvin8ec71442015-01-15 16:57:00 -08001495 main.log.info( "There are no devices to get id from" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001496 return idList
kelvin8ec71442015-01-15 16:57:00 -08001497
1498 # Split the string into list by comma
kelvin-onlabd3b64892015-01-20 13:26:24 -08001499 deviceList = devicesStr.split( "," )
kelvin8ec71442015-01-15 16:57:00 -08001500 # Get temporary list of all arguments with string 'id='
kelvin-onlabd3b64892015-01-20 13:26:24 -08001501 tempList = [ dev for dev in deviceList if "id=" in dev ]
kelvin8ec71442015-01-15 16:57:00 -08001502 # Split list further into arguments before and after string
1503 # 'id='. Get the latter portion ( the actual device id ) and
kelvin-onlabd3b64892015-01-20 13:26:24 -08001504 # append to idList
1505 for arg in tempList:
1506 idList.append( arg.split( "id=" )[ 1 ] )
1507 return idList
andrewonlab7e4d2d32014-10-15 13:23:21 -04001508
1509 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001510 main.log.error( self.name + ": EOF exception found" )
1511 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001512 main.cleanup()
1513 main.exit()
1514 except:
kelvin8ec71442015-01-15 16:57:00 -08001515 main.log.info( self.name + " ::::::" )
1516 main.log.error( traceback.print_exc() )
1517 main.log.info( self.name + " ::::::" )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001518 main.cleanup()
1519 main.exit()
1520
kelvin-onlabd3b64892015-01-20 13:26:24 -08001521 def getAllNodesId( self ):
kelvin8ec71442015-01-15 16:57:00 -08001522 """
andrewonlab7c211572014-10-15 16:45:20 -04001523 Uses 'nodes' function to obtain list of all nodes
1524 and parse the result of nodes to obtain just the
kelvin8ec71442015-01-15 16:57:00 -08001525 node id's.
andrewonlab7c211572014-10-15 16:45:20 -04001526 Returns:
1527 list of node id's
kelvin8ec71442015-01-15 16:57:00 -08001528 """
andrewonlab7c211572014-10-15 16:45:20 -04001529 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001530 nodesStr = self.nodes()
1531 idList = []
andrewonlab7c211572014-10-15 16:45:20 -04001532
kelvin-onlabd3b64892015-01-20 13:26:24 -08001533 if not nodesStr:
kelvin8ec71442015-01-15 16:57:00 -08001534 main.log.info( "There are no nodes to get id from" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001535 return idList
andrewonlab7c211572014-10-15 16:45:20 -04001536
kelvin-onlabd3b64892015-01-20 13:26:24 -08001537 # Sample nodesStr output
kelvin8ec71442015-01-15 16:57:00 -08001538 # id=local, address=127.0.0.1:9876, state=ACTIVE *
andrewonlab7c211572014-10-15 16:45:20 -04001539
kelvin8ec71442015-01-15 16:57:00 -08001540 # Split the string into list by comma
kelvin-onlabd3b64892015-01-20 13:26:24 -08001541 nodesList = nodesStr.split( "," )
1542 tempList = [ node for node in nodesList if "id=" in node ]
1543 for arg in tempList:
1544 idList.append( arg.split( "id=" )[ 1 ] )
andrewonlab7c211572014-10-15 16:45:20 -04001545
kelvin-onlabd3b64892015-01-20 13:26:24 -08001546 return idList
kelvin8ec71442015-01-15 16:57:00 -08001547
andrewonlab7c211572014-10-15 16:45:20 -04001548 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001549 main.log.error( self.name + ": EOF exception found" )
1550 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -04001551 main.cleanup()
1552 main.exit()
1553 except:
kelvin8ec71442015-01-15 16:57:00 -08001554 main.log.info( self.name + " ::::::" )
1555 main.log.error( traceback.print_exc() )
1556 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -04001557 main.cleanup()
1558 main.exit()
andrewonlab7e4d2d32014-10-15 13:23:21 -04001559
kelvin-onlabd3b64892015-01-20 13:26:24 -08001560 def getDevice( self, dpid=None ):
kelvin8ec71442015-01-15 16:57:00 -08001561 """
Jon Halla91c4dc2014-10-22 12:57:04 -04001562 Return the first device from the devices api whose 'id' contains 'dpid'
1563 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -08001564 """
Jon Halla91c4dc2014-10-22 12:57:04 -04001565 import json
1566 try:
kelvin8ec71442015-01-15 16:57:00 -08001567 if dpid is None:
Jon Halla91c4dc2014-10-22 12:57:04 -04001568 return None
1569 else:
kelvin8ec71442015-01-15 16:57:00 -08001570 dpid = dpid.replace( ':', '' )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001571 rawDevices = self.devices()
1572 devicesJson = json.loads( rawDevices )
kelvin8ec71442015-01-15 16:57:00 -08001573 # search json for the device with dpid then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -08001574 for device in devicesJson:
kelvin8ec71442015-01-15 16:57:00 -08001575 # print "%s in %s?" % ( dpid, device[ 'id' ] )
1576 if dpid in device[ 'id' ]:
Jon Halla91c4dc2014-10-22 12:57:04 -04001577 return device
1578 return None
1579 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001580 main.log.error( self.name + ": EOF exception found" )
1581 main.log.error( self.name + ": " + self.handle.before )
Jon Halla91c4dc2014-10-22 12:57:04 -04001582 main.cleanup()
1583 main.exit()
1584 except:
kelvin8ec71442015-01-15 16:57:00 -08001585 main.log.info( self.name + " ::::::" )
1586 main.log.error( traceback.print_exc() )
1587 main.log.info( self.name + " ::::::" )
Jon Halla91c4dc2014-10-22 12:57:04 -04001588 main.cleanup()
1589 main.exit()
1590
kelvin-onlabd3b64892015-01-20 13:26:24 -08001591 def checkStatus( self, ip, numoswitch, numolink, logLevel="info" ):
kelvin8ec71442015-01-15 16:57:00 -08001592 """
1593 Checks the number of swithes & links that ONOS sees against the
1594 supplied values. By default this will report to main.log, but the
Jon Hall42db6dc2014-10-24 19:03:48 -04001595 log level can be specifid.
kelvin8ec71442015-01-15 16:57:00 -08001596
Jon Hall42db6dc2014-10-24 19:03:48 -04001597 Params: ip = ip used for the onos cli
1598 numoswitch = expected number of switches
1599 numlink = expected number of links
kelvin-onlabd3b64892015-01-20 13:26:24 -08001600 logLevel = level to log to. Currently accepts
1601 'info', 'warn' and 'report'
Jon Hall42db6dc2014-10-24 19:03:48 -04001602
1603
kelvin-onlabd3b64892015-01-20 13:26:24 -08001604 logLevel can
Jon Hall42db6dc2014-10-24 19:03:48 -04001605
kelvin8ec71442015-01-15 16:57:00 -08001606 Returns: main.TRUE if the number of switchs and links are correct,
Jon Hall42db6dc2014-10-24 19:03:48 -04001607 main.FALSE if the numer of switches and links is incorrect,
1608 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08001609 """
Jon Hall42db6dc2014-10-24 19:03:48 -04001610 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001611 topology = self.getTopology( ip )
Jon Hall42db6dc2014-10-24 19:03:48 -04001612 if topology == {}:
1613 return main.ERROR
1614 output = ""
kelvin8ec71442015-01-15 16:57:00 -08001615 # Is the number of switches is what we expected
1616 devices = topology.get( 'devices', False )
1617 links = topology.get( 'links', False )
Jon Hall42db6dc2014-10-24 19:03:48 -04001618 if devices == False or links == False:
1619 return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -08001620 switchCheck = ( int( devices ) == int( numoswitch ) )
kelvin8ec71442015-01-15 16:57:00 -08001621 # Is the number of links is what we expected
kelvin-onlabd3b64892015-01-20 13:26:24 -08001622 linkCheck = ( int( links ) == int( numolink ) )
1623 if ( switchCheck and linkCheck ):
kelvin8ec71442015-01-15 16:57:00 -08001624 # We expected the correct numbers
Jon Hall42db6dc2014-10-24 19:03:48 -04001625 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08001626 + "what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04001627 result = main.TRUE
1628 else:
1629 output = output + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001630 "The number of links and switches does not matc\
1631 h what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04001632 result = main.FALSE
kelvin-onlabd3b64892015-01-20 13:26:24 -08001633 output = output + "\n ONOS sees %i devices (%i expected) \
1634 and %i links (%i expected)" % (
1635 int( devices ), int( numoswitch ), int( links ),
1636 int( numolink ) )
1637 if logLevel == "report":
kelvin8ec71442015-01-15 16:57:00 -08001638 main.log.report( output )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001639 elif logLevel == "warn":
kelvin8ec71442015-01-15 16:57:00 -08001640 main.log.warn( output )
Jon Hall42db6dc2014-10-24 19:03:48 -04001641 else:
kelvin8ec71442015-01-15 16:57:00 -08001642 main.log.info( output )
1643 return result
Jon Hall42db6dc2014-10-24 19:03:48 -04001644 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001645 main.log.error( self.name + ": EOF exception found" )
1646 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -04001647 main.cleanup()
1648 main.exit()
1649 except:
kelvin8ec71442015-01-15 16:57:00 -08001650 main.log.info( self.name + " ::::::" )
1651 main.log.error( traceback.print_exc() )
1652 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -04001653 main.cleanup()
1654 main.exit()
Jon Hall1c9e8732014-10-27 19:29:27 -04001655
kelvin-onlabd3b64892015-01-20 13:26:24 -08001656 def deviceRole( self, deviceId, onosNode, role="master" ):
kelvin8ec71442015-01-15 16:57:00 -08001657 """
Jon Hall1c9e8732014-10-27 19:29:27 -04001658 Calls the device-role cli command.
kelvin-onlabd3b64892015-01-20 13:26:24 -08001659 deviceId must be the id of a device as seen in the onos devices command
1660 onosNode is the ip of one of the onos nodes in the cluster
Jon Hall1c9e8732014-10-27 19:29:27 -04001661 role must be either master, standby, or none
1662
Jon Halle3f39ff2015-01-13 11:50:53 -08001663 Returns:
1664 main.TRUE or main.FALSE based on argument verification and
1665 main.ERROR if command returns and error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001666 """
Jon Hall1c9e8732014-10-27 19:29:27 -04001667 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001668 if role.lower() == "master" or role.lower() == "standby" or\
Jon Hall1c9e8732014-10-27 19:29:27 -04001669 role.lower() == "none":
kelvin-onlabd3b64892015-01-20 13:26:24 -08001670 cmdStr = "device-role " +\
1671 str( deviceId ) + " " +\
1672 str( onosNode ) + " " +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001673 str( role )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001674 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001675 if re.search( "Error", handle ):
1676 # end color output to escape any colours
1677 # from the cli
kelvin8ec71442015-01-15 16:57:00 -08001678 main.log.error( self.name + ": " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001679 handle + '\033[0m' )
kelvin8ec71442015-01-15 16:57:00 -08001680 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -08001681 return main.TRUE
Jon Hall1c9e8732014-10-27 19:29:27 -04001682 else:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001683 main.log.error( "Invalid 'role' given to device_role(). " +
1684 "Value was '" + str(role) + "'." )
Jon Hall1c9e8732014-10-27 19:29:27 -04001685 return main.FALSE
Jon Hall1c9e8732014-10-27 19:29:27 -04001686 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001687 main.log.error( self.name + ": EOF exception found" )
1688 main.log.error( self.name + ": " + self.handle.before )
Jon Hall1c9e8732014-10-27 19:29:27 -04001689 main.cleanup()
1690 main.exit()
1691 except:
kelvin8ec71442015-01-15 16:57:00 -08001692 main.log.info( self.name + " ::::::" )
1693 main.log.error( traceback.print_exc() )
1694 main.log.info( self.name + " ::::::" )
Jon Hall1c9e8732014-10-27 19:29:27 -04001695 main.cleanup()
1696 main.exit()
1697
kelvin-onlabd3b64892015-01-20 13:26:24 -08001698 def clusters( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001699 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001700 Lists all clusters
Jon Hallffb386d2014-11-21 13:43:38 -08001701 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001702 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -08001703 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001704 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001705 if jsonFormat:
1706 cmdStr = "clusters -j"
1707 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001708 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001709 handle variable here contains some ANSI escape color code
1710 sequences at the end which are invisible in the print command
Jon Halle3f39ff2015-01-13 11:50:53 -08001711 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -08001712 function. The repr( handle ) output when printed shows the ANSI
1713 escape sequences. In json.loads( somestring ), this somestring
kelvin-onlabd3b64892015-01-20 13:26:24 -08001714 variable is actually repr( somestring ) and json.loads would
1715 fail with the escape sequence. So we take off that escape
1716 sequence using:
Jon Halle3f39ff2015-01-13 11:50:53 -08001717
kelvin-onlabd3b64892015-01-20 13:26:24 -08001718 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1719 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001720 """
kelvin-onlabd3b64892015-01-20 13:26:24 -08001721 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1722 handle1 = ansiEscape.sub( '', handle )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001723 return handle1
1724 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001725 cmdStr = "clusters"
1726 handle = self.sendline( cmdStr )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001727 return handle
1728 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001729 main.log.error( self.name + ": EOF exception found" )
1730 main.log.error( self.name + ": " + self.handle.before )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001731 main.cleanup()
1732 main.exit()
1733 except:
kelvin8ec71442015-01-15 16:57:00 -08001734 main.log.info( self.name + " ::::::" )
1735 main.log.error( traceback.print_exc() )
1736 main.log.info( self.name + " ::::::" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001737 main.cleanup()
1738 main.exit()
1739
kelvin-onlabd3b64892015-01-20 13:26:24 -08001740 def electionTestLeader( self ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001741 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001742 CLI command to get the current leader for the Election test application
1743 NOTE: Requires installation of the onos-app-election feature
1744 Returns: Node IP of the leader if one exists
1745 None if none exists
1746 Main.FALSE on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001747 """
Jon Hall94fd0472014-12-08 11:52:42 -08001748 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001749 cmdStr = "election-test-leader"
1750 response = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001751 # Leader
1752 leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001753 "app\sis\s(?P<node>.+)\."
kelvin-onlabd3b64892015-01-20 13:26:24 -08001754 nodeSearch = re.search( leaderPattern, response )
1755 if nodeSearch:
1756 node = nodeSearch.group( 'node' )
Jon Halle3f39ff2015-01-13 11:50:53 -08001757 main.log.info( "Election-test-leader on " + str( self.name ) +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001758 " found " + node + " as the leader" )
Jon Hall94fd0472014-12-08 11:52:42 -08001759 return node
Jon Halle3f39ff2015-01-13 11:50:53 -08001760 # no leader
1761 nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001762 "the\sElection\sapp"
kelvin-onlabd3b64892015-01-20 13:26:24 -08001763 nullSearch = re.search( nullPattern, response )
1764 if nullSearch:
Jon Halle3f39ff2015-01-13 11:50:53 -08001765 main.log.info( "Election-test-leader found no leader on " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001766 self.name )
Jon Hall94fd0472014-12-08 11:52:42 -08001767 return None
kelvin-onlab898a6c62015-01-16 14:13:53 -08001768 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001769 errorPattern = "Command\snot\sfound"
kelvin-onlab898a6c62015-01-16 14:13:53 -08001770 if re.search( errorPattern, response ):
1771 main.log.error( "Election app is not loaded on " + self.name )
Jon Halle3f39ff2015-01-13 11:50:53 -08001772 # TODO: Should this be main.ERROR?
Jon Hall669173b2014-12-17 11:36:30 -08001773 return main.FALSE
1774 else:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001775 main.log.error( "Error in election_test_leader: " +
1776 "unexpected response" )
kelvin8ec71442015-01-15 16:57:00 -08001777 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001778 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001779 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001780 main.log.error( self.name + ": EOF exception found" )
1781 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001782 main.cleanup()
1783 main.exit()
1784 except:
kelvin8ec71442015-01-15 16:57:00 -08001785 main.log.info( self.name + " ::::::" )
1786 main.log.error( traceback.print_exc() )
1787 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001788 main.cleanup()
1789 main.exit()
1790
kelvin-onlabd3b64892015-01-20 13:26:24 -08001791 def electionTestRun( self ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001792 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001793 CLI command to run for leadership of the Election test application.
1794 NOTE: Requires installation of the onos-app-election feature
1795 Returns: Main.TRUE on success
1796 Main.FALSE on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001797 """
Jon Hall94fd0472014-12-08 11:52:42 -08001798 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001799 cmdStr = "election-test-run"
1800 response = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001801 # success
Jon Halle3f39ff2015-01-13 11:50:53 -08001802 successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001803 "Election\sapp."
Jon Halle3f39ff2015-01-13 11:50:53 -08001804 search = re.search( successPattern, response )
Jon Hall94fd0472014-12-08 11:52:42 -08001805 if search:
Jon Halle3f39ff2015-01-13 11:50:53 -08001806 main.log.info( self.name + " entering leadership elections " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001807 "for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08001808 return main.TRUE
kelvin-onlab898a6c62015-01-16 14:13:53 -08001809 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001810 errorPattern = "Command\snot\sfound"
1811 if re.search( errorPattern, response ):
1812 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08001813 return main.FALSE
1814 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001815 main.log.error( "Error in election_test_run: " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001816 "unexpected response" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001817 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001818 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001819 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001820 main.log.error( self.name + ": EOF exception found" )
1821 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001822 main.cleanup()
1823 main.exit()
1824 except:
kelvin8ec71442015-01-15 16:57:00 -08001825 main.log.info( self.name + " ::::::" )
1826 main.log.error( traceback.print_exc() )
1827 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001828 main.cleanup()
1829 main.exit()
1830
kelvin-onlabd3b64892015-01-20 13:26:24 -08001831 def electionTestWithdraw( self ):
kelvin8ec71442015-01-15 16:57:00 -08001832 """
Jon Hall94fd0472014-12-08 11:52:42 -08001833 * CLI command to withdraw the local node from leadership election for
1834 * the Election test application.
1835 #NOTE: Requires installation of the onos-app-election feature
1836 Returns: Main.TRUE on success
1837 Main.FALSE on error
kelvin8ec71442015-01-15 16:57:00 -08001838 """
Jon Hall94fd0472014-12-08 11:52:42 -08001839 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001840 cmdStr = "election-test-withdraw"
1841 response = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001842 # success
Jon Halle3f39ff2015-01-13 11:50:53 -08001843 successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001844 "\sthe\sElection\sapp."
Jon Halle3f39ff2015-01-13 11:50:53 -08001845 if re.search( successPattern, response ):
1846 main.log.info( self.name + " withdrawing from leadership " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001847 "elections for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08001848 return main.TRUE
kelvin-onlab898a6c62015-01-16 14:13:53 -08001849 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001850 errorPattern = "Command\snot\sfound"
1851 if re.search( errorPattern, response ):
1852 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08001853 return main.FALSE
1854 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001855 main.log.error( "Error in election_test_withdraw: " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001856 "unexpected response" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001857 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001858 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001859 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001860 main.log.error( self.name + ": EOF exception found" )
1861 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001862 main.cleanup()
1863 main.exit()
1864 except:
kelvin8ec71442015-01-15 16:57:00 -08001865 main.log.info( self.name + " ::::::" )
1866 main.log.error( traceback.print_exc() )
1867 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001868 main.cleanup()
1869 main.exit()
Jon Hall1c9e8732014-10-27 19:29:27 -04001870
kelvin8ec71442015-01-15 16:57:00 -08001871 def getDevicePortsEnabledCount( self, dpid ):
1872 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001873 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08001874 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001875 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001876 dpid = str( dpid )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001877 cmdStr = "onos:ports -e " + dpid + " | wc -l"
1878 output = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001879 if re.search( "No such device", output ):
1880 main.log.error( "Error in getting ports" )
1881 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001882 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001883 return output
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001884 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001885 main.log.error( self.name + ": EOF exception found" )
1886 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001887 main.cleanup()
1888 main.exit()
1889 except:
kelvin8ec71442015-01-15 16:57:00 -08001890 main.log.info( self.name + " ::::::" )
1891 main.log.error( traceback.print_exc() )
1892 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001893 main.cleanup()
1894 main.exit()
1895
kelvin8ec71442015-01-15 16:57:00 -08001896 def getDeviceLinksActiveCount( self, dpid ):
1897 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001898 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08001899 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001900 try:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001901 dpid = str( dpid )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001902 cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l"
1903 output = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001904 if re.search( "No such device", output ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001905 main.log.error( "Error in getting ports " )
1906 return ( output, "Error " )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001907 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001908 return output
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001909 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001910 main.log.error( self.name + ": EOF exception found" )
1911 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001912 main.cleanup()
1913 main.exit()
1914 except:
kelvin8ec71442015-01-15 16:57:00 -08001915 main.log.info( self.name + " ::::::" )
1916 main.log.error( traceback.print_exc() )
1917 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001918 main.cleanup()
1919 main.exit()
1920
kelvin8ec71442015-01-15 16:57:00 -08001921 def getAllIntentIds( self ):
1922 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001923 Return a list of all Intent IDs
kelvin8ec71442015-01-15 16:57:00 -08001924 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001925 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001926 cmdStr = "onos:intents | grep id="
1927 output = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001928 if re.search( "Error", output ):
1929 main.log.error( "Error in getting ports" )
1930 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001931 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001932 return output
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001933 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001934 main.log.error( self.name + ": EOF exception found" )
1935 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001936 main.cleanup()
1937 main.exit()
1938 except:
kelvin8ec71442015-01-15 16:57:00 -08001939 main.log.info( self.name + " ::::::" )
1940 main.log.error( traceback.print_exc() )
1941 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001942 main.cleanup()
1943 main.exit()