blob: b8a2bd5614c962a5fe27d8b7ea29b24f52980920 [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
kelvin-onlab898a6c62015-01-16 14:13:53 -080023#import os.path
kelvin8ec71442015-01-15 16:57:00 -080024sys.path.append( "../" )
andrewonlab95ce8322014-10-13 14:12:04 -040025from drivers.common.clidriver import CLI
26
andrewonlab95ce8322014-10-13 14:12:04 -040027
kelvin8ec71442015-01-15 16:57:00 -080028class OnosCliDriver( CLI ):
andrewonlab95ce8322014-10-13 14:12:04 -040029
kelvin8ec71442015-01-15 16:57:00 -080030 def __init__( self ):
31 """
32 Initialize client
33 """
34 super( CLI, self ).__init__()
35
36 def connect( self, **connectargs ):
37 """
andrewonlab95ce8322014-10-13 14:12:04 -040038 Creates ssh handle for ONOS cli.
kelvin8ec71442015-01-15 16:57:00 -080039 """
andrewonlab95ce8322014-10-13 14:12:04 -040040 try:
41 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080042 vars( self )[ key ] = connectargs[ key ]
andrewonlab95ce8322014-10-13 14:12:04 -040043 self.home = "~/ONOS"
44 for key in self.options:
45 if key == "home":
kelvin8ec71442015-01-15 16:57:00 -080046 self.home = self.options[ 'home' ]
andrewonlab95ce8322014-10-13 14:12:04 -040047 break
48
kelvin8ec71442015-01-15 16:57:00 -080049 self.name = self.options[ 'name' ]
50 self.handle = super( OnosCliDriver, self ).connect(
51 user_name=self.user_name,
kelvin-onlab898a6c62015-01-16 14:13:53 -080052 ip_address=self.ip_address,
53 port=self.port,
54 pwd=self.pwd,
55 home=self.home )
andrewonlab95ce8322014-10-13 14:12:04 -040056
kelvin8ec71442015-01-15 16:57:00 -080057 self.handle.sendline( "cd " + self.home )
58 self.handle.expect( "\$" )
andrewonlab95ce8322014-10-13 14:12:04 -040059 if self.handle:
60 return self.handle
kelvin8ec71442015-01-15 16:57:00 -080061 else:
62 main.log.info( "NO ONOS HANDLE" )
andrewonlab95ce8322014-10-13 14:12:04 -040063 return main.FALSE
64 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080065 main.log.error( self.name + ": EOF exception found" )
66 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -040067 main.cleanup()
68 main.exit()
69 except:
kelvin8ec71442015-01-15 16:57:00 -080070 main.log.info( self.name + ":::::::::::::::::::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -040071 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -080072 main.log.info( ":::::::::::::::::::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -040073 main.cleanup()
74 main.exit()
75
kelvin8ec71442015-01-15 16:57:00 -080076 def disconnect( self ):
77 """
andrewonlab95ce8322014-10-13 14:12:04 -040078 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -080079 """
andrewonlab95ce8322014-10-13 14:12:04 -040080 response = ''
81 try:
kelvin8ec71442015-01-15 16:57:00 -080082 self.handle.sendline( "" )
83 i = self.handle.expect( [ "onos>", "\$" ] )
Jon Hall7e5b9172014-10-22 12:32:47 -040084 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -080085 self.handle.sendline( "system:shutdown" )
86 self.handle.expect( "Confirm" )
87 self.handle.sendline( "yes" )
88 self.handle.expect( "\$" )
89 self.handle.sendline( "" )
90 self.handle.expect( "\$" )
91 self.handle.sendline( "exit" )
92 self.handle.expect( "closed" )
andrewonlabc2d05aa2014-10-13 16:51:10 -040093
andrewonlab95ce8322014-10-13 14:12:04 -040094 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080095 main.log.error( self.name + ": EOF exception found" )
96 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -040097 except:
kelvin8ec71442015-01-15 16:57:00 -080098 main.log.error( self.name + ": Connection failed to the host" )
andrewonlab95ce8322014-10-13 14:12:04 -040099 response = main.FALSE
100 return response
101
kelvin8ec71442015-01-15 16:57:00 -0800102 def logout( self ):
103 """
andrewonlab38d2b4a2014-11-13 16:28:47 -0500104 Sends 'logout' command to ONOS cli
kelvin8ec71442015-01-15 16:57:00 -0800105 """
andrewonlab38d2b4a2014-11-13 16:28:47 -0500106 try:
kelvin8ec71442015-01-15 16:57:00 -0800107 self.handle.sendline( "" )
108 i = self.handle.expect( [
andrewonlab9627f432014-11-14 12:45:10 -0500109 "onos>",
kelvin8ec71442015-01-15 16:57:00 -0800110 "\$" ], timeout=10 )
andrewonlab9627f432014-11-14 12:45:10 -0500111 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800112 self.handle.sendline( "logout" )
113 self.handle.expect( "\$" )
andrewonlab9627f432014-11-14 12:45:10 -0500114 elif i == 1:
115 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800116
andrewonlab38d2b4a2014-11-13 16:28:47 -0500117 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800118 main.log.error( self.name + ": eof exception found" )
119 main.log.error( self.name + ": " +
120 self.handle.before )
andrewonlab38d2b4a2014-11-13 16:28:47 -0500121 main.cleanup()
122 main.exit()
123 except:
kelvin8ec71442015-01-15 16:57:00 -0800124 main.log.info( self.name + " ::::::" )
125 main.log.error( traceback.print_exc() )
126 main.log.info( self.name + " ::::::" )
andrewonlab38d2b4a2014-11-13 16:28:47 -0500127 main.cleanup()
128 main.exit()
129
kelvin8ec71442015-01-15 16:57:00 -0800130 def set_cell( self, cellname ):
131 """
andrewonlab95ce8322014-10-13 14:12:04 -0400132 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800133
andrewonlab95ce8322014-10-13 14:12:04 -0400134 Before issuing any cli commands, set the environment variable first.
kelvin8ec71442015-01-15 16:57:00 -0800135 """
andrewonlab95ce8322014-10-13 14:12:04 -0400136 try:
137 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800138 main.log.error( "Must define cellname" )
andrewonlab95ce8322014-10-13 14:12:04 -0400139 main.cleanup()
140 main.exit()
141 else:
kelvin8ec71442015-01-15 16:57:00 -0800142 self.handle.sendline( "cell " + str( cellname ) )
143 # Expect the cellname in the ONOS_CELL variable.
144 # Note that this variable name is subject to change
andrewonlab95ce8322014-10-13 14:12:04 -0400145 # and that this driver will have to change accordingly
kelvin8ec71442015-01-15 16:57:00 -0800146 self.handle.expect( "ONOS_CELL=" + str( cellname ) )
andrewonlab95ce8322014-10-13 14:12:04 -0400147 handle_before = self.handle.before
148 handle_after = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800149 # Get the rest of the handle
150 self.handle.sendline( "" )
151 self.handle.expect( "\$" )
andrewonlab95ce8322014-10-13 14:12:04 -0400152 handle_more = self.handle.before
153
kelvin8ec71442015-01-15 16:57:00 -0800154 main.log.info( "Cell call returned: " + handle_before +
155 handle_after + handle_more )
andrewonlab95ce8322014-10-13 14:12:04 -0400156
157 return main.TRUE
158
159 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800160 main.log.error( self.name + ": eof exception found" )
161 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400162 main.cleanup()
163 main.exit()
164 except:
kelvin8ec71442015-01-15 16:57:00 -0800165 main.log.info( self.name + " ::::::" )
166 main.log.error( traceback.print_exc() )
167 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -0400168 main.cleanup()
169 main.exit()
kelvin8ec71442015-01-15 16:57:00 -0800170
171 def start_onos_cli( self, ONOS_ip, karafTimeout="" ):
172 """
173 karafTimeout is an optional arugument. karafTimeout value passed by user would be used to set the
Hari Krishnad7b9c202015-01-05 10:38:14 -0800174 current karaf shell idle timeout. Note that when ever this property is modified the shell will exit and
175 the subsequent login would reflect new idle timeout.
kelvin8ec71442015-01-15 16:57:00 -0800176 Below is an example to start a session with 60 seconds idle timeout ( input value is in milliseconds ):
177
Hari Krishna25d42f72015-01-05 15:08:28 -0800178 tValue = "60000"
kelvin8ec71442015-01-15 16:57:00 -0800179 main.ONOScli1.start_onos_cli( ONOS_ip, karafTimeout=tValue )
180
Hari Krishna25d42f72015-01-05 15:08:28 -0800181 Note: karafTimeout is left as str so that this could be read and passed to start_onos_cli from PARAMS file as str.
kelvin8ec71442015-01-15 16:57:00 -0800182 """
andrewonlab95ce8322014-10-13 14:12:04 -0400183 try:
kelvin8ec71442015-01-15 16:57:00 -0800184 self.handle.sendline( "" )
185 x = self.handle.expect( [
186 "\$", "onos>" ], timeout=10 )
andrewonlab48829f62014-11-17 13:49:01 -0500187
188 if x == 1:
kelvin8ec71442015-01-15 16:57:00 -0800189 main.log.info( "ONOS cli is already running" )
andrewonlab48829f62014-11-17 13:49:01 -0500190 return main.TRUE
andrewonlab95ce8322014-10-13 14:12:04 -0400191
kelvin8ec71442015-01-15 16:57:00 -0800192 # Wait for onos start ( -w ) and enter onos cli
193 self.handle.sendline( "onos -w " + str( ONOS_ip ) )
194 i = self.handle.expect( [
195 "onos>",
kelvin-onlab898a6c62015-01-16 14:13:53 -0800196 pexpect.TIMEOUT ], timeout=60 )
andrewonlab2a7ea9b2014-10-24 12:21:05 -0400197
198 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800199 main.log.info( str( ONOS_ip ) + " CLI Started successfully" )
Hari Krishnae36ef212015-01-04 14:09:13 -0800200 if karafTimeout:
kelvin8ec71442015-01-15 16:57:00 -0800201 self.handle.sendline(
202 "config:property-set -p org.apache.karaf.shell sshIdleTimeout " +
203 karafTimeout )
204 self.handle.expect( "\$" )
205 self.handle.sendline( "onos -w " + str( ONOS_ip ) )
206 self.handle.expect( "onos>" )
andrewonlab2a7ea9b2014-10-24 12:21:05 -0400207 return main.TRUE
208 else:
kelvin8ec71442015-01-15 16:57:00 -0800209 # If failed, send ctrl+c to process and try again
210 main.log.info( "Starting CLI failed. Retrying..." )
211 self.handle.send( "\x03" )
212 self.handle.sendline( "onos -w " + str( ONOS_ip ) )
213 i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ],
214 timeout=30 )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400215 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800216 main.log.info( str( ONOS_ip ) + " CLI Started " +
217 "successfully after retry attempt" )
Hari Krishnae36ef212015-01-04 14:09:13 -0800218 if karafTimeout:
kelvin8ec71442015-01-15 16:57:00 -0800219 self.handle.sendline(
220 "config:property-set -p org.apache.karaf.shell sshIdleTimeout " +
221 karafTimeout )
222 self.handle.expect( "\$" )
223 self.handle.sendline( "onos -w " + str( ONOS_ip ) )
224 self.handle.expect( "onos>" )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400225 return main.TRUE
226 else:
kelvin8ec71442015-01-15 16:57:00 -0800227 main.log.error( "Connection to CLI " +
228 str( ONOS_ip ) + " timeout" )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400229 return main.FALSE
andrewonlab95ce8322014-10-13 14:12:04 -0400230
231 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800232 main.log.error( self.name + ": EOF exception found" )
233 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400234 main.cleanup()
235 main.exit()
236 except:
kelvin8ec71442015-01-15 16:57:00 -0800237 main.log.info( self.name + " ::::::" )
238 main.log.error( traceback.print_exc() )
239 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -0400240 main.cleanup()
241 main.exit()
242
kelvin8ec71442015-01-15 16:57:00 -0800243 def sendline( self, cmd_str ):
244 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800245 Send a completely user specified string to
246 the onos> prompt. Use this function if you have
andrewonlaba18f6bf2014-10-13 19:31:54 -0400247 a very specific command to send.
Jon Halle3f39ff2015-01-13 11:50:53 -0800248
andrewonlaba18f6bf2014-10-13 19:31:54 -0400249 Warning: There are no sanity checking to commands
250 sent using this method.
kelvin8ec71442015-01-15 16:57:00 -0800251 """
andrewonlaba18f6bf2014-10-13 19:31:54 -0400252 try:
kelvin8ec71442015-01-15 16:57:00 -0800253 self.handle.sendline( "" )
254 self.handle.expect( "onos>" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400255
kelvin-onlab898a6c62015-01-16 14:13:53 -0800256 self.handle.sendline( "log:log \"Sending CLI command: '"
257 + cmd_str + "'\"" )
258 self.handle.expect( "onos>" )
Jon Halle3f39ff2015-01-13 11:50:53 -0800259 self.handle.sendline( cmd_str )
260 self.handle.expect( cmd_str )
kelvin8ec71442015-01-15 16:57:00 -0800261 self.handle.expect( "onos>" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400262
263 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800264
265 self.handle.sendline( "" )
266 self.handle.expect( "onos>" )
267
kelvin-onlab898a6c62015-01-16 14:13:53 -0800268 #handle += self.handle.before
269 #handle += self.handle.after
andrewonlaba18f6bf2014-10-13 19:31:54 -0400270
kelvin-onlab898a6c62015-01-16 14:13:53 -0800271 main.log.info( "Command '" + str(cmd_str) + "' sent to "
272 + self.name + "." )
kelvin8ec71442015-01-15 16:57:00 -0800273 ansi_escape = re.compile( r'\x1b[^m]*m' )
274 handle = ansi_escape.sub( '', handle )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400275
276 return handle
277 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800278 main.log.error( self.name + ": EOF exception found" )
279 main.log.error( self.name + ": " + self.handle.before )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400280 main.cleanup()
281 main.exit()
282 except:
kelvin8ec71442015-01-15 16:57:00 -0800283 main.log.info( self.name + " ::::::" )
284 main.log.error( traceback.print_exc() )
285 main.log.info( self.name + " ::::::" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400286 main.cleanup()
287 main.exit()
288
kelvin8ec71442015-01-15 16:57:00 -0800289 # IMPORTANT NOTE:
290 # For all cli commands, naming convention should match
291 # the cli command replacing ':' with '_'.
292 # Ex ) onos:topology > onos_topology
andrewonlab95ce8322014-10-13 14:12:04 -0400293 # onos:links > onos_links
294 # feature:list > feature_list
Jon Halle3f39ff2015-01-13 11:50:53 -0800295
kelvin8ec71442015-01-15 16:57:00 -0800296 def add_node( self, node_id, ONOS_ip, tcp_port="" ):
297 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400298 Adds a new cluster node by ID and address information.
299 Required:
300 * node_id
301 * ONOS_ip
302 Optional:
303 * tcp_port
kelvin8ec71442015-01-15 16:57:00 -0800304 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400305 try:
kelvin-onlab898a6c62015-01-16 14:13:53 -0800306 cmd_str = "add-node " + str( node_id ) + " " +\
307 str( ONOS_ip ) + " " + str( tcp_port )
Jon Halle3f39ff2015-01-13 11:50:53 -0800308 handle = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800309 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -0800310 main.log.error( "Error in adding node" )
311 main.log.error( handle )
Jon Halle3f39ff2015-01-13 11:50:53 -0800312 return main.FALSE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400313 else:
kelvin8ec71442015-01-15 16:57:00 -0800314 main.log.info( "Node " + str( ONOS_ip ) + " added" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400315 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400316 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800317 main.log.error( self.name + ": EOF exception found" )
318 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400319 main.cleanup()
320 main.exit()
321 except:
kelvin8ec71442015-01-15 16:57:00 -0800322 main.log.info( self.name + " ::::::" )
323 main.log.error( traceback.print_exc() )
324 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400325 main.cleanup()
326 main.exit()
327
kelvin8ec71442015-01-15 16:57:00 -0800328 def remove_node( self, node_id ):
329 """
andrewonlab86dc3082014-10-13 18:18:38 -0400330 Removes a cluster by ID
331 Issues command: 'remove-node [<node-id>]'
332 Required:
333 * node_id
kelvin8ec71442015-01-15 16:57:00 -0800334 """
andrewonlab86dc3082014-10-13 18:18:38 -0400335 try:
andrewonlab86dc3082014-10-13 18:18:38 -0400336
kelvin-onlab898a6c62015-01-16 14:13:53 -0800337 cmd_str = "remove-node " + str( node_id )
Jon Halle3f39ff2015-01-13 11:50:53 -0800338 self.sendline( cmd_str )
339 # TODO: add error checking. Does ONOS give any errors?
andrewonlab86dc3082014-10-13 18:18:38 -0400340
341 return main.TRUE
Jon Halle3f39ff2015-01-13 11:50:53 -0800342
andrewonlab86dc3082014-10-13 18:18:38 -0400343 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800344 main.log.error( self.name + ": EOF exception found" )
345 main.log.error( self.name + ": " + self.handle.before )
andrewonlab86dc3082014-10-13 18:18:38 -0400346 main.cleanup()
347 main.exit()
348 except:
kelvin8ec71442015-01-15 16:57:00 -0800349 main.log.info( self.name + " ::::::" )
350 main.log.error( traceback.print_exc() )
351 main.log.info( self.name + " ::::::" )
andrewonlab86dc3082014-10-13 18:18:38 -0400352 main.cleanup()
353 main.exit()
andrewonlabc2d05aa2014-10-13 16:51:10 -0400354
kelvin8ec71442015-01-15 16:57:00 -0800355 def nodes( self ):
356 """
andrewonlab7c211572014-10-15 16:45:20 -0400357 List the nodes currently visible
358 Issues command: 'nodes'
359 Returns: entire handle of list of nodes
kelvin8ec71442015-01-15 16:57:00 -0800360 """
andrewonlab7c211572014-10-15 16:45:20 -0400361 try:
Jon Halle3f39ff2015-01-13 11:50:53 -0800362 cmd_str = "nodes"
363 handle = self.sendline( cmd_str )
andrewonlab7c211572014-10-15 16:45:20 -0400364 return handle
andrewonlab7c211572014-10-15 16:45:20 -0400365 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800366 main.log.error( self.name + ": EOF exception found" )
367 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -0400368 main.cleanup()
369 main.exit()
370 except:
kelvin8ec71442015-01-15 16:57:00 -0800371 main.log.info( self.name + " ::::::" )
372 main.log.error( traceback.print_exc() )
373 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -0400374 main.cleanup()
375 main.exit()
376
kelvin8ec71442015-01-15 16:57:00 -0800377 def topology( self ):
378 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400379 Shows the current state of the topology
380 by issusing command: 'onos> onos:topology'
kelvin8ec71442015-01-15 16:57:00 -0800381 """
andrewonlab95ce8322014-10-13 14:12:04 -0400382 try:
Jon Halle3f39ff2015-01-13 11:50:53 -0800383 # either onos:topology or 'topology' will work in CLI
384 cmd_str = "onos:topology"
385 handle = self.sendline( cmd_str )
386 main.log.info( "onos:topology returned: " + str( handle ) )
andrewonlab95ce8322014-10-13 14:12:04 -0400387 return handle
andrewonlab95ce8322014-10-13 14:12:04 -0400388 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800389 main.log.error( self.name + ": EOF exception found" )
390 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400391 main.cleanup()
392 main.exit()
393 except:
kelvin8ec71442015-01-15 16:57:00 -0800394 main.log.info( self.name + " ::::::" )
395 main.log.error( traceback.print_exc() )
396 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -0400397 main.cleanup()
398 main.exit()
Jon Halle3f39ff2015-01-13 11:50:53 -0800399
kelvin8ec71442015-01-15 16:57:00 -0800400 def feature_install( self, feature_str ):
401 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800402 Installs a specified feature
andrewonlabc2d05aa2014-10-13 16:51:10 -0400403 by issuing command: 'onos> feature:install <feature_str>'
kelvin8ec71442015-01-15 16:57:00 -0800404 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400405 try:
Jon Halle3f39ff2015-01-13 11:50:53 -0800406 cmd_str = "feature:install " + str( feature_str )
407 self.sendline( cmd_str )
408 # TODO: Check for possible error responses from karaf
andrewonlabc2d05aa2014-10-13 16:51:10 -0400409 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400410 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800411 main.log.error( self.name + ": EOF exception found" )
412 main.log.error( self.name + ": " + self.handle.before )
413 main.log.report( "Failed to install feature" )
414 main.log.report( "Exiting test" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400415 main.cleanup()
416 main.exit()
417 except:
kelvin8ec71442015-01-15 16:57:00 -0800418 main.log.info( self.name + " ::::::" )
419 main.log.error( traceback.print_exc() )
420 main.log.report( "Failed to install feature" )
421 main.log.report( "Exiting test" )
422 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400423 main.cleanup()
424 main.exit()
Jon Halle3f39ff2015-01-13 11:50:53 -0800425
kelvin8ec71442015-01-15 16:57:00 -0800426 def feature_uninstall( self, feature_str ):
427 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400428 Uninstalls a specified feature
429 by issuing command: 'onos> feature:uninstall <feature_str>'
kelvin8ec71442015-01-15 16:57:00 -0800430 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400431 try:
Jon Halle3f39ff2015-01-13 11:50:53 -0800432 cmd_str = "feature:uninstall " + str( feature_str )
433 self.sendline( cmd_str )
434 # TODO: Check for possible error responses from karaf
andrewonlabc2d05aa2014-10-13 16:51:10 -0400435 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400436 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800437 main.log.error( self.name + ": EOF exception found" )
438 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400439 main.cleanup()
440 main.exit()
441 except:
kelvin8ec71442015-01-15 16:57:00 -0800442 main.log.info( self.name + " ::::::" )
443 main.log.error( traceback.print_exc() )
444 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400445 main.cleanup()
446 main.exit()
Jon Hallffb386d2014-11-21 13:43:38 -0800447
kelvin8ec71442015-01-15 16:57:00 -0800448 def devices( self, json_format=True ):
449 """
Jon Hall7b02d952014-10-17 20:14:54 -0400450 Lists all infrastructure devices or switches
andrewonlab86dc3082014-10-13 18:18:38 -0400451 Optional argument:
Jon Hallffb386d2014-11-21 13:43:38 -0800452 * json_format - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800453 """
andrewonlab86dc3082014-10-13 18:18:38 -0400454 try:
Jon Halle8217482014-10-17 13:49:14 -0400455 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -0800456 cmd_str = "devices -j"
457 handle = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800458 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800459 handle variable here contains some ANSI escape color code
460 sequences at the end which are invisible in the print command
461 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800462 function. The repr( handle ) output when printed shows the
463 ANSI escape sequences. In json.loads( somestring ), this
464 somestring variable is actually repr( somestring ) and
Jon Halle3f39ff2015-01-13 11:50:53 -0800465 json.loads would fail with the escape sequence. So we take off
466 that escape sequence using:
467
kelvin-onlab898a6c62015-01-16 14:13:53 -0800468 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
469 handle1 = ansi_escape.sub( '', handle )
470 """
471 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
472 handle1 = ansi_escape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400473 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400474 else:
Jon Halle3f39ff2015-01-13 11:50:53 -0800475 cmd_str = "devices"
476 handle = self.sendline( cmd_str )
Jon Hallcd707292014-10-17 19:06:17 -0400477 return handle
andrewonlab7c211572014-10-15 16:45:20 -0400478 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800479 main.log.error( self.name + ": EOF exception found" )
480 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -0400481 main.cleanup()
482 main.exit()
483 except:
kelvin8ec71442015-01-15 16:57:00 -0800484 main.log.info( self.name + " ::::::" )
485 main.log.error( traceback.print_exc() )
486 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -0400487 main.cleanup()
488 main.exit()
489
kelvin8ec71442015-01-15 16:57:00 -0800490 def balance_masters( self ):
491 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800492 This balances the devices across all controllers
493 by issuing command: 'onos> onos:balance-masters'
494 If required this could be extended to return devices balanced output.
kelvin8ec71442015-01-15 16:57:00 -0800495 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800496 try:
Jon Halle3f39ff2015-01-13 11:50:53 -0800497 cmd_str = "onos:balance-masters"
498 self.sendline( cmd_str )
499 # TODO: Check for error responses from ONOS
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800500 return main.TRUE
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800501 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800502 main.log.error( self.name + ": EOF exception found" )
503 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800504 main.cleanup()
505 main.exit()
506 except:
kelvin8ec71442015-01-15 16:57:00 -0800507 main.log.info( self.name + " ::::::" )
508 main.log.error( traceback.print_exc() )
509 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800510 main.cleanup()
511 main.exit()
512
kelvin8ec71442015-01-15 16:57:00 -0800513 def links( self, json_format=True ):
514 """
Jon Halle8217482014-10-17 13:49:14 -0400515 Lists all core links
516 Optional argument:
Jon Hallffb386d2014-11-21 13:43:38 -0800517 * json_format - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800518 """
Jon Halle8217482014-10-17 13:49:14 -0400519 try:
Jon Halle8217482014-10-17 13:49:14 -0400520 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -0800521 cmd_str = "links -j"
522 handle = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800523 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800524 handle variable here contains some ANSI escape color code
525 sequences at the end which are invisible in the print command
526 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800527 function. The repr( handle ) output when printed shows the ANSI
528 escape sequences. In json.loads( somestring ), this somestring
529 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800530 fail with the escape sequence. So we take off that escape
531 sequence using:
532
kelvin-onlab898a6c62015-01-16 14:13:53 -0800533 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
534 handle1 = ansi_escape.sub( '', handle )
535 """
536 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
537 handle1 = ansi_escape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400538 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400539 else:
Jon Halle3f39ff2015-01-13 11:50:53 -0800540 cmd_str = "links"
541 handle = self.sendline( cmd_str )
Jon Halla001c392014-10-17 18:50:59 -0400542 return handle
Jon Halle8217482014-10-17 13:49:14 -0400543 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800544 main.log.error( self.name + ": EOF exception found" )
545 main.log.error( self.name + ": " + self.handle.before )
Jon Halle8217482014-10-17 13:49:14 -0400546 main.cleanup()
547 main.exit()
548 except:
kelvin8ec71442015-01-15 16:57:00 -0800549 main.log.info( self.name + " ::::::" )
550 main.log.error( traceback.print_exc() )
551 main.log.info( self.name + " ::::::" )
Jon Halle8217482014-10-17 13:49:14 -0400552 main.cleanup()
553 main.exit()
554
kelvin8ec71442015-01-15 16:57:00 -0800555 def ports( self, json_format=True ):
556 """
Jon Halle8217482014-10-17 13:49:14 -0400557 Lists all ports
558 Optional argument:
Jon Hallffb386d2014-11-21 13:43:38 -0800559 * json_format - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800560 """
Jon Halle8217482014-10-17 13:49:14 -0400561 try:
Jon Halle8217482014-10-17 13:49:14 -0400562 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -0800563 cmd_str = "ports -j"
564 handle = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800565 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800566 handle variable here contains some ANSI escape color code
567 sequences at the end which are invisible in the print command
568 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800569 function. The repr( handle ) output when printed shows the ANSI
570 escape sequences. In json.loads( somestring ), this somestring
571 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800572 fail with the escape sequence. So we take off that escape
573 sequence using the following commads:
574
kelvin-onlab898a6c62015-01-16 14:13:53 -0800575 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
576 handle1 = ansi_escape.sub( '', handle )
577 """
578 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
579 handle1 = ansi_escape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400580 return handle1
581
Jon Halle8217482014-10-17 13:49:14 -0400582 else:
Jon Halle3f39ff2015-01-13 11:50:53 -0800583 cmd_str = "ports"
584 handle = self.sendline( cmd_str )
Jon Hallffb386d2014-11-21 13:43:38 -0800585 return handle
Jon Halle8217482014-10-17 13:49:14 -0400586 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800587 main.log.error( self.name + ": EOF exception found" )
588 main.log.error( self.name + ": " + self.handle.before )
Jon Halle8217482014-10-17 13:49:14 -0400589 main.cleanup()
590 main.exit()
591 except:
kelvin8ec71442015-01-15 16:57:00 -0800592 main.log.info( self.name + " ::::::" )
593 main.log.error( traceback.print_exc() )
594 main.log.info( self.name + " ::::::" )
Jon Halle8217482014-10-17 13:49:14 -0400595 main.cleanup()
596 main.exit()
597
kelvin8ec71442015-01-15 16:57:00 -0800598 def roles( self, json_format=True ):
599 """
Jon Hall983a1702014-10-28 18:44:22 -0400600 Lists all devices and the controllers with roles assigned to them
601 Optional argument:
Jon Hallffb386d2014-11-21 13:43:38 -0800602 * json_format - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800603 """
andrewonlab7c211572014-10-15 16:45:20 -0400604 try:
Jon Hall983a1702014-10-28 18:44:22 -0400605 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -0800606 cmd_str = "roles -j"
607 handle = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800608 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800609 handle variable here contains some ANSI escape color code
610 sequences at the end which are invisible in the print command
611 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800612 function. The repr( handle ) output when printed shows the ANSI
613 escape sequences. In json.loads( somestring ), this somestring
614 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800615 fail with the escape sequence.
Jon Hallb1290e82014-11-18 16:17:48 -0500616
Jon Halle3f39ff2015-01-13 11:50:53 -0800617 So we take off that escape sequence using the following
618 commads:
619
kelvin-onlab898a6c62015-01-16 14:13:53 -0800620 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
621 handle1 = ansi_escape.sub( '', handle )
622 """
623 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
624 handle1 = ansi_escape.sub( '', handle )
Jon Hall983a1702014-10-28 18:44:22 -0400625 return handle1
andrewonlab7c211572014-10-15 16:45:20 -0400626
andrewonlab7c211572014-10-15 16:45:20 -0400627 else:
Jon Halle3f39ff2015-01-13 11:50:53 -0800628 cmd_str = "roles"
629 handle = self.sendline( cmd_str )
Jon Hallffb386d2014-11-21 13:43:38 -0800630 return handle
Jon Hall983a1702014-10-28 18:44:22 -0400631 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800632 main.log.error( self.name + ": EOF exception found" )
633 main.log.error( self.name + ": " + self.handle.before )
Jon Hall983a1702014-10-28 18:44:22 -0400634 main.cleanup()
635 main.exit()
636 except:
kelvin8ec71442015-01-15 16:57:00 -0800637 main.log.info( self.name + " ::::::" )
638 main.log.error( traceback.print_exc() )
639 main.log.info( self.name + " ::::::" )
Jon Hall983a1702014-10-28 18:44:22 -0400640 main.cleanup()
641 main.exit()
642
kelvin-onlab898a6c62015-01-16 14:13:53 -0800643 def get_role( self, device_id ):
644 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800645 Given the a string containing the json representation of the "roles"
646 cli command and a partial or whole device id, returns a json object
647 containing the roles output for the first device whose id contains
648 "device_id"
Jon Hall983a1702014-10-28 18:44:22 -0400649
650 Returns:
Jon Halle3f39ff2015-01-13 11:50:53 -0800651 A dict of the role assignments for the given device or
652 None if no match
kelvin8ec71442015-01-15 16:57:00 -0800653 """
Jon Hall983a1702014-10-28 18:44:22 -0400654 try:
655 import json
kelvin8ec71442015-01-15 16:57:00 -0800656 if device_id is None:
Jon Hall983a1702014-10-28 18:44:22 -0400657 return None
658 else:
659 raw_roles = self.roles()
kelvin8ec71442015-01-15 16:57:00 -0800660 roles_json = json.loads( raw_roles )
661 # search json for the device with id then return the device
Jon Hall983a1702014-10-28 18:44:22 -0400662 for device in roles_json:
kelvin8ec71442015-01-15 16:57:00 -0800663 # print device
664 if str( device_id ) in device[ 'id' ]:
Jon Hall983a1702014-10-28 18:44:22 -0400665 return device
666 return None
andrewonlab7c211572014-10-15 16:45:20 -0400667
andrewonlab86dc3082014-10-13 18:18:38 -0400668 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800669 main.log.error( self.name + ": EOF exception found" )
670 main.log.error( self.name + ": " + self.handle.before )
andrewonlab86dc3082014-10-13 18:18:38 -0400671 main.cleanup()
672 main.exit()
673 except:
kelvin8ec71442015-01-15 16:57:00 -0800674 main.log.info( self.name + " ::::::" )
675 main.log.error( traceback.print_exc() )
676 main.log.info( self.name + " ::::::" )
andrewonlab86dc3082014-10-13 18:18:38 -0400677 main.cleanup()
678 main.exit()
Jon Hall94fd0472014-12-08 11:52:42 -0800679
kelvin8ec71442015-01-15 16:57:00 -0800680 def roles_not_null( self ):
681 """
Jon Hall94fd0472014-12-08 11:52:42 -0800682 Iterates through each device and checks if there is a master assigned
683 Returns: main.TRUE if each device has a master
684 main.FALSE any device has no master
kelvin8ec71442015-01-15 16:57:00 -0800685 """
Jon Hall94fd0472014-12-08 11:52:42 -0800686 try:
687 import json
688 raw_roles = self.roles()
kelvin8ec71442015-01-15 16:57:00 -0800689 roles_json = json.loads( raw_roles )
690 # search json for the device with id then return the device
Jon Hall94fd0472014-12-08 11:52:42 -0800691 for device in roles_json:
kelvin8ec71442015-01-15 16:57:00 -0800692 # print device
693 if device[ 'master' ] == "none":
694 main.log.warn( "Device has no master: " + str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800695 return main.FALSE
696 return main.TRUE
697
698 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800699 main.log.error( self.name + ": EOF exception found" )
700 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -0800701 main.cleanup()
702 main.exit()
703 except:
kelvin8ec71442015-01-15 16:57:00 -0800704 main.log.info( self.name + " ::::::" )
705 main.log.error( traceback.print_exc() )
706 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -0800707 main.cleanup()
708 main.exit()
709
kelvin8ec71442015-01-15 16:57:00 -0800710 def paths( self, src_id, dst_id ):
711 """
andrewonlab3e15ead2014-10-15 14:21:34 -0400712 Returns string of paths, and the cost.
713 Issues command: onos:paths <src> <dst>
kelvin8ec71442015-01-15 16:57:00 -0800714 """
andrewonlab3e15ead2014-10-15 14:21:34 -0400715 try:
kelvin-onlab898a6c62015-01-16 14:13:53 -0800716 cmd_str = "onos:paths " + str( src_id ) + " " + str( dst_id )
Jon Halle3f39ff2015-01-13 11:50:53 -0800717 handle = self.sendline( cmd_str )
718 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -0800719 main.log.error( "Error in getting paths" )
720 return ( handle, "Error" )
andrewonlab3e15ead2014-10-15 14:21:34 -0400721 else:
kelvin8ec71442015-01-15 16:57:00 -0800722 path = handle.split( ";" )[ 0 ]
723 cost = handle.split( ";" )[ 1 ]
724 return ( path, cost )
andrewonlab3e15ead2014-10-15 14:21:34 -0400725 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800726 main.log.error( self.name + ": EOF exception found" )
727 main.log.error( self.name + ": " + self.handle.before )
andrewonlab3e15ead2014-10-15 14:21:34 -0400728 main.cleanup()
729 main.exit()
730 except:
kelvin8ec71442015-01-15 16:57:00 -0800731 main.log.info( self.name + " ::::::" )
732 main.log.error( traceback.print_exc() )
733 main.log.info( self.name + " ::::::" )
andrewonlab3e15ead2014-10-15 14:21:34 -0400734 main.cleanup()
735 main.exit()
Jon Hallffb386d2014-11-21 13:43:38 -0800736
kelvin8ec71442015-01-15 16:57:00 -0800737 def hosts( self, json_format=True ):
738 """
Jon Hallffb386d2014-11-21 13:43:38 -0800739 Lists all discovered hosts
Jon Hall42db6dc2014-10-24 19:03:48 -0400740 Optional argument:
Jon Hallffb386d2014-11-21 13:43:38 -0800741 * json_format - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800742 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400743 try:
Jon Hall42db6dc2014-10-24 19:03:48 -0400744 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -0800745 cmd_str = "hosts -j"
746 handle = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800747 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800748 handle variable here contains some ANSI escape color code
749 sequences at the end which are invisible in the print command
750 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800751 function. The repr( handle ) output when printed shows the ANSI
752 escape sequences. In json.loads( somestring ), this somestring
753 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800754 fail with the escape sequence. So we take off that escape
755 sequence using:
756
kelvin-onlab898a6c62015-01-16 14:13:53 -0800757 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
758 handle1 = ansi_escape.sub( '', handle )
759 """
760 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
761 handle1 = ansi_escape.sub( '', handle )
Jon Hall42db6dc2014-10-24 19:03:48 -0400762 return handle1
763 else:
Jon Halle3f39ff2015-01-13 11:50:53 -0800764 cmd_str = "hosts"
765 handle = self.sendline( cmd_str )
Jon Hall42db6dc2014-10-24 19:03:48 -0400766 return handle
767 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800768 main.log.error( self.name + ": EOF exception found" )
769 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -0400770 main.cleanup()
771 main.exit()
772 except:
kelvin8ec71442015-01-15 16:57:00 -0800773 main.log.info( self.name + " ::::::" )
774 main.log.error( traceback.print_exc() )
775 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -0400776 main.cleanup()
777 main.exit()
778
kelvin8ec71442015-01-15 16:57:00 -0800779 def get_host( self, mac ):
780 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400781 Return the first host from the hosts api whose 'id' contains 'mac'
Jon Halle3f39ff2015-01-13 11:50:53 -0800782
783 Note: mac must be a colon seperated mac address, but could be a
784 partial mac address
785
Jon Hall42db6dc2014-10-24 19:03:48 -0400786 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -0800787 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400788 import json
789 try:
kelvin8ec71442015-01-15 16:57:00 -0800790 if mac is None:
Jon Hall42db6dc2014-10-24 19:03:48 -0400791 return None
792 else:
793 mac = mac
794 raw_hosts = self.hosts()
kelvin8ec71442015-01-15 16:57:00 -0800795 hosts_json = json.loads( raw_hosts )
796 # search json for the host with mac then return the device
Jon Hall42db6dc2014-10-24 19:03:48 -0400797 for host in hosts_json:
kelvin8ec71442015-01-15 16:57:00 -0800798 # print "%s in %s?" % ( mac, host[ 'id' ] )
799 if mac in host[ 'id' ]:
Jon Hall42db6dc2014-10-24 19:03:48 -0400800 return host
801 return None
802 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800803 main.log.error( self.name + ": EOF exception found" )
804 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -0400805 main.cleanup()
806 main.exit()
807 except:
kelvin8ec71442015-01-15 16:57:00 -0800808 main.log.info( self.name + " ::::::" )
809 main.log.error( traceback.print_exc() )
810 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -0400811 main.cleanup()
812 main.exit()
813
kelvin8ec71442015-01-15 16:57:00 -0800814 def get_hosts_id( self, host_list ):
815 """
816 Obtain list of hosts
andrewonlab3f0a4af2014-10-17 12:25:14 -0400817 Issues command: 'onos> hosts'
kelvin8ec71442015-01-15 16:57:00 -0800818
andrewonlab3f0a4af2014-10-17 12:25:14 -0400819 Required:
820 * host_list: List of hosts obtained by Mininet
821 IMPORTANT:
822 This function assumes that you started your
kelvin8ec71442015-01-15 16:57:00 -0800823 topology with the option '--mac'.
andrewonlab3f0a4af2014-10-17 12:25:14 -0400824 Furthermore, it assumes that value of VLAN is '-1'
825 Description:
kelvin8ec71442015-01-15 16:57:00 -0800826 Converts mininet hosts ( h1, h2, h3... ) into
827 ONOS format ( 00:00:00:00:00:01/-1 , ... )
828 """
andrewonlab3f0a4af2014-10-17 12:25:14 -0400829 try:
andrewonlab3f0a4af2014-10-17 12:25:14 -0400830 onos_host_list = []
831
832 for host in host_list:
kelvin8ec71442015-01-15 16:57:00 -0800833 host = host.replace( "h", "" )
834 host_hex = hex( int( host ) ).zfill( 12 )
835 host_hex = str( host_hex ).replace( 'x', '0' )
836 i = iter( str( host_hex ) )
837 host_hex = ":".join( a + b for a, b in zip( i, i ) )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400838 host_hex = host_hex + "/-1"
kelvin8ec71442015-01-15 16:57:00 -0800839 onos_host_list.append( host_hex )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400840
kelvin8ec71442015-01-15 16:57:00 -0800841 return onos_host_list
andrewonlab3f0a4af2014-10-17 12:25:14 -0400842
843 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800844 main.log.error( self.name + ": EOF exception found" )
845 main.log.error( self.name + ": " + self.handle.before )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400846 main.cleanup()
847 main.exit()
848 except:
kelvin8ec71442015-01-15 16:57:00 -0800849 main.log.info( self.name + " ::::::" )
850 main.log.error( traceback.print_exc() )
851 main.log.info( self.name + " ::::::" )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400852 main.cleanup()
853 main.exit()
andrewonlab3e15ead2014-10-15 14:21:34 -0400854
kelvin8ec71442015-01-15 16:57:00 -0800855 def add_host_intent( self, host_id_one, host_id_two ):
856 """
andrewonlabe6745342014-10-17 14:29:13 -0400857 Required:
858 * host_id_one: ONOS host id for host1
859 * host_id_two: ONOS host id for host2
860 Description:
kelvin8ec71442015-01-15 16:57:00 -0800861 Adds a host-to-host intent ( bidrectional ) by
Jon Hallb1290e82014-11-18 16:17:48 -0500862 specifying the two hosts.
kelvin8ec71442015-01-15 16:57:00 -0800863 """
andrewonlabe6745342014-10-17 14:29:13 -0400864 try:
kelvin-onlab898a6c62015-01-16 14:13:53 -0800865 cmd_str = "add-host-intent " + str( host_id_one ) +\
866 " " + str( host_id_two )
Jon Halle3f39ff2015-01-13 11:50:53 -0800867 handle = self.sendline( cmd_str )
kelvin8ec71442015-01-15 16:57:00 -0800868 main.log.info( "Host intent installed between " +
869 str( host_id_one ) + " and " + str( host_id_two ) )
andrewonlabe6745342014-10-17 14:29:13 -0400870 return handle
andrewonlabe6745342014-10-17 14:29:13 -0400871 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800872 main.log.error( self.name + ": EOF exception found" )
873 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe6745342014-10-17 14:29:13 -0400874 main.cleanup()
875 main.exit()
876 except:
kelvin8ec71442015-01-15 16:57:00 -0800877 main.log.info( self.name + " ::::::" )
878 main.log.error( traceback.print_exc() )
879 main.log.info( self.name + " ::::::" )
andrewonlabe6745342014-10-17 14:29:13 -0400880 main.cleanup()
881 main.exit()
882
kelvin8ec71442015-01-15 16:57:00 -0800883 def add_optical_intent( self, ingress_device, egress_device ):
884 """
andrewonlab7b31d232014-10-24 13:31:47 -0400885 Required:
886 * ingress_device: device id of ingress device
887 * egress_device: device id of egress device
888 Optional:
889 TODO: Still needs to be implemented via dev side
kelvin-onlab898a6c62015-01-16 14:13:53 -0800890 """
andrewonlab7b31d232014-10-24 13:31:47 -0400891 try:
Jon Halle3f39ff2015-01-13 11:50:53 -0800892 cmd_str = "add-optical-intent " + str( ingress_device ) +\
kelvin-onlab898a6c62015-01-16 14:13:53 -0800893 " " + str( egress_device )
Jon Halle3f39ff2015-01-13 11:50:53 -0800894 handle = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800895 # If error, return error message
Jon Halle3f39ff2015-01-13 11:50:53 -0800896 if re.search( "Error", handle ):
andrewonlab7b31d232014-10-24 13:31:47 -0400897 return handle
898 else:
899 return main.TRUE
andrewonlab7b31d232014-10-24 13:31:47 -0400900 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800901 main.log.error( self.name + ": EOF exception found" )
902 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7b31d232014-10-24 13:31:47 -0400903 main.cleanup()
904 main.exit()
905 except:
kelvin8ec71442015-01-15 16:57:00 -0800906 main.log.info( self.name + " ::::::" )
907 main.log.error( traceback.print_exc() )
908 main.log.info( self.name + " ::::::" )
andrewonlab7b31d232014-10-24 13:31:47 -0400909 main.cleanup()
910 main.exit()
911
kelvin-onlab898a6c62015-01-16 14:13:53 -0800912 def add_point_intent(
913 self,
914 ingress_device,
915 egress_device,
916 port_ingress="",
917 port_egress="",
918 ethType="",
919 ethSrc="",
920 ethDst="",
921 bandwidth="",
922 lambda_alloc=False,
923 ipProto="",
924 ipSrc="",
925 ipDst="",
926 tcpSrc="",
927 tcpDst="" ):
kelvin8ec71442015-01-15 16:57:00 -0800928 """
andrewonlab4dbb4d82014-10-17 18:22:31 -0400929 Required:
930 * ingress_device: device id of ingress device
931 * egress_device: device id of egress device
andrewonlab289e4b72014-10-21 21:24:18 -0400932 Optional:
933 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -0800934 * ethSrc: specify ethSrc ( i.e. src mac addr )
935 * ethDst: specify ethDst ( i.e. dst mac addr )
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500936 * bandwidth: specify bandwidth capacity of link
Jon Halle3f39ff2015-01-13 11:50:53 -0800937 * lambda_alloc: if True, intent will allocate lambda
andrewonlab40ccd8b2014-11-06 16:23:34 -0500938 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -0800939 * ipProto: specify ip protocol
andrewonlabf77e0cb2014-11-11 17:17:59 -0500940 * ipSrc: specify ip source address
941 * ipDst: specify ip destination address
942 * tcpSrc: specify tcp source port
943 * tcpDst: specify tcp destination port
andrewonlab4dbb4d82014-10-17 18:22:31 -0400944 Description:
kelvin8ec71442015-01-15 16:57:00 -0800945 Adds a point-to-point intent ( uni-directional ) by
andrewonlab289e4b72014-10-21 21:24:18 -0400946 specifying device id's and optional fields
947
Jon Halle3f39ff2015-01-13 11:50:53 -0800948 NOTE: This function may change depending on the
andrewonlab4dbb4d82014-10-17 18:22:31 -0400949 options developers provide for point-to-point
950 intent via cli
kelvin8ec71442015-01-15 16:57:00 -0800951 """
andrewonlab4dbb4d82014-10-17 18:22:31 -0400952 try:
andrewonlab289e4b72014-10-21 21:24:18 -0400953 cmd = ""
954
kelvin8ec71442015-01-15 16:57:00 -0800955 # If there are no optional arguments
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500956 if not ethType and not ethSrc and not ethDst\
andrewonlabfa4ff502014-11-11 16:41:30 -0500957 and not bandwidth and not lambda_alloc \
958 and not ipProto and not ipSrc and not ipDst \
959 and not tcpSrc and not tcpDst:
andrewonlab36af3822014-11-18 17:48:18 -0500960 cmd = "add-point-intent"
andrewonlab36af3822014-11-18 17:48:18 -0500961
andrewonlab289e4b72014-10-21 21:24:18 -0400962 else:
andrewonlab36af3822014-11-18 17:48:18 -0500963 cmd = "add-point-intent"
Jon Halle3f39ff2015-01-13 11:50:53 -0800964
andrewonlab0c0a6772014-10-22 12:31:18 -0400965 if ethType:
kelvin8ec71442015-01-15 16:57:00 -0800966 cmd += " --ethType " + str( ethType )
andrewonlab289e4b72014-10-21 21:24:18 -0400967 if ethSrc:
kelvin8ec71442015-01-15 16:57:00 -0800968 cmd += " --ethSrc " + str( ethSrc )
969 if ethDst:
970 cmd += " --ethDst " + str( ethDst )
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500971 if bandwidth:
kelvin8ec71442015-01-15 16:57:00 -0800972 cmd += " --bandwidth " + str( bandwidth )
andrewonlab0dbb6ec2014-11-06 13:46:55 -0500973 if lambda_alloc:
andrewonlabfa4ff502014-11-11 16:41:30 -0500974 cmd += " --lambda "
975 if ipProto:
kelvin8ec71442015-01-15 16:57:00 -0800976 cmd += " --ipProto " + str( ipProto )
andrewonlabfa4ff502014-11-11 16:41:30 -0500977 if ipSrc:
kelvin8ec71442015-01-15 16:57:00 -0800978 cmd += " --ipSrc " + str( ipSrc )
andrewonlabfa4ff502014-11-11 16:41:30 -0500979 if ipDst:
kelvin8ec71442015-01-15 16:57:00 -0800980 cmd += " --ipDst " + str( ipDst )
andrewonlabfa4ff502014-11-11 16:41:30 -0500981 if tcpSrc:
kelvin8ec71442015-01-15 16:57:00 -0800982 cmd += " --tcpSrc " + str( tcpSrc )
andrewonlabfa4ff502014-11-11 16:41:30 -0500983 if tcpDst:
kelvin8ec71442015-01-15 16:57:00 -0800984 cmd += " --tcpDst " + str( tcpDst )
andrewonlab289e4b72014-10-21 21:24:18 -0400985
kelvin8ec71442015-01-15 16:57:00 -0800986 # Check whether the user appended the port
987 # or provided it as an input
andrewonlab36af3822014-11-18 17:48:18 -0500988 if "/" in ingress_device:
kelvin8ec71442015-01-15 16:57:00 -0800989 cmd += " " + str( ingress_device )
andrewonlab36af3822014-11-18 17:48:18 -0500990 else:
991 if not port_ingress:
kelvin8ec71442015-01-15 16:57:00 -0800992 main.log.error( "You must specify " +
993 "the ingress port" )
994 # TODO: perhaps more meaningful return
andrewonlab36af3822014-11-18 17:48:18 -0500995 return main.FALSE
996
kelvin8ec71442015-01-15 16:57:00 -0800997 cmd += " " + \
998 str( ingress_device ) + "/" +\
999 str( port_ingress ) + " "
andrewonlab36af3822014-11-18 17:48:18 -05001000
1001 if "/" in egress_device:
kelvin8ec71442015-01-15 16:57:00 -08001002 cmd += " " + str( egress_device )
andrewonlab36af3822014-11-18 17:48:18 -05001003 else:
1004 if not port_egress:
kelvin8ec71442015-01-15 16:57:00 -08001005 main.log.error( "You must specify " +
1006 "the egress port" )
andrewonlab36af3822014-11-18 17:48:18 -05001007 return main.FALSE
Jon Halle3f39ff2015-01-13 11:50:53 -08001008
kelvin8ec71442015-01-15 16:57:00 -08001009 cmd += " " +\
1010 str( egress_device ) + "/" +\
1011 str( port_egress )
1012
kelvin-onlab898a6c62015-01-16 14:13:53 -08001013 handle = self.sendline( cmd )
1014 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -08001015 main.log.error( "Error in adding point-to-point intent" )
Jon Hall47a93fb2015-01-06 16:46:06 -08001016 return main.FALSE
andrewonlab4dbb4d82014-10-17 18:22:31 -04001017 else:
1018 return main.TRUE
andrewonlab4dbb4d82014-10-17 18:22:31 -04001019 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001020 main.log.error( self.name + ": EOF exception found" )
1021 main.log.error( self.name + ": " + self.handle.before )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001022 main.cleanup()
1023 main.exit()
1024 except:
kelvin8ec71442015-01-15 16:57:00 -08001025 main.log.info( self.name + " ::::::" )
1026 main.log.error( traceback.print_exc() )
1027 main.log.info( self.name + " ::::::" )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001028 main.cleanup()
1029 main.exit()
1030
kelvin8ec71442015-01-15 16:57:00 -08001031 def add_multipoint_to_singlepoint_intent(
kelvin-onlab898a6c62015-01-16 14:13:53 -08001032 self,
1033 ingress_device1,
1034 ingress_device2,
1035 egress_device,
1036 port_ingress="",
1037 port_egress="",
1038 ethType="",
1039 ethSrc="",
1040 ethDst="",
1041 bandwidth="",
1042 lambda_alloc=False,
1043 ipProto="",
1044 ipSrc="",
1045 ipDst="",
1046 tcpSrc="",
1047 tcpDst="",
1048 setEthSrc="",
1049 setEthDst="" ):
kelvin8ec71442015-01-15 16:57:00 -08001050 """
shahshreyad0c80432014-12-04 16:56:05 -08001051 Note:
Jon Halle3f39ff2015-01-13 11:50:53 -08001052 This function assumes that there would be 2 ingress devices and
1053 one egress device. For more number of ingress devices, this
1054 function needs to be modified
shahshreyad0c80432014-12-04 16:56:05 -08001055 Required:
1056 * ingress_device1: device id of ingress device1
1057 * ingress_device2: device id of ingress device2
1058 * egress_device: device id of egress device
1059 Optional:
1060 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -08001061 * ethSrc: specify ethSrc ( i.e. src mac addr )
1062 * ethDst: specify ethDst ( i.e. dst mac addr )
shahshreyad0c80432014-12-04 16:56:05 -08001063 * bandwidth: specify bandwidth capacity of link
Jon Halle3f39ff2015-01-13 11:50:53 -08001064 * lambda_alloc: if True, intent will allocate lambda
shahshreyad0c80432014-12-04 16:56:05 -08001065 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -08001066 * ipProto: specify ip protocol
shahshreyad0c80432014-12-04 16:56:05 -08001067 * ipSrc: specify ip source address
1068 * ipDst: specify ip destination address
1069 * tcpSrc: specify tcp source port
1070 * tcpDst: specify tcp destination port
1071 * setEthSrc: action to Rewrite Source MAC Address
1072 * setEthDst: action to Rewrite Destination MAC Address
1073 Description:
kelvin8ec71442015-01-15 16:57:00 -08001074 Adds a multipoint-to-singlepoint intent ( uni-directional ) by
shahshreyad0c80432014-12-04 16:56:05 -08001075 specifying device id's and optional fields
1076
Jon Halle3f39ff2015-01-13 11:50:53 -08001077 NOTE: This function may change depending on the
shahshreyad0c80432014-12-04 16:56:05 -08001078 options developers provide for multipointpoint-to-singlepoint
1079 intent via cli
kelvin8ec71442015-01-15 16:57:00 -08001080 """
shahshreyad0c80432014-12-04 16:56:05 -08001081 try:
1082 cmd = ""
1083
kelvin8ec71442015-01-15 16:57:00 -08001084 # If there are no optional arguments
shahshreyad0c80432014-12-04 16:56:05 -08001085 if not ethType and not ethSrc and not ethDst\
Jon Halle3f39ff2015-01-13 11:50:53 -08001086 and not bandwidth and not lambda_alloc\
1087 and not ipProto and not ipSrc and not ipDst\
1088 and not tcpSrc and not tcpDst and not setEthSrc\
1089 and not setEthDst:
shahshreyad0c80432014-12-04 16:56:05 -08001090 cmd = "add-multi-to-single-intent"
shahshreyad0c80432014-12-04 16:56:05 -08001091
1092 else:
1093 cmd = "add-multi-to-single-intent"
Jon Halle3f39ff2015-01-13 11:50:53 -08001094
shahshreyad0c80432014-12-04 16:56:05 -08001095 if ethType:
kelvin8ec71442015-01-15 16:57:00 -08001096 cmd += " --ethType " + str( ethType )
shahshreyad0c80432014-12-04 16:56:05 -08001097 if ethSrc:
kelvin8ec71442015-01-15 16:57:00 -08001098 cmd += " --ethSrc " + str( ethSrc )
1099 if ethDst:
1100 cmd += " --ethDst " + str( ethDst )
shahshreyad0c80432014-12-04 16:56:05 -08001101 if bandwidth:
kelvin8ec71442015-01-15 16:57:00 -08001102 cmd += " --bandwidth " + str( bandwidth )
shahshreyad0c80432014-12-04 16:56:05 -08001103 if lambda_alloc:
1104 cmd += " --lambda "
1105 if ipProto:
kelvin8ec71442015-01-15 16:57:00 -08001106 cmd += " --ipProto " + str( ipProto )
shahshreyad0c80432014-12-04 16:56:05 -08001107 if ipSrc:
kelvin8ec71442015-01-15 16:57:00 -08001108 cmd += " --ipSrc " + str( ipSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001109 if ipDst:
kelvin8ec71442015-01-15 16:57:00 -08001110 cmd += " --ipDst " + str( ipDst )
shahshreyad0c80432014-12-04 16:56:05 -08001111 if tcpSrc:
kelvin8ec71442015-01-15 16:57:00 -08001112 cmd += " --tcpSrc " + str( tcpSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001113 if tcpDst:
kelvin8ec71442015-01-15 16:57:00 -08001114 cmd += " --tcpDst " + str( tcpDst )
shahshreyad0c80432014-12-04 16:56:05 -08001115 if setEthSrc:
kelvin8ec71442015-01-15 16:57:00 -08001116 cmd += " --setEthSrc " + str( setEthSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001117 if setEthDst:
kelvin8ec71442015-01-15 16:57:00 -08001118 cmd += " --setEthDst " + str( setEthDst )
shahshreyad0c80432014-12-04 16:56:05 -08001119
kelvin8ec71442015-01-15 16:57:00 -08001120 # Check whether the user appended the port
1121 # or provided it as an input
shahshreyad0c80432014-12-04 16:56:05 -08001122 if "/" in ingress_device1:
kelvin8ec71442015-01-15 16:57:00 -08001123 cmd += " " + str( ingress_device1 )
shahshreyad0c80432014-12-04 16:56:05 -08001124 else:
1125 if not port_ingress1:
kelvin8ec71442015-01-15 16:57:00 -08001126 main.log.error( "You must specify " +
1127 "the ingress port1" )
1128 # TODO: perhaps more meaningful return
shahshreyad0c80432014-12-04 16:56:05 -08001129 return main.FALSE
1130
kelvin8ec71442015-01-15 16:57:00 -08001131 cmd += " " + \
1132 str( ingress_device1 ) + "/" +\
1133 str( port_ingress1 ) + " "
shahshreyad0c80432014-12-04 16:56:05 -08001134
1135 if "/" in ingress_device2:
kelvin8ec71442015-01-15 16:57:00 -08001136 cmd += " " + str( ingress_device2 )
shahshreyad0c80432014-12-04 16:56:05 -08001137 else:
1138 if not port_ingress2:
kelvin8ec71442015-01-15 16:57:00 -08001139 main.log.error( "You must specify " +
1140 "the ingress port2" )
1141 # TODO: perhaps more meaningful return
shahshreyad0c80432014-12-04 16:56:05 -08001142 return main.FALSE
1143
kelvin8ec71442015-01-15 16:57:00 -08001144 cmd += " " + \
1145 str( ingress_device2 ) + "/" +\
1146 str( port_ingress2 ) + " "
shahshreyad0c80432014-12-04 16:56:05 -08001147
1148 if "/" in egress_device:
kelvin8ec71442015-01-15 16:57:00 -08001149 cmd += " " + str( egress_device )
shahshreyad0c80432014-12-04 16:56:05 -08001150 else:
1151 if not port_egress:
kelvin8ec71442015-01-15 16:57:00 -08001152 main.log.error( "You must specify " +
1153 "the egress port" )
shahshreyad0c80432014-12-04 16:56:05 -08001154 return main.FALSE
Jon Halle3f39ff2015-01-13 11:50:53 -08001155
kelvin8ec71442015-01-15 16:57:00 -08001156 cmd += " " +\
1157 str( egress_device ) + "/" +\
1158 str( port_egress )
1159 print "cmd= ", cmd
kelvin-onlab898a6c62015-01-16 14:13:53 -08001160 handle = self.sendline( cmd )
1161 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -08001162 main.log.error( "Error in adding point-to-point intent" )
shahshreyad0c80432014-12-04 16:56:05 -08001163 return self.handle
1164 else:
1165 return main.TRUE
shahshreyad0c80432014-12-04 16:56:05 -08001166 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001167 main.log.error( self.name + ": EOF exception found" )
1168 main.log.error( self.name + ": " + self.handle.before )
shahshreyad0c80432014-12-04 16:56:05 -08001169 main.cleanup()
1170 main.exit()
1171 except:
kelvin8ec71442015-01-15 16:57:00 -08001172 main.log.info( self.name + " ::::::" )
1173 main.log.error( traceback.print_exc() )
1174 main.log.info( self.name + " ::::::" )
shahshreyad0c80432014-12-04 16:56:05 -08001175 main.cleanup()
1176 main.exit()
1177
kelvin-onlab898a6c62015-01-16 14:13:53 -08001178 def remove_intent( self, intent_id ):
1179 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001180 Remove intent for specified intent id
Jon Halle3f39ff2015-01-13 11:50:53 -08001181
1182 Returns:
1183 main.False on error and
1184 cli output otherwise
kelvin-onlab898a6c62015-01-16 14:13:53 -08001185 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001186 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001187 cmd_str = "remove-intent " + str( intent_id )
1188 handle = self.sendline( cmd_str )
1189 if re.search( "Error", handle ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001190 main.log.error( "Error in removing intent" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001191 return main.FALSE
andrewonlab9a50dfe2014-10-17 17:22:31 -04001192 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001193 # TODO: Should this be main.TRUE
1194 return handle
andrewonlab9a50dfe2014-10-17 17:22:31 -04001195 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001196 main.log.error( self.name + ": EOF exception found" )
1197 main.log.error( self.name + ": " + self.handle.before )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001198 main.cleanup()
1199 main.exit()
1200 except:
kelvin8ec71442015-01-15 16:57:00 -08001201 main.log.info( self.name + " ::::::" )
1202 main.log.error( traceback.print_exc() )
1203 main.log.info( self.name + " ::::::" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001204 main.cleanup()
1205 main.exit()
1206
kelvin8ec71442015-01-15 16:57:00 -08001207 def routes( self, json_format=False ):
1208 """
kelvin-onlab898a6c62015-01-16 14:13:53 -08001209 NOTE: This method should be used after installing application:
1210 onos-app-sdnip
pingping-lin8b306ac2014-11-17 18:13:51 -08001211 Optional:
1212 * json_format: enable output formatting in json
1213 Description:
1214 Obtain all routes in the system
kelvin8ec71442015-01-15 16:57:00 -08001215 """
pingping-lin8b306ac2014-11-17 18:13:51 -08001216 try:
1217 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -08001218 cmd_str = "routes -j"
1219 handle_tmp = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001220 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1221 handle = ansi_escape.sub( '', handle_tmp )
pingping-lin8b306ac2014-11-17 18:13:51 -08001222 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001223 cmd_str = "routes"
1224 handle = self.sendline( cmd_str )
pingping-lin8b306ac2014-11-17 18:13:51 -08001225 return handle
pingping-lin8b306ac2014-11-17 18:13:51 -08001226 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001227 main.log.error( self.name + ": EOF exception found" )
1228 main.log.error( self.name + ": " + self.handle.before )
pingping-lin8b306ac2014-11-17 18:13:51 -08001229 main.cleanup()
1230 main.exit()
1231 except:
kelvin8ec71442015-01-15 16:57:00 -08001232 main.log.info( self.name + " ::::::" )
1233 main.log.error( traceback.print_exc() )
1234 main.log.info( self.name + " ::::::" )
pingping-lin8b306ac2014-11-17 18:13:51 -08001235 main.cleanup()
1236 main.exit()
1237
kelvin8ec71442015-01-15 16:57:00 -08001238 def intents( self, json_format=True ):
1239 """
andrewonlab377693f2014-10-21 16:00:30 -04001240 Optional:
1241 * json_format: enable output formatting in json
andrewonlabe6745342014-10-17 14:29:13 -04001242 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001243 Obtain intents currently installed
kelvin-onlab898a6c62015-01-16 14:13:53 -08001244 """
andrewonlabe6745342014-10-17 14:29:13 -04001245 try:
andrewonlab377693f2014-10-21 16:00:30 -04001246 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -08001247 cmd_str = "intents -j"
1248 handle = self.sendline( cmd_str )
kelvin8ec71442015-01-15 16:57:00 -08001249 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1250 handle = ansi_escape.sub( '', handle )
1251 else:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001252 cmd_str = "intents"
1253 handle = self.sendline( cmd_str )
andrewonlabe6745342014-10-17 14:29:13 -04001254 return handle
andrewonlabe6745342014-10-17 14:29:13 -04001255 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001256 main.log.error( self.name + ": EOF exception found" )
1257 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe6745342014-10-17 14:29:13 -04001258 main.cleanup()
1259 main.exit()
1260 except:
kelvin8ec71442015-01-15 16:57:00 -08001261 main.log.info( self.name + " ::::::" )
1262 main.log.error( traceback.print_exc() )
1263 main.log.info( self.name + " ::::::" )
andrewonlabe6745342014-10-17 14:29:13 -04001264 main.cleanup()
1265 main.exit()
1266
kelvin8ec71442015-01-15 16:57:00 -08001267 def flows( self, json_format=True ):
1268 """
Shreya Shah0f01c812014-10-26 20:15:28 -04001269 Optional:
1270 * json_format: enable output formatting in json
1271 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001272 Obtain flows currently installed
kelvin-onlab898a6c62015-01-16 14:13:53 -08001273 """
Shreya Shah0f01c812014-10-26 20:15:28 -04001274 try:
1275 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -08001276 cmd_str = "flows -j"
1277 handle = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001278 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1279 handle = ansi_escape.sub( '', handle )
Shreya Shah0f01c812014-10-26 20:15:28 -04001280 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001281 cmd_str = "flows"
1282 handle = self.sendline( cmd_str )
kelvin8ec71442015-01-15 16:57:00 -08001283 if re.search( "Error\sexecuting\scommand:", handle ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001284 main.log.error( self.name + ".flows() response: " +
1285 str( handle ) )
Shreya Shah0f01c812014-10-26 20:15:28 -04001286 return handle
Shreya Shah0f01c812014-10-26 20:15:28 -04001287 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001288 main.log.error( self.name + ": EOF exception found" )
1289 main.log.error( self.name + ": " + self.handle.before )
Shreya Shah0f01c812014-10-26 20:15:28 -04001290 main.cleanup()
1291 main.exit()
1292 except:
kelvin8ec71442015-01-15 16:57:00 -08001293 main.log.info( self.name + " ::::::" )
1294 main.log.error( traceback.print_exc() )
1295 main.log.info( self.name + " ::::::" )
Shreya Shah0f01c812014-10-26 20:15:28 -04001296 main.cleanup()
1297 main.exit()
1298
kelvin8ec71442015-01-15 16:57:00 -08001299 def push_test_intents( self, dpid_src, dpid_dst, num_intents,
1300 num_mult="", app_id="", report=True ):
1301 """
andrewonlab87852b02014-11-19 18:44:19 -05001302 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001303 Push a number of intents in a batch format to
andrewonlab87852b02014-11-19 18:44:19 -05001304 a specific point-to-point intent definition
1305 Required:
1306 * dpid_src: specify source dpid
1307 * dpid_dst: specify destination dpid
1308 * num_intents: specify number of intents to push
1309 Optional:
andrewonlabb66dfa12014-12-02 15:51:10 -05001310 * num_mult: number multiplier for multiplying
1311 the number of intents specified
1312 * app_id: specify the application id init to further
1313 modularize the intents
andrewonlab87852b02014-11-19 18:44:19 -05001314 * report: default True, returns latency information
kelvin8ec71442015-01-15 16:57:00 -08001315 """
andrewonlab87852b02014-11-19 18:44:19 -05001316 try:
kelvin8ec71442015-01-15 16:57:00 -08001317 cmd = "push-test-intents " +\
1318 str( dpid_src ) + " " + str( dpid_dst ) + " " +\
1319 str( num_intents )
andrewonlabb66dfa12014-12-02 15:51:10 -05001320 if num_mult:
kelvin8ec71442015-01-15 16:57:00 -08001321 cmd += " " + str( num_mult )
1322 # If app id is specified, then num_mult
1323 # must exist because of the way this command
kelvin-onlab898a6c62015-01-16 14:13:53 -08001324 #takes in arguments
andrewonlabb66dfa12014-12-02 15:51:10 -05001325 if app_id:
kelvin8ec71442015-01-15 16:57:00 -08001326 cmd += " " + str( app_id )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001327 handle = self.sendline( cmd )
kelvin8ec71442015-01-15 16:57:00 -08001328 # Some color thing that we want to escape
1329 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1330 handle = ansi_escape.sub( '', handle )
andrewonlab87852b02014-11-19 18:44:19 -05001331 if report:
andrewonlabb66dfa12014-12-02 15:51:10 -05001332 lat_result = []
kelvin8ec71442015-01-15 16:57:00 -08001333 main.log.info( handle )
1334 # Split result by newline
1335 newline = handle.split( "\r\r\n" )
1336 # Ignore the first object of list, which is empty
1337 newline = newline[ 1: ]
1338 # Some sloppy parsing method to get the latency
andrewonlabb66dfa12014-12-02 15:51:10 -05001339 for result in newline:
kelvin8ec71442015-01-15 16:57:00 -08001340 result = result.split( ": " )
1341 # Append the first result of second parse
1342 lat_result.append( result[ 1 ].split( " " )[ 0 ] )
kelvin8ec71442015-01-15 16:57:00 -08001343 main.log.info( lat_result )
Jon Halle3f39ff2015-01-13 11:50:53 -08001344 return lat_result
andrewonlab87852b02014-11-19 18:44:19 -05001345 else:
1346 return main.TRUE
andrewonlab87852b02014-11-19 18:44:19 -05001347 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001348 main.log.error( self.name + ": EOF exception found" )
1349 main.log.error( self.name + ": " + self.handle.before )
andrewonlab87852b02014-11-19 18:44:19 -05001350 main.cleanup()
1351 main.exit()
1352 except:
kelvin8ec71442015-01-15 16:57:00 -08001353 main.log.info( self.name + " ::::::" )
1354 main.log.error( traceback.print_exc() )
1355 main.log.info( self.name + " ::::::" )
andrewonlab87852b02014-11-19 18:44:19 -05001356 main.cleanup()
1357 main.exit()
1358
kelvin8ec71442015-01-15 16:57:00 -08001359 def intents_events_metrics( self, json_format=True ):
1360 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001361 Description:Returns topology metrics
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001362 Optional:
1363 * json_format: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08001364 """
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001365 try:
1366 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -08001367 cmd_str = "intents-events-metrics -j"
1368 handle = self.sendline( cmd_str )
1369 # Some color thing that we want to escape
kelvin-onlab898a6c62015-01-16 14:13:53 -08001370 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1371 handle = ansi_escape.sub( '', handle )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001372 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001373 cmd_str = "intents-events-metrics"
1374 handle = self.sendline( cmd_str )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001375 return handle
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001376 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001377 main.log.error( self.name + ": EOF exception found" )
1378 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001379 main.cleanup()
1380 main.exit()
1381 except:
kelvin8ec71442015-01-15 16:57:00 -08001382 main.log.info( self.name + " ::::::" )
1383 main.log.error( traceback.print_exc() )
1384 main.log.info( self.name + " ::::::" )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001385 main.cleanup()
1386 main.exit()
Shreya Shah0f01c812014-10-26 20:15:28 -04001387
kelvin8ec71442015-01-15 16:57:00 -08001388 def topology_events_metrics( self, json_format=True ):
1389 """
1390 Description:Returns topology metrics
andrewonlab867212a2014-10-22 20:13:38 -04001391 Optional:
1392 * json_format: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08001393 """
andrewonlab867212a2014-10-22 20:13:38 -04001394 try:
1395 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -08001396 cmd_str = "topology-events-metrics -j"
1397 handle = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001398 # Some color thing that we want to escape
1399 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1400 handle = ansi_escape.sub( '', handle )
andrewonlab867212a2014-10-22 20:13:38 -04001401 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001402 cmd_str = "topology-events-metrics"
1403 handle = self.sendline( cmd_str )
andrewonlab867212a2014-10-22 20:13:38 -04001404 return handle
andrewonlab867212a2014-10-22 20:13:38 -04001405 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001406 main.log.error( self.name + ": EOF exception found" )
1407 main.log.error( self.name + ": " + self.handle.before )
andrewonlab867212a2014-10-22 20:13:38 -04001408 main.cleanup()
1409 main.exit()
1410 except:
kelvin8ec71442015-01-15 16:57:00 -08001411 main.log.info( self.name + " ::::::" )
1412 main.log.error( traceback.print_exc() )
1413 main.log.info( self.name + " ::::::" )
andrewonlab867212a2014-10-22 20:13:38 -04001414 main.cleanup()
1415 main.exit()
1416
kelvin8ec71442015-01-15 16:57:00 -08001417 # Wrapper functions ****************
1418 # Wrapper functions use existing driver
1419 # functions and extends their use case.
1420 # For example, we may use the output of
1421 # a normal driver function, and parse it
1422 # using a wrapper function
andrewonlabc2d05aa2014-10-13 16:51:10 -04001423
kelvin8ec71442015-01-15 16:57:00 -08001424 def get_all_intents_id( self ):
1425 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001426 Description:
1427 Obtain all intent id's in a list
kelvin8ec71442015-01-15 16:57:00 -08001428 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001429 try:
kelvin8ec71442015-01-15 16:57:00 -08001430 # Obtain output of intents function
andrewonlab9a50dfe2014-10-17 17:22:31 -04001431 intents_str = self.intents()
1432 all_intent_list = []
1433 intent_id_list = []
1434
kelvin8ec71442015-01-15 16:57:00 -08001435 # Parse the intents output for ID's
1436 intents_list = [ s.strip() for s in intents_str.splitlines() ]
andrewonlab9a50dfe2014-10-17 17:22:31 -04001437 for intents in intents_list:
1438 if "onos>" in intents:
1439 continue
1440 elif "intents" in intents:
1441 continue
1442 else:
kelvin8ec71442015-01-15 16:57:00 -08001443 line_list = intents.split( " " )
1444 all_intent_list.append( line_list[ 0 ] )
1445
1446 all_intent_list = all_intent_list[ 1:-2 ]
andrewonlab9a50dfe2014-10-17 17:22:31 -04001447
1448 for intents in all_intent_list:
1449 if not intents:
1450 continue
1451 else:
kelvin8ec71442015-01-15 16:57:00 -08001452 intent_id_list.append( intents )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001453
1454 return intent_id_list
1455
1456 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001457 main.log.error( self.name + ": EOF exception found" )
1458 main.log.error( self.name + ": " + self.handle.before )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001459 main.cleanup()
1460 main.exit()
1461 except:
kelvin8ec71442015-01-15 16:57:00 -08001462 main.log.info( self.name + " ::::::" )
1463 main.log.error( traceback.print_exc() )
1464 main.log.info( self.name + " ::::::" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001465 main.cleanup()
1466 main.exit()
1467
kelvin8ec71442015-01-15 16:57:00 -08001468 def get_all_devices_id( self ):
1469 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04001470 Use 'devices' function to obtain list of all devices
1471 and parse the result to obtain a list of all device
1472 id's. Returns this list. Returns empty list if no
1473 devices exist
kelvin8ec71442015-01-15 16:57:00 -08001474 List is ordered sequentially
1475
andrewonlab3e15ead2014-10-15 14:21:34 -04001476 This function may be useful if you are not sure of the
kelvin8ec71442015-01-15 16:57:00 -08001477 device id, and wish to execute other commands using
andrewonlab3e15ead2014-10-15 14:21:34 -04001478 the ids. By obtaining the list of device ids on the fly,
1479 you can iterate through the list to get mastership, etc.
kelvin8ec71442015-01-15 16:57:00 -08001480 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04001481 try:
kelvin8ec71442015-01-15 16:57:00 -08001482 # Call devices and store result string
1483 devices_str = self.devices( json_format=False )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001484 id_list = []
kelvin8ec71442015-01-15 16:57:00 -08001485
andrewonlab7e4d2d32014-10-15 13:23:21 -04001486 if not devices_str:
kelvin8ec71442015-01-15 16:57:00 -08001487 main.log.info( "There are no devices to get id from" )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001488 return id_list
kelvin8ec71442015-01-15 16:57:00 -08001489
1490 # Split the string into list by comma
1491 device_list = devices_str.split( "," )
1492 # Get temporary list of all arguments with string 'id='
1493 temp_list = [ dev for dev in device_list if "id=" in dev ]
1494 # Split list further into arguments before and after string
1495 # 'id='. Get the latter portion ( the actual device id ) and
andrewonlab7e4d2d32014-10-15 13:23:21 -04001496 # append to id_list
1497 for arg in temp_list:
kelvin8ec71442015-01-15 16:57:00 -08001498 id_list.append( arg.split( "id=" )[ 1 ] )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001499 return id_list
1500
1501 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001502 main.log.error( self.name + ": EOF exception found" )
1503 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001504 main.cleanup()
1505 main.exit()
1506 except:
kelvin8ec71442015-01-15 16:57:00 -08001507 main.log.info( self.name + " ::::::" )
1508 main.log.error( traceback.print_exc() )
1509 main.log.info( self.name + " ::::::" )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001510 main.cleanup()
1511 main.exit()
1512
kelvin8ec71442015-01-15 16:57:00 -08001513 def get_all_nodes_id( self ):
1514 """
andrewonlab7c211572014-10-15 16:45:20 -04001515 Uses 'nodes' function to obtain list of all nodes
1516 and parse the result of nodes to obtain just the
kelvin8ec71442015-01-15 16:57:00 -08001517 node id's.
andrewonlab7c211572014-10-15 16:45:20 -04001518 Returns:
1519 list of node id's
kelvin8ec71442015-01-15 16:57:00 -08001520 """
andrewonlab7c211572014-10-15 16:45:20 -04001521 try:
1522 nodes_str = self.nodes()
1523 id_list = []
1524
1525 if not nodes_str:
kelvin8ec71442015-01-15 16:57:00 -08001526 main.log.info( "There are no nodes to get id from" )
andrewonlab7c211572014-10-15 16:45:20 -04001527 return id_list
1528
kelvin8ec71442015-01-15 16:57:00 -08001529 # Sample nodes_str output
1530 # id=local, address=127.0.0.1:9876, state=ACTIVE *
andrewonlab7c211572014-10-15 16:45:20 -04001531
kelvin8ec71442015-01-15 16:57:00 -08001532 # Split the string into list by comma
1533 nodes_list = nodes_str.split( "," )
1534 temp_list = [ node for node in nodes_list if "id=" in node ]
andrewonlab7c211572014-10-15 16:45:20 -04001535 for arg in temp_list:
kelvin8ec71442015-01-15 16:57:00 -08001536 id_list.append( arg.split( "id=" )[ 1 ] )
andrewonlab7c211572014-10-15 16:45:20 -04001537
1538 return id_list
kelvin8ec71442015-01-15 16:57:00 -08001539
andrewonlab7c211572014-10-15 16:45:20 -04001540 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001541 main.log.error( self.name + ": EOF exception found" )
1542 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -04001543 main.cleanup()
1544 main.exit()
1545 except:
kelvin8ec71442015-01-15 16:57:00 -08001546 main.log.info( self.name + " ::::::" )
1547 main.log.error( traceback.print_exc() )
1548 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -04001549 main.cleanup()
1550 main.exit()
andrewonlab7e4d2d32014-10-15 13:23:21 -04001551
kelvin8ec71442015-01-15 16:57:00 -08001552 def get_device( self, dpid=None ):
1553 """
Jon Halla91c4dc2014-10-22 12:57:04 -04001554 Return the first device from the devices api whose 'id' contains 'dpid'
1555 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -08001556 """
Jon Halla91c4dc2014-10-22 12:57:04 -04001557 import json
1558 try:
kelvin8ec71442015-01-15 16:57:00 -08001559 if dpid is None:
Jon Halla91c4dc2014-10-22 12:57:04 -04001560 return None
1561 else:
kelvin8ec71442015-01-15 16:57:00 -08001562 dpid = dpid.replace( ':', '' )
Jon Halla91c4dc2014-10-22 12:57:04 -04001563 raw_devices = self.devices()
kelvin8ec71442015-01-15 16:57:00 -08001564 devices_json = json.loads( raw_devices )
1565 # search json for the device with dpid then return the device
Jon Halla91c4dc2014-10-22 12:57:04 -04001566 for device in devices_json:
kelvin8ec71442015-01-15 16:57:00 -08001567 # print "%s in %s?" % ( dpid, device[ 'id' ] )
1568 if dpid in device[ 'id' ]:
Jon Halla91c4dc2014-10-22 12:57:04 -04001569 return device
1570 return None
1571 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001572 main.log.error( self.name + ": EOF exception found" )
1573 main.log.error( self.name + ": " + self.handle.before )
Jon Halla91c4dc2014-10-22 12:57:04 -04001574 main.cleanup()
1575 main.exit()
1576 except:
kelvin8ec71442015-01-15 16:57:00 -08001577 main.log.info( self.name + " ::::::" )
1578 main.log.error( traceback.print_exc() )
1579 main.log.info( self.name + " ::::::" )
Jon Halla91c4dc2014-10-22 12:57:04 -04001580 main.cleanup()
1581 main.exit()
1582
kelvin8ec71442015-01-15 16:57:00 -08001583 def check_status( self, ip, numoswitch, numolink, log_level="info" ):
1584 """
1585 Checks the number of swithes & links that ONOS sees against the
1586 supplied values. By default this will report to main.log, but the
Jon Hall42db6dc2014-10-24 19:03:48 -04001587 log level can be specifid.
kelvin8ec71442015-01-15 16:57:00 -08001588
Jon Hall42db6dc2014-10-24 19:03:48 -04001589 Params: ip = ip used for the onos cli
1590 numoswitch = expected number of switches
1591 numlink = expected number of links
1592 log_level = level to log to. Currently accepts 'info', 'warn' and 'report'
1593
1594
1595 log_level can
1596
kelvin8ec71442015-01-15 16:57:00 -08001597 Returns: main.TRUE if the number of switchs and links are correct,
Jon Hall42db6dc2014-10-24 19:03:48 -04001598 main.FALSE if the numer of switches and links is incorrect,
1599 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08001600 """
Jon Hall42db6dc2014-10-24 19:03:48 -04001601 try:
kelvin8ec71442015-01-15 16:57:00 -08001602 topology = self.get_topology( ip )
Jon Hall42db6dc2014-10-24 19:03:48 -04001603 if topology == {}:
1604 return main.ERROR
1605 output = ""
kelvin8ec71442015-01-15 16:57:00 -08001606 # Is the number of switches is what we expected
1607 devices = topology.get( 'devices', False )
1608 links = topology.get( 'links', False )
Jon Hall42db6dc2014-10-24 19:03:48 -04001609 if devices == False or links == False:
1610 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -08001611 switch_check = ( int( devices ) == int( numoswitch ) )
1612 # Is the number of links is what we expected
1613 link_check = ( int( links ) == int( numolink ) )
1614 if ( switch_check and link_check ):
1615 # We expected the correct numbers
Jon Hall42db6dc2014-10-24 19:03:48 -04001616 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08001617 + "what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04001618 result = main.TRUE
1619 else:
1620 output = output + \
kelvin8ec71442015-01-15 16:57:00 -08001621 "The number of links and switches does not match what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04001622 result = main.FALSE
kelvin-onlab898a6c62015-01-16 14:13:53 -08001623 output = output + "\n ONOS sees %i devices (%i expected) and %i links (%i expected)" % (
1624 int( devices ), int( numoswitch ), int( links ), int( numolink ) )
Jon Hall42db6dc2014-10-24 19:03:48 -04001625 if log_level == "report":
kelvin8ec71442015-01-15 16:57:00 -08001626 main.log.report( output )
Jon Hall42db6dc2014-10-24 19:03:48 -04001627 elif log_level == "warn":
kelvin8ec71442015-01-15 16:57:00 -08001628 main.log.warn( output )
Jon Hall42db6dc2014-10-24 19:03:48 -04001629 else:
kelvin8ec71442015-01-15 16:57:00 -08001630 main.log.info( output )
1631 return result
Jon Hall42db6dc2014-10-24 19:03:48 -04001632 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001633 main.log.error( self.name + ": EOF exception found" )
1634 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -04001635 main.cleanup()
1636 main.exit()
1637 except:
kelvin8ec71442015-01-15 16:57:00 -08001638 main.log.info( self.name + " ::::::" )
1639 main.log.error( traceback.print_exc() )
1640 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -04001641 main.cleanup()
1642 main.exit()
Jon Hall1c9e8732014-10-27 19:29:27 -04001643
kelvin8ec71442015-01-15 16:57:00 -08001644 def device_role( self, device_id, onos_node, role="master" ):
1645 """
Jon Hall1c9e8732014-10-27 19:29:27 -04001646 Calls the device-role cli command.
1647 device_id must be the id of a device as seen in the onos devices command
1648 onos_node is the ip of one of the onos nodes in the cluster
1649 role must be either master, standby, or none
1650
Jon Halle3f39ff2015-01-13 11:50:53 -08001651 Returns:
1652 main.TRUE or main.FALSE based on argument verification and
1653 main.ERROR if command returns and error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001654 """
Jon Hall1c9e8732014-10-27 19:29:27 -04001655 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001656 if role.lower() == "master" or role.lower() == "standby" or\
Jon Hall1c9e8732014-10-27 19:29:27 -04001657 role.lower() == "none":
kelvin-onlab898a6c62015-01-16 14:13:53 -08001658 cmd_str = "device-role " +\
1659 str( device_id ) + " " +\
1660 str( onos_node ) + " " +\
1661 str( role )
1662 handle = self.sendline( cmd_str )
1663 if re.search( "Error", handle ):
1664 # end color output to escape any colours
1665 # from the cli
kelvin8ec71442015-01-15 16:57:00 -08001666 main.log.error( self.name + ": " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001667 handle + '\033[0m' )
kelvin8ec71442015-01-15 16:57:00 -08001668 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -08001669 return main.TRUE
Jon Hall1c9e8732014-10-27 19:29:27 -04001670 else:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001671 main.log.error( "Invalid 'role' given to device_role(). " +
1672 "Value was '" + str(role) + "'." )
Jon Hall1c9e8732014-10-27 19:29:27 -04001673 return main.FALSE
Jon Hall1c9e8732014-10-27 19:29:27 -04001674 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001675 main.log.error( self.name + ": EOF exception found" )
1676 main.log.error( self.name + ": " + self.handle.before )
Jon Hall1c9e8732014-10-27 19:29:27 -04001677 main.cleanup()
1678 main.exit()
1679 except:
kelvin8ec71442015-01-15 16:57:00 -08001680 main.log.info( self.name + " ::::::" )
1681 main.log.error( traceback.print_exc() )
1682 main.log.info( self.name + " ::::::" )
Jon Hall1c9e8732014-10-27 19:29:27 -04001683 main.cleanup()
1684 main.exit()
1685
kelvin8ec71442015-01-15 16:57:00 -08001686 def clusters( self, json_format=True ):
1687 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001688 Lists all clusters
Jon Hallffb386d2014-11-21 13:43:38 -08001689 Optional argument:
1690 * json_format - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -08001691 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001692 try:
Jon Hall73cf9cc2014-11-20 22:28:38 -08001693 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -08001694 cmd_str = "clusters -j"
1695 handle = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001696 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001697 handle variable here contains some ANSI escape color code
1698 sequences at the end which are invisible in the print command
Jon Halle3f39ff2015-01-13 11:50:53 -08001699 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -08001700 function. The repr( handle ) output when printed shows the ANSI
1701 escape sequences. In json.loads( somestring ), this somestring
1702 variable is actually repr( somestring ) and json.loads would fail
Jon Halle3f39ff2015-01-13 11:50:53 -08001703 with the escape sequence. So we take off that escape sequence
1704 using:
1705
kelvin-onlab898a6c62015-01-16 14:13:53 -08001706 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1707 handle1 = ansi_escape.sub( '', handle )
1708 """
1709 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1710 handle1 = ansi_escape.sub( '', handle )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001711 return handle1
1712 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001713 cmd_str = "clusters"
1714 handle = self.sendline( cmd_str )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001715 return handle
1716 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001717 main.log.error( self.name + ": EOF exception found" )
1718 main.log.error( self.name + ": " + self.handle.before )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001719 main.cleanup()
1720 main.exit()
1721 except:
kelvin8ec71442015-01-15 16:57:00 -08001722 main.log.info( self.name + " ::::::" )
1723 main.log.error( traceback.print_exc() )
1724 main.log.info( self.name + " ::::::" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001725 main.cleanup()
1726 main.exit()
1727
kelvin-onlab898a6c62015-01-16 14:13:53 -08001728 def election_test_leader( self ):
1729 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001730 CLI command to get the current leader for the Election test application
1731 NOTE: Requires installation of the onos-app-election feature
1732 Returns: Node IP of the leader if one exists
1733 None if none exists
1734 Main.FALSE on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001735 """
Jon Hall94fd0472014-12-08 11:52:42 -08001736 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001737 cmd_str = "election-test-leader"
1738 response = self.sendline( cmd_str )
1739 # Leader
1740 leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001741 "app\sis\s(?P<node>.+)\."
1742 node_search = re.search( leaderPattern, response )
Jon Hall94fd0472014-12-08 11:52:42 -08001743 if node_search:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001744 node = node_search.group( 'node' )
Jon Halle3f39ff2015-01-13 11:50:53 -08001745 main.log.info( "Election-test-leader on " + str( self.name ) +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001746 " found " + node + " as the leader" )
Jon Hall94fd0472014-12-08 11:52:42 -08001747 return node
Jon Halle3f39ff2015-01-13 11:50:53 -08001748 # no leader
1749 nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001750 "the\sElection\sapp"
1751 null_search = re.search( nullPattern, response )
Jon Hall94fd0472014-12-08 11:52:42 -08001752 if null_search:
Jon Halle3f39ff2015-01-13 11:50:53 -08001753 main.log.info( "Election-test-leader found no leader on " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001754 self.name )
Jon Hall94fd0472014-12-08 11:52:42 -08001755 return None
kelvin-onlab898a6c62015-01-16 14:13:53 -08001756 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001757 errorPattern = "Command\snot\sfound"
kelvin-onlab898a6c62015-01-16 14:13:53 -08001758 if re.search( errorPattern, response ):
1759 main.log.error( "Election app is not loaded on " + self.name )
Jon Halle3f39ff2015-01-13 11:50:53 -08001760 # TODO: Should this be main.ERROR?
Jon Hall669173b2014-12-17 11:36:30 -08001761 return main.FALSE
1762 else:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001763 main.log.error( "Error in election_test_leader: " +
1764 "unexpected response" )
kelvin8ec71442015-01-15 16:57:00 -08001765 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001766 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001767 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001768 main.log.error( self.name + ": EOF exception found" )
1769 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001770 main.cleanup()
1771 main.exit()
1772 except:
kelvin8ec71442015-01-15 16:57:00 -08001773 main.log.info( self.name + " ::::::" )
1774 main.log.error( traceback.print_exc() )
1775 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001776 main.cleanup()
1777 main.exit()
1778
kelvin-onlab898a6c62015-01-16 14:13:53 -08001779 def election_test_run( self ):
1780 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001781 CLI command to run for leadership of the Election test application.
1782 NOTE: Requires installation of the onos-app-election feature
1783 Returns: Main.TRUE on success
1784 Main.FALSE on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001785 """
Jon Hall94fd0472014-12-08 11:52:42 -08001786 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001787 cmd_str = "election-test-run"
1788 response = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001789 # success
Jon Halle3f39ff2015-01-13 11:50:53 -08001790 successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001791 "Election\sapp."
Jon Halle3f39ff2015-01-13 11:50:53 -08001792 search = re.search( successPattern, response )
Jon Hall94fd0472014-12-08 11:52:42 -08001793 if search:
Jon Halle3f39ff2015-01-13 11:50:53 -08001794 main.log.info( self.name + " entering leadership elections " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001795 "for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08001796 return main.TRUE
kelvin-onlab898a6c62015-01-16 14:13:53 -08001797 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001798 errorPattern = "Command\snot\sfound"
1799 if re.search( errorPattern, response ):
1800 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08001801 return main.FALSE
1802 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001803 main.log.error( "Error in election_test_run: " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001804 "unexpected response" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001805 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001806 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001807 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001808 main.log.error( self.name + ": EOF exception found" )
1809 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001810 main.cleanup()
1811 main.exit()
1812 except:
kelvin8ec71442015-01-15 16:57:00 -08001813 main.log.info( self.name + " ::::::" )
1814 main.log.error( traceback.print_exc() )
1815 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001816 main.cleanup()
1817 main.exit()
1818
kelvin8ec71442015-01-15 16:57:00 -08001819 def election_test_withdraw( self ):
1820 """
Jon Hall94fd0472014-12-08 11:52:42 -08001821 * CLI command to withdraw the local node from leadership election for
1822 * the Election test application.
1823 #NOTE: Requires installation of the onos-app-election feature
1824 Returns: Main.TRUE on success
1825 Main.FALSE on error
kelvin8ec71442015-01-15 16:57:00 -08001826 """
Jon Hall94fd0472014-12-08 11:52:42 -08001827 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001828 cmd_str = "election-test-withdraw"
1829 response = self.sendline( cmd_str )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001830 # success
Jon Halle3f39ff2015-01-13 11:50:53 -08001831 successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001832 "\sthe\sElection\sapp."
Jon Halle3f39ff2015-01-13 11:50:53 -08001833 if re.search( successPattern, response ):
1834 main.log.info( self.name + " withdrawing from leadership " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001835 "elections for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08001836 return main.TRUE
kelvin-onlab898a6c62015-01-16 14:13:53 -08001837 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001838 errorPattern = "Command\snot\sfound"
1839 if re.search( errorPattern, response ):
1840 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08001841 return main.FALSE
1842 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001843 main.log.error( "Error in election_test_withdraw: " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001844 "unexpected response" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001845 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001846 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001847 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001848 main.log.error( self.name + ": EOF exception found" )
1849 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001850 main.cleanup()
1851 main.exit()
1852 except:
kelvin8ec71442015-01-15 16:57:00 -08001853 main.log.info( self.name + " ::::::" )
1854 main.log.error( traceback.print_exc() )
1855 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001856 main.cleanup()
1857 main.exit()
Jon Hall1c9e8732014-10-27 19:29:27 -04001858
andrewonlab7e4d2d32014-10-15 13:23:21 -04001859 #***********************************
kelvin8ec71442015-01-15 16:57:00 -08001860 def getDevicePortsEnabledCount( self, dpid ):
1861 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001862 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08001863 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001864 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001865 dpid = str( dpid )
1866 cmd_str = "onos:ports -e " + dpid + " | wc -l"
1867 output = self.sendline( cmd_str )
1868 if re.search( "No such device", output ):
1869 main.log.error( "Error in getting ports" )
1870 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001871 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001872 return output
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001873 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001874 main.log.error( self.name + ": EOF exception found" )
1875 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001876 main.cleanup()
1877 main.exit()
1878 except:
kelvin8ec71442015-01-15 16:57:00 -08001879 main.log.info( self.name + " ::::::" )
1880 main.log.error( traceback.print_exc() )
1881 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001882 main.cleanup()
1883 main.exit()
1884
kelvin8ec71442015-01-15 16:57:00 -08001885 def getDeviceLinksActiveCount( self, dpid ):
1886 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001887 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08001888 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001889 try:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001890 dpid = str( dpid )
Jon Halle3f39ff2015-01-13 11:50:53 -08001891 cmd_str = "onos:links " + dpid + " | grep ACTIVE | wc -l"
1892 output = self.sendline( cmd_str )
1893 if re.search( "No such device", output ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001894 main.log.error( "Error in getting ports " )
1895 return ( output, "Error " )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001896 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001897 return output
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001898 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001899 main.log.error( self.name + ": EOF exception found" )
1900 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001901 main.cleanup()
1902 main.exit()
1903 except:
kelvin8ec71442015-01-15 16:57:00 -08001904 main.log.info( self.name + " ::::::" )
1905 main.log.error( traceback.print_exc() )
1906 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001907 main.cleanup()
1908 main.exit()
1909
kelvin8ec71442015-01-15 16:57:00 -08001910 def getAllIntentIds( self ):
1911 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001912 Return a list of all Intent IDs
kelvin8ec71442015-01-15 16:57:00 -08001913 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001914 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001915 cmd_str = "onos:intents | grep id="
1916 output = self.sendline( cmd_str )
1917 if re.search( "Error", output ):
1918 main.log.error( "Error in getting ports" )
1919 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001920 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001921 return output
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001922 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001923 main.log.error( self.name + ": EOF exception found" )
1924 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001925 main.cleanup()
1926 main.exit()
1927 except:
kelvin8ec71442015-01-15 16:57:00 -08001928 main.log.info( self.name + " ::::::" )
1929 main.log.error( traceback.print_exc() )
1930 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001931 main.cleanup()
1932 main.exit()