blob: 93badda216bbb9bccd1b47c3fb3951268b70ad71 [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
47
kelvin8ec71442015-01-15 16:57:00 -080048 self.name = self.options[ 'name' ]
49 self.handle = super( OnosCliDriver, self ).connect(
kelvin-onlab08679eb2015-01-21 16:11:48 -080050 user_name=self.user_name,
51 ip_address=self.ip_address,
kelvin-onlab898a6c62015-01-16 14:13:53 -080052 port=self.port,
53 pwd=self.pwd,
54 home=self.home )
andrewonlab95ce8322014-10-13 14:12:04 -040055
kelvin8ec71442015-01-15 16:57:00 -080056 self.handle.sendline( "cd " + self.home )
57 self.handle.expect( "\$" )
andrewonlab95ce8322014-10-13 14:12:04 -040058 if self.handle:
59 return self.handle
kelvin8ec71442015-01-15 16:57:00 -080060 else:
61 main.log.info( "NO ONOS HANDLE" )
andrewonlab95ce8322014-10-13 14:12:04 -040062 return main.FALSE
63 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080064 main.log.error( self.name + ": EOF exception found" )
65 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -040066 main.cleanup()
67 main.exit()
68 except:
kelvin8ec71442015-01-15 16:57:00 -080069 main.log.info( self.name + ":::::::::::::::::::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -040070 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -080071 main.log.info( ":::::::::::::::::::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -040072 main.cleanup()
73 main.exit()
74
kelvin8ec71442015-01-15 16:57:00 -080075 def disconnect( self ):
76 """
andrewonlab95ce8322014-10-13 14:12:04 -040077 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -080078 """
andrewonlab95ce8322014-10-13 14:12:04 -040079 response = ''
80 try:
kelvin8ec71442015-01-15 16:57:00 -080081 self.handle.sendline( "" )
82 i = self.handle.expect( [ "onos>", "\$" ] )
Jon Hall7e5b9172014-10-22 12:32:47 -040083 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -080084 self.handle.sendline( "system:shutdown" )
85 self.handle.expect( "Confirm" )
86 self.handle.sendline( "yes" )
87 self.handle.expect( "\$" )
88 self.handle.sendline( "" )
89 self.handle.expect( "\$" )
90 self.handle.sendline( "exit" )
91 self.handle.expect( "closed" )
andrewonlabc2d05aa2014-10-13 16:51:10 -040092
andrewonlab95ce8322014-10-13 14:12:04 -040093 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080094 main.log.error( self.name + ": EOF exception found" )
95 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -040096 except:
kelvin8ec71442015-01-15 16:57:00 -080097 main.log.error( self.name + ": Connection failed to the host" )
andrewonlab95ce8322014-10-13 14:12:04 -040098 response = main.FALSE
99 return response
100
kelvin8ec71442015-01-15 16:57:00 -0800101 def logout( self ):
102 """
andrewonlab38d2b4a2014-11-13 16:28:47 -0500103 Sends 'logout' command to ONOS cli
kelvin8ec71442015-01-15 16:57:00 -0800104 """
andrewonlab38d2b4a2014-11-13 16:28:47 -0500105 try:
kelvin8ec71442015-01-15 16:57:00 -0800106 self.handle.sendline( "" )
107 i = self.handle.expect( [
andrewonlab9627f432014-11-14 12:45:10 -0500108 "onos>",
kelvin8ec71442015-01-15 16:57:00 -0800109 "\$" ], timeout=10 )
andrewonlab9627f432014-11-14 12:45:10 -0500110 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800111 self.handle.sendline( "logout" )
112 self.handle.expect( "\$" )
andrewonlab9627f432014-11-14 12:45:10 -0500113 elif i == 1:
114 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800115
andrewonlab38d2b4a2014-11-13 16:28:47 -0500116 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800117 main.log.error( self.name + ": eof exception found" )
118 main.log.error( self.name + ": " +
119 self.handle.before )
andrewonlab38d2b4a2014-11-13 16:28:47 -0500120 main.cleanup()
121 main.exit()
122 except:
kelvin8ec71442015-01-15 16:57:00 -0800123 main.log.info( self.name + " ::::::" )
124 main.log.error( traceback.print_exc() )
125 main.log.info( self.name + " ::::::" )
andrewonlab38d2b4a2014-11-13 16:28:47 -0500126 main.cleanup()
127 main.exit()
128
kelvin-onlabd3b64892015-01-20 13:26:24 -0800129 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800130 """
andrewonlab95ce8322014-10-13 14:12:04 -0400131 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800132
andrewonlab95ce8322014-10-13 14:12:04 -0400133 Before issuing any cli commands, set the environment variable first.
kelvin8ec71442015-01-15 16:57:00 -0800134 """
andrewonlab95ce8322014-10-13 14:12:04 -0400135 try:
136 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800137 main.log.error( "Must define cellname" )
andrewonlab95ce8322014-10-13 14:12:04 -0400138 main.cleanup()
139 main.exit()
140 else:
kelvin8ec71442015-01-15 16:57:00 -0800141 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800142 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800143 # Note that this variable name is subject to change
andrewonlab95ce8322014-10-13 14:12:04 -0400144 # and that this driver will have to change accordingly
kelvin8ec71442015-01-15 16:57:00 -0800145 self.handle.expect( "ONOS_CELL=" + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800146 handleBefore = self.handle.before
147 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800148 # Get the rest of the handle
149 self.handle.sendline( "" )
150 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800151 handleMore = self.handle.before
andrewonlab95ce8322014-10-13 14:12:04 -0400152
kelvin-onlabd3b64892015-01-20 13:26:24 -0800153 main.log.info( "Cell call returned: " + handleBefore +
154 handleAfter + handleMore )
andrewonlab95ce8322014-10-13 14:12:04 -0400155
156 return main.TRUE
157
158 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800159 main.log.error( self.name + ": eof exception found" )
160 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400161 main.cleanup()
162 main.exit()
163 except:
kelvin8ec71442015-01-15 16:57:00 -0800164 main.log.info( self.name + " ::::::" )
165 main.log.error( traceback.print_exc() )
166 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -0400167 main.cleanup()
168 main.exit()
kelvin8ec71442015-01-15 16:57:00 -0800169
pingping-lin57a56ce2015-05-20 16:43:48 -0700170 def startOnosCli( self, ONOSIp, karafTimeout="",
171 commandlineTimeout=10, onosStartTimeout=60 ):
kelvin8ec71442015-01-15 16:57:00 -0800172 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800173 karafTimeout is an optional arugument. karafTimeout value passed
174 by user would be used to set the current karaf shell idle timeout.
175 Note that when ever this property is modified the shell will exit and
Hari Krishnad7b9c202015-01-05 10:38:14 -0800176 the subsequent login would reflect new idle timeout.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800177 Below is an example to start a session with 60 seconds idle timeout
178 ( input value is in milliseconds ):
kelvin8ec71442015-01-15 16:57:00 -0800179
Hari Krishna25d42f72015-01-05 15:08:28 -0800180 tValue = "60000"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800181 main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue )
kelvin8ec71442015-01-15 16:57:00 -0800182
kelvin-onlabd3b64892015-01-20 13:26:24 -0800183 Note: karafTimeout is left as str so that this could be read
184 and passed to startOnosCli from PARAMS file as str.
kelvin8ec71442015-01-15 16:57:00 -0800185 """
andrewonlab95ce8322014-10-13 14:12:04 -0400186 try:
kelvin8ec71442015-01-15 16:57:00 -0800187 self.handle.sendline( "" )
188 x = self.handle.expect( [
pingping-lin57a56ce2015-05-20 16:43:48 -0700189 "\$", "onos>" ], commandlineTimeout)
andrewonlab48829f62014-11-17 13:49:01 -0500190
191 if x == 1:
kelvin8ec71442015-01-15 16:57:00 -0800192 main.log.info( "ONOS cli is already running" )
andrewonlab48829f62014-11-17 13:49:01 -0500193 return main.TRUE
andrewonlab95ce8322014-10-13 14:12:04 -0400194
kelvin8ec71442015-01-15 16:57:00 -0800195 # Wait for onos start ( -w ) and enter onos cli
kelvin-onlabd3b64892015-01-20 13:26:24 -0800196 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800197 i = self.handle.expect( [
198 "onos>",
pingping-lin57a56ce2015-05-20 16:43:48 -0700199 pexpect.TIMEOUT ], onosStartTimeout )
andrewonlab2a7ea9b2014-10-24 12:21:05 -0400200
201 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800202 main.log.info( str( ONOSIp ) + " CLI Started successfully" )
Hari Krishnae36ef212015-01-04 14:09:13 -0800203 if karafTimeout:
kelvin8ec71442015-01-15 16:57:00 -0800204 self.handle.sendline(
Hari Krishnaac4e1782015-01-26 12:09:12 -0800205 "config:property-set -p org.apache.karaf.shell\
206 sshIdleTimeout " +
kelvin8ec71442015-01-15 16:57:00 -0800207 karafTimeout )
208 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800209 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800210 self.handle.expect( "onos>" )
andrewonlab2a7ea9b2014-10-24 12:21:05 -0400211 return main.TRUE
212 else:
kelvin8ec71442015-01-15 16:57:00 -0800213 # If failed, send ctrl+c to process and try again
214 main.log.info( "Starting CLI failed. Retrying..." )
215 self.handle.send( "\x03" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800216 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800217 i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ],
218 timeout=30 )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400219 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800220 main.log.info( str( ONOSIp ) + " CLI Started " +
kelvin8ec71442015-01-15 16:57:00 -0800221 "successfully after retry attempt" )
Hari Krishnae36ef212015-01-04 14:09:13 -0800222 if karafTimeout:
kelvin8ec71442015-01-15 16:57:00 -0800223 self.handle.sendline(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800224 "config:property-set -p org.apache.karaf.shell\
225 sshIdleTimeout " +
kelvin8ec71442015-01-15 16:57:00 -0800226 karafTimeout )
227 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800228 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800229 self.handle.expect( "onos>" )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400230 return main.TRUE
231 else:
kelvin8ec71442015-01-15 16:57:00 -0800232 main.log.error( "Connection to CLI " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800233 str( ONOSIp ) + " timeout" )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400234 return main.FALSE
andrewonlab95ce8322014-10-13 14:12:04 -0400235
236 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800237 main.log.error( self.name + ": EOF exception found" )
238 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400239 main.cleanup()
240 main.exit()
241 except:
kelvin8ec71442015-01-15 16:57:00 -0800242 main.log.info( self.name + " ::::::" )
243 main.log.error( traceback.print_exc() )
244 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -0400245 main.cleanup()
246 main.exit()
247
kelvin-onlabd3b64892015-01-20 13:26:24 -0800248 def sendline( self, cmdStr ):
kelvin8ec71442015-01-15 16:57:00 -0800249 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800250 Send a completely user specified string to
251 the onos> prompt. Use this function if you have
andrewonlaba18f6bf2014-10-13 19:31:54 -0400252 a very specific command to send.
Jon Halle3f39ff2015-01-13 11:50:53 -0800253
andrewonlaba18f6bf2014-10-13 19:31:54 -0400254 Warning: There are no sanity checking to commands
255 sent using this method.
kelvin8ec71442015-01-15 16:57:00 -0800256 """
andrewonlaba18f6bf2014-10-13 19:31:54 -0400257 try:
kelvin8ec71442015-01-15 16:57:00 -0800258 self.handle.sendline( "" )
259 self.handle.expect( "onos>" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400260
kelvin-onlab898a6c62015-01-16 14:13:53 -0800261 self.handle.sendline( "log:log \"Sending CLI command: '"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800262 + cmdStr + "'\"" )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800263 self.handle.expect( "onos>" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800264 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -0800265 self.handle.expect( "onos>" )
Jon Hallaea67aa2015-01-23 13:30:57 -0800266 main.log.info( "Command '" + str( cmdStr ) + "' sent to "
267 + self.name + "." )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400268
269 handle = self.handle.before
Jon Hall7bdfc122015-01-23 11:45:32 -0800270 # Remove control strings from output
271 ansiEscape = re.compile( r'\x1b[^m]*m' )
272 handle = ansiEscape.sub( '', handle )
Jon Hall44225f82015-01-23 13:45:14 -0800273 #Remove extra return chars that get added
Jon Hallaea67aa2015-01-23 13:30:57 -0800274 handle = re.sub( r"\s\r", "", handle )
275 handle = handle.strip()
Jon Hall7bdfc122015-01-23 11:45:32 -0800276 # parse for just the output, remove the cmd from handle
277 output = handle.split( cmdStr, 1 )[1]
kelvin8ec71442015-01-15 16:57:00 -0800278
andrewonlaba18f6bf2014-10-13 19:31:54 -0400279
Jon Hall7bdfc122015-01-23 11:45:32 -0800280 return output
andrewonlaba18f6bf2014-10-13 19:31:54 -0400281 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800282 main.log.error( self.name + ": EOF exception found" )
283 main.log.error( self.name + ": " + self.handle.before )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400284 main.cleanup()
285 main.exit()
286 except:
kelvin8ec71442015-01-15 16:57:00 -0800287 main.log.info( self.name + " ::::::" )
288 main.log.error( traceback.print_exc() )
289 main.log.info( self.name + " ::::::" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400290 main.cleanup()
291 main.exit()
292
kelvin8ec71442015-01-15 16:57:00 -0800293 # IMPORTANT NOTE:
294 # For all cli commands, naming convention should match
kelvin-onlabd3b64892015-01-20 13:26:24 -0800295 # the cli command changing 'a:b' with 'aB'.
296 # Ex ) onos:topology > onosTopology
297 # onos:links > onosLinks
298 # feature:list > featureList
Jon Halle3f39ff2015-01-13 11:50:53 -0800299
kelvin-onlabd3b64892015-01-20 13:26:24 -0800300 def addNode( self, nodeId, ONOSIp, tcpPort="" ):
kelvin8ec71442015-01-15 16:57:00 -0800301 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400302 Adds a new cluster node by ID and address information.
303 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800304 * nodeId
305 * ONOSIp
andrewonlabc2d05aa2014-10-13 16:51:10 -0400306 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800307 * tcpPort
kelvin8ec71442015-01-15 16:57:00 -0800308 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400309 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800310 cmdStr = "add-node " + str( nodeId ) + " " +\
311 str( ONOSIp ) + " " + str( tcpPort )
312 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800313 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -0800314 main.log.error( "Error in adding node" )
315 main.log.error( handle )
Jon Halle3f39ff2015-01-13 11:50:53 -0800316 return main.FALSE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400317 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800318 main.log.info( "Node " + str( ONOSIp ) + " added" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400319 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400320 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800321 main.log.error( self.name + ": EOF exception found" )
322 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400323 main.cleanup()
324 main.exit()
325 except:
kelvin8ec71442015-01-15 16:57:00 -0800326 main.log.info( self.name + " ::::::" )
327 main.log.error( traceback.print_exc() )
328 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400329 main.cleanup()
330 main.exit()
331
kelvin-onlabd3b64892015-01-20 13:26:24 -0800332 def removeNode( self, nodeId ):
kelvin8ec71442015-01-15 16:57:00 -0800333 """
andrewonlab86dc3082014-10-13 18:18:38 -0400334 Removes a cluster by ID
335 Issues command: 'remove-node [<node-id>]'
336 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800337 * nodeId
kelvin8ec71442015-01-15 16:57:00 -0800338 """
andrewonlab86dc3082014-10-13 18:18:38 -0400339 try:
andrewonlab86dc3082014-10-13 18:18:38 -0400340
kelvin-onlabd3b64892015-01-20 13:26:24 -0800341 cmdStr = "remove-node " + str( nodeId )
342 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800343 # TODO: add error checking. Does ONOS give any errors?
andrewonlab86dc3082014-10-13 18:18:38 -0400344
345 return main.TRUE
Jon Halle3f39ff2015-01-13 11:50:53 -0800346
andrewonlab86dc3082014-10-13 18:18:38 -0400347 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800348 main.log.error( self.name + ": EOF exception found" )
349 main.log.error( self.name + ": " + self.handle.before )
andrewonlab86dc3082014-10-13 18:18:38 -0400350 main.cleanup()
351 main.exit()
352 except:
kelvin8ec71442015-01-15 16:57:00 -0800353 main.log.info( self.name + " ::::::" )
354 main.log.error( traceback.print_exc() )
355 main.log.info( self.name + " ::::::" )
andrewonlab86dc3082014-10-13 18:18:38 -0400356 main.cleanup()
357 main.exit()
andrewonlabc2d05aa2014-10-13 16:51:10 -0400358
kelvin8ec71442015-01-15 16:57:00 -0800359 def nodes( self ):
360 """
andrewonlab7c211572014-10-15 16:45:20 -0400361 List the nodes currently visible
362 Issues command: 'nodes'
363 Returns: entire handle of list of nodes
kelvin8ec71442015-01-15 16:57:00 -0800364 """
andrewonlab7c211572014-10-15 16:45:20 -0400365 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800366 cmdStr = "nodes"
367 handle = self.sendline( cmdStr )
andrewonlab7c211572014-10-15 16:45:20 -0400368 return handle
andrewonlab7c211572014-10-15 16:45:20 -0400369 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800370 main.log.error( self.name + ": EOF exception found" )
371 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -0400372 main.cleanup()
373 main.exit()
374 except:
kelvin8ec71442015-01-15 16:57:00 -0800375 main.log.info( self.name + " ::::::" )
376 main.log.error( traceback.print_exc() )
377 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -0400378 main.cleanup()
379 main.exit()
380
kelvin8ec71442015-01-15 16:57:00 -0800381 def topology( self ):
382 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400383 Shows the current state of the topology
384 by issusing command: 'onos> onos:topology'
kelvin8ec71442015-01-15 16:57:00 -0800385 """
andrewonlab95ce8322014-10-13 14:12:04 -0400386 try:
Jon Halle3f39ff2015-01-13 11:50:53 -0800387 # either onos:topology or 'topology' will work in CLI
kelvin-onlabd3b64892015-01-20 13:26:24 -0800388 cmdStr = "onos:topology"
389 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800390 main.log.info( "onos:topology returned: " + str( handle ) )
andrewonlab95ce8322014-10-13 14:12:04 -0400391 return handle
andrewonlab95ce8322014-10-13 14:12:04 -0400392 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800393 main.log.error( self.name + ": EOF exception found" )
394 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400395 main.cleanup()
396 main.exit()
397 except:
kelvin8ec71442015-01-15 16:57:00 -0800398 main.log.info( self.name + " ::::::" )
399 main.log.error( traceback.print_exc() )
400 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -0400401 main.cleanup()
402 main.exit()
Jon Halle3f39ff2015-01-13 11:50:53 -0800403
kelvin-onlabd3b64892015-01-20 13:26:24 -0800404 def featureInstall( self, featureStr ):
kelvin8ec71442015-01-15 16:57:00 -0800405 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800406 Installs a specified feature
andrewonlabc2d05aa2014-10-13 16:51:10 -0400407 by issuing command: 'onos> feature:install <feature_str>'
kelvin8ec71442015-01-15 16:57:00 -0800408 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400409 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800410 cmdStr = "feature:install " + str( featureStr )
411 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800412 # TODO: Check for possible error responses from karaf
andrewonlabc2d05aa2014-10-13 16:51:10 -0400413 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400414 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800415 main.log.error( self.name + ": EOF exception found" )
416 main.log.error( self.name + ": " + self.handle.before )
417 main.log.report( "Failed to install feature" )
418 main.log.report( "Exiting test" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400419 main.cleanup()
420 main.exit()
421 except:
kelvin8ec71442015-01-15 16:57:00 -0800422 main.log.info( self.name + " ::::::" )
423 main.log.error( traceback.print_exc() )
424 main.log.report( "Failed to install feature" )
425 main.log.report( "Exiting test" )
426 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400427 main.cleanup()
428 main.exit()
Jon Halle3f39ff2015-01-13 11:50:53 -0800429
kelvin-onlabd3b64892015-01-20 13:26:24 -0800430 def featureUninstall( self, featureStr ):
kelvin8ec71442015-01-15 16:57:00 -0800431 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400432 Uninstalls a specified feature
433 by issuing command: 'onos> feature:uninstall <feature_str>'
kelvin8ec71442015-01-15 16:57:00 -0800434 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400435 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800436 cmdStr = "feature:uninstall " + str( featureStr )
437 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800438 # TODO: Check for possible error responses from karaf
andrewonlabc2d05aa2014-10-13 16:51:10 -0400439 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400440 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800441 main.log.error( self.name + ": EOF exception found" )
442 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400443 main.cleanup()
444 main.exit()
445 except:
kelvin8ec71442015-01-15 16:57:00 -0800446 main.log.info( self.name + " ::::::" )
447 main.log.error( traceback.print_exc() )
448 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400449 main.cleanup()
450 main.exit()
Jon Hallffb386d2014-11-21 13:43:38 -0800451
kelvin-onlabd3b64892015-01-20 13:26:24 -0800452 def devices( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800453 """
Jon Hall7b02d952014-10-17 20:14:54 -0400454 Lists all infrastructure devices or switches
andrewonlab86dc3082014-10-13 18:18:38 -0400455 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800456 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800457 """
andrewonlab86dc3082014-10-13 18:18:38 -0400458 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800459 if jsonFormat:
460 cmdStr = "devices -j"
461 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800462 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800463 handle variable here contains some ANSI escape color code
464 sequences at the end which are invisible in the print command
465 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800466 function. The repr( handle ) output when printed shows the
467 ANSI escape sequences. In json.loads( somestring ), this
468 somestring variable is actually repr( somestring ) and
Jon Halle3f39ff2015-01-13 11:50:53 -0800469 json.loads would fail with the escape sequence. So we take off
470 that escape sequence using:
471
kelvin-onlabd3b64892015-01-20 13:26:24 -0800472 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
473 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800474 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800475 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
476 handle1 = ansiEscape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400477 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400478 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800479 cmdStr = "devices"
480 handle = self.sendline( cmdStr )
Jon Hallcd707292014-10-17 19:06:17 -0400481 return handle
andrewonlab7c211572014-10-15 16:45:20 -0400482 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800483 main.log.error( self.name + ": EOF exception found" )
484 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -0400485 main.cleanup()
486 main.exit()
487 except:
kelvin8ec71442015-01-15 16:57:00 -0800488 main.log.info( self.name + " ::::::" )
489 main.log.error( traceback.print_exc() )
490 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -0400491 main.cleanup()
492 main.exit()
493
kelvin-onlabd3b64892015-01-20 13:26:24 -0800494 def balanceMasters( self ):
kelvin8ec71442015-01-15 16:57:00 -0800495 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800496 This balances the devices across all controllers
497 by issuing command: 'onos> onos:balance-masters'
498 If required this could be extended to return devices balanced output.
kelvin8ec71442015-01-15 16:57:00 -0800499 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800500 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800501 cmdStr = "onos:balance-masters"
502 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800503 # TODO: Check for error responses from ONOS
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800504 return main.TRUE
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800505 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800506 main.log.error( self.name + ": EOF exception found" )
507 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800508 main.cleanup()
509 main.exit()
510 except:
kelvin8ec71442015-01-15 16:57:00 -0800511 main.log.info( self.name + " ::::::" )
512 main.log.error( traceback.print_exc() )
513 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800514 main.cleanup()
515 main.exit()
516
kelvin-onlabd3b64892015-01-20 13:26:24 -0800517 def links( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800518 """
Jon Halle8217482014-10-17 13:49:14 -0400519 Lists all core links
520 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800521 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800522 """
Jon Halle8217482014-10-17 13:49:14 -0400523 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800524 if jsonFormat:
525 cmdStr = "links -j"
526 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800527 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800528 handle variable here contains some ANSI escape color code
529 sequences at the end which are invisible in the print command
530 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800531 function. The repr( handle ) output when printed shows the ANSI
532 escape sequences. In json.loads( somestring ), this somestring
533 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800534 fail with the escape sequence. So we take off that escape
535 sequence using:
536
kelvin-onlabd3b64892015-01-20 13:26:24 -0800537 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
538 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800539 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800540 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
541 handle1 = ansiEscape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400542 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400543 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800544 cmdStr = "links"
545 handle = self.sendline( cmdStr )
Jon Halla001c392014-10-17 18:50:59 -0400546 return handle
Jon Halle8217482014-10-17 13:49:14 -0400547 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800548 main.log.error( self.name + ": EOF exception found" )
549 main.log.error( self.name + ": " + self.handle.before )
Jon Halle8217482014-10-17 13:49:14 -0400550 main.cleanup()
551 main.exit()
552 except:
kelvin8ec71442015-01-15 16:57:00 -0800553 main.log.info( self.name + " ::::::" )
554 main.log.error( traceback.print_exc() )
555 main.log.info( self.name + " ::::::" )
Jon Halle8217482014-10-17 13:49:14 -0400556 main.cleanup()
557 main.exit()
558
kelvin-onlabd3b64892015-01-20 13:26:24 -0800559 def ports( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800560 """
Jon Halle8217482014-10-17 13:49:14 -0400561 Lists all ports
562 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800563 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800564 """
Jon Halle8217482014-10-17 13:49:14 -0400565 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800566 if jsonFormat:
567 cmdStr = "ports -j"
568 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800569 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800570 handle variable here contains some ANSI escape color code
571 sequences at the end which are invisible in the print command
572 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800573 function. The repr( handle ) output when printed shows the ANSI
574 escape sequences. In json.loads( somestring ), this somestring
575 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800576 fail with the escape sequence. So we take off that escape
577 sequence using the following commads:
578
kelvin-onlabd3b64892015-01-20 13:26:24 -0800579 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
580 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800581 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800582 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
583 handle1 = ansiEscape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400584 return handle1
585
Jon Halle8217482014-10-17 13:49:14 -0400586 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800587 cmdStr = "ports"
588 handle = self.sendline( cmdStr )
Jon Hallffb386d2014-11-21 13:43:38 -0800589 return handle
Jon Halle8217482014-10-17 13:49:14 -0400590 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800591 main.log.error( self.name + ": EOF exception found" )
592 main.log.error( self.name + ": " + self.handle.before )
Jon Halle8217482014-10-17 13:49:14 -0400593 main.cleanup()
594 main.exit()
595 except:
kelvin8ec71442015-01-15 16:57:00 -0800596 main.log.info( self.name + " ::::::" )
597 main.log.error( traceback.print_exc() )
598 main.log.info( self.name + " ::::::" )
Jon Halle8217482014-10-17 13:49:14 -0400599 main.cleanup()
600 main.exit()
601
kelvin-onlabd3b64892015-01-20 13:26:24 -0800602 def roles( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800603 """
Jon Hall983a1702014-10-28 18:44:22 -0400604 Lists all devices and the controllers with roles assigned to them
605 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800606 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800607 """
andrewonlab7c211572014-10-15 16:45:20 -0400608 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800609 if jsonFormat:
610 cmdStr = "roles -j"
611 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800612 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800613 handle variable here contains some ANSI escape color code
614 sequences at the end which are invisible in the print command
615 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800616 function. The repr( handle ) output when printed shows the ANSI
617 escape sequences. In json.loads( somestring ), this somestring
618 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800619 fail with the escape sequence.
Jon Hallb1290e82014-11-18 16:17:48 -0500620
Jon Halle3f39ff2015-01-13 11:50:53 -0800621 So we take off that escape sequence using the following
622 commads:
623
kelvin-onlabd3b64892015-01-20 13:26:24 -0800624 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
625 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800626 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800627 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
628 handle1 = ansiEscape.sub( '', handle )
Jon Hall983a1702014-10-28 18:44:22 -0400629 return handle1
andrewonlab7c211572014-10-15 16:45:20 -0400630
andrewonlab7c211572014-10-15 16:45:20 -0400631 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800632 cmdStr = "roles"
633 handle = self.sendline( cmdStr )
Jon Hallffb386d2014-11-21 13:43:38 -0800634 return handle
Jon Hall983a1702014-10-28 18:44:22 -0400635 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800636 main.log.error( self.name + ": EOF exception found" )
637 main.log.error( self.name + ": " + self.handle.before )
Jon Hall983a1702014-10-28 18:44:22 -0400638 main.cleanup()
639 main.exit()
640 except:
kelvin8ec71442015-01-15 16:57:00 -0800641 main.log.info( self.name + " ::::::" )
642 main.log.error( traceback.print_exc() )
643 main.log.info( self.name + " ::::::" )
Jon Hall983a1702014-10-28 18:44:22 -0400644 main.cleanup()
645 main.exit()
646
kelvin-onlabd3b64892015-01-20 13:26:24 -0800647 def getRole( self, deviceId ):
kelvin-onlab898a6c62015-01-16 14:13:53 -0800648 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800649 Given the a string containing the json representation of the "roles"
650 cli command and a partial or whole device id, returns a json object
651 containing the roles output for the first device whose id contains
652 "device_id"
Jon Hall983a1702014-10-28 18:44:22 -0400653
654 Returns:
Jon Halle3f39ff2015-01-13 11:50:53 -0800655 A dict of the role assignments for the given device or
656 None if no match
kelvin8ec71442015-01-15 16:57:00 -0800657 """
Jon Hall983a1702014-10-28 18:44:22 -0400658 try:
659 import json
kelvin-onlabd3b64892015-01-20 13:26:24 -0800660 if deviceId is None:
Jon Hall983a1702014-10-28 18:44:22 -0400661 return None
662 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800663 rawRoles = self.roles()
664 rolesJson = json.loads( rawRoles )
kelvin8ec71442015-01-15 16:57:00 -0800665 # search json for the device with id then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800666 for device in rolesJson:
kelvin8ec71442015-01-15 16:57:00 -0800667 # print device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800668 if str( deviceId ) in device[ 'id' ]:
Jon Hall983a1702014-10-28 18:44:22 -0400669 return device
670 return None
andrewonlab7c211572014-10-15 16:45:20 -0400671
andrewonlab86dc3082014-10-13 18:18:38 -0400672 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800673 main.log.error( self.name + ": EOF exception found" )
674 main.log.error( self.name + ": " + self.handle.before )
andrewonlab86dc3082014-10-13 18:18:38 -0400675 main.cleanup()
676 main.exit()
677 except:
kelvin8ec71442015-01-15 16:57:00 -0800678 main.log.info( self.name + " ::::::" )
679 main.log.error( traceback.print_exc() )
680 main.log.info( self.name + " ::::::" )
andrewonlab86dc3082014-10-13 18:18:38 -0400681 main.cleanup()
682 main.exit()
Jon Hall94fd0472014-12-08 11:52:42 -0800683
kelvin-onlabd3b64892015-01-20 13:26:24 -0800684 def rolesNotNull( self ):
kelvin8ec71442015-01-15 16:57:00 -0800685 """
Jon Hall94fd0472014-12-08 11:52:42 -0800686 Iterates through each device and checks if there is a master assigned
687 Returns: main.TRUE if each device has a master
688 main.FALSE any device has no master
kelvin8ec71442015-01-15 16:57:00 -0800689 """
Jon Hall94fd0472014-12-08 11:52:42 -0800690 try:
691 import json
kelvin-onlabd3b64892015-01-20 13:26:24 -0800692 rawRoles = self.roles()
693 rolesJson = json.loads( rawRoles )
kelvin8ec71442015-01-15 16:57:00 -0800694 # search json for the device with id then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800695 for device in rolesJson:
kelvin8ec71442015-01-15 16:57:00 -0800696 # print device
697 if device[ 'master' ] == "none":
698 main.log.warn( "Device has no master: " + str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800699 return main.FALSE
700 return main.TRUE
701
702 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800703 main.log.error( self.name + ": EOF exception found" )
704 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -0800705 main.cleanup()
706 main.exit()
707 except:
kelvin8ec71442015-01-15 16:57:00 -0800708 main.log.info( self.name + " ::::::" )
709 main.log.error( traceback.print_exc() )
710 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -0800711 main.cleanup()
712 main.exit()
713
kelvin-onlabd3b64892015-01-20 13:26:24 -0800714 def paths( self, srcId, dstId ):
kelvin8ec71442015-01-15 16:57:00 -0800715 """
andrewonlab3e15ead2014-10-15 14:21:34 -0400716 Returns string of paths, and the cost.
717 Issues command: onos:paths <src> <dst>
kelvin8ec71442015-01-15 16:57:00 -0800718 """
andrewonlab3e15ead2014-10-15 14:21:34 -0400719 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800720 cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId )
721 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800722 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -0800723 main.log.error( "Error in getting paths" )
724 return ( handle, "Error" )
andrewonlab3e15ead2014-10-15 14:21:34 -0400725 else:
kelvin8ec71442015-01-15 16:57:00 -0800726 path = handle.split( ";" )[ 0 ]
727 cost = handle.split( ";" )[ 1 ]
728 return ( path, cost )
andrewonlab3e15ead2014-10-15 14:21:34 -0400729 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800730 main.log.error( self.name + ": EOF exception found" )
731 main.log.error( self.name + ": " + self.handle.before )
andrewonlab3e15ead2014-10-15 14:21:34 -0400732 main.cleanup()
733 main.exit()
734 except:
kelvin8ec71442015-01-15 16:57:00 -0800735 main.log.info( self.name + " ::::::" )
736 main.log.error( traceback.print_exc() )
737 main.log.info( self.name + " ::::::" )
andrewonlab3e15ead2014-10-15 14:21:34 -0400738 main.cleanup()
739 main.exit()
Jon Hallffb386d2014-11-21 13:43:38 -0800740
kelvin-onlabd3b64892015-01-20 13:26:24 -0800741 def hosts( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800742 """
Jon Hallffb386d2014-11-21 13:43:38 -0800743 Lists all discovered hosts
Jon Hall42db6dc2014-10-24 19:03:48 -0400744 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800745 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800746 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400747 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800748 if jsonFormat:
749 cmdStr = "hosts -j"
750 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800751 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800752 handle variable here contains some ANSI escape color code
753 sequences at the end which are invisible in the print command
754 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800755 function. The repr( handle ) output when printed shows the ANSI
756 escape sequences. In json.loads( somestring ), this somestring
757 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800758 fail with the escape sequence. So we take off that escape
759 sequence using:
760
kelvin-onlabd3b64892015-01-20 13:26:24 -0800761 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
762 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800763 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800764 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
765 handle1 = ansiEscape.sub( '', handle )
Jon Hall42db6dc2014-10-24 19:03:48 -0400766 return handle1
767 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800768 cmdStr = "hosts"
769 handle = self.sendline( cmdStr )
Jon Hall42db6dc2014-10-24 19:03:48 -0400770 return handle
771 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800772 main.log.error( self.name + ": EOF exception found" )
773 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -0400774 main.cleanup()
775 main.exit()
776 except:
kelvin8ec71442015-01-15 16:57:00 -0800777 main.log.info( self.name + " ::::::" )
778 main.log.error( traceback.print_exc() )
779 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -0400780 main.cleanup()
781 main.exit()
782
kelvin-onlabd3b64892015-01-20 13:26:24 -0800783 def getHost( self, mac ):
kelvin8ec71442015-01-15 16:57:00 -0800784 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400785 Return the first host from the hosts api whose 'id' contains 'mac'
Jon Halle3f39ff2015-01-13 11:50:53 -0800786
787 Note: mac must be a colon seperated mac address, but could be a
788 partial mac address
789
Jon Hall42db6dc2014-10-24 19:03:48 -0400790 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -0800791 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400792 import json
793 try:
kelvin8ec71442015-01-15 16:57:00 -0800794 if mac is None:
Jon Hall42db6dc2014-10-24 19:03:48 -0400795 return None
796 else:
797 mac = mac
kelvin-onlabd3b64892015-01-20 13:26:24 -0800798 rawHosts = self.hosts()
799 hostsJson = json.loads( rawHosts )
kelvin8ec71442015-01-15 16:57:00 -0800800 # search json for the host with mac then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800801 for host in hostsJson:
kelvin8ec71442015-01-15 16:57:00 -0800802 # print "%s in %s?" % ( mac, host[ 'id' ] )
803 if mac in host[ 'id' ]:
Jon Hall42db6dc2014-10-24 19:03:48 -0400804 return host
805 return None
806 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800807 main.log.error( self.name + ": EOF exception found" )
808 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -0400809 main.cleanup()
810 main.exit()
811 except:
kelvin8ec71442015-01-15 16:57:00 -0800812 main.log.info( self.name + " ::::::" )
813 main.log.error( traceback.print_exc() )
814 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -0400815 main.cleanup()
816 main.exit()
817
kelvin-onlabd3b64892015-01-20 13:26:24 -0800818 def getHostsId( self, hostList ):
kelvin8ec71442015-01-15 16:57:00 -0800819 """
820 Obtain list of hosts
andrewonlab3f0a4af2014-10-17 12:25:14 -0400821 Issues command: 'onos> hosts'
kelvin8ec71442015-01-15 16:57:00 -0800822
andrewonlab3f0a4af2014-10-17 12:25:14 -0400823 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800824 * hostList: List of hosts obtained by Mininet
andrewonlab3f0a4af2014-10-17 12:25:14 -0400825 IMPORTANT:
826 This function assumes that you started your
kelvin8ec71442015-01-15 16:57:00 -0800827 topology with the option '--mac'.
andrewonlab3f0a4af2014-10-17 12:25:14 -0400828 Furthermore, it assumes that value of VLAN is '-1'
829 Description:
kelvin8ec71442015-01-15 16:57:00 -0800830 Converts mininet hosts ( h1, h2, h3... ) into
831 ONOS format ( 00:00:00:00:00:01/-1 , ... )
832 """
andrewonlab3f0a4af2014-10-17 12:25:14 -0400833 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800834 onosHostList = []
andrewonlab3f0a4af2014-10-17 12:25:14 -0400835
kelvin-onlabd3b64892015-01-20 13:26:24 -0800836 for host in hostList:
kelvin8ec71442015-01-15 16:57:00 -0800837 host = host.replace( "h", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800838 hostHex = hex( int( host ) ).zfill( 12 )
839 hostHex = str( hostHex ).replace( 'x', '0' )
840 i = iter( str( hostHex ) )
841 hostHex = ":".join( a + b for a, b in zip( i, i ) )
842 hostHex = hostHex + "/-1"
843 onosHostList.append( hostHex )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400844
kelvin-onlabd3b64892015-01-20 13:26:24 -0800845 return onosHostList
andrewonlab3f0a4af2014-10-17 12:25:14 -0400846
847 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800848 main.log.error( self.name + ": EOF exception found" )
849 main.log.error( self.name + ": " + self.handle.before )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400850 main.cleanup()
851 main.exit()
852 except:
kelvin8ec71442015-01-15 16:57:00 -0800853 main.log.info( self.name + " ::::::" )
854 main.log.error( traceback.print_exc() )
855 main.log.info( self.name + " ::::::" )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400856 main.cleanup()
857 main.exit()
andrewonlab3e15ead2014-10-15 14:21:34 -0400858
kelvin-onlabd3b64892015-01-20 13:26:24 -0800859 def addHostIntent( self, hostIdOne, hostIdTwo ):
kelvin8ec71442015-01-15 16:57:00 -0800860 """
andrewonlabe6745342014-10-17 14:29:13 -0400861 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800862 * hostIdOne: ONOS host id for host1
863 * hostIdTwo: ONOS host id for host2
andrewonlabe6745342014-10-17 14:29:13 -0400864 Description:
kelvin8ec71442015-01-15 16:57:00 -0800865 Adds a host-to-host intent ( bidrectional ) by
Jon Hallb1290e82014-11-18 16:17:48 -0500866 specifying the two hosts.
kelvin8ec71442015-01-15 16:57:00 -0800867 """
andrewonlabe6745342014-10-17 14:29:13 -0400868 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800869 cmdStr = "add-host-intent " + str( hostIdOne ) +\
870 " " + str( hostIdTwo )
871 handle = self.sendline( cmdStr )
Hari Krishnaac4e1782015-01-26 12:09:12 -0800872 if re.search( "Error", handle ):
873 main.log.error( "Error in adding Host intent" )
874 return handle
875 else:
876 main.log.info( "Host intent installed between " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800877 str( hostIdOne ) + " and " + str( hostIdTwo ) )
Hari Krishnaac4e1782015-01-26 12:09:12 -0800878 return main.TRUE
879
andrewonlabe6745342014-10-17 14:29:13 -0400880 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800881 main.log.error( self.name + ": EOF exception found" )
882 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe6745342014-10-17 14:29:13 -0400883 main.cleanup()
884 main.exit()
885 except:
kelvin8ec71442015-01-15 16:57:00 -0800886 main.log.info( self.name + " ::::::" )
887 main.log.error( traceback.print_exc() )
888 main.log.info( self.name + " ::::::" )
andrewonlabe6745342014-10-17 14:29:13 -0400889 main.cleanup()
890 main.exit()
891
kelvin-onlabd3b64892015-01-20 13:26:24 -0800892 def addOpticalIntent( self, ingressDevice, egressDevice ):
kelvin8ec71442015-01-15 16:57:00 -0800893 """
andrewonlab7b31d232014-10-24 13:31:47 -0400894 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800895 * ingressDevice: device id of ingress device
896 * egressDevice: device id of egress device
andrewonlab7b31d232014-10-24 13:31:47 -0400897 Optional:
898 TODO: Still needs to be implemented via dev side
kelvin-onlab898a6c62015-01-16 14:13:53 -0800899 """
andrewonlab7b31d232014-10-24 13:31:47 -0400900 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800901 cmdStr = "add-optical-intent " + str( ingressDevice ) +\
902 " " + str( egressDevice )
903 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800904 # If error, return error message
Jon Halle3f39ff2015-01-13 11:50:53 -0800905 if re.search( "Error", handle ):
andrewonlab7b31d232014-10-24 13:31:47 -0400906 return handle
907 else:
908 return main.TRUE
andrewonlab7b31d232014-10-24 13:31:47 -0400909 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800910 main.log.error( self.name + ": EOF exception found" )
911 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7b31d232014-10-24 13:31:47 -0400912 main.cleanup()
913 main.exit()
914 except:
kelvin8ec71442015-01-15 16:57:00 -0800915 main.log.info( self.name + " ::::::" )
916 main.log.error( traceback.print_exc() )
917 main.log.info( self.name + " ::::::" )
andrewonlab7b31d232014-10-24 13:31:47 -0400918 main.cleanup()
919 main.exit()
920
kelvin-onlabd3b64892015-01-20 13:26:24 -0800921 def addPointIntent(
kelvin-onlab898a6c62015-01-16 14:13:53 -0800922 self,
kelvin-onlabd3b64892015-01-20 13:26:24 -0800923 ingressDevice,
924 egressDevice,
925 portIngress="",
926 portEgress="",
kelvin-onlab898a6c62015-01-16 14:13:53 -0800927 ethType="",
928 ethSrc="",
929 ethDst="",
930 bandwidth="",
kelvin-onlabd3b64892015-01-20 13:26:24 -0800931 lambdaAlloc=False,
kelvin-onlab898a6c62015-01-16 14:13:53 -0800932 ipProto="",
933 ipSrc="",
934 ipDst="",
935 tcpSrc="",
936 tcpDst="" ):
kelvin8ec71442015-01-15 16:57:00 -0800937 """
andrewonlab4dbb4d82014-10-17 18:22:31 -0400938 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800939 * ingressDevice: device id of ingress device
940 * egressDevice: device id of egress device
andrewonlab289e4b72014-10-21 21:24:18 -0400941 Optional:
942 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -0800943 * ethSrc: specify ethSrc ( i.e. src mac addr )
944 * ethDst: specify ethDst ( i.e. dst mac addr )
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500945 * bandwidth: specify bandwidth capacity of link
kelvin-onlabd3b64892015-01-20 13:26:24 -0800946 * lambdaAlloc: if True, intent will allocate lambda
andrewonlab40ccd8b2014-11-06 16:23:34 -0500947 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -0800948 * ipProto: specify ip protocol
andrewonlabf77e0cb2014-11-11 17:17:59 -0500949 * ipSrc: specify ip source address
950 * ipDst: specify ip destination address
951 * tcpSrc: specify tcp source port
952 * tcpDst: specify tcp destination port
andrewonlab4dbb4d82014-10-17 18:22:31 -0400953 Description:
kelvin8ec71442015-01-15 16:57:00 -0800954 Adds a point-to-point intent ( uni-directional ) by
andrewonlab289e4b72014-10-21 21:24:18 -0400955 specifying device id's and optional fields
956
Jon Halle3f39ff2015-01-13 11:50:53 -0800957 NOTE: This function may change depending on the
andrewonlab4dbb4d82014-10-17 18:22:31 -0400958 options developers provide for point-to-point
959 intent via cli
kelvin8ec71442015-01-15 16:57:00 -0800960 """
andrewonlab4dbb4d82014-10-17 18:22:31 -0400961 try:
andrewonlab289e4b72014-10-21 21:24:18 -0400962 cmd = ""
963
kelvin8ec71442015-01-15 16:57:00 -0800964 # If there are no optional arguments
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500965 if not ethType and not ethSrc and not ethDst\
kelvin-onlabd3b64892015-01-20 13:26:24 -0800966 and not bandwidth and not lambdaAlloc \
andrewonlabfa4ff502014-11-11 16:41:30 -0500967 and not ipProto and not ipSrc and not ipDst \
968 and not tcpSrc and not tcpDst:
andrewonlab36af3822014-11-18 17:48:18 -0500969 cmd = "add-point-intent"
andrewonlab36af3822014-11-18 17:48:18 -0500970
andrewonlab289e4b72014-10-21 21:24:18 -0400971 else:
andrewonlab36af3822014-11-18 17:48:18 -0500972 cmd = "add-point-intent"
Jon Halle3f39ff2015-01-13 11:50:53 -0800973
andrewonlab0c0a6772014-10-22 12:31:18 -0400974 if ethType:
kelvin8ec71442015-01-15 16:57:00 -0800975 cmd += " --ethType " + str( ethType )
andrewonlab289e4b72014-10-21 21:24:18 -0400976 if ethSrc:
kelvin8ec71442015-01-15 16:57:00 -0800977 cmd += " --ethSrc " + str( ethSrc )
978 if ethDst:
979 cmd += " --ethDst " + str( ethDst )
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500980 if bandwidth:
kelvin8ec71442015-01-15 16:57:00 -0800981 cmd += " --bandwidth " + str( bandwidth )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800982 if lambdaAlloc:
andrewonlabfa4ff502014-11-11 16:41:30 -0500983 cmd += " --lambda "
984 if ipProto:
kelvin8ec71442015-01-15 16:57:00 -0800985 cmd += " --ipProto " + str( ipProto )
andrewonlabfa4ff502014-11-11 16:41:30 -0500986 if ipSrc:
kelvin8ec71442015-01-15 16:57:00 -0800987 cmd += " --ipSrc " + str( ipSrc )
andrewonlabfa4ff502014-11-11 16:41:30 -0500988 if ipDst:
kelvin8ec71442015-01-15 16:57:00 -0800989 cmd += " --ipDst " + str( ipDst )
andrewonlabfa4ff502014-11-11 16:41:30 -0500990 if tcpSrc:
kelvin8ec71442015-01-15 16:57:00 -0800991 cmd += " --tcpSrc " + str( tcpSrc )
andrewonlabfa4ff502014-11-11 16:41:30 -0500992 if tcpDst:
kelvin8ec71442015-01-15 16:57:00 -0800993 cmd += " --tcpDst " + str( tcpDst )
andrewonlab289e4b72014-10-21 21:24:18 -0400994
kelvin8ec71442015-01-15 16:57:00 -0800995 # Check whether the user appended the port
996 # or provided it as an input
kelvin-onlabd3b64892015-01-20 13:26:24 -0800997 if "/" in ingressDevice:
998 cmd += " " + str( ingressDevice )
andrewonlab36af3822014-11-18 17:48:18 -0500999 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001000 if not portIngress:
kelvin8ec71442015-01-15 16:57:00 -08001001 main.log.error( "You must specify " +
1002 "the ingress port" )
1003 # TODO: perhaps more meaningful return
andrewonlab36af3822014-11-18 17:48:18 -05001004 return main.FALSE
1005
kelvin8ec71442015-01-15 16:57:00 -08001006 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001007 str( ingressDevice ) + "/" +\
1008 str( portIngress ) + " "
andrewonlab36af3822014-11-18 17:48:18 -05001009
kelvin-onlabd3b64892015-01-20 13:26:24 -08001010 if "/" in egressDevice:
1011 cmd += " " + str( egressDevice )
andrewonlab36af3822014-11-18 17:48:18 -05001012 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001013 if not portEgress:
kelvin8ec71442015-01-15 16:57:00 -08001014 main.log.error( "You must specify " +
1015 "the egress port" )
andrewonlab36af3822014-11-18 17:48:18 -05001016 return main.FALSE
Jon Halle3f39ff2015-01-13 11:50:53 -08001017
kelvin8ec71442015-01-15 16:57:00 -08001018 cmd += " " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001019 str( egressDevice ) + "/" +\
1020 str( portEgress )
kelvin8ec71442015-01-15 16:57:00 -08001021
kelvin-onlab898a6c62015-01-16 14:13:53 -08001022 handle = self.sendline( cmd )
1023 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -08001024 main.log.error( "Error in adding point-to-point intent" )
Jon Hall47a93fb2015-01-06 16:46:06 -08001025 return main.FALSE
andrewonlab4dbb4d82014-10-17 18:22:31 -04001026 else:
1027 return main.TRUE
andrewonlab4dbb4d82014-10-17 18:22:31 -04001028 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001029 main.log.error( self.name + ": EOF exception found" )
1030 main.log.error( self.name + ": " + self.handle.before )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001031 main.cleanup()
1032 main.exit()
1033 except:
kelvin8ec71442015-01-15 16:57:00 -08001034 main.log.info( self.name + " ::::::" )
1035 main.log.error( traceback.print_exc() )
1036 main.log.info( self.name + " ::::::" )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001037 main.cleanup()
1038 main.exit()
1039
kelvin-onlabd3b64892015-01-20 13:26:24 -08001040 def addMultipointToSinglepointIntent(
kelvin-onlab898a6c62015-01-16 14:13:53 -08001041 self,
kelvin-onlabd3b64892015-01-20 13:26:24 -08001042 ingressDevice1,
1043 ingressDevice2,
1044 egressDevice,
1045 portIngress="",
1046 portEgress="",
kelvin-onlab898a6c62015-01-16 14:13:53 -08001047 ethType="",
1048 ethSrc="",
1049 ethDst="",
1050 bandwidth="",
kelvin-onlabd3b64892015-01-20 13:26:24 -08001051 lambdaAlloc=False,
kelvin-onlab898a6c62015-01-16 14:13:53 -08001052 ipProto="",
1053 ipSrc="",
1054 ipDst="",
1055 tcpSrc="",
1056 tcpDst="",
1057 setEthSrc="",
1058 setEthDst="" ):
kelvin8ec71442015-01-15 16:57:00 -08001059 """
shahshreyad0c80432014-12-04 16:56:05 -08001060 Note:
Jon Halle3f39ff2015-01-13 11:50:53 -08001061 This function assumes that there would be 2 ingress devices and
1062 one egress device. For more number of ingress devices, this
1063 function needs to be modified
shahshreyad0c80432014-12-04 16:56:05 -08001064 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001065 * ingressDevice1: device id of ingress device1
1066 * ingressDevice2: device id of ingress device2
1067 * egressDevice: device id of egress device
shahshreyad0c80432014-12-04 16:56:05 -08001068 Optional:
1069 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -08001070 * ethSrc: specify ethSrc ( i.e. src mac addr )
1071 * ethDst: specify ethDst ( i.e. dst mac addr )
shahshreyad0c80432014-12-04 16:56:05 -08001072 * bandwidth: specify bandwidth capacity of link
kelvin-onlabd3b64892015-01-20 13:26:24 -08001073 * lambdaAlloc: if True, intent will allocate lambda
shahshreyad0c80432014-12-04 16:56:05 -08001074 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -08001075 * ipProto: specify ip protocol
shahshreyad0c80432014-12-04 16:56:05 -08001076 * ipSrc: specify ip source address
1077 * ipDst: specify ip destination address
1078 * tcpSrc: specify tcp source port
1079 * tcpDst: specify tcp destination port
1080 * setEthSrc: action to Rewrite Source MAC Address
1081 * setEthDst: action to Rewrite Destination MAC Address
1082 Description:
kelvin8ec71442015-01-15 16:57:00 -08001083 Adds a multipoint-to-singlepoint intent ( uni-directional ) by
shahshreyad0c80432014-12-04 16:56:05 -08001084 specifying device id's and optional fields
1085
Jon Halle3f39ff2015-01-13 11:50:53 -08001086 NOTE: This function may change depending on the
shahshreyad0c80432014-12-04 16:56:05 -08001087 options developers provide for multipointpoint-to-singlepoint
1088 intent via cli
kelvin8ec71442015-01-15 16:57:00 -08001089 """
shahshreyad0c80432014-12-04 16:56:05 -08001090 try:
1091 cmd = ""
1092
kelvin8ec71442015-01-15 16:57:00 -08001093 # If there are no optional arguments
shahshreyad0c80432014-12-04 16:56:05 -08001094 if not ethType and not ethSrc and not ethDst\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001095 and not bandwidth and not lambdaAlloc\
Jon Halle3f39ff2015-01-13 11:50:53 -08001096 and not ipProto and not ipSrc and not ipDst\
1097 and not tcpSrc and not tcpDst and not setEthSrc\
1098 and not setEthDst:
shahshreyad0c80432014-12-04 16:56:05 -08001099 cmd = "add-multi-to-single-intent"
shahshreyad0c80432014-12-04 16:56:05 -08001100
1101 else:
1102 cmd = "add-multi-to-single-intent"
Jon Halle3f39ff2015-01-13 11:50:53 -08001103
shahshreyad0c80432014-12-04 16:56:05 -08001104 if ethType:
kelvin8ec71442015-01-15 16:57:00 -08001105 cmd += " --ethType " + str( ethType )
shahshreyad0c80432014-12-04 16:56:05 -08001106 if ethSrc:
kelvin8ec71442015-01-15 16:57:00 -08001107 cmd += " --ethSrc " + str( ethSrc )
1108 if ethDst:
1109 cmd += " --ethDst " + str( ethDst )
shahshreyad0c80432014-12-04 16:56:05 -08001110 if bandwidth:
kelvin8ec71442015-01-15 16:57:00 -08001111 cmd += " --bandwidth " + str( bandwidth )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001112 if lambdaAlloc:
shahshreyad0c80432014-12-04 16:56:05 -08001113 cmd += " --lambda "
1114 if ipProto:
kelvin8ec71442015-01-15 16:57:00 -08001115 cmd += " --ipProto " + str( ipProto )
shahshreyad0c80432014-12-04 16:56:05 -08001116 if ipSrc:
kelvin8ec71442015-01-15 16:57:00 -08001117 cmd += " --ipSrc " + str( ipSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001118 if ipDst:
kelvin8ec71442015-01-15 16:57:00 -08001119 cmd += " --ipDst " + str( ipDst )
shahshreyad0c80432014-12-04 16:56:05 -08001120 if tcpSrc:
kelvin8ec71442015-01-15 16:57:00 -08001121 cmd += " --tcpSrc " + str( tcpSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001122 if tcpDst:
kelvin8ec71442015-01-15 16:57:00 -08001123 cmd += " --tcpDst " + str( tcpDst )
shahshreyad0c80432014-12-04 16:56:05 -08001124 if setEthSrc:
kelvin8ec71442015-01-15 16:57:00 -08001125 cmd += " --setEthSrc " + str( setEthSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001126 if setEthDst:
kelvin8ec71442015-01-15 16:57:00 -08001127 cmd += " --setEthDst " + str( setEthDst )
shahshreyad0c80432014-12-04 16:56:05 -08001128
kelvin8ec71442015-01-15 16:57:00 -08001129 # Check whether the user appended the port
1130 # or provided it as an input
kelvin-onlabd3b64892015-01-20 13:26:24 -08001131 if "/" in ingressDevice1:
1132 cmd += " " + str( ingressDevice1 )
shahshreyad0c80432014-12-04 16:56:05 -08001133 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001134 if not portIngress1:
kelvin8ec71442015-01-15 16:57:00 -08001135 main.log.error( "You must specify " +
1136 "the ingress port1" )
1137 # TODO: perhaps more meaningful return
shahshreyad0c80432014-12-04 16:56:05 -08001138 return main.FALSE
1139
kelvin8ec71442015-01-15 16:57:00 -08001140 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001141 str( ingressDevice1 ) + "/" +\
1142 str( portIngress1 ) + " "
shahshreyad0c80432014-12-04 16:56:05 -08001143
kelvin-onlabd3b64892015-01-20 13:26:24 -08001144 if "/" in ingressDevice2:
1145 cmd += " " + str( ingressDevice2 )
shahshreyad0c80432014-12-04 16:56:05 -08001146 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001147 if not portIngress2:
kelvin8ec71442015-01-15 16:57:00 -08001148 main.log.error( "You must specify " +
1149 "the ingress port2" )
1150 # TODO: perhaps more meaningful return
shahshreyad0c80432014-12-04 16:56:05 -08001151 return main.FALSE
1152
kelvin8ec71442015-01-15 16:57:00 -08001153 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001154 str( ingressDevice2 ) + "/" +\
1155 str( portIngress2 ) + " "
shahshreyad0c80432014-12-04 16:56:05 -08001156
kelvin-onlabd3b64892015-01-20 13:26:24 -08001157 if "/" in egressDevice:
1158 cmd += " " + str( egressDevice )
shahshreyad0c80432014-12-04 16:56:05 -08001159 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001160 if not portEgress:
kelvin8ec71442015-01-15 16:57:00 -08001161 main.log.error( "You must specify " +
1162 "the egress port" )
shahshreyad0c80432014-12-04 16:56:05 -08001163 return main.FALSE
Jon Halle3f39ff2015-01-13 11:50:53 -08001164
kelvin8ec71442015-01-15 16:57:00 -08001165 cmd += " " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001166 str( egressDevice ) + "/" +\
1167 str( portEgress )
kelvin8ec71442015-01-15 16:57:00 -08001168 print "cmd= ", cmd
kelvin-onlab898a6c62015-01-16 14:13:53 -08001169 handle = self.sendline( cmd )
1170 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -08001171 main.log.error( "Error in adding point-to-point intent" )
shahshreyad0c80432014-12-04 16:56:05 -08001172 return self.handle
1173 else:
1174 return main.TRUE
shahshreyad0c80432014-12-04 16:56:05 -08001175 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001176 main.log.error( self.name + ": EOF exception found" )
1177 main.log.error( self.name + ": " + self.handle.before )
shahshreyad0c80432014-12-04 16:56:05 -08001178 main.cleanup()
1179 main.exit()
1180 except:
kelvin8ec71442015-01-15 16:57:00 -08001181 main.log.info( self.name + " ::::::" )
1182 main.log.error( traceback.print_exc() )
1183 main.log.info( self.name + " ::::::" )
shahshreyad0c80432014-12-04 16:56:05 -08001184 main.cleanup()
1185 main.exit()
1186
kelvin-onlabd3b64892015-01-20 13:26:24 -08001187 def removeIntent( self, intentId ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001188 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001189 Remove intent for specified intent id
Jon Halle3f39ff2015-01-13 11:50:53 -08001190
1191 Returns:
1192 main.False on error and
1193 cli output otherwise
kelvin-onlab898a6c62015-01-16 14:13:53 -08001194 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001195 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001196 cmdStr = "remove-intent " + str( intentId )
1197 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001198 if re.search( "Error", handle ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001199 main.log.error( "Error in removing intent" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001200 return main.FALSE
andrewonlab9a50dfe2014-10-17 17:22:31 -04001201 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001202 # TODO: Should this be main.TRUE
1203 return handle
andrewonlab9a50dfe2014-10-17 17:22:31 -04001204 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001205 main.log.error( self.name + ": EOF exception found" )
1206 main.log.error( self.name + ": " + self.handle.before )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001207 main.cleanup()
1208 main.exit()
1209 except:
kelvin8ec71442015-01-15 16:57:00 -08001210 main.log.info( self.name + " ::::::" )
1211 main.log.error( traceback.print_exc() )
1212 main.log.info( self.name + " ::::::" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001213 main.cleanup()
1214 main.exit()
1215
kelvin-onlabd3b64892015-01-20 13:26:24 -08001216 def routes( self, jsonFormat=False ):
kelvin8ec71442015-01-15 16:57:00 -08001217 """
kelvin-onlab898a6c62015-01-16 14:13:53 -08001218 NOTE: This method should be used after installing application:
1219 onos-app-sdnip
pingping-lin8b306ac2014-11-17 18:13:51 -08001220 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001221 * jsonFormat: enable output formatting in json
pingping-lin8b306ac2014-11-17 18:13:51 -08001222 Description:
1223 Obtain all routes in the system
kelvin8ec71442015-01-15 16:57:00 -08001224 """
pingping-lin8b306ac2014-11-17 18:13:51 -08001225 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001226 if jsonFormat:
1227 cmdStr = "routes -j"
1228 handleTmp = self.sendline( cmdStr )
1229 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1230 handle = ansiEscape.sub( '', handleTmp )
pingping-lin8b306ac2014-11-17 18:13:51 -08001231 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001232 cmdStr = "routes"
1233 handle = self.sendline( cmdStr )
pingping-lin8b306ac2014-11-17 18:13:51 -08001234 return handle
pingping-lin8b306ac2014-11-17 18:13:51 -08001235 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001236 main.log.error( self.name + ": EOF exception found" )
1237 main.log.error( self.name + ": " + self.handle.before )
pingping-lin8b306ac2014-11-17 18:13:51 -08001238 main.cleanup()
1239 main.exit()
1240 except:
kelvin8ec71442015-01-15 16:57:00 -08001241 main.log.info( self.name + " ::::::" )
1242 main.log.error( traceback.print_exc() )
1243 main.log.info( self.name + " ::::::" )
pingping-lin8b306ac2014-11-17 18:13:51 -08001244 main.cleanup()
1245 main.exit()
1246
kelvin-onlabd3b64892015-01-20 13:26:24 -08001247 def intents( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001248 """
andrewonlab377693f2014-10-21 16:00:30 -04001249 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001250 * jsonFormat: enable output formatting in json
andrewonlabe6745342014-10-17 14:29:13 -04001251 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001252 Obtain intents currently installed
kelvin-onlab898a6c62015-01-16 14:13:53 -08001253 """
andrewonlabe6745342014-10-17 14:29:13 -04001254 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001255 if jsonFormat:
1256 cmdStr = "intents -j"
1257 handle = self.sendline( cmdStr )
1258 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1259 handle = ansiEscape.sub( '', handle )
kelvin8ec71442015-01-15 16:57:00 -08001260 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001261 cmdStr = "intents"
1262 handle = self.sendline( cmdStr )
andrewonlabe6745342014-10-17 14:29:13 -04001263 return handle
andrewonlabe6745342014-10-17 14:29:13 -04001264 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001265 main.log.error( self.name + ": EOF exception found" )
1266 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe6745342014-10-17 14:29:13 -04001267 main.cleanup()
1268 main.exit()
1269 except:
kelvin8ec71442015-01-15 16:57:00 -08001270 main.log.info( self.name + " ::::::" )
1271 main.log.error( traceback.print_exc() )
1272 main.log.info( self.name + " ::::::" )
andrewonlabe6745342014-10-17 14:29:13 -04001273 main.cleanup()
1274 main.exit()
1275
kelvin-onlabd3b64892015-01-20 13:26:24 -08001276 def flows( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001277 """
Shreya Shah0f01c812014-10-26 20:15:28 -04001278 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001279 * jsonFormat: enable output formatting in json
Shreya Shah0f01c812014-10-26 20:15:28 -04001280 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001281 Obtain flows currently installed
kelvin-onlab898a6c62015-01-16 14:13:53 -08001282 """
Shreya Shah0f01c812014-10-26 20:15:28 -04001283 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001284 if jsonFormat:
1285 cmdStr = "flows -j"
1286 handle = self.sendline( cmdStr )
1287 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1288 handle = ansiEscape.sub( '', handle )
Shreya Shah0f01c812014-10-26 20:15:28 -04001289 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001290 cmdStr = "flows"
1291 handle = self.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -08001292 if re.search( "Error\sexecuting\scommand:", handle ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001293 main.log.error( self.name + ".flows() response: " +
1294 str( handle ) )
Shreya Shah0f01c812014-10-26 20:15:28 -04001295 return handle
Shreya Shah0f01c812014-10-26 20:15:28 -04001296 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001297 main.log.error( self.name + ": EOF exception found" )
1298 main.log.error( self.name + ": " + self.handle.before )
Shreya Shah0f01c812014-10-26 20:15:28 -04001299 main.cleanup()
1300 main.exit()
1301 except:
kelvin8ec71442015-01-15 16:57:00 -08001302 main.log.info( self.name + " ::::::" )
1303 main.log.error( traceback.print_exc() )
1304 main.log.info( self.name + " ::::::" )
Shreya Shah0f01c812014-10-26 20:15:28 -04001305 main.cleanup()
1306 main.exit()
1307
kelvin-onlabd3b64892015-01-20 13:26:24 -08001308 def pushTestIntents( self, dpidSrc, dpidDst, numIntents,
1309 numMult="", appId="", report=True ):
kelvin8ec71442015-01-15 16:57:00 -08001310 """
andrewonlab87852b02014-11-19 18:44:19 -05001311 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001312 Push a number of intents in a batch format to
andrewonlab87852b02014-11-19 18:44:19 -05001313 a specific point-to-point intent definition
1314 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001315 * dpidSrc: specify source dpid
1316 * dpidDst: specify destination dpid
1317 * numIntents: specify number of intents to push
andrewonlab87852b02014-11-19 18:44:19 -05001318 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001319 * numMult: number multiplier for multiplying
andrewonlabb66dfa12014-12-02 15:51:10 -05001320 the number of intents specified
kelvin-onlabd3b64892015-01-20 13:26:24 -08001321 * appId: specify the application id init to further
andrewonlabb66dfa12014-12-02 15:51:10 -05001322 modularize the intents
andrewonlab87852b02014-11-19 18:44:19 -05001323 * report: default True, returns latency information
kelvin8ec71442015-01-15 16:57:00 -08001324 """
andrewonlab87852b02014-11-19 18:44:19 -05001325 try:
kelvin8ec71442015-01-15 16:57:00 -08001326 cmd = "push-test-intents " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001327 str( dpidSrc ) + " " + str( dpidDst ) + " " +\
1328 str( numIntents )
1329 if numMult:
1330 cmd += " " + str( numMult )
1331 # If app id is specified, then numMult
kelvin8ec71442015-01-15 16:57:00 -08001332 # must exist because of the way this command
kelvin-onlabd3b64892015-01-20 13:26:24 -08001333 if appId:
1334 cmd += " " + str( appId )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001335 handle = self.sendline( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001336 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1337 handle = ansiEscape.sub( '', handle )
andrewonlab87852b02014-11-19 18:44:19 -05001338 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001339 latResult = []
kelvin8ec71442015-01-15 16:57:00 -08001340 main.log.info( handle )
1341 # Split result by newline
1342 newline = handle.split( "\r\r\n" )
1343 # Ignore the first object of list, which is empty
1344 newline = newline[ 1: ]
1345 # Some sloppy parsing method to get the latency
andrewonlabb66dfa12014-12-02 15:51:10 -05001346 for result in newline:
kelvin8ec71442015-01-15 16:57:00 -08001347 result = result.split( ": " )
1348 # Append the first result of second parse
kelvin-onlabd3b64892015-01-20 13:26:24 -08001349 latResult.append( result[ 1 ].split( " " )[ 0 ] )
1350 main.log.info( latResult )
1351 return latResult
andrewonlab87852b02014-11-19 18:44:19 -05001352 else:
1353 return main.TRUE
andrewonlab87852b02014-11-19 18:44:19 -05001354 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001355 main.log.error( self.name + ": EOF exception found" )
1356 main.log.error( self.name + ": " + self.handle.before )
andrewonlab87852b02014-11-19 18:44:19 -05001357 main.cleanup()
1358 main.exit()
1359 except:
kelvin8ec71442015-01-15 16:57:00 -08001360 main.log.info( self.name + " ::::::" )
1361 main.log.error( traceback.print_exc() )
1362 main.log.info( self.name + " ::::::" )
andrewonlab87852b02014-11-19 18:44:19 -05001363 main.cleanup()
1364 main.exit()
1365
kelvin-onlabd3b64892015-01-20 13:26:24 -08001366 def intentsEventsMetrics( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001367 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001368 Description:Returns topology metrics
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001369 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001370 * jsonFormat: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08001371 """
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001372 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001373 if jsonFormat:
1374 cmdStr = "intents-events-metrics -j"
1375 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001376 # Some color thing that we want to escape
kelvin-onlabd3b64892015-01-20 13:26:24 -08001377 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1378 handle = ansiEscape.sub( '', handle )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001379 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001380 cmdStr = "intents-events-metrics"
1381 handle = self.sendline( cmdStr )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001382 return handle
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001383 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001384 main.log.error( self.name + ": EOF exception found" )
1385 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001386 main.cleanup()
1387 main.exit()
1388 except:
kelvin8ec71442015-01-15 16:57:00 -08001389 main.log.info( self.name + " ::::::" )
1390 main.log.error( traceback.print_exc() )
1391 main.log.info( self.name + " ::::::" )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001392 main.cleanup()
1393 main.exit()
Shreya Shah0f01c812014-10-26 20:15:28 -04001394
kelvin-onlabd3b64892015-01-20 13:26:24 -08001395 def topologyEventsMetrics( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001396 """
1397 Description:Returns topology metrics
andrewonlab867212a2014-10-22 20:13:38 -04001398 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001399 * jsonFormat: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08001400 """
andrewonlab867212a2014-10-22 20:13:38 -04001401 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001402 if jsonFormat:
1403 cmdStr = "topology-events-metrics -j"
1404 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001405 # Some color thing that we want to escape
kelvin-onlabd3b64892015-01-20 13:26:24 -08001406 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1407 handle = ansiEscape.sub( '', handle )
andrewonlab867212a2014-10-22 20:13:38 -04001408 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001409 cmdStr = "topology-events-metrics"
1410 handle = self.sendline( cmdStr )
andrewonlab867212a2014-10-22 20:13:38 -04001411 return handle
andrewonlab867212a2014-10-22 20:13:38 -04001412 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001413 main.log.error( self.name + ": EOF exception found" )
1414 main.log.error( self.name + ": " + self.handle.before )
andrewonlab867212a2014-10-22 20:13:38 -04001415 main.cleanup()
1416 main.exit()
1417 except:
kelvin8ec71442015-01-15 16:57:00 -08001418 main.log.info( self.name + " ::::::" )
1419 main.log.error( traceback.print_exc() )
1420 main.log.info( self.name + " ::::::" )
andrewonlab867212a2014-10-22 20:13:38 -04001421 main.cleanup()
1422 main.exit()
1423
kelvin8ec71442015-01-15 16:57:00 -08001424 # Wrapper functions ****************
1425 # Wrapper functions use existing driver
1426 # functions and extends their use case.
1427 # For example, we may use the output of
1428 # a normal driver function, and parse it
1429 # using a wrapper function
andrewonlabc2d05aa2014-10-13 16:51:10 -04001430
kelvin-onlabd3b64892015-01-20 13:26:24 -08001431 def getAllIntentsId( self ):
kelvin8ec71442015-01-15 16:57:00 -08001432 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001433 Description:
1434 Obtain all intent id's in a list
kelvin8ec71442015-01-15 16:57:00 -08001435 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001436 try:
kelvin8ec71442015-01-15 16:57:00 -08001437 # Obtain output of intents function
kelvin-onlabd3b64892015-01-20 13:26:24 -08001438 intentsStr = self.intents()
1439 allIntentList = []
1440 intentIdList = []
andrewonlab9a50dfe2014-10-17 17:22:31 -04001441
kelvin8ec71442015-01-15 16:57:00 -08001442 # Parse the intents output for ID's
kelvin-onlabd3b64892015-01-20 13:26:24 -08001443 intentsList = [ s.strip() for s in intentsStr.splitlines() ]
1444 for intents in intentsList:
andrewonlab9a50dfe2014-10-17 17:22:31 -04001445 if "onos>" in intents:
1446 continue
1447 elif "intents" in intents:
1448 continue
1449 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001450 lineList = intents.split( " " )
1451 allIntentList.append( lineList[ 0 ] )
kelvin8ec71442015-01-15 16:57:00 -08001452
kelvin-onlabd3b64892015-01-20 13:26:24 -08001453 allIntentList = allIntentList[ 1:-2 ]
andrewonlab9a50dfe2014-10-17 17:22:31 -04001454
kelvin-onlabd3b64892015-01-20 13:26:24 -08001455 for intents in allIntentList:
andrewonlab9a50dfe2014-10-17 17:22:31 -04001456 if not intents:
1457 continue
1458 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001459 intentIdList.append( intents )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001460
kelvin-onlabd3b64892015-01-20 13:26:24 -08001461 return intentIdList
andrewonlab9a50dfe2014-10-17 17:22:31 -04001462
1463 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001464 main.log.error( self.name + ": EOF exception found" )
1465 main.log.error( self.name + ": " + self.handle.before )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001466 main.cleanup()
1467 main.exit()
1468 except:
kelvin8ec71442015-01-15 16:57:00 -08001469 main.log.info( self.name + " ::::::" )
1470 main.log.error( traceback.print_exc() )
1471 main.log.info( self.name + " ::::::" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001472 main.cleanup()
1473 main.exit()
1474
kelvin-onlabd3b64892015-01-20 13:26:24 -08001475 def getAllDevicesId( self ):
kelvin8ec71442015-01-15 16:57:00 -08001476 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04001477 Use 'devices' function to obtain list of all devices
1478 and parse the result to obtain a list of all device
1479 id's. Returns this list. Returns empty list if no
1480 devices exist
kelvin8ec71442015-01-15 16:57:00 -08001481 List is ordered sequentially
1482
andrewonlab3e15ead2014-10-15 14:21:34 -04001483 This function may be useful if you are not sure of the
kelvin8ec71442015-01-15 16:57:00 -08001484 device id, and wish to execute other commands using
andrewonlab3e15ead2014-10-15 14:21:34 -04001485 the ids. By obtaining the list of device ids on the fly,
1486 you can iterate through the list to get mastership, etc.
kelvin8ec71442015-01-15 16:57:00 -08001487 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04001488 try:
kelvin8ec71442015-01-15 16:57:00 -08001489 # Call devices and store result string
kelvin-onlabd3b64892015-01-20 13:26:24 -08001490 devicesStr = self.devices( jsonFormat=False )
1491 idList = []
kelvin8ec71442015-01-15 16:57:00 -08001492
kelvin-onlabd3b64892015-01-20 13:26:24 -08001493 if not devicesStr:
kelvin8ec71442015-01-15 16:57:00 -08001494 main.log.info( "There are no devices to get id from" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001495 return idList
kelvin8ec71442015-01-15 16:57:00 -08001496
1497 # Split the string into list by comma
kelvin-onlabd3b64892015-01-20 13:26:24 -08001498 deviceList = devicesStr.split( "," )
kelvin8ec71442015-01-15 16:57:00 -08001499 # Get temporary list of all arguments with string 'id='
kelvin-onlabd3b64892015-01-20 13:26:24 -08001500 tempList = [ dev for dev in deviceList if "id=" in dev ]
kelvin8ec71442015-01-15 16:57:00 -08001501 # Split list further into arguments before and after string
1502 # 'id='. Get the latter portion ( the actual device id ) and
kelvin-onlabd3b64892015-01-20 13:26:24 -08001503 # append to idList
1504 for arg in tempList:
1505 idList.append( arg.split( "id=" )[ 1 ] )
1506 return idList
andrewonlab7e4d2d32014-10-15 13:23:21 -04001507
1508 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001509 main.log.error( self.name + ": EOF exception found" )
1510 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001511 main.cleanup()
1512 main.exit()
1513 except:
kelvin8ec71442015-01-15 16:57:00 -08001514 main.log.info( self.name + " ::::::" )
1515 main.log.error( traceback.print_exc() )
1516 main.log.info( self.name + " ::::::" )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001517 main.cleanup()
1518 main.exit()
1519
kelvin-onlabd3b64892015-01-20 13:26:24 -08001520 def getAllNodesId( self ):
kelvin8ec71442015-01-15 16:57:00 -08001521 """
andrewonlab7c211572014-10-15 16:45:20 -04001522 Uses 'nodes' function to obtain list of all nodes
1523 and parse the result of nodes to obtain just the
kelvin8ec71442015-01-15 16:57:00 -08001524 node id's.
andrewonlab7c211572014-10-15 16:45:20 -04001525 Returns:
1526 list of node id's
kelvin8ec71442015-01-15 16:57:00 -08001527 """
andrewonlab7c211572014-10-15 16:45:20 -04001528 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001529 nodesStr = self.nodes()
1530 idList = []
andrewonlab7c211572014-10-15 16:45:20 -04001531
kelvin-onlabd3b64892015-01-20 13:26:24 -08001532 if not nodesStr:
kelvin8ec71442015-01-15 16:57:00 -08001533 main.log.info( "There are no nodes to get id from" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001534 return idList
andrewonlab7c211572014-10-15 16:45:20 -04001535
kelvin-onlabd3b64892015-01-20 13:26:24 -08001536 # Sample nodesStr output
kelvin8ec71442015-01-15 16:57:00 -08001537 # id=local, address=127.0.0.1:9876, state=ACTIVE *
andrewonlab7c211572014-10-15 16:45:20 -04001538
kelvin8ec71442015-01-15 16:57:00 -08001539 # Split the string into list by comma
kelvin-onlabd3b64892015-01-20 13:26:24 -08001540 nodesList = nodesStr.split( "," )
1541 tempList = [ node for node in nodesList if "id=" in node ]
1542 for arg in tempList:
1543 idList.append( arg.split( "id=" )[ 1 ] )
andrewonlab7c211572014-10-15 16:45:20 -04001544
kelvin-onlabd3b64892015-01-20 13:26:24 -08001545 return idList
kelvin8ec71442015-01-15 16:57:00 -08001546
andrewonlab7c211572014-10-15 16:45:20 -04001547 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001548 main.log.error( self.name + ": EOF exception found" )
1549 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -04001550 main.cleanup()
1551 main.exit()
1552 except:
kelvin8ec71442015-01-15 16:57:00 -08001553 main.log.info( self.name + " ::::::" )
1554 main.log.error( traceback.print_exc() )
1555 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -04001556 main.cleanup()
1557 main.exit()
andrewonlab7e4d2d32014-10-15 13:23:21 -04001558
kelvin-onlabd3b64892015-01-20 13:26:24 -08001559 def getDevice( self, dpid=None ):
kelvin8ec71442015-01-15 16:57:00 -08001560 """
Jon Halla91c4dc2014-10-22 12:57:04 -04001561 Return the first device from the devices api whose 'id' contains 'dpid'
1562 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -08001563 """
Jon Halla91c4dc2014-10-22 12:57:04 -04001564 import json
1565 try:
kelvin8ec71442015-01-15 16:57:00 -08001566 if dpid is None:
Jon Halla91c4dc2014-10-22 12:57:04 -04001567 return None
1568 else:
kelvin8ec71442015-01-15 16:57:00 -08001569 dpid = dpid.replace( ':', '' )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001570 rawDevices = self.devices()
1571 devicesJson = json.loads( rawDevices )
kelvin8ec71442015-01-15 16:57:00 -08001572 # search json for the device with dpid then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -08001573 for device in devicesJson:
kelvin8ec71442015-01-15 16:57:00 -08001574 # print "%s in %s?" % ( dpid, device[ 'id' ] )
1575 if dpid in device[ 'id' ]:
Jon Halla91c4dc2014-10-22 12:57:04 -04001576 return device
1577 return None
1578 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001579 main.log.error( self.name + ": EOF exception found" )
1580 main.log.error( self.name + ": " + self.handle.before )
Jon Halla91c4dc2014-10-22 12:57:04 -04001581 main.cleanup()
1582 main.exit()
1583 except:
kelvin8ec71442015-01-15 16:57:00 -08001584 main.log.info( self.name + " ::::::" )
1585 main.log.error( traceback.print_exc() )
1586 main.log.info( self.name + " ::::::" )
Jon Halla91c4dc2014-10-22 12:57:04 -04001587 main.cleanup()
1588 main.exit()
1589
kelvin-onlabd3b64892015-01-20 13:26:24 -08001590 def checkStatus( self, ip, numoswitch, numolink, logLevel="info" ):
kelvin8ec71442015-01-15 16:57:00 -08001591 """
1592 Checks the number of swithes & links that ONOS sees against the
1593 supplied values. By default this will report to main.log, but the
Jon Hall42db6dc2014-10-24 19:03:48 -04001594 log level can be specifid.
kelvin8ec71442015-01-15 16:57:00 -08001595
Jon Hall42db6dc2014-10-24 19:03:48 -04001596 Params: ip = ip used for the onos cli
1597 numoswitch = expected number of switches
1598 numlink = expected number of links
kelvin-onlabd3b64892015-01-20 13:26:24 -08001599 logLevel = level to log to. Currently accepts
1600 'info', 'warn' and 'report'
Jon Hall42db6dc2014-10-24 19:03:48 -04001601
1602
kelvin-onlabd3b64892015-01-20 13:26:24 -08001603 logLevel can
Jon Hall42db6dc2014-10-24 19:03:48 -04001604
kelvin8ec71442015-01-15 16:57:00 -08001605 Returns: main.TRUE if the number of switchs and links are correct,
Jon Hall42db6dc2014-10-24 19:03:48 -04001606 main.FALSE if the numer of switches and links is incorrect,
1607 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08001608 """
Jon Hall42db6dc2014-10-24 19:03:48 -04001609 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001610 topology = self.getTopology( ip )
Jon Hall42db6dc2014-10-24 19:03:48 -04001611 if topology == {}:
1612 return main.ERROR
1613 output = ""
kelvin8ec71442015-01-15 16:57:00 -08001614 # Is the number of switches is what we expected
1615 devices = topology.get( 'devices', False )
1616 links = topology.get( 'links', False )
Jon Hall42db6dc2014-10-24 19:03:48 -04001617 if devices == False or links == False:
1618 return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -08001619 switchCheck = ( int( devices ) == int( numoswitch ) )
kelvin8ec71442015-01-15 16:57:00 -08001620 # Is the number of links is what we expected
kelvin-onlabd3b64892015-01-20 13:26:24 -08001621 linkCheck = ( int( links ) == int( numolink ) )
1622 if ( switchCheck and linkCheck ):
kelvin8ec71442015-01-15 16:57:00 -08001623 # We expected the correct numbers
Jon Hall42db6dc2014-10-24 19:03:48 -04001624 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08001625 + "what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04001626 result = main.TRUE
1627 else:
1628 output = output + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001629 "The number of links and switches does not matc\
1630 h what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04001631 result = main.FALSE
kelvin-onlabd3b64892015-01-20 13:26:24 -08001632 output = output + "\n ONOS sees %i devices (%i expected) \
1633 and %i links (%i expected)" % (
1634 int( devices ), int( numoswitch ), int( links ),
1635 int( numolink ) )
1636 if logLevel == "report":
kelvin8ec71442015-01-15 16:57:00 -08001637 main.log.report( output )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001638 elif logLevel == "warn":
kelvin8ec71442015-01-15 16:57:00 -08001639 main.log.warn( output )
Jon Hall42db6dc2014-10-24 19:03:48 -04001640 else:
kelvin8ec71442015-01-15 16:57:00 -08001641 main.log.info( output )
1642 return result
Jon Hall42db6dc2014-10-24 19:03:48 -04001643 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001644 main.log.error( self.name + ": EOF exception found" )
1645 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -04001646 main.cleanup()
1647 main.exit()
1648 except:
kelvin8ec71442015-01-15 16:57:00 -08001649 main.log.info( self.name + " ::::::" )
1650 main.log.error( traceback.print_exc() )
1651 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -04001652 main.cleanup()
1653 main.exit()
Jon Hall1c9e8732014-10-27 19:29:27 -04001654
kelvin-onlabd3b64892015-01-20 13:26:24 -08001655 def deviceRole( self, deviceId, onosNode, role="master" ):
kelvin8ec71442015-01-15 16:57:00 -08001656 """
Jon Hall1c9e8732014-10-27 19:29:27 -04001657 Calls the device-role cli command.
kelvin-onlabd3b64892015-01-20 13:26:24 -08001658 deviceId must be the id of a device as seen in the onos devices command
1659 onosNode is the ip of one of the onos nodes in the cluster
Jon Hall1c9e8732014-10-27 19:29:27 -04001660 role must be either master, standby, or none
1661
Jon Halle3f39ff2015-01-13 11:50:53 -08001662 Returns:
1663 main.TRUE or main.FALSE based on argument verification and
1664 main.ERROR if command returns and error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001665 """
Jon Hall1c9e8732014-10-27 19:29:27 -04001666 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001667 if role.lower() == "master" or role.lower() == "standby" or\
Jon Hall1c9e8732014-10-27 19:29:27 -04001668 role.lower() == "none":
kelvin-onlabd3b64892015-01-20 13:26:24 -08001669 cmdStr = "device-role " +\
1670 str( deviceId ) + " " +\
1671 str( onosNode ) + " " +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001672 str( role )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001673 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001674 if re.search( "Error", handle ):
1675 # end color output to escape any colours
1676 # from the cli
kelvin8ec71442015-01-15 16:57:00 -08001677 main.log.error( self.name + ": " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001678 handle + '\033[0m' )
kelvin8ec71442015-01-15 16:57:00 -08001679 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -08001680 return main.TRUE
Jon Hall1c9e8732014-10-27 19:29:27 -04001681 else:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001682 main.log.error( "Invalid 'role' given to device_role(). " +
1683 "Value was '" + str(role) + "'." )
Jon Hall1c9e8732014-10-27 19:29:27 -04001684 return main.FALSE
Jon Hall1c9e8732014-10-27 19:29:27 -04001685 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001686 main.log.error( self.name + ": EOF exception found" )
1687 main.log.error( self.name + ": " + self.handle.before )
Jon Hall1c9e8732014-10-27 19:29:27 -04001688 main.cleanup()
1689 main.exit()
1690 except:
kelvin8ec71442015-01-15 16:57:00 -08001691 main.log.info( self.name + " ::::::" )
1692 main.log.error( traceback.print_exc() )
1693 main.log.info( self.name + " ::::::" )
Jon Hall1c9e8732014-10-27 19:29:27 -04001694 main.cleanup()
1695 main.exit()
1696
kelvin-onlabd3b64892015-01-20 13:26:24 -08001697 def clusters( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001698 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001699 Lists all clusters
Jon Hallffb386d2014-11-21 13:43:38 -08001700 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001701 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -08001702 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001703 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001704 if jsonFormat:
1705 cmdStr = "clusters -j"
1706 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001707 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001708 handle variable here contains some ANSI escape color code
1709 sequences at the end which are invisible in the print command
Jon Halle3f39ff2015-01-13 11:50:53 -08001710 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -08001711 function. The repr( handle ) output when printed shows the ANSI
1712 escape sequences. In json.loads( somestring ), this somestring
kelvin-onlabd3b64892015-01-20 13:26:24 -08001713 variable is actually repr( somestring ) and json.loads would
1714 fail with the escape sequence. So we take off that escape
1715 sequence using:
Jon Halle3f39ff2015-01-13 11:50:53 -08001716
kelvin-onlabd3b64892015-01-20 13:26:24 -08001717 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1718 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001719 """
kelvin-onlabd3b64892015-01-20 13:26:24 -08001720 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1721 handle1 = ansiEscape.sub( '', handle )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001722 return handle1
1723 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001724 cmdStr = "clusters"
1725 handle = self.sendline( cmdStr )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001726 return handle
1727 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001728 main.log.error( self.name + ": EOF exception found" )
1729 main.log.error( self.name + ": " + self.handle.before )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001730 main.cleanup()
1731 main.exit()
1732 except:
kelvin8ec71442015-01-15 16:57:00 -08001733 main.log.info( self.name + " ::::::" )
1734 main.log.error( traceback.print_exc() )
1735 main.log.info( self.name + " ::::::" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001736 main.cleanup()
1737 main.exit()
1738
kelvin-onlabd3b64892015-01-20 13:26:24 -08001739 def electionTestLeader( self ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001740 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001741 CLI command to get the current leader for the Election test application
1742 NOTE: Requires installation of the onos-app-election feature
1743 Returns: Node IP of the leader if one exists
1744 None if none exists
1745 Main.FALSE on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001746 """
Jon Hall94fd0472014-12-08 11:52:42 -08001747 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001748 cmdStr = "election-test-leader"
1749 response = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001750 # Leader
1751 leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001752 "app\sis\s(?P<node>.+)\."
kelvin-onlabd3b64892015-01-20 13:26:24 -08001753 nodeSearch = re.search( leaderPattern, response )
1754 if nodeSearch:
1755 node = nodeSearch.group( 'node' )
Jon Halle3f39ff2015-01-13 11:50:53 -08001756 main.log.info( "Election-test-leader on " + str( self.name ) +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001757 " found " + node + " as the leader" )
Jon Hall94fd0472014-12-08 11:52:42 -08001758 return node
Jon Halle3f39ff2015-01-13 11:50:53 -08001759 # no leader
1760 nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001761 "the\sElection\sapp"
kelvin-onlabd3b64892015-01-20 13:26:24 -08001762 nullSearch = re.search( nullPattern, response )
1763 if nullSearch:
Jon Halle3f39ff2015-01-13 11:50:53 -08001764 main.log.info( "Election-test-leader found no leader on " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001765 self.name )
Jon Hall94fd0472014-12-08 11:52:42 -08001766 return None
kelvin-onlab898a6c62015-01-16 14:13:53 -08001767 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001768 errorPattern = "Command\snot\sfound"
kelvin-onlab898a6c62015-01-16 14:13:53 -08001769 if re.search( errorPattern, response ):
1770 main.log.error( "Election app is not loaded on " + self.name )
Jon Halle3f39ff2015-01-13 11:50:53 -08001771 # TODO: Should this be main.ERROR?
Jon Hall669173b2014-12-17 11:36:30 -08001772 return main.FALSE
1773 else:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001774 main.log.error( "Error in election_test_leader: " +
1775 "unexpected response" )
kelvin8ec71442015-01-15 16:57:00 -08001776 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001777 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001778 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001779 main.log.error( self.name + ": EOF exception found" )
1780 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001781 main.cleanup()
1782 main.exit()
1783 except:
kelvin8ec71442015-01-15 16:57:00 -08001784 main.log.info( self.name + " ::::::" )
1785 main.log.error( traceback.print_exc() )
1786 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001787 main.cleanup()
1788 main.exit()
1789
kelvin-onlabd3b64892015-01-20 13:26:24 -08001790 def electionTestRun( self ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001791 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001792 CLI command to run for leadership of the Election test application.
1793 NOTE: Requires installation of the onos-app-election feature
1794 Returns: Main.TRUE on success
1795 Main.FALSE on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001796 """
Jon Hall94fd0472014-12-08 11:52:42 -08001797 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001798 cmdStr = "election-test-run"
1799 response = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001800 # success
Jon Halle3f39ff2015-01-13 11:50:53 -08001801 successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001802 "Election\sapp."
Jon Halle3f39ff2015-01-13 11:50:53 -08001803 search = re.search( successPattern, response )
Jon Hall94fd0472014-12-08 11:52:42 -08001804 if search:
Jon Halle3f39ff2015-01-13 11:50:53 -08001805 main.log.info( self.name + " entering leadership elections " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001806 "for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08001807 return main.TRUE
kelvin-onlab898a6c62015-01-16 14:13:53 -08001808 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001809 errorPattern = "Command\snot\sfound"
1810 if re.search( errorPattern, response ):
1811 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08001812 return main.FALSE
1813 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001814 main.log.error( "Error in election_test_run: " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001815 "unexpected response" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001816 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001817 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001818 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001819 main.log.error( self.name + ": EOF exception found" )
1820 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001821 main.cleanup()
1822 main.exit()
1823 except:
kelvin8ec71442015-01-15 16:57:00 -08001824 main.log.info( self.name + " ::::::" )
1825 main.log.error( traceback.print_exc() )
1826 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001827 main.cleanup()
1828 main.exit()
1829
kelvin-onlabd3b64892015-01-20 13:26:24 -08001830 def electionTestWithdraw( self ):
kelvin8ec71442015-01-15 16:57:00 -08001831 """
Jon Hall94fd0472014-12-08 11:52:42 -08001832 * CLI command to withdraw the local node from leadership election for
1833 * the Election test application.
1834 #NOTE: Requires installation of the onos-app-election feature
1835 Returns: Main.TRUE on success
1836 Main.FALSE on error
kelvin8ec71442015-01-15 16:57:00 -08001837 """
Jon Hall94fd0472014-12-08 11:52:42 -08001838 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001839 cmdStr = "election-test-withdraw"
1840 response = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001841 # success
Jon Halle3f39ff2015-01-13 11:50:53 -08001842 successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001843 "\sthe\sElection\sapp."
Jon Halle3f39ff2015-01-13 11:50:53 -08001844 if re.search( successPattern, response ):
1845 main.log.info( self.name + " withdrawing from leadership " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001846 "elections for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08001847 return main.TRUE
kelvin-onlab898a6c62015-01-16 14:13:53 -08001848 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001849 errorPattern = "Command\snot\sfound"
1850 if re.search( errorPattern, response ):
1851 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08001852 return main.FALSE
1853 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001854 main.log.error( "Error in election_test_withdraw: " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001855 "unexpected response" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001856 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001857 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001858 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001859 main.log.error( self.name + ": EOF exception found" )
1860 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001861 main.cleanup()
1862 main.exit()
1863 except:
kelvin8ec71442015-01-15 16:57:00 -08001864 main.log.info( self.name + " ::::::" )
1865 main.log.error( traceback.print_exc() )
1866 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001867 main.cleanup()
1868 main.exit()
Jon Hall1c9e8732014-10-27 19:29:27 -04001869
kelvin8ec71442015-01-15 16:57:00 -08001870 def getDevicePortsEnabledCount( self, dpid ):
1871 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001872 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08001873 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001874 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001875 dpid = str( dpid )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001876 cmdStr = "onos:ports -e " + dpid + " | wc -l"
1877 output = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001878 if re.search( "No such device", output ):
1879 main.log.error( "Error in getting ports" )
1880 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001881 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001882 return output
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001883 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001884 main.log.error( self.name + ": EOF exception found" )
1885 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001886 main.cleanup()
1887 main.exit()
1888 except:
kelvin8ec71442015-01-15 16:57:00 -08001889 main.log.info( self.name + " ::::::" )
1890 main.log.error( traceback.print_exc() )
1891 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001892 main.cleanup()
1893 main.exit()
1894
kelvin8ec71442015-01-15 16:57:00 -08001895 def getDeviceLinksActiveCount( self, dpid ):
1896 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001897 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08001898 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001899 try:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001900 dpid = str( dpid )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001901 cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l"
1902 output = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001903 if re.search( "No such device", output ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001904 main.log.error( "Error in getting ports " )
1905 return ( output, "Error " )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001906 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001907 return output
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001908 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001909 main.log.error( self.name + ": EOF exception found" )
1910 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001911 main.cleanup()
1912 main.exit()
1913 except:
kelvin8ec71442015-01-15 16:57:00 -08001914 main.log.info( self.name + " ::::::" )
1915 main.log.error( traceback.print_exc() )
1916 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001917 main.cleanup()
1918 main.exit()
1919
kelvin8ec71442015-01-15 16:57:00 -08001920 def getAllIntentIds( self ):
1921 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001922 Return a list of all Intent IDs
kelvin8ec71442015-01-15 16:57:00 -08001923 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001924 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001925 cmdStr = "onos:intents | grep id="
1926 output = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001927 if re.search( "Error", output ):
1928 main.log.error( "Error in getting ports" )
1929 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001930 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001931 return output
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001932 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001933 main.log.error( self.name + ": EOF exception found" )
1934 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001935 main.cleanup()
1936 main.exit()
1937 except:
kelvin8ec71442015-01-15 16:57:00 -08001938 main.log.info( self.name + " ::::::" )
1939 main.log.error( traceback.print_exc() )
1940 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001941 main.cleanup()
1942 main.exit()