blob: 097a303ee524a1f16ad9674e96b7bd52e029949c [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
kelvin-onlabd3b64892015-01-20 13:26:24 -0800170 def startOnosCli( self, ONOSIp, karafTimeout="" ):
kelvin8ec71442015-01-15 16:57:00 -0800171 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800172 karafTimeout is an optional arugument. karafTimeout value passed
173 by user would be used to set the current karaf shell idle timeout.
174 Note that when ever this property is modified the shell will exit and
Hari Krishnad7b9c202015-01-05 10:38:14 -0800175 the subsequent login would reflect new idle timeout.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800176 Below is an example to start a session with 60 seconds idle timeout
177 ( input value is in milliseconds ):
kelvin8ec71442015-01-15 16:57:00 -0800178
Hari Krishna25d42f72015-01-05 15:08:28 -0800179 tValue = "60000"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800180 main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue )
kelvin8ec71442015-01-15 16:57:00 -0800181
kelvin-onlabd3b64892015-01-20 13:26:24 -0800182 Note: karafTimeout is left as str so that this could be read
183 and passed to startOnosCli from PARAMS file as str.
kelvin8ec71442015-01-15 16:57:00 -0800184 """
andrewonlab95ce8322014-10-13 14:12:04 -0400185 try:
kelvin8ec71442015-01-15 16:57:00 -0800186 self.handle.sendline( "" )
187 x = self.handle.expect( [
188 "\$", "onos>" ], timeout=10 )
andrewonlab48829f62014-11-17 13:49:01 -0500189
190 if x == 1:
kelvin8ec71442015-01-15 16:57:00 -0800191 main.log.info( "ONOS cli is already running" )
andrewonlab48829f62014-11-17 13:49:01 -0500192 return main.TRUE
andrewonlab95ce8322014-10-13 14:12:04 -0400193
kelvin8ec71442015-01-15 16:57:00 -0800194 # Wait for onos start ( -w ) and enter onos cli
kelvin-onlabd3b64892015-01-20 13:26:24 -0800195 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800196 i = self.handle.expect( [
197 "onos>",
kelvin-onlab898a6c62015-01-16 14:13:53 -0800198 pexpect.TIMEOUT ], timeout=60 )
andrewonlab2a7ea9b2014-10-24 12:21:05 -0400199
200 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800201 main.log.info( str( ONOSIp ) + " CLI Started successfully" )
Hari Krishnae36ef212015-01-04 14:09:13 -0800202 if karafTimeout:
kelvin8ec71442015-01-15 16:57:00 -0800203 self.handle.sendline(
Hari Krishnaac4e1782015-01-26 12:09:12 -0800204 "config:property-set -p org.apache.karaf.shell\
205 sshIdleTimeout " +
kelvin8ec71442015-01-15 16:57:00 -0800206 karafTimeout )
207 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800208 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800209 self.handle.expect( "onos>" )
andrewonlab2a7ea9b2014-10-24 12:21:05 -0400210 return main.TRUE
211 else:
kelvin8ec71442015-01-15 16:57:00 -0800212 # If failed, send ctrl+c to process and try again
213 main.log.info( "Starting CLI failed. Retrying..." )
214 self.handle.send( "\x03" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800215 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800216 i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ],
217 timeout=30 )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400218 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800219 main.log.info( str( ONOSIp ) + " CLI Started " +
kelvin8ec71442015-01-15 16:57:00 -0800220 "successfully after retry attempt" )
Hari Krishnae36ef212015-01-04 14:09:13 -0800221 if karafTimeout:
kelvin8ec71442015-01-15 16:57:00 -0800222 self.handle.sendline(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800223 "config:property-set -p org.apache.karaf.shell\
224 sshIdleTimeout " +
kelvin8ec71442015-01-15 16:57:00 -0800225 karafTimeout )
226 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800227 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800228 self.handle.expect( "onos>" )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400229 return main.TRUE
230 else:
kelvin8ec71442015-01-15 16:57:00 -0800231 main.log.error( "Connection to CLI " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800232 str( ONOSIp ) + " timeout" )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400233 return main.FALSE
andrewonlab95ce8322014-10-13 14:12:04 -0400234
235 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800236 main.log.error( self.name + ": EOF exception found" )
237 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400238 main.cleanup()
239 main.exit()
240 except:
kelvin8ec71442015-01-15 16:57:00 -0800241 main.log.info( self.name + " ::::::" )
242 main.log.error( traceback.print_exc() )
243 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -0400244 main.cleanup()
245 main.exit()
246
kelvin-onlabd3b64892015-01-20 13:26:24 -0800247 def sendline( self, cmdStr ):
kelvin8ec71442015-01-15 16:57:00 -0800248 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800249 Send a completely user specified string to
250 the onos> prompt. Use this function if you have
andrewonlaba18f6bf2014-10-13 19:31:54 -0400251 a very specific command to send.
Jon Halle3f39ff2015-01-13 11:50:53 -0800252
andrewonlaba18f6bf2014-10-13 19:31:54 -0400253 Warning: There are no sanity checking to commands
254 sent using this method.
kelvin8ec71442015-01-15 16:57:00 -0800255 """
andrewonlaba18f6bf2014-10-13 19:31:54 -0400256 try:
kelvin8ec71442015-01-15 16:57:00 -0800257 self.handle.sendline( "" )
258 self.handle.expect( "onos>" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400259
kelvin-onlab898a6c62015-01-16 14:13:53 -0800260 self.handle.sendline( "log:log \"Sending CLI command: '"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800261 + cmdStr + "'\"" )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800262 self.handle.expect( "onos>" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800263 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -0800264 self.handle.expect( "onos>" )
Jon Hallaea67aa2015-01-23 13:30:57 -0800265 main.log.info( "Command '" + str( cmdStr ) + "' sent to "
266 + self.name + "." )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400267
268 handle = self.handle.before
Jon Hall7bdfc122015-01-23 11:45:32 -0800269 # Remove control strings from output
270 ansiEscape = re.compile( r'\x1b[^m]*m' )
271 handle = ansiEscape.sub( '', handle )
Jon Hall44225f82015-01-23 13:45:14 -0800272 #Remove extra return chars that get added
Jon Hallaea67aa2015-01-23 13:30:57 -0800273 handle = re.sub( r"\s\r", "", handle )
274 handle = handle.strip()
Jon Hall7bdfc122015-01-23 11:45:32 -0800275 # parse for just the output, remove the cmd from handle
276 output = handle.split( cmdStr, 1 )[1]
kelvin8ec71442015-01-15 16:57:00 -0800277
andrewonlaba18f6bf2014-10-13 19:31:54 -0400278
Jon Hall7bdfc122015-01-23 11:45:32 -0800279 return output
andrewonlaba18f6bf2014-10-13 19:31:54 -0400280 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800281 main.log.error( self.name + ": EOF exception found" )
282 main.log.error( self.name + ": " + self.handle.before )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400283 main.cleanup()
284 main.exit()
285 except:
kelvin8ec71442015-01-15 16:57:00 -0800286 main.log.info( self.name + " ::::::" )
287 main.log.error( traceback.print_exc() )
288 main.log.info( self.name + " ::::::" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400289 main.cleanup()
290 main.exit()
291
kelvin8ec71442015-01-15 16:57:00 -0800292 # IMPORTANT NOTE:
293 # For all cli commands, naming convention should match
kelvin-onlabd3b64892015-01-20 13:26:24 -0800294 # the cli command changing 'a:b' with 'aB'.
295 # Ex ) onos:topology > onosTopology
296 # onos:links > onosLinks
297 # feature:list > featureList
Jon Halle3f39ff2015-01-13 11:50:53 -0800298
kelvin-onlabd3b64892015-01-20 13:26:24 -0800299 def addNode( self, nodeId, ONOSIp, tcpPort="" ):
kelvin8ec71442015-01-15 16:57:00 -0800300 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400301 Adds a new cluster node by ID and address information.
302 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800303 * nodeId
304 * ONOSIp
andrewonlabc2d05aa2014-10-13 16:51:10 -0400305 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800306 * tcpPort
kelvin8ec71442015-01-15 16:57:00 -0800307 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400308 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800309 cmdStr = "add-node " + str( nodeId ) + " " +\
310 str( ONOSIp ) + " " + str( tcpPort )
311 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800312 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -0800313 main.log.error( "Error in adding node" )
314 main.log.error( handle )
Jon Halle3f39ff2015-01-13 11:50:53 -0800315 return main.FALSE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400316 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800317 main.log.info( "Node " + str( ONOSIp ) + " added" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400318 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400319 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800320 main.log.error( self.name + ": EOF exception found" )
321 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400322 main.cleanup()
323 main.exit()
324 except:
kelvin8ec71442015-01-15 16:57:00 -0800325 main.log.info( self.name + " ::::::" )
326 main.log.error( traceback.print_exc() )
327 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400328 main.cleanup()
329 main.exit()
330
kelvin-onlabd3b64892015-01-20 13:26:24 -0800331 def removeNode( self, nodeId ):
kelvin8ec71442015-01-15 16:57:00 -0800332 """
andrewonlab86dc3082014-10-13 18:18:38 -0400333 Removes a cluster by ID
334 Issues command: 'remove-node [<node-id>]'
335 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800336 * nodeId
kelvin8ec71442015-01-15 16:57:00 -0800337 """
andrewonlab86dc3082014-10-13 18:18:38 -0400338 try:
andrewonlab86dc3082014-10-13 18:18:38 -0400339
kelvin-onlabd3b64892015-01-20 13:26:24 -0800340 cmdStr = "remove-node " + str( nodeId )
341 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800342 # TODO: add error checking. Does ONOS give any errors?
andrewonlab86dc3082014-10-13 18:18:38 -0400343
344 return main.TRUE
Jon Halle3f39ff2015-01-13 11:50:53 -0800345
andrewonlab86dc3082014-10-13 18:18:38 -0400346 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800347 main.log.error( self.name + ": EOF exception found" )
348 main.log.error( self.name + ": " + self.handle.before )
andrewonlab86dc3082014-10-13 18:18:38 -0400349 main.cleanup()
350 main.exit()
351 except:
kelvin8ec71442015-01-15 16:57:00 -0800352 main.log.info( self.name + " ::::::" )
353 main.log.error( traceback.print_exc() )
354 main.log.info( self.name + " ::::::" )
andrewonlab86dc3082014-10-13 18:18:38 -0400355 main.cleanup()
356 main.exit()
andrewonlabc2d05aa2014-10-13 16:51:10 -0400357
kelvin8ec71442015-01-15 16:57:00 -0800358 def nodes( self ):
359 """
andrewonlab7c211572014-10-15 16:45:20 -0400360 List the nodes currently visible
361 Issues command: 'nodes'
362 Returns: entire handle of list of nodes
kelvin8ec71442015-01-15 16:57:00 -0800363 """
andrewonlab7c211572014-10-15 16:45:20 -0400364 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800365 cmdStr = "nodes"
366 handle = self.sendline( cmdStr )
andrewonlab7c211572014-10-15 16:45:20 -0400367 return handle
andrewonlab7c211572014-10-15 16:45:20 -0400368 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800369 main.log.error( self.name + ": EOF exception found" )
370 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -0400371 main.cleanup()
372 main.exit()
373 except:
kelvin8ec71442015-01-15 16:57:00 -0800374 main.log.info( self.name + " ::::::" )
375 main.log.error( traceback.print_exc() )
376 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -0400377 main.cleanup()
378 main.exit()
379
kelvin8ec71442015-01-15 16:57:00 -0800380 def topology( self ):
381 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400382 Shows the current state of the topology
383 by issusing command: 'onos> onos:topology'
kelvin8ec71442015-01-15 16:57:00 -0800384 """
andrewonlab95ce8322014-10-13 14:12:04 -0400385 try:
Jon Halle3f39ff2015-01-13 11:50:53 -0800386 # either onos:topology or 'topology' will work in CLI
kelvin-onlabd3b64892015-01-20 13:26:24 -0800387 cmdStr = "onos:topology"
388 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800389 main.log.info( "onos:topology returned: " + str( handle ) )
andrewonlab95ce8322014-10-13 14:12:04 -0400390 return handle
andrewonlab95ce8322014-10-13 14:12:04 -0400391 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800392 main.log.error( self.name + ": EOF exception found" )
393 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400394 main.cleanup()
395 main.exit()
396 except:
kelvin8ec71442015-01-15 16:57:00 -0800397 main.log.info( self.name + " ::::::" )
398 main.log.error( traceback.print_exc() )
399 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -0400400 main.cleanup()
401 main.exit()
Jon Halle3f39ff2015-01-13 11:50:53 -0800402
kelvin-onlabd3b64892015-01-20 13:26:24 -0800403 def featureInstall( self, featureStr ):
kelvin8ec71442015-01-15 16:57:00 -0800404 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800405 Installs a specified feature
andrewonlabc2d05aa2014-10-13 16:51:10 -0400406 by issuing command: 'onos> feature:install <feature_str>'
kelvin8ec71442015-01-15 16:57:00 -0800407 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400408 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800409 cmdStr = "feature:install " + str( featureStr )
410 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800411 # TODO: Check for possible error responses from karaf
andrewonlabc2d05aa2014-10-13 16:51:10 -0400412 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400413 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800414 main.log.error( self.name + ": EOF exception found" )
415 main.log.error( self.name + ": " + self.handle.before )
416 main.log.report( "Failed to install feature" )
417 main.log.report( "Exiting test" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400418 main.cleanup()
419 main.exit()
420 except:
kelvin8ec71442015-01-15 16:57:00 -0800421 main.log.info( self.name + " ::::::" )
422 main.log.error( traceback.print_exc() )
423 main.log.report( "Failed to install feature" )
424 main.log.report( "Exiting test" )
425 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400426 main.cleanup()
427 main.exit()
Jon Halle3f39ff2015-01-13 11:50:53 -0800428
kelvin-onlabd3b64892015-01-20 13:26:24 -0800429 def featureUninstall( self, featureStr ):
kelvin8ec71442015-01-15 16:57:00 -0800430 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400431 Uninstalls a specified feature
432 by issuing command: 'onos> feature:uninstall <feature_str>'
kelvin8ec71442015-01-15 16:57:00 -0800433 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400434 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800435 cmdStr = "feature:uninstall " + str( featureStr )
436 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800437 # TODO: Check for possible error responses from karaf
andrewonlabc2d05aa2014-10-13 16:51:10 -0400438 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400439 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800440 main.log.error( self.name + ": EOF exception found" )
441 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400442 main.cleanup()
443 main.exit()
444 except:
kelvin8ec71442015-01-15 16:57:00 -0800445 main.log.info( self.name + " ::::::" )
446 main.log.error( traceback.print_exc() )
447 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400448 main.cleanup()
449 main.exit()
Jon Hallffb386d2014-11-21 13:43:38 -0800450
kelvin-onlabd3b64892015-01-20 13:26:24 -0800451 def devices( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800452 """
Jon Hall7b02d952014-10-17 20:14:54 -0400453 Lists all infrastructure devices or switches
andrewonlab86dc3082014-10-13 18:18:38 -0400454 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800455 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800456 """
andrewonlab86dc3082014-10-13 18:18:38 -0400457 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800458 if jsonFormat:
459 cmdStr = "devices -j"
460 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800461 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800462 handle variable here contains some ANSI escape color code
463 sequences at the end which are invisible in the print command
464 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800465 function. The repr( handle ) output when printed shows the
466 ANSI escape sequences. In json.loads( somestring ), this
467 somestring variable is actually repr( somestring ) and
Jon Halle3f39ff2015-01-13 11:50:53 -0800468 json.loads would fail with the escape sequence. So we take off
469 that escape sequence using:
470
kelvin-onlabd3b64892015-01-20 13:26:24 -0800471 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
472 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800473 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800474 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
475 handle1 = ansiEscape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400476 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400477 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800478 cmdStr = "devices"
479 handle = self.sendline( cmdStr )
Jon Hallcd707292014-10-17 19:06:17 -0400480 return handle
andrewonlab7c211572014-10-15 16:45:20 -0400481 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800482 main.log.error( self.name + ": EOF exception found" )
483 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -0400484 main.cleanup()
485 main.exit()
486 except:
kelvin8ec71442015-01-15 16:57:00 -0800487 main.log.info( self.name + " ::::::" )
488 main.log.error( traceback.print_exc() )
489 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -0400490 main.cleanup()
491 main.exit()
492
kelvin-onlabd3b64892015-01-20 13:26:24 -0800493 def balanceMasters( self ):
kelvin8ec71442015-01-15 16:57:00 -0800494 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800495 This balances the devices across all controllers
496 by issuing command: 'onos> onos:balance-masters'
497 If required this could be extended to return devices balanced output.
kelvin8ec71442015-01-15 16:57:00 -0800498 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800499 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800500 cmdStr = "onos:balance-masters"
501 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800502 # TODO: Check for error responses from ONOS
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800503 return main.TRUE
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800504 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800505 main.log.error( self.name + ": EOF exception found" )
506 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800507 main.cleanup()
508 main.exit()
509 except:
kelvin8ec71442015-01-15 16:57:00 -0800510 main.log.info( self.name + " ::::::" )
511 main.log.error( traceback.print_exc() )
512 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800513 main.cleanup()
514 main.exit()
515
kelvin-onlabd3b64892015-01-20 13:26:24 -0800516 def links( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800517 """
Jon Halle8217482014-10-17 13:49:14 -0400518 Lists all core links
519 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800520 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800521 """
Jon Halle8217482014-10-17 13:49:14 -0400522 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800523 if jsonFormat:
524 cmdStr = "links -j"
525 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800526 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800527 handle variable here contains some ANSI escape color code
528 sequences at the end which are invisible in the print command
529 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800530 function. The repr( handle ) output when printed shows the ANSI
531 escape sequences. In json.loads( somestring ), this somestring
532 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800533 fail with the escape sequence. So we take off that escape
534 sequence using:
535
kelvin-onlabd3b64892015-01-20 13:26:24 -0800536 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
537 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800538 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800539 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
540 handle1 = ansiEscape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400541 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400542 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800543 cmdStr = "links"
544 handle = self.sendline( cmdStr )
Jon Halla001c392014-10-17 18:50:59 -0400545 return handle
Jon Halle8217482014-10-17 13:49:14 -0400546 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800547 main.log.error( self.name + ": EOF exception found" )
548 main.log.error( self.name + ": " + self.handle.before )
Jon Halle8217482014-10-17 13:49:14 -0400549 main.cleanup()
550 main.exit()
551 except:
kelvin8ec71442015-01-15 16:57:00 -0800552 main.log.info( self.name + " ::::::" )
553 main.log.error( traceback.print_exc() )
554 main.log.info( self.name + " ::::::" )
Jon Halle8217482014-10-17 13:49:14 -0400555 main.cleanup()
556 main.exit()
557
kelvin-onlabd3b64892015-01-20 13:26:24 -0800558 def ports( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800559 """
Jon Halle8217482014-10-17 13:49:14 -0400560 Lists all ports
561 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800562 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800563 """
Jon Halle8217482014-10-17 13:49:14 -0400564 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800565 if jsonFormat:
566 cmdStr = "ports -j"
567 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800568 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800569 handle variable here contains some ANSI escape color code
570 sequences at the end which are invisible in the print command
571 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800572 function. The repr( handle ) output when printed shows the ANSI
573 escape sequences. In json.loads( somestring ), this somestring
574 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800575 fail with the escape sequence. So we take off that escape
576 sequence using the following commads:
577
kelvin-onlabd3b64892015-01-20 13:26:24 -0800578 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
579 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800580 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800581 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
582 handle1 = ansiEscape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400583 return handle1
584
Jon Halle8217482014-10-17 13:49:14 -0400585 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800586 cmdStr = "ports"
587 handle = self.sendline( cmdStr )
Jon Hallffb386d2014-11-21 13:43:38 -0800588 return handle
Jon Halle8217482014-10-17 13:49:14 -0400589 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800590 main.log.error( self.name + ": EOF exception found" )
591 main.log.error( self.name + ": " + self.handle.before )
Jon Halle8217482014-10-17 13:49:14 -0400592 main.cleanup()
593 main.exit()
594 except:
kelvin8ec71442015-01-15 16:57:00 -0800595 main.log.info( self.name + " ::::::" )
596 main.log.error( traceback.print_exc() )
597 main.log.info( self.name + " ::::::" )
Jon Halle8217482014-10-17 13:49:14 -0400598 main.cleanup()
599 main.exit()
600
kelvin-onlabd3b64892015-01-20 13:26:24 -0800601 def roles( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800602 """
Jon Hall983a1702014-10-28 18:44:22 -0400603 Lists all devices and the controllers with roles assigned to them
604 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800605 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800606 """
andrewonlab7c211572014-10-15 16:45:20 -0400607 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800608 if jsonFormat:
609 cmdStr = "roles -j"
610 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800611 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800612 handle variable here contains some ANSI escape color code
613 sequences at the end which are invisible in the print command
614 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800615 function. The repr( handle ) output when printed shows the ANSI
616 escape sequences. In json.loads( somestring ), this somestring
617 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800618 fail with the escape sequence.
Jon Hallb1290e82014-11-18 16:17:48 -0500619
Jon Halle3f39ff2015-01-13 11:50:53 -0800620 So we take off that escape sequence using the following
621 commads:
622
kelvin-onlabd3b64892015-01-20 13:26:24 -0800623 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
624 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800625 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800626 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
627 handle1 = ansiEscape.sub( '', handle )
Jon Hall983a1702014-10-28 18:44:22 -0400628 return handle1
andrewonlab7c211572014-10-15 16:45:20 -0400629
andrewonlab7c211572014-10-15 16:45:20 -0400630 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800631 cmdStr = "roles"
632 handle = self.sendline( cmdStr )
Jon Hallffb386d2014-11-21 13:43:38 -0800633 return handle
Jon Hall983a1702014-10-28 18:44:22 -0400634 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800635 main.log.error( self.name + ": EOF exception found" )
636 main.log.error( self.name + ": " + self.handle.before )
Jon Hall983a1702014-10-28 18:44:22 -0400637 main.cleanup()
638 main.exit()
639 except:
kelvin8ec71442015-01-15 16:57:00 -0800640 main.log.info( self.name + " ::::::" )
641 main.log.error( traceback.print_exc() )
642 main.log.info( self.name + " ::::::" )
Jon Hall983a1702014-10-28 18:44:22 -0400643 main.cleanup()
644 main.exit()
645
kelvin-onlabd3b64892015-01-20 13:26:24 -0800646 def getRole( self, deviceId ):
kelvin-onlab898a6c62015-01-16 14:13:53 -0800647 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800648 Given the a string containing the json representation of the "roles"
649 cli command and a partial or whole device id, returns a json object
650 containing the roles output for the first device whose id contains
651 "device_id"
Jon Hall983a1702014-10-28 18:44:22 -0400652
653 Returns:
Jon Halle3f39ff2015-01-13 11:50:53 -0800654 A dict of the role assignments for the given device or
655 None if no match
kelvin8ec71442015-01-15 16:57:00 -0800656 """
Jon Hall983a1702014-10-28 18:44:22 -0400657 try:
658 import json
kelvin-onlabd3b64892015-01-20 13:26:24 -0800659 if deviceId is None:
Jon Hall983a1702014-10-28 18:44:22 -0400660 return None
661 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800662 rawRoles = self.roles()
663 rolesJson = json.loads( rawRoles )
kelvin8ec71442015-01-15 16:57:00 -0800664 # search json for the device with id then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800665 for device in rolesJson:
kelvin8ec71442015-01-15 16:57:00 -0800666 # print device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800667 if str( deviceId ) in device[ 'id' ]:
Jon Hall983a1702014-10-28 18:44:22 -0400668 return device
669 return None
andrewonlab7c211572014-10-15 16:45:20 -0400670
andrewonlab86dc3082014-10-13 18:18:38 -0400671 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800672 main.log.error( self.name + ": EOF exception found" )
673 main.log.error( self.name + ": " + self.handle.before )
andrewonlab86dc3082014-10-13 18:18:38 -0400674 main.cleanup()
675 main.exit()
676 except:
kelvin8ec71442015-01-15 16:57:00 -0800677 main.log.info( self.name + " ::::::" )
678 main.log.error( traceback.print_exc() )
679 main.log.info( self.name + " ::::::" )
andrewonlab86dc3082014-10-13 18:18:38 -0400680 main.cleanup()
681 main.exit()
Jon Hall94fd0472014-12-08 11:52:42 -0800682
kelvin-onlabd3b64892015-01-20 13:26:24 -0800683 def rolesNotNull( self ):
kelvin8ec71442015-01-15 16:57:00 -0800684 """
Jon Hall94fd0472014-12-08 11:52:42 -0800685 Iterates through each device and checks if there is a master assigned
686 Returns: main.TRUE if each device has a master
687 main.FALSE any device has no master
kelvin8ec71442015-01-15 16:57:00 -0800688 """
Jon Hall94fd0472014-12-08 11:52:42 -0800689 try:
690 import json
kelvin-onlabd3b64892015-01-20 13:26:24 -0800691 rawRoles = self.roles()
692 rolesJson = json.loads( rawRoles )
kelvin8ec71442015-01-15 16:57:00 -0800693 # search json for the device with id then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800694 for device in rolesJson:
kelvin8ec71442015-01-15 16:57:00 -0800695 # print device
696 if device[ 'master' ] == "none":
697 main.log.warn( "Device has no master: " + str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800698 return main.FALSE
699 return main.TRUE
700
701 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800702 main.log.error( self.name + ": EOF exception found" )
703 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -0800704 main.cleanup()
705 main.exit()
706 except:
kelvin8ec71442015-01-15 16:57:00 -0800707 main.log.info( self.name + " ::::::" )
708 main.log.error( traceback.print_exc() )
709 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -0800710 main.cleanup()
711 main.exit()
712
kelvin-onlabd3b64892015-01-20 13:26:24 -0800713 def paths( self, srcId, dstId ):
kelvin8ec71442015-01-15 16:57:00 -0800714 """
andrewonlab3e15ead2014-10-15 14:21:34 -0400715 Returns string of paths, and the cost.
716 Issues command: onos:paths <src> <dst>
kelvin8ec71442015-01-15 16:57:00 -0800717 """
andrewonlab3e15ead2014-10-15 14:21:34 -0400718 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800719 cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId )
720 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800721 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -0800722 main.log.error( "Error in getting paths" )
723 return ( handle, "Error" )
andrewonlab3e15ead2014-10-15 14:21:34 -0400724 else:
kelvin8ec71442015-01-15 16:57:00 -0800725 path = handle.split( ";" )[ 0 ]
726 cost = handle.split( ";" )[ 1 ]
727 return ( path, cost )
andrewonlab3e15ead2014-10-15 14:21:34 -0400728 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800729 main.log.error( self.name + ": EOF exception found" )
730 main.log.error( self.name + ": " + self.handle.before )
andrewonlab3e15ead2014-10-15 14:21:34 -0400731 main.cleanup()
732 main.exit()
733 except:
kelvin8ec71442015-01-15 16:57:00 -0800734 main.log.info( self.name + " ::::::" )
735 main.log.error( traceback.print_exc() )
736 main.log.info( self.name + " ::::::" )
andrewonlab3e15ead2014-10-15 14:21:34 -0400737 main.cleanup()
738 main.exit()
Jon Hallffb386d2014-11-21 13:43:38 -0800739
kelvin-onlabd3b64892015-01-20 13:26:24 -0800740 def hosts( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800741 """
Jon Hallffb386d2014-11-21 13:43:38 -0800742 Lists all discovered hosts
Jon Hall42db6dc2014-10-24 19:03:48 -0400743 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800744 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800745 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400746 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800747 if jsonFormat:
748 cmdStr = "hosts -j"
749 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800750 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800751 handle variable here contains some ANSI escape color code
752 sequences at the end which are invisible in the print command
753 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800754 function. The repr( handle ) output when printed shows the ANSI
755 escape sequences. In json.loads( somestring ), this somestring
756 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800757 fail with the escape sequence. So we take off that escape
758 sequence using:
759
kelvin-onlabd3b64892015-01-20 13:26:24 -0800760 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
761 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800762 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800763 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
764 handle1 = ansiEscape.sub( '', handle )
Jon Hall42db6dc2014-10-24 19:03:48 -0400765 return handle1
766 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800767 cmdStr = "hosts"
768 handle = self.sendline( cmdStr )
Jon Hall42db6dc2014-10-24 19:03:48 -0400769 return handle
770 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800771 main.log.error( self.name + ": EOF exception found" )
772 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -0400773 main.cleanup()
774 main.exit()
775 except:
kelvin8ec71442015-01-15 16:57:00 -0800776 main.log.info( self.name + " ::::::" )
777 main.log.error( traceback.print_exc() )
778 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -0400779 main.cleanup()
780 main.exit()
781
kelvin-onlabd3b64892015-01-20 13:26:24 -0800782 def getHost( self, mac ):
kelvin8ec71442015-01-15 16:57:00 -0800783 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400784 Return the first host from the hosts api whose 'id' contains 'mac'
Jon Halle3f39ff2015-01-13 11:50:53 -0800785
786 Note: mac must be a colon seperated mac address, but could be a
787 partial mac address
788
Jon Hall42db6dc2014-10-24 19:03:48 -0400789 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -0800790 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400791 import json
792 try:
kelvin8ec71442015-01-15 16:57:00 -0800793 if mac is None:
Jon Hall42db6dc2014-10-24 19:03:48 -0400794 return None
795 else:
796 mac = mac
kelvin-onlabd3b64892015-01-20 13:26:24 -0800797 rawHosts = self.hosts()
798 hostsJson = json.loads( rawHosts )
kelvin8ec71442015-01-15 16:57:00 -0800799 # search json for the host with mac then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800800 for host in hostsJson:
kelvin8ec71442015-01-15 16:57:00 -0800801 # print "%s in %s?" % ( mac, host[ 'id' ] )
802 if mac in host[ 'id' ]:
Jon Hall42db6dc2014-10-24 19:03:48 -0400803 return host
804 return None
805 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800806 main.log.error( self.name + ": EOF exception found" )
807 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -0400808 main.cleanup()
809 main.exit()
810 except:
kelvin8ec71442015-01-15 16:57:00 -0800811 main.log.info( self.name + " ::::::" )
812 main.log.error( traceback.print_exc() )
813 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -0400814 main.cleanup()
815 main.exit()
816
kelvin-onlabd3b64892015-01-20 13:26:24 -0800817 def getHostsId( self, hostList ):
kelvin8ec71442015-01-15 16:57:00 -0800818 """
819 Obtain list of hosts
andrewonlab3f0a4af2014-10-17 12:25:14 -0400820 Issues command: 'onos> hosts'
kelvin8ec71442015-01-15 16:57:00 -0800821
andrewonlab3f0a4af2014-10-17 12:25:14 -0400822 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800823 * hostList: List of hosts obtained by Mininet
andrewonlab3f0a4af2014-10-17 12:25:14 -0400824 IMPORTANT:
825 This function assumes that you started your
kelvin8ec71442015-01-15 16:57:00 -0800826 topology with the option '--mac'.
andrewonlab3f0a4af2014-10-17 12:25:14 -0400827 Furthermore, it assumes that value of VLAN is '-1'
828 Description:
kelvin8ec71442015-01-15 16:57:00 -0800829 Converts mininet hosts ( h1, h2, h3... ) into
830 ONOS format ( 00:00:00:00:00:01/-1 , ... )
831 """
andrewonlab3f0a4af2014-10-17 12:25:14 -0400832 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800833 onosHostList = []
andrewonlab3f0a4af2014-10-17 12:25:14 -0400834
kelvin-onlabd3b64892015-01-20 13:26:24 -0800835 for host in hostList:
kelvin8ec71442015-01-15 16:57:00 -0800836 host = host.replace( "h", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800837 hostHex = hex( int( host ) ).zfill( 12 )
838 hostHex = str( hostHex ).replace( 'x', '0' )
839 i = iter( str( hostHex ) )
840 hostHex = ":".join( a + b for a, b in zip( i, i ) )
841 hostHex = hostHex + "/-1"
842 onosHostList.append( hostHex )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400843
kelvin-onlabd3b64892015-01-20 13:26:24 -0800844 return onosHostList
andrewonlab3f0a4af2014-10-17 12:25:14 -0400845
846 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800847 main.log.error( self.name + ": EOF exception found" )
848 main.log.error( self.name + ": " + self.handle.before )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400849 main.cleanup()
850 main.exit()
851 except:
kelvin8ec71442015-01-15 16:57:00 -0800852 main.log.info( self.name + " ::::::" )
853 main.log.error( traceback.print_exc() )
854 main.log.info( self.name + " ::::::" )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400855 main.cleanup()
856 main.exit()
andrewonlab3e15ead2014-10-15 14:21:34 -0400857
kelvin-onlabd3b64892015-01-20 13:26:24 -0800858 def addHostIntent( self, hostIdOne, hostIdTwo ):
kelvin8ec71442015-01-15 16:57:00 -0800859 """
andrewonlabe6745342014-10-17 14:29:13 -0400860 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800861 * hostIdOne: ONOS host id for host1
862 * hostIdTwo: ONOS host id for host2
andrewonlabe6745342014-10-17 14:29:13 -0400863 Description:
kelvin8ec71442015-01-15 16:57:00 -0800864 Adds a host-to-host intent ( bidrectional ) by
Jon Hallb1290e82014-11-18 16:17:48 -0500865 specifying the two hosts.
kelvin8ec71442015-01-15 16:57:00 -0800866 """
andrewonlabe6745342014-10-17 14:29:13 -0400867 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800868 cmdStr = "add-host-intent " + str( hostIdOne ) +\
869 " " + str( hostIdTwo )
870 handle = self.sendline( cmdStr )
Hari Krishnaac4e1782015-01-26 12:09:12 -0800871 if re.search( "Error", handle ):
872 main.log.error( "Error in adding Host intent" )
873 return handle
874 else:
875 main.log.info( "Host intent installed between " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800876 str( hostIdOne ) + " and " + str( hostIdTwo ) )
Hari Krishnaac4e1782015-01-26 12:09:12 -0800877 return main.TRUE
878
andrewonlabe6745342014-10-17 14:29:13 -0400879 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800880 main.log.error( self.name + ": EOF exception found" )
881 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe6745342014-10-17 14:29:13 -0400882 main.cleanup()
883 main.exit()
884 except:
kelvin8ec71442015-01-15 16:57:00 -0800885 main.log.info( self.name + " ::::::" )
886 main.log.error( traceback.print_exc() )
887 main.log.info( self.name + " ::::::" )
andrewonlabe6745342014-10-17 14:29:13 -0400888 main.cleanup()
889 main.exit()
890
kelvin-onlabd3b64892015-01-20 13:26:24 -0800891 def addOpticalIntent( self, ingressDevice, egressDevice ):
kelvin8ec71442015-01-15 16:57:00 -0800892 """
andrewonlab7b31d232014-10-24 13:31:47 -0400893 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800894 * ingressDevice: device id of ingress device
895 * egressDevice: device id of egress device
andrewonlab7b31d232014-10-24 13:31:47 -0400896 Optional:
897 TODO: Still needs to be implemented via dev side
kelvin-onlab898a6c62015-01-16 14:13:53 -0800898 """
andrewonlab7b31d232014-10-24 13:31:47 -0400899 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800900 cmdStr = "add-optical-intent " + str( ingressDevice ) +\
901 " " + str( egressDevice )
902 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800903 # If error, return error message
Jon Halle3f39ff2015-01-13 11:50:53 -0800904 if re.search( "Error", handle ):
andrewonlab7b31d232014-10-24 13:31:47 -0400905 return handle
906 else:
907 return main.TRUE
andrewonlab7b31d232014-10-24 13:31:47 -0400908 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800909 main.log.error( self.name + ": EOF exception found" )
910 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7b31d232014-10-24 13:31:47 -0400911 main.cleanup()
912 main.exit()
913 except:
kelvin8ec71442015-01-15 16:57:00 -0800914 main.log.info( self.name + " ::::::" )
915 main.log.error( traceback.print_exc() )
916 main.log.info( self.name + " ::::::" )
andrewonlab7b31d232014-10-24 13:31:47 -0400917 main.cleanup()
918 main.exit()
919
kelvin-onlabd3b64892015-01-20 13:26:24 -0800920 def addPointIntent(
kelvin-onlab898a6c62015-01-16 14:13:53 -0800921 self,
kelvin-onlabd3b64892015-01-20 13:26:24 -0800922 ingressDevice,
923 egressDevice,
924 portIngress="",
925 portEgress="",
kelvin-onlab898a6c62015-01-16 14:13:53 -0800926 ethType="",
927 ethSrc="",
928 ethDst="",
929 bandwidth="",
kelvin-onlabd3b64892015-01-20 13:26:24 -0800930 lambdaAlloc=False,
kelvin-onlab898a6c62015-01-16 14:13:53 -0800931 ipProto="",
932 ipSrc="",
933 ipDst="",
934 tcpSrc="",
935 tcpDst="" ):
kelvin8ec71442015-01-15 16:57:00 -0800936 """
andrewonlab4dbb4d82014-10-17 18:22:31 -0400937 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800938 * ingressDevice: device id of ingress device
939 * egressDevice: device id of egress device
andrewonlab289e4b72014-10-21 21:24:18 -0400940 Optional:
941 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -0800942 * ethSrc: specify ethSrc ( i.e. src mac addr )
943 * ethDst: specify ethDst ( i.e. dst mac addr )
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500944 * bandwidth: specify bandwidth capacity of link
kelvin-onlabd3b64892015-01-20 13:26:24 -0800945 * lambdaAlloc: if True, intent will allocate lambda
andrewonlab40ccd8b2014-11-06 16:23:34 -0500946 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -0800947 * ipProto: specify ip protocol
andrewonlabf77e0cb2014-11-11 17:17:59 -0500948 * ipSrc: specify ip source address
949 * ipDst: specify ip destination address
950 * tcpSrc: specify tcp source port
951 * tcpDst: specify tcp destination port
andrewonlab4dbb4d82014-10-17 18:22:31 -0400952 Description:
kelvin8ec71442015-01-15 16:57:00 -0800953 Adds a point-to-point intent ( uni-directional ) by
andrewonlab289e4b72014-10-21 21:24:18 -0400954 specifying device id's and optional fields
955
Jon Halle3f39ff2015-01-13 11:50:53 -0800956 NOTE: This function may change depending on the
andrewonlab4dbb4d82014-10-17 18:22:31 -0400957 options developers provide for point-to-point
958 intent via cli
kelvin8ec71442015-01-15 16:57:00 -0800959 """
andrewonlab4dbb4d82014-10-17 18:22:31 -0400960 try:
andrewonlab289e4b72014-10-21 21:24:18 -0400961 cmd = ""
962
kelvin8ec71442015-01-15 16:57:00 -0800963 # If there are no optional arguments
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500964 if not ethType and not ethSrc and not ethDst\
kelvin-onlabd3b64892015-01-20 13:26:24 -0800965 and not bandwidth and not lambdaAlloc \
andrewonlabfa4ff502014-11-11 16:41:30 -0500966 and not ipProto and not ipSrc and not ipDst \
967 and not tcpSrc and not tcpDst:
andrewonlab36af3822014-11-18 17:48:18 -0500968 cmd = "add-point-intent"
andrewonlab36af3822014-11-18 17:48:18 -0500969
andrewonlab289e4b72014-10-21 21:24:18 -0400970 else:
andrewonlab36af3822014-11-18 17:48:18 -0500971 cmd = "add-point-intent"
Jon Halle3f39ff2015-01-13 11:50:53 -0800972
andrewonlab0c0a6772014-10-22 12:31:18 -0400973 if ethType:
kelvin8ec71442015-01-15 16:57:00 -0800974 cmd += " --ethType " + str( ethType )
andrewonlab289e4b72014-10-21 21:24:18 -0400975 if ethSrc:
kelvin8ec71442015-01-15 16:57:00 -0800976 cmd += " --ethSrc " + str( ethSrc )
977 if ethDst:
978 cmd += " --ethDst " + str( ethDst )
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500979 if bandwidth:
kelvin8ec71442015-01-15 16:57:00 -0800980 cmd += " --bandwidth " + str( bandwidth )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800981 if lambdaAlloc:
andrewonlabfa4ff502014-11-11 16:41:30 -0500982 cmd += " --lambda "
983 if ipProto:
kelvin8ec71442015-01-15 16:57:00 -0800984 cmd += " --ipProto " + str( ipProto )
andrewonlabfa4ff502014-11-11 16:41:30 -0500985 if ipSrc:
kelvin8ec71442015-01-15 16:57:00 -0800986 cmd += " --ipSrc " + str( ipSrc )
andrewonlabfa4ff502014-11-11 16:41:30 -0500987 if ipDst:
kelvin8ec71442015-01-15 16:57:00 -0800988 cmd += " --ipDst " + str( ipDst )
andrewonlabfa4ff502014-11-11 16:41:30 -0500989 if tcpSrc:
kelvin8ec71442015-01-15 16:57:00 -0800990 cmd += " --tcpSrc " + str( tcpSrc )
andrewonlabfa4ff502014-11-11 16:41:30 -0500991 if tcpDst:
kelvin8ec71442015-01-15 16:57:00 -0800992 cmd += " --tcpDst " + str( tcpDst )
andrewonlab289e4b72014-10-21 21:24:18 -0400993
kelvin8ec71442015-01-15 16:57:00 -0800994 # Check whether the user appended the port
995 # or provided it as an input
kelvin-onlabd3b64892015-01-20 13:26:24 -0800996 if "/" in ingressDevice:
997 cmd += " " + str( ingressDevice )
andrewonlab36af3822014-11-18 17:48:18 -0500998 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800999 if not portIngress:
kelvin8ec71442015-01-15 16:57:00 -08001000 main.log.error( "You must specify " +
1001 "the ingress port" )
1002 # TODO: perhaps more meaningful return
andrewonlab36af3822014-11-18 17:48:18 -05001003 return main.FALSE
1004
kelvin8ec71442015-01-15 16:57:00 -08001005 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001006 str( ingressDevice ) + "/" +\
1007 str( portIngress ) + " "
andrewonlab36af3822014-11-18 17:48:18 -05001008
kelvin-onlabd3b64892015-01-20 13:26:24 -08001009 if "/" in egressDevice:
1010 cmd += " " + str( egressDevice )
andrewonlab36af3822014-11-18 17:48:18 -05001011 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001012 if not portEgress:
kelvin8ec71442015-01-15 16:57:00 -08001013 main.log.error( "You must specify " +
1014 "the egress port" )
andrewonlab36af3822014-11-18 17:48:18 -05001015 return main.FALSE
Jon Halle3f39ff2015-01-13 11:50:53 -08001016
kelvin8ec71442015-01-15 16:57:00 -08001017 cmd += " " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001018 str( egressDevice ) + "/" +\
1019 str( portEgress )
kelvin8ec71442015-01-15 16:57:00 -08001020
kelvin-onlab898a6c62015-01-16 14:13:53 -08001021 handle = self.sendline( cmd )
1022 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -08001023 main.log.error( "Error in adding point-to-point intent" )
Jon Hall47a93fb2015-01-06 16:46:06 -08001024 return main.FALSE
andrewonlab4dbb4d82014-10-17 18:22:31 -04001025 else:
1026 return main.TRUE
andrewonlab4dbb4d82014-10-17 18:22:31 -04001027 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001028 main.log.error( self.name + ": EOF exception found" )
1029 main.log.error( self.name + ": " + self.handle.before )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001030 main.cleanup()
1031 main.exit()
1032 except:
kelvin8ec71442015-01-15 16:57:00 -08001033 main.log.info( self.name + " ::::::" )
1034 main.log.error( traceback.print_exc() )
1035 main.log.info( self.name + " ::::::" )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001036 main.cleanup()
1037 main.exit()
1038
kelvin-onlabd3b64892015-01-20 13:26:24 -08001039 def addMultipointToSinglepointIntent(
kelvin-onlab898a6c62015-01-16 14:13:53 -08001040 self,
kelvin-onlabd3b64892015-01-20 13:26:24 -08001041 ingressDevice1,
1042 ingressDevice2,
1043 egressDevice,
1044 portIngress="",
1045 portEgress="",
kelvin-onlab898a6c62015-01-16 14:13:53 -08001046 ethType="",
1047 ethSrc="",
1048 ethDst="",
1049 bandwidth="",
kelvin-onlabd3b64892015-01-20 13:26:24 -08001050 lambdaAlloc=False,
kelvin-onlab898a6c62015-01-16 14:13:53 -08001051 ipProto="",
1052 ipSrc="",
1053 ipDst="",
1054 tcpSrc="",
1055 tcpDst="",
1056 setEthSrc="",
1057 setEthDst="" ):
kelvin8ec71442015-01-15 16:57:00 -08001058 """
shahshreyad0c80432014-12-04 16:56:05 -08001059 Note:
Jon Halle3f39ff2015-01-13 11:50:53 -08001060 This function assumes that there would be 2 ingress devices and
1061 one egress device. For more number of ingress devices, this
1062 function needs to be modified
shahshreyad0c80432014-12-04 16:56:05 -08001063 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001064 * ingressDevice1: device id of ingress device1
1065 * ingressDevice2: device id of ingress device2
1066 * egressDevice: device id of egress device
shahshreyad0c80432014-12-04 16:56:05 -08001067 Optional:
1068 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -08001069 * ethSrc: specify ethSrc ( i.e. src mac addr )
1070 * ethDst: specify ethDst ( i.e. dst mac addr )
shahshreyad0c80432014-12-04 16:56:05 -08001071 * bandwidth: specify bandwidth capacity of link
kelvin-onlabd3b64892015-01-20 13:26:24 -08001072 * lambdaAlloc: if True, intent will allocate lambda
shahshreyad0c80432014-12-04 16:56:05 -08001073 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -08001074 * ipProto: specify ip protocol
shahshreyad0c80432014-12-04 16:56:05 -08001075 * ipSrc: specify ip source address
1076 * ipDst: specify ip destination address
1077 * tcpSrc: specify tcp source port
1078 * tcpDst: specify tcp destination port
1079 * setEthSrc: action to Rewrite Source MAC Address
1080 * setEthDst: action to Rewrite Destination MAC Address
1081 Description:
kelvin8ec71442015-01-15 16:57:00 -08001082 Adds a multipoint-to-singlepoint intent ( uni-directional ) by
shahshreyad0c80432014-12-04 16:56:05 -08001083 specifying device id's and optional fields
1084
Jon Halle3f39ff2015-01-13 11:50:53 -08001085 NOTE: This function may change depending on the
shahshreyad0c80432014-12-04 16:56:05 -08001086 options developers provide for multipointpoint-to-singlepoint
1087 intent via cli
kelvin8ec71442015-01-15 16:57:00 -08001088 """
shahshreyad0c80432014-12-04 16:56:05 -08001089 try:
1090 cmd = ""
1091
kelvin8ec71442015-01-15 16:57:00 -08001092 # If there are no optional arguments
shahshreyad0c80432014-12-04 16:56:05 -08001093 if not ethType and not ethSrc and not ethDst\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001094 and not bandwidth and not lambdaAlloc\
Jon Halle3f39ff2015-01-13 11:50:53 -08001095 and not ipProto and not ipSrc and not ipDst\
1096 and not tcpSrc and not tcpDst and not setEthSrc\
1097 and not setEthDst:
shahshreyad0c80432014-12-04 16:56:05 -08001098 cmd = "add-multi-to-single-intent"
shahshreyad0c80432014-12-04 16:56:05 -08001099
1100 else:
1101 cmd = "add-multi-to-single-intent"
Jon Halle3f39ff2015-01-13 11:50:53 -08001102
shahshreyad0c80432014-12-04 16:56:05 -08001103 if ethType:
kelvin8ec71442015-01-15 16:57:00 -08001104 cmd += " --ethType " + str( ethType )
shahshreyad0c80432014-12-04 16:56:05 -08001105 if ethSrc:
kelvin8ec71442015-01-15 16:57:00 -08001106 cmd += " --ethSrc " + str( ethSrc )
1107 if ethDst:
1108 cmd += " --ethDst " + str( ethDst )
shahshreyad0c80432014-12-04 16:56:05 -08001109 if bandwidth:
kelvin8ec71442015-01-15 16:57:00 -08001110 cmd += " --bandwidth " + str( bandwidth )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001111 if lambdaAlloc:
shahshreyad0c80432014-12-04 16:56:05 -08001112 cmd += " --lambda "
1113 if ipProto:
kelvin8ec71442015-01-15 16:57:00 -08001114 cmd += " --ipProto " + str( ipProto )
shahshreyad0c80432014-12-04 16:56:05 -08001115 if ipSrc:
kelvin8ec71442015-01-15 16:57:00 -08001116 cmd += " --ipSrc " + str( ipSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001117 if ipDst:
kelvin8ec71442015-01-15 16:57:00 -08001118 cmd += " --ipDst " + str( ipDst )
shahshreyad0c80432014-12-04 16:56:05 -08001119 if tcpSrc:
kelvin8ec71442015-01-15 16:57:00 -08001120 cmd += " --tcpSrc " + str( tcpSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001121 if tcpDst:
kelvin8ec71442015-01-15 16:57:00 -08001122 cmd += " --tcpDst " + str( tcpDst )
shahshreyad0c80432014-12-04 16:56:05 -08001123 if setEthSrc:
kelvin8ec71442015-01-15 16:57:00 -08001124 cmd += " --setEthSrc " + str( setEthSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001125 if setEthDst:
kelvin8ec71442015-01-15 16:57:00 -08001126 cmd += " --setEthDst " + str( setEthDst )
shahshreyad0c80432014-12-04 16:56:05 -08001127
kelvin8ec71442015-01-15 16:57:00 -08001128 # Check whether the user appended the port
1129 # or provided it as an input
kelvin-onlabd3b64892015-01-20 13:26:24 -08001130 if "/" in ingressDevice1:
1131 cmd += " " + str( ingressDevice1 )
shahshreyad0c80432014-12-04 16:56:05 -08001132 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001133 if not portIngress1:
kelvin8ec71442015-01-15 16:57:00 -08001134 main.log.error( "You must specify " +
1135 "the ingress port1" )
1136 # TODO: perhaps more meaningful return
shahshreyad0c80432014-12-04 16:56:05 -08001137 return main.FALSE
1138
kelvin8ec71442015-01-15 16:57:00 -08001139 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001140 str( ingressDevice1 ) + "/" +\
1141 str( portIngress1 ) + " "
shahshreyad0c80432014-12-04 16:56:05 -08001142
kelvin-onlabd3b64892015-01-20 13:26:24 -08001143 if "/" in ingressDevice2:
1144 cmd += " " + str( ingressDevice2 )
shahshreyad0c80432014-12-04 16:56:05 -08001145 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001146 if not portIngress2:
kelvin8ec71442015-01-15 16:57:00 -08001147 main.log.error( "You must specify " +
1148 "the ingress port2" )
1149 # TODO: perhaps more meaningful return
shahshreyad0c80432014-12-04 16:56:05 -08001150 return main.FALSE
1151
kelvin8ec71442015-01-15 16:57:00 -08001152 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001153 str( ingressDevice2 ) + "/" +\
1154 str( portIngress2 ) + " "
shahshreyad0c80432014-12-04 16:56:05 -08001155
kelvin-onlabd3b64892015-01-20 13:26:24 -08001156 if "/" in egressDevice:
1157 cmd += " " + str( egressDevice )
shahshreyad0c80432014-12-04 16:56:05 -08001158 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001159 if not portEgress:
kelvin8ec71442015-01-15 16:57:00 -08001160 main.log.error( "You must specify " +
1161 "the egress port" )
shahshreyad0c80432014-12-04 16:56:05 -08001162 return main.FALSE
Jon Halle3f39ff2015-01-13 11:50:53 -08001163
kelvin8ec71442015-01-15 16:57:00 -08001164 cmd += " " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001165 str( egressDevice ) + "/" +\
1166 str( portEgress )
kelvin8ec71442015-01-15 16:57:00 -08001167 print "cmd= ", cmd
kelvin-onlab898a6c62015-01-16 14:13:53 -08001168 handle = self.sendline( cmd )
1169 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -08001170 main.log.error( "Error in adding point-to-point intent" )
shahshreyad0c80432014-12-04 16:56:05 -08001171 return self.handle
1172 else:
1173 return main.TRUE
shahshreyad0c80432014-12-04 16:56:05 -08001174 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001175 main.log.error( self.name + ": EOF exception found" )
1176 main.log.error( self.name + ": " + self.handle.before )
shahshreyad0c80432014-12-04 16:56:05 -08001177 main.cleanup()
1178 main.exit()
1179 except:
kelvin8ec71442015-01-15 16:57:00 -08001180 main.log.info( self.name + " ::::::" )
1181 main.log.error( traceback.print_exc() )
1182 main.log.info( self.name + " ::::::" )
shahshreyad0c80432014-12-04 16:56:05 -08001183 main.cleanup()
1184 main.exit()
1185
kelvin-onlabd3b64892015-01-20 13:26:24 -08001186 def removeIntent( self, intentId ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001187 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001188 Remove intent for specified intent id
Jon Halle3f39ff2015-01-13 11:50:53 -08001189
1190 Returns:
1191 main.False on error and
1192 cli output otherwise
kelvin-onlab898a6c62015-01-16 14:13:53 -08001193 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001194 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001195 cmdStr = "remove-intent " + str( intentId )
1196 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001197 if re.search( "Error", handle ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001198 main.log.error( "Error in removing intent" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001199 return main.FALSE
andrewonlab9a50dfe2014-10-17 17:22:31 -04001200 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001201 # TODO: Should this be main.TRUE
1202 return handle
andrewonlab9a50dfe2014-10-17 17:22:31 -04001203 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001204 main.log.error( self.name + ": EOF exception found" )
1205 main.log.error( self.name + ": " + self.handle.before )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001206 main.cleanup()
1207 main.exit()
1208 except:
kelvin8ec71442015-01-15 16:57:00 -08001209 main.log.info( self.name + " ::::::" )
1210 main.log.error( traceback.print_exc() )
1211 main.log.info( self.name + " ::::::" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001212 main.cleanup()
1213 main.exit()
1214
kelvin-onlabd3b64892015-01-20 13:26:24 -08001215 def routes( self, jsonFormat=False ):
kelvin8ec71442015-01-15 16:57:00 -08001216 """
kelvin-onlab898a6c62015-01-16 14:13:53 -08001217 NOTE: This method should be used after installing application:
1218 onos-app-sdnip
pingping-lin8b306ac2014-11-17 18:13:51 -08001219 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001220 * jsonFormat: enable output formatting in json
pingping-lin8b306ac2014-11-17 18:13:51 -08001221 Description:
1222 Obtain all routes in the system
kelvin8ec71442015-01-15 16:57:00 -08001223 """
pingping-lin8b306ac2014-11-17 18:13:51 -08001224 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001225 if jsonFormat:
1226 cmdStr = "routes -j"
1227 handleTmp = self.sendline( cmdStr )
1228 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1229 handle = ansiEscape.sub( '', handleTmp )
pingping-lin8b306ac2014-11-17 18:13:51 -08001230 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001231 cmdStr = "routes"
1232 handle = self.sendline( cmdStr )
pingping-lin8b306ac2014-11-17 18:13:51 -08001233 return handle
pingping-lin8b306ac2014-11-17 18:13:51 -08001234 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001235 main.log.error( self.name + ": EOF exception found" )
1236 main.log.error( self.name + ": " + self.handle.before )
pingping-lin8b306ac2014-11-17 18:13:51 -08001237 main.cleanup()
1238 main.exit()
1239 except:
kelvin8ec71442015-01-15 16:57:00 -08001240 main.log.info( self.name + " ::::::" )
1241 main.log.error( traceback.print_exc() )
1242 main.log.info( self.name + " ::::::" )
pingping-lin8b306ac2014-11-17 18:13:51 -08001243 main.cleanup()
1244 main.exit()
1245
kelvin-onlabd3b64892015-01-20 13:26:24 -08001246 def intents( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001247 """
andrewonlab377693f2014-10-21 16:00:30 -04001248 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001249 * jsonFormat: enable output formatting in json
andrewonlabe6745342014-10-17 14:29:13 -04001250 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001251 Obtain intents currently installed
kelvin-onlab898a6c62015-01-16 14:13:53 -08001252 """
andrewonlabe6745342014-10-17 14:29:13 -04001253 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001254 if jsonFormat:
1255 cmdStr = "intents -j"
1256 handle = self.sendline( cmdStr )
1257 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1258 handle = ansiEscape.sub( '', handle )
kelvin8ec71442015-01-15 16:57:00 -08001259 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001260 cmdStr = "intents"
1261 handle = self.sendline( cmdStr )
andrewonlabe6745342014-10-17 14:29:13 -04001262 return handle
andrewonlabe6745342014-10-17 14:29:13 -04001263 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001264 main.log.error( self.name + ": EOF exception found" )
1265 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe6745342014-10-17 14:29:13 -04001266 main.cleanup()
1267 main.exit()
1268 except:
kelvin8ec71442015-01-15 16:57:00 -08001269 main.log.info( self.name + " ::::::" )
1270 main.log.error( traceback.print_exc() )
1271 main.log.info( self.name + " ::::::" )
andrewonlabe6745342014-10-17 14:29:13 -04001272 main.cleanup()
1273 main.exit()
1274
kelvin-onlabd3b64892015-01-20 13:26:24 -08001275 def flows( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001276 """
Shreya Shah0f01c812014-10-26 20:15:28 -04001277 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001278 * jsonFormat: enable output formatting in json
Shreya Shah0f01c812014-10-26 20:15:28 -04001279 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001280 Obtain flows currently installed
kelvin-onlab898a6c62015-01-16 14:13:53 -08001281 """
Shreya Shah0f01c812014-10-26 20:15:28 -04001282 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001283 if jsonFormat:
1284 cmdStr = "flows -j"
1285 handle = self.sendline( cmdStr )
1286 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1287 handle = ansiEscape.sub( '', handle )
Shreya Shah0f01c812014-10-26 20:15:28 -04001288 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001289 cmdStr = "flows"
1290 handle = self.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -08001291 if re.search( "Error\sexecuting\scommand:", handle ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001292 main.log.error( self.name + ".flows() response: " +
1293 str( handle ) )
Shreya Shah0f01c812014-10-26 20:15:28 -04001294 return handle
Shreya Shah0f01c812014-10-26 20:15:28 -04001295 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001296 main.log.error( self.name + ": EOF exception found" )
1297 main.log.error( self.name + ": " + self.handle.before )
Shreya Shah0f01c812014-10-26 20:15:28 -04001298 main.cleanup()
1299 main.exit()
1300 except:
kelvin8ec71442015-01-15 16:57:00 -08001301 main.log.info( self.name + " ::::::" )
1302 main.log.error( traceback.print_exc() )
1303 main.log.info( self.name + " ::::::" )
Shreya Shah0f01c812014-10-26 20:15:28 -04001304 main.cleanup()
1305 main.exit()
1306
kelvin-onlabd3b64892015-01-20 13:26:24 -08001307 def pushTestIntents( self, dpidSrc, dpidDst, numIntents,
1308 numMult="", appId="", report=True ):
kelvin8ec71442015-01-15 16:57:00 -08001309 """
andrewonlab87852b02014-11-19 18:44:19 -05001310 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001311 Push a number of intents in a batch format to
andrewonlab87852b02014-11-19 18:44:19 -05001312 a specific point-to-point intent definition
1313 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001314 * dpidSrc: specify source dpid
1315 * dpidDst: specify destination dpid
1316 * numIntents: specify number of intents to push
andrewonlab87852b02014-11-19 18:44:19 -05001317 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001318 * numMult: number multiplier for multiplying
andrewonlabb66dfa12014-12-02 15:51:10 -05001319 the number of intents specified
kelvin-onlabd3b64892015-01-20 13:26:24 -08001320 * appId: specify the application id init to further
andrewonlabb66dfa12014-12-02 15:51:10 -05001321 modularize the intents
andrewonlab87852b02014-11-19 18:44:19 -05001322 * report: default True, returns latency information
kelvin8ec71442015-01-15 16:57:00 -08001323 """
andrewonlab87852b02014-11-19 18:44:19 -05001324 try:
kelvin8ec71442015-01-15 16:57:00 -08001325 cmd = "push-test-intents " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001326 str( dpidSrc ) + " " + str( dpidDst ) + " " +\
1327 str( numIntents )
1328 if numMult:
1329 cmd += " " + str( numMult )
1330 # If app id is specified, then numMult
kelvin8ec71442015-01-15 16:57:00 -08001331 # must exist because of the way this command
kelvin-onlabd3b64892015-01-20 13:26:24 -08001332 if appId:
1333 cmd += " " + str( appId )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001334 handle = self.sendline( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001335 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1336 handle = ansiEscape.sub( '', handle )
andrewonlab87852b02014-11-19 18:44:19 -05001337 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001338 latResult = []
kelvin8ec71442015-01-15 16:57:00 -08001339 main.log.info( handle )
1340 # Split result by newline
1341 newline = handle.split( "\r\r\n" )
1342 # Ignore the first object of list, which is empty
1343 newline = newline[ 1: ]
1344 # Some sloppy parsing method to get the latency
andrewonlabb66dfa12014-12-02 15:51:10 -05001345 for result in newline:
kelvin8ec71442015-01-15 16:57:00 -08001346 result = result.split( ": " )
1347 # Append the first result of second parse
kelvin-onlabd3b64892015-01-20 13:26:24 -08001348 latResult.append( result[ 1 ].split( " " )[ 0 ] )
1349 main.log.info( latResult )
1350 return latResult
andrewonlab87852b02014-11-19 18:44:19 -05001351 else:
1352 return main.TRUE
andrewonlab87852b02014-11-19 18:44:19 -05001353 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001354 main.log.error( self.name + ": EOF exception found" )
1355 main.log.error( self.name + ": " + self.handle.before )
andrewonlab87852b02014-11-19 18:44:19 -05001356 main.cleanup()
1357 main.exit()
1358 except:
kelvin8ec71442015-01-15 16:57:00 -08001359 main.log.info( self.name + " ::::::" )
1360 main.log.error( traceback.print_exc() )
1361 main.log.info( self.name + " ::::::" )
andrewonlab87852b02014-11-19 18:44:19 -05001362 main.cleanup()
1363 main.exit()
1364
kelvin-onlabd3b64892015-01-20 13:26:24 -08001365 def intentsEventsMetrics( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001366 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001367 Description:Returns topology metrics
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001368 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001369 * jsonFormat: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08001370 """
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001371 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001372 if jsonFormat:
1373 cmdStr = "intents-events-metrics -j"
1374 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001375 # Some color thing that we want to escape
kelvin-onlabd3b64892015-01-20 13:26:24 -08001376 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1377 handle = ansiEscape.sub( '', handle )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001378 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001379 cmdStr = "intents-events-metrics"
1380 handle = self.sendline( cmdStr )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001381 return handle
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001382 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001383 main.log.error( self.name + ": EOF exception found" )
1384 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001385 main.cleanup()
1386 main.exit()
1387 except:
kelvin8ec71442015-01-15 16:57:00 -08001388 main.log.info( self.name + " ::::::" )
1389 main.log.error( traceback.print_exc() )
1390 main.log.info( self.name + " ::::::" )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001391 main.cleanup()
1392 main.exit()
Shreya Shah0f01c812014-10-26 20:15:28 -04001393
kelvin-onlabd3b64892015-01-20 13:26:24 -08001394 def topologyEventsMetrics( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001395 """
1396 Description:Returns topology metrics
andrewonlab867212a2014-10-22 20:13:38 -04001397 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001398 * jsonFormat: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08001399 """
andrewonlab867212a2014-10-22 20:13:38 -04001400 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001401 if jsonFormat:
1402 cmdStr = "topology-events-metrics -j"
1403 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001404 # Some color thing that we want to escape
kelvin-onlabd3b64892015-01-20 13:26:24 -08001405 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1406 handle = ansiEscape.sub( '', handle )
andrewonlab867212a2014-10-22 20:13:38 -04001407 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001408 cmdStr = "topology-events-metrics"
1409 handle = self.sendline( cmdStr )
andrewonlab867212a2014-10-22 20:13:38 -04001410 return handle
andrewonlab867212a2014-10-22 20:13:38 -04001411 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001412 main.log.error( self.name + ": EOF exception found" )
1413 main.log.error( self.name + ": " + self.handle.before )
andrewonlab867212a2014-10-22 20:13:38 -04001414 main.cleanup()
1415 main.exit()
1416 except:
kelvin8ec71442015-01-15 16:57:00 -08001417 main.log.info( self.name + " ::::::" )
1418 main.log.error( traceback.print_exc() )
1419 main.log.info( self.name + " ::::::" )
andrewonlab867212a2014-10-22 20:13:38 -04001420 main.cleanup()
1421 main.exit()
1422
kelvin8ec71442015-01-15 16:57:00 -08001423 # Wrapper functions ****************
1424 # Wrapper functions use existing driver
1425 # functions and extends their use case.
1426 # For example, we may use the output of
1427 # a normal driver function, and parse it
1428 # using a wrapper function
andrewonlabc2d05aa2014-10-13 16:51:10 -04001429
kelvin-onlabd3b64892015-01-20 13:26:24 -08001430 def getAllIntentsId( self ):
kelvin8ec71442015-01-15 16:57:00 -08001431 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001432 Description:
1433 Obtain all intent id's in a list
kelvin8ec71442015-01-15 16:57:00 -08001434 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001435 try:
kelvin8ec71442015-01-15 16:57:00 -08001436 # Obtain output of intents function
kelvin-onlabd3b64892015-01-20 13:26:24 -08001437 intentsStr = self.intents()
1438 allIntentList = []
1439 intentIdList = []
andrewonlab9a50dfe2014-10-17 17:22:31 -04001440
kelvin8ec71442015-01-15 16:57:00 -08001441 # Parse the intents output for ID's
kelvin-onlabd3b64892015-01-20 13:26:24 -08001442 intentsList = [ s.strip() for s in intentsStr.splitlines() ]
1443 for intents in intentsList:
andrewonlab9a50dfe2014-10-17 17:22:31 -04001444 if "onos>" in intents:
1445 continue
1446 elif "intents" in intents:
1447 continue
1448 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001449 lineList = intents.split( " " )
1450 allIntentList.append( lineList[ 0 ] )
kelvin8ec71442015-01-15 16:57:00 -08001451
kelvin-onlabd3b64892015-01-20 13:26:24 -08001452 allIntentList = allIntentList[ 1:-2 ]
andrewonlab9a50dfe2014-10-17 17:22:31 -04001453
kelvin-onlabd3b64892015-01-20 13:26:24 -08001454 for intents in allIntentList:
andrewonlab9a50dfe2014-10-17 17:22:31 -04001455 if not intents:
1456 continue
1457 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001458 intentIdList.append( intents )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001459
kelvin-onlabd3b64892015-01-20 13:26:24 -08001460 return intentIdList
andrewonlab9a50dfe2014-10-17 17:22:31 -04001461
1462 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001463 main.log.error( self.name + ": EOF exception found" )
1464 main.log.error( self.name + ": " + self.handle.before )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001465 main.cleanup()
1466 main.exit()
1467 except:
kelvin8ec71442015-01-15 16:57:00 -08001468 main.log.info( self.name + " ::::::" )
1469 main.log.error( traceback.print_exc() )
1470 main.log.info( self.name + " ::::::" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001471 main.cleanup()
1472 main.exit()
1473
kelvin-onlabd3b64892015-01-20 13:26:24 -08001474 def getAllDevicesId( self ):
kelvin8ec71442015-01-15 16:57:00 -08001475 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04001476 Use 'devices' function to obtain list of all devices
1477 and parse the result to obtain a list of all device
1478 id's. Returns this list. Returns empty list if no
1479 devices exist
kelvin8ec71442015-01-15 16:57:00 -08001480 List is ordered sequentially
1481
andrewonlab3e15ead2014-10-15 14:21:34 -04001482 This function may be useful if you are not sure of the
kelvin8ec71442015-01-15 16:57:00 -08001483 device id, and wish to execute other commands using
andrewonlab3e15ead2014-10-15 14:21:34 -04001484 the ids. By obtaining the list of device ids on the fly,
1485 you can iterate through the list to get mastership, etc.
kelvin8ec71442015-01-15 16:57:00 -08001486 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04001487 try:
kelvin8ec71442015-01-15 16:57:00 -08001488 # Call devices and store result string
kelvin-onlabd3b64892015-01-20 13:26:24 -08001489 devicesStr = self.devices( jsonFormat=False )
1490 idList = []
kelvin8ec71442015-01-15 16:57:00 -08001491
kelvin-onlabd3b64892015-01-20 13:26:24 -08001492 if not devicesStr:
kelvin8ec71442015-01-15 16:57:00 -08001493 main.log.info( "There are no devices to get id from" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001494 return idList
kelvin8ec71442015-01-15 16:57:00 -08001495
1496 # Split the string into list by comma
kelvin-onlabd3b64892015-01-20 13:26:24 -08001497 deviceList = devicesStr.split( "," )
kelvin8ec71442015-01-15 16:57:00 -08001498 # Get temporary list of all arguments with string 'id='
kelvin-onlabd3b64892015-01-20 13:26:24 -08001499 tempList = [ dev for dev in deviceList if "id=" in dev ]
kelvin8ec71442015-01-15 16:57:00 -08001500 # Split list further into arguments before and after string
1501 # 'id='. Get the latter portion ( the actual device id ) and
kelvin-onlabd3b64892015-01-20 13:26:24 -08001502 # append to idList
1503 for arg in tempList:
1504 idList.append( arg.split( "id=" )[ 1 ] )
1505 return idList
andrewonlab7e4d2d32014-10-15 13:23:21 -04001506
1507 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001508 main.log.error( self.name + ": EOF exception found" )
1509 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001510 main.cleanup()
1511 main.exit()
1512 except:
kelvin8ec71442015-01-15 16:57:00 -08001513 main.log.info( self.name + " ::::::" )
1514 main.log.error( traceback.print_exc() )
1515 main.log.info( self.name + " ::::::" )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001516 main.cleanup()
1517 main.exit()
1518
kelvin-onlabd3b64892015-01-20 13:26:24 -08001519 def getAllNodesId( self ):
kelvin8ec71442015-01-15 16:57:00 -08001520 """
andrewonlab7c211572014-10-15 16:45:20 -04001521 Uses 'nodes' function to obtain list of all nodes
1522 and parse the result of nodes to obtain just the
kelvin8ec71442015-01-15 16:57:00 -08001523 node id's.
andrewonlab7c211572014-10-15 16:45:20 -04001524 Returns:
1525 list of node id's
kelvin8ec71442015-01-15 16:57:00 -08001526 """
andrewonlab7c211572014-10-15 16:45:20 -04001527 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001528 nodesStr = self.nodes()
1529 idList = []
andrewonlab7c211572014-10-15 16:45:20 -04001530
kelvin-onlabd3b64892015-01-20 13:26:24 -08001531 if not nodesStr:
kelvin8ec71442015-01-15 16:57:00 -08001532 main.log.info( "There are no nodes to get id from" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001533 return idList
andrewonlab7c211572014-10-15 16:45:20 -04001534
kelvin-onlabd3b64892015-01-20 13:26:24 -08001535 # Sample nodesStr output
kelvin8ec71442015-01-15 16:57:00 -08001536 # id=local, address=127.0.0.1:9876, state=ACTIVE *
andrewonlab7c211572014-10-15 16:45:20 -04001537
kelvin8ec71442015-01-15 16:57:00 -08001538 # Split the string into list by comma
kelvin-onlabd3b64892015-01-20 13:26:24 -08001539 nodesList = nodesStr.split( "," )
1540 tempList = [ node for node in nodesList if "id=" in node ]
1541 for arg in tempList:
1542 idList.append( arg.split( "id=" )[ 1 ] )
andrewonlab7c211572014-10-15 16:45:20 -04001543
kelvin-onlabd3b64892015-01-20 13:26:24 -08001544 return idList
kelvin8ec71442015-01-15 16:57:00 -08001545
andrewonlab7c211572014-10-15 16:45:20 -04001546 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001547 main.log.error( self.name + ": EOF exception found" )
1548 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -04001549 main.cleanup()
1550 main.exit()
1551 except:
kelvin8ec71442015-01-15 16:57:00 -08001552 main.log.info( self.name + " ::::::" )
1553 main.log.error( traceback.print_exc() )
1554 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -04001555 main.cleanup()
1556 main.exit()
andrewonlab7e4d2d32014-10-15 13:23:21 -04001557
kelvin-onlabd3b64892015-01-20 13:26:24 -08001558 def getDevice( self, dpid=None ):
kelvin8ec71442015-01-15 16:57:00 -08001559 """
Jon Halla91c4dc2014-10-22 12:57:04 -04001560 Return the first device from the devices api whose 'id' contains 'dpid'
1561 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -08001562 """
Jon Halla91c4dc2014-10-22 12:57:04 -04001563 import json
1564 try:
kelvin8ec71442015-01-15 16:57:00 -08001565 if dpid is None:
Jon Halla91c4dc2014-10-22 12:57:04 -04001566 return None
1567 else:
kelvin8ec71442015-01-15 16:57:00 -08001568 dpid = dpid.replace( ':', '' )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001569 rawDevices = self.devices()
1570 devicesJson = json.loads( rawDevices )
kelvin8ec71442015-01-15 16:57:00 -08001571 # search json for the device with dpid then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -08001572 for device in devicesJson:
kelvin8ec71442015-01-15 16:57:00 -08001573 # print "%s in %s?" % ( dpid, device[ 'id' ] )
1574 if dpid in device[ 'id' ]:
Jon Halla91c4dc2014-10-22 12:57:04 -04001575 return device
1576 return None
1577 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001578 main.log.error( self.name + ": EOF exception found" )
1579 main.log.error( self.name + ": " + self.handle.before )
Jon Halla91c4dc2014-10-22 12:57:04 -04001580 main.cleanup()
1581 main.exit()
1582 except:
kelvin8ec71442015-01-15 16:57:00 -08001583 main.log.info( self.name + " ::::::" )
1584 main.log.error( traceback.print_exc() )
1585 main.log.info( self.name + " ::::::" )
Jon Halla91c4dc2014-10-22 12:57:04 -04001586 main.cleanup()
1587 main.exit()
1588
kelvin-onlabd3b64892015-01-20 13:26:24 -08001589 def checkStatus( self, ip, numoswitch, numolink, logLevel="info" ):
kelvin8ec71442015-01-15 16:57:00 -08001590 """
1591 Checks the number of swithes & links that ONOS sees against the
1592 supplied values. By default this will report to main.log, but the
Jon Hall42db6dc2014-10-24 19:03:48 -04001593 log level can be specifid.
kelvin8ec71442015-01-15 16:57:00 -08001594
Jon Hall42db6dc2014-10-24 19:03:48 -04001595 Params: ip = ip used for the onos cli
1596 numoswitch = expected number of switches
1597 numlink = expected number of links
kelvin-onlabd3b64892015-01-20 13:26:24 -08001598 logLevel = level to log to. Currently accepts
1599 'info', 'warn' and 'report'
Jon Hall42db6dc2014-10-24 19:03:48 -04001600
1601
kelvin-onlabd3b64892015-01-20 13:26:24 -08001602 logLevel can
Jon Hall42db6dc2014-10-24 19:03:48 -04001603
kelvin8ec71442015-01-15 16:57:00 -08001604 Returns: main.TRUE if the number of switchs and links are correct,
Jon Hall42db6dc2014-10-24 19:03:48 -04001605 main.FALSE if the numer of switches and links is incorrect,
1606 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08001607 """
Jon Hall42db6dc2014-10-24 19:03:48 -04001608 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001609 topology = self.getTopology( ip )
Jon Hall42db6dc2014-10-24 19:03:48 -04001610 if topology == {}:
1611 return main.ERROR
1612 output = ""
kelvin8ec71442015-01-15 16:57:00 -08001613 # Is the number of switches is what we expected
1614 devices = topology.get( 'devices', False )
1615 links = topology.get( 'links', False )
Jon Hall42db6dc2014-10-24 19:03:48 -04001616 if devices == False or links == False:
1617 return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -08001618 switchCheck = ( int( devices ) == int( numoswitch ) )
kelvin8ec71442015-01-15 16:57:00 -08001619 # Is the number of links is what we expected
kelvin-onlabd3b64892015-01-20 13:26:24 -08001620 linkCheck = ( int( links ) == int( numolink ) )
1621 if ( switchCheck and linkCheck ):
kelvin8ec71442015-01-15 16:57:00 -08001622 # We expected the correct numbers
Jon Hall42db6dc2014-10-24 19:03:48 -04001623 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08001624 + "what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04001625 result = main.TRUE
1626 else:
1627 output = output + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001628 "The number of links and switches does not matc\
1629 h what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04001630 result = main.FALSE
kelvin-onlabd3b64892015-01-20 13:26:24 -08001631 output = output + "\n ONOS sees %i devices (%i expected) \
1632 and %i links (%i expected)" % (
1633 int( devices ), int( numoswitch ), int( links ),
1634 int( numolink ) )
1635 if logLevel == "report":
kelvin8ec71442015-01-15 16:57:00 -08001636 main.log.report( output )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001637 elif logLevel == "warn":
kelvin8ec71442015-01-15 16:57:00 -08001638 main.log.warn( output )
Jon Hall42db6dc2014-10-24 19:03:48 -04001639 else:
kelvin8ec71442015-01-15 16:57:00 -08001640 main.log.info( output )
1641 return result
Jon Hall42db6dc2014-10-24 19:03:48 -04001642 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001643 main.log.error( self.name + ": EOF exception found" )
1644 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -04001645 main.cleanup()
1646 main.exit()
1647 except:
kelvin8ec71442015-01-15 16:57:00 -08001648 main.log.info( self.name + " ::::::" )
1649 main.log.error( traceback.print_exc() )
1650 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -04001651 main.cleanup()
1652 main.exit()
Jon Hall1c9e8732014-10-27 19:29:27 -04001653
kelvin-onlabd3b64892015-01-20 13:26:24 -08001654 def deviceRole( self, deviceId, onosNode, role="master" ):
kelvin8ec71442015-01-15 16:57:00 -08001655 """
Jon Hall1c9e8732014-10-27 19:29:27 -04001656 Calls the device-role cli command.
kelvin-onlabd3b64892015-01-20 13:26:24 -08001657 deviceId must be the id of a device as seen in the onos devices command
1658 onosNode is the ip of one of the onos nodes in the cluster
Jon Hall1c9e8732014-10-27 19:29:27 -04001659 role must be either master, standby, or none
1660
Jon Halle3f39ff2015-01-13 11:50:53 -08001661 Returns:
1662 main.TRUE or main.FALSE based on argument verification and
1663 main.ERROR if command returns and error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001664 """
Jon Hall1c9e8732014-10-27 19:29:27 -04001665 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001666 if role.lower() == "master" or role.lower() == "standby" or\
Jon Hall1c9e8732014-10-27 19:29:27 -04001667 role.lower() == "none":
kelvin-onlabd3b64892015-01-20 13:26:24 -08001668 cmdStr = "device-role " +\
1669 str( deviceId ) + " " +\
1670 str( onosNode ) + " " +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001671 str( role )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001672 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001673 if re.search( "Error", handle ):
1674 # end color output to escape any colours
1675 # from the cli
kelvin8ec71442015-01-15 16:57:00 -08001676 main.log.error( self.name + ": " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001677 handle + '\033[0m' )
kelvin8ec71442015-01-15 16:57:00 -08001678 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -08001679 return main.TRUE
Jon Hall1c9e8732014-10-27 19:29:27 -04001680 else:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001681 main.log.error( "Invalid 'role' given to device_role(). " +
1682 "Value was '" + str(role) + "'." )
Jon Hall1c9e8732014-10-27 19:29:27 -04001683 return main.FALSE
Jon Hall1c9e8732014-10-27 19:29:27 -04001684 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001685 main.log.error( self.name + ": EOF exception found" )
1686 main.log.error( self.name + ": " + self.handle.before )
Jon Hall1c9e8732014-10-27 19:29:27 -04001687 main.cleanup()
1688 main.exit()
1689 except:
kelvin8ec71442015-01-15 16:57:00 -08001690 main.log.info( self.name + " ::::::" )
1691 main.log.error( traceback.print_exc() )
1692 main.log.info( self.name + " ::::::" )
Jon Hall1c9e8732014-10-27 19:29:27 -04001693 main.cleanup()
1694 main.exit()
1695
kelvin-onlabd3b64892015-01-20 13:26:24 -08001696 def clusters( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001697 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001698 Lists all clusters
Jon Hallffb386d2014-11-21 13:43:38 -08001699 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001700 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -08001701 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001702 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001703 if jsonFormat:
1704 cmdStr = "clusters -j"
1705 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001706 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001707 handle variable here contains some ANSI escape color code
1708 sequences at the end which are invisible in the print command
Jon Halle3f39ff2015-01-13 11:50:53 -08001709 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -08001710 function. The repr( handle ) output when printed shows the ANSI
1711 escape sequences. In json.loads( somestring ), this somestring
kelvin-onlabd3b64892015-01-20 13:26:24 -08001712 variable is actually repr( somestring ) and json.loads would
1713 fail with the escape sequence. So we take off that escape
1714 sequence using:
Jon Halle3f39ff2015-01-13 11:50:53 -08001715
kelvin-onlabd3b64892015-01-20 13:26:24 -08001716 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1717 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001718 """
kelvin-onlabd3b64892015-01-20 13:26:24 -08001719 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1720 handle1 = ansiEscape.sub( '', handle )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001721 return handle1
1722 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001723 cmdStr = "clusters"
1724 handle = self.sendline( cmdStr )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001725 return handle
1726 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001727 main.log.error( self.name + ": EOF exception found" )
1728 main.log.error( self.name + ": " + self.handle.before )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001729 main.cleanup()
1730 main.exit()
1731 except:
kelvin8ec71442015-01-15 16:57:00 -08001732 main.log.info( self.name + " ::::::" )
1733 main.log.error( traceback.print_exc() )
1734 main.log.info( self.name + " ::::::" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001735 main.cleanup()
1736 main.exit()
1737
kelvin-onlabd3b64892015-01-20 13:26:24 -08001738 def electionTestLeader( self ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001739 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001740 CLI command to get the current leader for the Election test application
1741 NOTE: Requires installation of the onos-app-election feature
1742 Returns: Node IP of the leader if one exists
1743 None if none exists
1744 Main.FALSE on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001745 """
Jon Hall94fd0472014-12-08 11:52:42 -08001746 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001747 cmdStr = "election-test-leader"
1748 response = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001749 # Leader
1750 leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001751 "app\sis\s(?P<node>.+)\."
kelvin-onlabd3b64892015-01-20 13:26:24 -08001752 nodeSearch = re.search( leaderPattern, response )
1753 if nodeSearch:
1754 node = nodeSearch.group( 'node' )
Jon Halle3f39ff2015-01-13 11:50:53 -08001755 main.log.info( "Election-test-leader on " + str( self.name ) +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001756 " found " + node + " as the leader" )
Jon Hall94fd0472014-12-08 11:52:42 -08001757 return node
Jon Halle3f39ff2015-01-13 11:50:53 -08001758 # no leader
1759 nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001760 "the\sElection\sapp"
kelvin-onlabd3b64892015-01-20 13:26:24 -08001761 nullSearch = re.search( nullPattern, response )
1762 if nullSearch:
Jon Halle3f39ff2015-01-13 11:50:53 -08001763 main.log.info( "Election-test-leader found no leader on " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001764 self.name )
Jon Hall94fd0472014-12-08 11:52:42 -08001765 return None
kelvin-onlab898a6c62015-01-16 14:13:53 -08001766 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001767 errorPattern = "Command\snot\sfound"
kelvin-onlab898a6c62015-01-16 14:13:53 -08001768 if re.search( errorPattern, response ):
1769 main.log.error( "Election app is not loaded on " + self.name )
Jon Halle3f39ff2015-01-13 11:50:53 -08001770 # TODO: Should this be main.ERROR?
Jon Hall669173b2014-12-17 11:36:30 -08001771 return main.FALSE
1772 else:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001773 main.log.error( "Error in election_test_leader: " +
1774 "unexpected response" )
kelvin8ec71442015-01-15 16:57:00 -08001775 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001776 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001777 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001778 main.log.error( self.name + ": EOF exception found" )
1779 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001780 main.cleanup()
1781 main.exit()
1782 except:
kelvin8ec71442015-01-15 16:57:00 -08001783 main.log.info( self.name + " ::::::" )
1784 main.log.error( traceback.print_exc() )
1785 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001786 main.cleanup()
1787 main.exit()
1788
kelvin-onlabd3b64892015-01-20 13:26:24 -08001789 def electionTestRun( self ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001790 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001791 CLI command to run for leadership of the Election test application.
1792 NOTE: Requires installation of the onos-app-election feature
1793 Returns: Main.TRUE on success
1794 Main.FALSE on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001795 """
Jon Hall94fd0472014-12-08 11:52:42 -08001796 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001797 cmdStr = "election-test-run"
1798 response = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001799 # success
Jon Halle3f39ff2015-01-13 11:50:53 -08001800 successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001801 "Election\sapp."
Jon Halle3f39ff2015-01-13 11:50:53 -08001802 search = re.search( successPattern, response )
Jon Hall94fd0472014-12-08 11:52:42 -08001803 if search:
Jon Halle3f39ff2015-01-13 11:50:53 -08001804 main.log.info( self.name + " entering leadership elections " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001805 "for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08001806 return main.TRUE
kelvin-onlab898a6c62015-01-16 14:13:53 -08001807 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001808 errorPattern = "Command\snot\sfound"
1809 if re.search( errorPattern, response ):
1810 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08001811 return main.FALSE
1812 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001813 main.log.error( "Error in election_test_run: " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001814 "unexpected response" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001815 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001816 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001817 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001818 main.log.error( self.name + ": EOF exception found" )
1819 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001820 main.cleanup()
1821 main.exit()
1822 except:
kelvin8ec71442015-01-15 16:57:00 -08001823 main.log.info( self.name + " ::::::" )
1824 main.log.error( traceback.print_exc() )
1825 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001826 main.cleanup()
1827 main.exit()
1828
kelvin-onlabd3b64892015-01-20 13:26:24 -08001829 def electionTestWithdraw( self ):
kelvin8ec71442015-01-15 16:57:00 -08001830 """
Jon Hall94fd0472014-12-08 11:52:42 -08001831 * CLI command to withdraw the local node from leadership election for
1832 * the Election test application.
1833 #NOTE: Requires installation of the onos-app-election feature
1834 Returns: Main.TRUE on success
1835 Main.FALSE on error
kelvin8ec71442015-01-15 16:57:00 -08001836 """
Jon Hall94fd0472014-12-08 11:52:42 -08001837 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001838 cmdStr = "election-test-withdraw"
1839 response = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001840 # success
Jon Halle3f39ff2015-01-13 11:50:53 -08001841 successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001842 "\sthe\sElection\sapp."
Jon Halle3f39ff2015-01-13 11:50:53 -08001843 if re.search( successPattern, response ):
1844 main.log.info( self.name + " withdrawing from leadership " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001845 "elections for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08001846 return main.TRUE
kelvin-onlab898a6c62015-01-16 14:13:53 -08001847 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001848 errorPattern = "Command\snot\sfound"
1849 if re.search( errorPattern, response ):
1850 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08001851 return main.FALSE
1852 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001853 main.log.error( "Error in election_test_withdraw: " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001854 "unexpected response" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001855 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001856 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001857 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001858 main.log.error( self.name + ": EOF exception found" )
1859 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001860 main.cleanup()
1861 main.exit()
1862 except:
kelvin8ec71442015-01-15 16:57:00 -08001863 main.log.info( self.name + " ::::::" )
1864 main.log.error( traceback.print_exc() )
1865 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001866 main.cleanup()
1867 main.exit()
Jon Hall1c9e8732014-10-27 19:29:27 -04001868
kelvin8ec71442015-01-15 16:57:00 -08001869 def getDevicePortsEnabledCount( self, dpid ):
1870 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001871 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08001872 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001873 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001874 dpid = str( dpid )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001875 cmdStr = "onos:ports -e " + dpid + " | wc -l"
1876 output = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001877 if re.search( "No such device", output ):
1878 main.log.error( "Error in getting ports" )
1879 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001880 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001881 return output
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001882 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001883 main.log.error( self.name + ": EOF exception found" )
1884 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001885 main.cleanup()
1886 main.exit()
1887 except:
kelvin8ec71442015-01-15 16:57:00 -08001888 main.log.info( self.name + " ::::::" )
1889 main.log.error( traceback.print_exc() )
1890 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001891 main.cleanup()
1892 main.exit()
1893
kelvin8ec71442015-01-15 16:57:00 -08001894 def getDeviceLinksActiveCount( self, dpid ):
1895 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001896 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08001897 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001898 try:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001899 dpid = str( dpid )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001900 cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l"
1901 output = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001902 if re.search( "No such device", output ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001903 main.log.error( "Error in getting ports " )
1904 return ( output, "Error " )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001905 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001906 return output
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001907 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001908 main.log.error( self.name + ": EOF exception found" )
1909 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001910 main.cleanup()
1911 main.exit()
1912 except:
kelvin8ec71442015-01-15 16:57:00 -08001913 main.log.info( self.name + " ::::::" )
1914 main.log.error( traceback.print_exc() )
1915 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001916 main.cleanup()
1917 main.exit()
1918
kelvin8ec71442015-01-15 16:57:00 -08001919 def getAllIntentIds( self ):
1920 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001921 Return a list of all Intent IDs
kelvin8ec71442015-01-15 16:57:00 -08001922 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001923 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001924 cmdStr = "onos:intents | grep id="
1925 output = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001926 if re.search( "Error", output ):
1927 main.log.error( "Error in getting ports" )
1928 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001929 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001930 return output
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001931 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001932 main.log.error( self.name + ": EOF exception found" )
1933 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001934 main.cleanup()
1935 main.exit()
1936 except:
kelvin8ec71442015-01-15 16:57:00 -08001937 main.log.info( self.name + " ::::::" )
1938 main.log.error( traceback.print_exc() )
1939 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001940 main.cleanup()
1941 main.exit()