blob: aec61220593644b272635a2e1f2d23f494680a05 [file] [log] [blame]
andrewonlab95ce8322014-10-13 14:12:04 -04001#!/usr/bin/env python
2
kelvin8ec71442015-01-15 16:57:00 -08003"""
andrewonlab95ce8322014-10-13 14:12:04 -04004This driver enters the onos> prompt to issue commands.
5
kelvin8ec71442015-01-15 16:57:00 -08006Please follow the coding style demonstrated by existing
andrewonlab95ce8322014-10-13 14:12:04 -04007functions and document properly.
8
9If you are a contributor to the driver, please
10list your email here for future contact:
11
12jhall@onlab.us
13andrew@onlab.us
Jon Halle8217482014-10-17 13:49:14 -040014shreya@onlab.us
andrewonlab95ce8322014-10-13 14:12:04 -040015
16OCT 13 2014
17
kelvin8ec71442015-01-15 16:57:00 -080018"""
andrewonlab95ce8322014-10-13 14:12:04 -040019import sys
andrewonlab95ce8322014-10-13 14:12:04 -040020import pexpect
21import re
22import traceback
kelvin8ec71442015-01-15 16:57:00 -080023# import os.path
24sys.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,
52 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>",
196 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
kelvin9c3d4912015-01-15 17:36:47 -0800243<<<<<<< HEAD
andrewonlaba18f6bf2014-10-13 19:31:54 -0400244 def sendline(self, cmd_str):
245 '''
kelvin9c3d4912015-01-15 17:36:47 -0800246=======
kelvin8ec71442015-01-15 16:57:00 -0800247 def sendline( self, cmd_str ):
248 """
kelvin9c3d4912015-01-15 17:36:47 -0800249>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Halle3f39ff2015-01-13 11:50:53 -0800250 Send a completely user specified string to
251 the onos> prompt. Use this function if you have
andrewonlaba18f6bf2014-10-13 19:31:54 -0400252 a very specific command to send.
Jon Halle3f39ff2015-01-13 11:50:53 -0800253
andrewonlaba18f6bf2014-10-13 19:31:54 -0400254 Warning: There are no sanity checking to commands
255 sent using this method.
kelvin8ec71442015-01-15 16:57:00 -0800256 """
andrewonlaba18f6bf2014-10-13 19:31:54 -0400257 try:
kelvin8ec71442015-01-15 16:57:00 -0800258 self.handle.sendline( "" )
259 self.handle.expect( "onos>" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400260
kelvin9c3d4912015-01-15 17:36:47 -0800261<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -0800262 self.handle.sendline("log:log \"Sending CLI command: '"
263 + cmd_str + "'\"")
264 self.handle.expect("onos>")
265 self.handle.sendline( cmd_str )
266 self.handle.expect( cmd_str )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400267 self.handle.expect("onos>")
268
269 handle = self.handle.before
Jon Halle3f39ff2015-01-13 11:50:53 -0800270
andrewonlaba18f6bf2014-10-13 19:31:54 -0400271 self.handle.sendline("")
272 self.handle.expect("onos>")
andrewonlaba18f6bf2014-10-13 19:31:54 -0400273
Jon Halle3f39ff2015-01-13 11:50:53 -0800274 #handle += self.handle.before
275 #handle += self.handle.after
276
277 main.log.info("Command '" + str( cmd_str ) + "' sent to "
278 + self.name + ".")
Jon Hall42db6dc2014-10-24 19:03:48 -0400279 ansi_escape = re.compile(r'\x1b[^m]*m')
280 handle = ansi_escape.sub('', handle)
kelvin9c3d4912015-01-15 17:36:47 -0800281=======
kelvin8ec71442015-01-15 16:57:00 -0800282 self.handle.sendline( cmd_str )
283 self.handle.expect( "onos>" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400284
285 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800286
287 self.handle.sendline( "" )
288 self.handle.expect( "onos>" )
289
andrewonlaba18f6bf2014-10-13 19:31:54 -0400290 handle += self.handle.before
291 handle += self.handle.after
292
kelvin8ec71442015-01-15 16:57:00 -0800293 main.log.info( "Command sent." )
294 ansi_escape = re.compile( r'\x1b[^m]*m' )
295 handle = ansi_escape.sub( '', handle )
kelvin9c3d4912015-01-15 17:36:47 -0800296>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlaba18f6bf2014-10-13 19:31:54 -0400297
298 return handle
299 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800300 main.log.error( self.name + ": EOF exception found" )
301 main.log.error( self.name + ": " + self.handle.before )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400302 main.cleanup()
303 main.exit()
304 except:
kelvin8ec71442015-01-15 16:57:00 -0800305 main.log.info( self.name + " ::::::" )
306 main.log.error( traceback.print_exc() )
307 main.log.info( self.name + " ::::::" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400308 main.cleanup()
309 main.exit()
310
kelvin8ec71442015-01-15 16:57:00 -0800311 # IMPORTANT NOTE:
312 # For all cli commands, naming convention should match
313 # the cli command replacing ':' with '_'.
314 # Ex ) onos:topology > onos_topology
andrewonlab95ce8322014-10-13 14:12:04 -0400315 # onos:links > onos_links
316 # feature:list > feature_list
Jon Halle3f39ff2015-01-13 11:50:53 -0800317
kelvin9c3d4912015-01-15 17:36:47 -0800318<<<<<<< HEAD
andrewonlabc2d05aa2014-10-13 16:51:10 -0400319 def add_node(self, node_id, ONOS_ip, tcp_port=""):
320 '''
kelvin9c3d4912015-01-15 17:36:47 -0800321=======
kelvin8ec71442015-01-15 16:57:00 -0800322 def add_node( self, node_id, ONOS_ip, tcp_port="" ):
323 """
kelvin9c3d4912015-01-15 17:36:47 -0800324>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlabc2d05aa2014-10-13 16:51:10 -0400325 Adds a new cluster node by ID and address information.
326 Required:
327 * node_id
328 * ONOS_ip
329 Optional:
330 * tcp_port
kelvin8ec71442015-01-15 16:57:00 -0800331 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400332 try:
kelvin9c3d4912015-01-15 17:36:47 -0800333<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -0800334 cmd_str = "add-node " + str(node_id) + " " +\
335 str(ONOS_ip) + " " + str(tcp_port)
336 handle = self.sendline( cmd_str )
337 if re.search("Error", handle):
andrewonlabc2d05aa2014-10-13 16:51:10 -0400338 main.log.error("Error in adding node")
339 main.log.error(handle)
kelvin9c3d4912015-01-15 17:36:47 -0800340=======
kelvin8ec71442015-01-15 16:57:00 -0800341 self.handle.sendline( "" )
342 self.handle.expect( "onos>" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400343
kelvin8ec71442015-01-15 16:57:00 -0800344 self.handle.sendline( "add-node " +
345 str( node_id ) + " " +
346 str( ONOS_ip ) + " " +
347 str( tcp_port ) )
348
349 i = self.handle.expect( [
andrewonlabc2d05aa2014-10-13 16:51:10 -0400350 "Error",
kelvin8ec71442015-01-15 16:57:00 -0800351 "onos>" ] )
352
353 # Clear handle to get previous output
354 self.handle.sendline( "" )
355 self.handle.expect( "onos>" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400356
357 handle = self.handle.before
358
359 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800360 main.log.error( "Error in adding node" )
361 main.log.error( handle )
kelvin9c3d4912015-01-15 17:36:47 -0800362>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Halle3f39ff2015-01-13 11:50:53 -0800363 return main.FALSE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400364 else:
kelvin8ec71442015-01-15 16:57:00 -0800365 main.log.info( "Node " + str( ONOS_ip ) + " added" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400366 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400367 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800368 main.log.error( self.name + ": EOF exception found" )
369 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400370 main.cleanup()
371 main.exit()
372 except:
kelvin8ec71442015-01-15 16:57:00 -0800373 main.log.info( self.name + " ::::::" )
374 main.log.error( traceback.print_exc() )
375 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400376 main.cleanup()
377 main.exit()
378
kelvin8ec71442015-01-15 16:57:00 -0800379 def remove_node( self, node_id ):
380 """
andrewonlab86dc3082014-10-13 18:18:38 -0400381 Removes a cluster by ID
382 Issues command: 'remove-node [<node-id>]'
383 Required:
384 * node_id
kelvin8ec71442015-01-15 16:57:00 -0800385 """
andrewonlab86dc3082014-10-13 18:18:38 -0400386 try:
kelvin9c3d4912015-01-15 17:36:47 -0800387<<<<<<< HEAD
andrewonlab86dc3082014-10-13 18:18:38 -0400388
Jon Halle3f39ff2015-01-13 11:50:53 -0800389 cmd_str = "remove-node " + str(node_id)
390 self.sendline( cmd_str )
391 # TODO: add error checking. Does ONOS give any errors?
kelvin9c3d4912015-01-15 17:36:47 -0800392=======
kelvin8ec71442015-01-15 16:57:00 -0800393 self.handle.sendline( "" )
394 self.handle.expect( "onos>" )
andrewonlab86dc3082014-10-13 18:18:38 -0400395
kelvin8ec71442015-01-15 16:57:00 -0800396 self.handle.sendline( "remove-node " + str( node_id ) )
397 self.handle.expect( "onos>" )
kelvin9c3d4912015-01-15 17:36:47 -0800398>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab86dc3082014-10-13 18:18:38 -0400399
400 return main.TRUE
Jon Halle3f39ff2015-01-13 11:50:53 -0800401
andrewonlab86dc3082014-10-13 18:18:38 -0400402 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800403 main.log.error( self.name + ": EOF exception found" )
404 main.log.error( self.name + ": " + self.handle.before )
andrewonlab86dc3082014-10-13 18:18:38 -0400405 main.cleanup()
406 main.exit()
407 except:
kelvin8ec71442015-01-15 16:57:00 -0800408 main.log.info( self.name + " ::::::" )
409 main.log.error( traceback.print_exc() )
410 main.log.info( self.name + " ::::::" )
andrewonlab86dc3082014-10-13 18:18:38 -0400411 main.cleanup()
412 main.exit()
andrewonlabc2d05aa2014-10-13 16:51:10 -0400413
kelvin8ec71442015-01-15 16:57:00 -0800414 def nodes( self ):
415 """
andrewonlab7c211572014-10-15 16:45:20 -0400416 List the nodes currently visible
417 Issues command: 'nodes'
418 Returns: entire handle of list of nodes
kelvin8ec71442015-01-15 16:57:00 -0800419 """
andrewonlab7c211572014-10-15 16:45:20 -0400420 try:
kelvin9c3d4912015-01-15 17:36:47 -0800421<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -0800422 cmd_str = "nodes"
423 handle = self.sendline( cmd_str )
kelvin9c3d4912015-01-15 17:36:47 -0800424=======
kelvin8ec71442015-01-15 16:57:00 -0800425 self.handle.sendline( "" )
426 self.handle.expect( "onos>" )
andrewonlab7c211572014-10-15 16:45:20 -0400427
kelvin8ec71442015-01-15 16:57:00 -0800428 self.handle.sendline( "nodes" )
429 self.handle.expect( "onos>" )
andrewonlab7c211572014-10-15 16:45:20 -0400430
kelvin8ec71442015-01-15 16:57:00 -0800431 self.handle.sendline( "" )
432 self.handle.expect( "onos>" )
andrewonlab7c211572014-10-15 16:45:20 -0400433
434 handle = self.handle.before
435
kelvin9c3d4912015-01-15 17:36:47 -0800436>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab7c211572014-10-15 16:45:20 -0400437 return handle
andrewonlab7c211572014-10-15 16:45:20 -0400438 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800439 main.log.error( self.name + ": EOF exception found" )
440 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -0400441 main.cleanup()
442 main.exit()
443 except:
kelvin8ec71442015-01-15 16:57:00 -0800444 main.log.info( self.name + " ::::::" )
445 main.log.error( traceback.print_exc() )
446 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -0400447 main.cleanup()
448 main.exit()
449
kelvin8ec71442015-01-15 16:57:00 -0800450 def topology( self ):
451 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400452 Shows the current state of the topology
453 by issusing command: 'onos> onos:topology'
kelvin8ec71442015-01-15 16:57:00 -0800454 """
andrewonlab95ce8322014-10-13 14:12:04 -0400455 try:
kelvin9c3d4912015-01-15 17:36:47 -0800456<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -0800457 # either onos:topology or 'topology' will work in CLI
458 cmd_str = "onos:topology"
459 handle = self.sendline( cmd_str )
460 main.log.info( "onos:topology returned: " + str( handle ) )
andrewonlab95ce8322014-10-13 14:12:04 -0400461 return handle
kelvin9c3d4912015-01-15 17:36:47 -0800462=======
kelvin8ec71442015-01-15 16:57:00 -0800463 self.handle.sendline( "" )
464 self.handle.expect( "onos>" )
465 # either onos:topology or 'topology' will work in CLI
466 self.handle.sendline( "onos:topology" )
467 self.handle.expect( "onos>" )
andrewonlab95ce8322014-10-13 14:12:04 -0400468
469 handle = self.handle.before
470
kelvin8ec71442015-01-15 16:57:00 -0800471 main.log.info( "onos:topology returned: " +
472 str( handle ) )
473
andrewonlab95ce8322014-10-13 14:12:04 -0400474 return handle
kelvin8ec71442015-01-15 16:57:00 -0800475
kelvin9c3d4912015-01-15 17:36:47 -0800476>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab95ce8322014-10-13 14:12:04 -0400477 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800478 main.log.error( self.name + ": EOF exception found" )
479 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400480 main.cleanup()
481 main.exit()
482 except:
kelvin8ec71442015-01-15 16:57:00 -0800483 main.log.info( self.name + " ::::::" )
484 main.log.error( traceback.print_exc() )
485 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -0400486 main.cleanup()
487 main.exit()
Jon Halle3f39ff2015-01-13 11:50:53 -0800488
kelvin9c3d4912015-01-15 17:36:47 -0800489<<<<<<< HEAD
andrewonlabc2d05aa2014-10-13 16:51:10 -0400490 def feature_install(self, feature_str):
491 '''
kelvin9c3d4912015-01-15 17:36:47 -0800492=======
kelvin8ec71442015-01-15 16:57:00 -0800493 def feature_install( self, feature_str ):
494 """
kelvin9c3d4912015-01-15 17:36:47 -0800495>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Halle3f39ff2015-01-13 11:50:53 -0800496 Installs a specified feature
andrewonlabc2d05aa2014-10-13 16:51:10 -0400497 by issuing command: 'onos> feature:install <feature_str>'
kelvin8ec71442015-01-15 16:57:00 -0800498 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400499 try:
kelvin9c3d4912015-01-15 17:36:47 -0800500<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -0800501 cmd_str = "feature:install " + str( feature_str )
502 self.sendline( cmd_str )
503 # TODO: Check for possible error responses from karaf
kelvin9c3d4912015-01-15 17:36:47 -0800504=======
kelvin8ec71442015-01-15 16:57:00 -0800505 self.handle.sendline( "" )
506 self.handle.expect( "onos>" )
507
508 self.handle.sendline( "feature:install " + str( feature_str ) )
509 self.handle.expect( "onos>" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400510
kelvin9c3d4912015-01-15 17:36:47 -0800511>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlabc2d05aa2014-10-13 16:51:10 -0400512 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400513 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800514 main.log.error( self.name + ": EOF exception found" )
515 main.log.error( self.name + ": " + self.handle.before )
516 main.log.report( "Failed to install feature" )
517 main.log.report( "Exiting test" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400518 main.cleanup()
519 main.exit()
520 except:
kelvin8ec71442015-01-15 16:57:00 -0800521 main.log.info( self.name + " ::::::" )
522 main.log.error( traceback.print_exc() )
523 main.log.report( "Failed to install feature" )
524 main.log.report( "Exiting test" )
525 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400526 main.cleanup()
527 main.exit()
Jon Halle3f39ff2015-01-13 11:50:53 -0800528
kelvin9c3d4912015-01-15 17:36:47 -0800529<<<<<<< HEAD
andrewonlabc2d05aa2014-10-13 16:51:10 -0400530 def feature_uninstall(self, feature_str):
531 '''
kelvin9c3d4912015-01-15 17:36:47 -0800532=======
kelvin8ec71442015-01-15 16:57:00 -0800533 def feature_uninstall( self, feature_str ):
534 """
kelvin9c3d4912015-01-15 17:36:47 -0800535>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlabc2d05aa2014-10-13 16:51:10 -0400536 Uninstalls a specified feature
537 by issuing command: 'onos> feature:uninstall <feature_str>'
kelvin8ec71442015-01-15 16:57:00 -0800538 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400539 try:
kelvin9c3d4912015-01-15 17:36:47 -0800540<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -0800541 cmd_str = "feature:uninstall " + str( feature_str )
542 self.sendline( cmd_str )
543 # TODO: Check for possible error responses from karaf
kelvin9c3d4912015-01-15 17:36:47 -0800544=======
kelvin8ec71442015-01-15 16:57:00 -0800545 self.handle.sendline( "" )
546 self.handle.expect( "onos>" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400547
kelvin8ec71442015-01-15 16:57:00 -0800548 self.handle.sendline( "feature:uninstall " + str( feature_str ) )
549 self.handle.expect( "onos>" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400550
kelvin9c3d4912015-01-15 17:36:47 -0800551>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlabc2d05aa2014-10-13 16:51:10 -0400552 return main.TRUE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400553 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800554 main.log.error( self.name + ": EOF exception found" )
555 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400556 main.cleanup()
557 main.exit()
558 except:
kelvin8ec71442015-01-15 16:57:00 -0800559 main.log.info( self.name + " ::::::" )
560 main.log.error( traceback.print_exc() )
561 main.log.info( self.name + " ::::::" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400562 main.cleanup()
563 main.exit()
Jon Hallffb386d2014-11-21 13:43:38 -0800564
kelvin8ec71442015-01-15 16:57:00 -0800565 def devices( self, json_format=True ):
566 """
Jon Hall7b02d952014-10-17 20:14:54 -0400567 Lists all infrastructure devices or switches
andrewonlab86dc3082014-10-13 18:18:38 -0400568 Optional argument:
Jon Hallffb386d2014-11-21 13:43:38 -0800569 * json_format - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800570 """
andrewonlab86dc3082014-10-13 18:18:38 -0400571 try:
kelvin9c3d4912015-01-15 17:36:47 -0800572<<<<<<< HEAD
Jon Halle8217482014-10-17 13:49:14 -0400573 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -0800574 cmd_str = "devices -j"
575 handle = self.sendline( cmd_str )
Jon Halld815ce42014-10-17 19:52:30 -0400576 '''
Jon Halle3f39ff2015-01-13 11:50:53 -0800577 handle variable here contains some ANSI escape color code
578 sequences at the end which are invisible in the print command
579 output. To make that escape sequence visible, use repr()
580 function. The repr(handle) output when printed shows the
581 ANSI escape sequences. In json.loads(somestring), this
582 somestring variable is actually repr(somestring) and
583 json.loads would fail with the escape sequence. So we take off
584 that escape sequence using:
585
Jon Halld815ce42014-10-17 19:52:30 -0400586 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
Jon Hall983a1702014-10-28 18:44:22 -0400587 handle1 = ansi_escape.sub('', handle)
Jon Halld815ce42014-10-17 19:52:30 -0400588 '''
Jon Halla001c392014-10-17 18:50:59 -0400589 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
590 handle1 = ansi_escape.sub('', handle)
Jon Halla001c392014-10-17 18:50:59 -0400591 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400592 else:
Jon Halle3f39ff2015-01-13 11:50:53 -0800593 cmd_str = "devices"
594 handle = self.sendline( cmd_str )
kelvin9c3d4912015-01-15 17:36:47 -0800595=======
kelvin8ec71442015-01-15 16:57:00 -0800596 self.handle.sendline( "" )
597 self.handle.expect( "onos>" )
andrewonlab95ce8322014-10-13 14:12:04 -0400598
andrewonlab86dc3082014-10-13 18:18:38 -0400599 if json_format:
kelvin8ec71442015-01-15 16:57:00 -0800600 self.handle.sendline( "devices -j" )
601 self.handle.expect( "devices -j" )
602 self.handle.expect( "onos>" )
andrewonlab86dc3082014-10-13 18:18:38 -0400603 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800604 """
andrewonlab86dc3082014-10-13 18:18:38 -0400605 handle variable here contains some ANSI escape color code sequences at the end which are invisible in the print command output
kelvin8ec71442015-01-15 16:57:00 -0800606 To make that escape sequence visible, use repr() function. The repr( handle ) output when printed shows the ANSI escape sequences.
607 In json.loads( somestring ), this somestring variable is actually repr( somestring ) and json.loads would fail with the escape sequence.
andrewonlab86dc3082014-10-13 18:18:38 -0400608 So we take off that escape sequence using
kelvin8ec71442015-01-15 16:57:00 -0800609 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
610 handle1 = ansi_escape.sub( '', handle )
611 """
612 # print "repr(handle) =", repr( handle )
613 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
614 handle1 = ansi_escape.sub( '', handle )
615 # print "repr(handle1) = ", repr( handle1 )
Jon Halle8217482014-10-17 13:49:14 -0400616 return handle1
617 else:
kelvin8ec71442015-01-15 16:57:00 -0800618 self.handle.sendline( "devices" )
619 self.handle.expect( "onos>" )
Jon Hallcd707292014-10-17 19:06:17 -0400620 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800621 # print "handle =",handle
kelvin9c3d4912015-01-15 17:36:47 -0800622>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Hallcd707292014-10-17 19:06:17 -0400623 return handle
andrewonlab7c211572014-10-15 16:45:20 -0400624 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800625 main.log.error( self.name + ": EOF exception found" )
626 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -0400627 main.cleanup()
628 main.exit()
629 except:
kelvin8ec71442015-01-15 16:57:00 -0800630 main.log.info( self.name + " ::::::" )
631 main.log.error( traceback.print_exc() )
632 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -0400633 main.cleanup()
634 main.exit()
635
kelvin9c3d4912015-01-15 17:36:47 -0800636<<<<<<< HEAD
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800637 def balance_masters(self):
638 '''
kelvin9c3d4912015-01-15 17:36:47 -0800639=======
kelvin8ec71442015-01-15 16:57:00 -0800640 def balance_masters( self ):
641 """
kelvin9c3d4912015-01-15 17:36:47 -0800642>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800643 This balances the devices across all controllers
644 by issuing command: 'onos> onos:balance-masters'
645 If required this could be extended to return devices balanced output.
kelvin8ec71442015-01-15 16:57:00 -0800646 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800647 try:
kelvin9c3d4912015-01-15 17:36:47 -0800648<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -0800649 cmd_str = "onos:balance-masters"
650 self.sendline( cmd_str )
651 # TODO: Check for error responses from ONOS
kelvin9c3d4912015-01-15 17:36:47 -0800652=======
kelvin8ec71442015-01-15 16:57:00 -0800653 self.handle.sendline( "" )
654 self.handle.expect( "onos>" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800655
kelvin8ec71442015-01-15 16:57:00 -0800656 self.handle.sendline( "onos:balance-masters" )
657 self.handle.expect( "onos>" )
kelvin9c3d4912015-01-15 17:36:47 -0800658>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800659 return main.TRUE
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800660 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800661 main.log.error( self.name + ": EOF exception found" )
662 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800663 main.cleanup()
664 main.exit()
665 except:
kelvin8ec71442015-01-15 16:57:00 -0800666 main.log.info( self.name + " ::::::" )
667 main.log.error( traceback.print_exc() )
668 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800669 main.cleanup()
670 main.exit()
671
kelvin8ec71442015-01-15 16:57:00 -0800672 def links( self, json_format=True ):
673 """
Jon Halle8217482014-10-17 13:49:14 -0400674 Lists all core links
675 Optional argument:
Jon Hallffb386d2014-11-21 13:43:38 -0800676 * json_format - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800677 """
Jon Halle8217482014-10-17 13:49:14 -0400678 try:
kelvin9c3d4912015-01-15 17:36:47 -0800679<<<<<<< HEAD
Jon Halle8217482014-10-17 13:49:14 -0400680 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -0800681 cmd_str = "links -j"
682 handle = self.sendline( cmd_str )
Jon Halld815ce42014-10-17 19:52:30 -0400683 '''
Jon Halle3f39ff2015-01-13 11:50:53 -0800684 handle variable here contains some ANSI escape color code
685 sequences at the end which are invisible in the print command
686 output. To make that escape sequence visible, use repr()
687 function. The repr(handle) output when printed shows the ANSI
688 escape sequences. In json.loads(somestring), this somestring
689 variable is actually repr(somestring) and json.loads would
690 fail with the escape sequence. So we take off that escape
691 sequence using:
692
Jon Halld815ce42014-10-17 19:52:30 -0400693 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
Jon Hallffb386d2014-11-21 13:43:38 -0800694 handle1 = ansi_escape.sub('', handle)
Jon Halld815ce42014-10-17 19:52:30 -0400695 '''
Jon Halla001c392014-10-17 18:50:59 -0400696 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
697 handle1 = ansi_escape.sub('', handle)
Jon Halla001c392014-10-17 18:50:59 -0400698 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400699 else:
Jon Halle3f39ff2015-01-13 11:50:53 -0800700 cmd_str = "links"
701 handle = self.sendline( cmd_str )
kelvin9c3d4912015-01-15 17:36:47 -0800702=======
kelvin8ec71442015-01-15 16:57:00 -0800703 self.handle.sendline( "" )
704 self.handle.expect( "onos>" )
Jon Halle8217482014-10-17 13:49:14 -0400705
706 if json_format:
kelvin8ec71442015-01-15 16:57:00 -0800707 self.handle.sendline( "links -j" )
708 self.handle.expect( "links -j" )
709 self.handle.expect( "onos>" )
Jon Halle8217482014-10-17 13:49:14 -0400710 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800711 """
Jon Halle8217482014-10-17 13:49:14 -0400712 handle variable here contains some ANSI escape color code sequences at the end which are invisible in the print command output
kelvin8ec71442015-01-15 16:57:00 -0800713 To make that escape sequence visible, use repr() function. The repr( handle ) output when printed shows the ANSI escape sequences.
714 In json.loads( somestring ), this somestring variable is actually repr( somestring ) and json.loads would fail with the escape sequence.
Jon Halle8217482014-10-17 13:49:14 -0400715 So we take off that escape sequence using
kelvin8ec71442015-01-15 16:57:00 -0800716 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
717 handle1 = ansi_escape.sub( '', handle )
718 """
719 # print "repr(handle) =", repr( handle )
720 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
721 handle1 = ansi_escape.sub( '', handle )
722 # print "repr(handle1) = ", repr( handle1 )
Jon Halle8217482014-10-17 13:49:14 -0400723 return handle1
724 else:
kelvin8ec71442015-01-15 16:57:00 -0800725 self.handle.sendline( "links" )
726 self.handle.expect( "onos>" )
Jon Halla001c392014-10-17 18:50:59 -0400727 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800728 # print "handle =",handle
kelvin9c3d4912015-01-15 17:36:47 -0800729>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Halla001c392014-10-17 18:50:59 -0400730 return handle
Jon Halle8217482014-10-17 13:49:14 -0400731 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800732 main.log.error( self.name + ": EOF exception found" )
733 main.log.error( self.name + ": " + self.handle.before )
Jon Halle8217482014-10-17 13:49:14 -0400734 main.cleanup()
735 main.exit()
736 except:
kelvin8ec71442015-01-15 16:57:00 -0800737 main.log.info( self.name + " ::::::" )
738 main.log.error( traceback.print_exc() )
739 main.log.info( self.name + " ::::::" )
Jon Halle8217482014-10-17 13:49:14 -0400740 main.cleanup()
741 main.exit()
742
kelvin9c3d4912015-01-15 17:36:47 -0800743<<<<<<< HEAD
Jon Hallffb386d2014-11-21 13:43:38 -0800744 def ports(self, json_format=True):
Jon Halle8217482014-10-17 13:49:14 -0400745 '''
kelvin9c3d4912015-01-15 17:36:47 -0800746=======
kelvin8ec71442015-01-15 16:57:00 -0800747 def ports( self, json_format=True ):
748 """
kelvin9c3d4912015-01-15 17:36:47 -0800749>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Halle8217482014-10-17 13:49:14 -0400750 Lists all ports
751 Optional argument:
Jon Hallffb386d2014-11-21 13:43:38 -0800752 * json_format - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800753 """
Jon Halle8217482014-10-17 13:49:14 -0400754 try:
kelvin9c3d4912015-01-15 17:36:47 -0800755<<<<<<< HEAD
Jon Halle8217482014-10-17 13:49:14 -0400756 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -0800757 cmd_str = "ports -j"
758 handle = self.sendline( cmd_str )
Jon Halld815ce42014-10-17 19:52:30 -0400759 '''
Jon Halle3f39ff2015-01-13 11:50:53 -0800760 handle variable here contains some ANSI escape color code
761 sequences at the end which are invisible in the print command
762 output. To make that escape sequence visible, use repr()
763 function. The repr(handle) output when printed shows the ANSI
764 escape sequences. In json.loads(somestring), this somestring
765 variable is actually repr(somestring) and json.loads would
766 fail with the escape sequence. So we take off that escape
767 sequence using the following commads:
768
Jon Halld815ce42014-10-17 19:52:30 -0400769 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
Jon Hallffb386d2014-11-21 13:43:38 -0800770 handle1 = ansi_escape.sub('', handle)
Jon Halld815ce42014-10-17 19:52:30 -0400771 '''
Jon Halla001c392014-10-17 18:50:59 -0400772 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
773 handle1 = ansi_escape.sub('', handle)
Jon Halla001c392014-10-17 18:50:59 -0400774 return handle1
775
Jon Halle8217482014-10-17 13:49:14 -0400776 else:
Jon Halle3f39ff2015-01-13 11:50:53 -0800777 cmd_str = "ports"
778 handle = self.sendline( cmd_str )
kelvin9c3d4912015-01-15 17:36:47 -0800779=======
kelvin8ec71442015-01-15 16:57:00 -0800780 self.handle.sendline( "" )
781 self.handle.expect( "onos>" )
andrewonlab9a50dfe2014-10-17 17:22:31 -0400782
Jon Halle8217482014-10-17 13:49:14 -0400783 if json_format:
kelvin8ec71442015-01-15 16:57:00 -0800784 self.handle.sendline( "ports -j" )
785 self.handle.expect( "ports -j" )
786 self.handle.expect( "onos>" )
Jon Halle8217482014-10-17 13:49:14 -0400787 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800788 """
Jon Halle8217482014-10-17 13:49:14 -0400789 handle variable here contains some ANSI escape color code sequences at the end which are invisible in the print command output
kelvin8ec71442015-01-15 16:57:00 -0800790 To make that escape sequence visible, use repr() function. The repr( handle ) output when printed shows the ANSI escape sequences.
791 In json.loads( somestring ), this somestring variable is actually repr( somestring ) and json.loads would fail with the escape sequence.
Jon Hallcd707292014-10-17 19:06:17 -0400792 So we take off that escape sequence using the following commads:
kelvin8ec71442015-01-15 16:57:00 -0800793 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
794 handle1 = ansi_escape.sub( '', handle )
795 """
796 # print "repr(handle) =", repr( handle )
797 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
798 handle1 = ansi_escape.sub( '', handle )
799 # print "repr(handle1) = ", repr( handle1 )
Jon Halle8217482014-10-17 13:49:14 -0400800 return handle1
801
802 else:
kelvin8ec71442015-01-15 16:57:00 -0800803 self.handle.sendline( "ports" )
804 self.handle.expect( "onos>" )
805 self.handle.sendline( "" )
806 self.handle.expect( "onos>" )
Jon Halle8217482014-10-17 13:49:14 -0400807 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800808 # print "handle =",handle
kelvin9c3d4912015-01-15 17:36:47 -0800809>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Hallffb386d2014-11-21 13:43:38 -0800810 return handle
Jon Halle8217482014-10-17 13:49:14 -0400811 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800812 main.log.error( self.name + ": EOF exception found" )
813 main.log.error( self.name + ": " + self.handle.before )
Jon Halle8217482014-10-17 13:49:14 -0400814 main.cleanup()
815 main.exit()
816 except:
kelvin8ec71442015-01-15 16:57:00 -0800817 main.log.info( self.name + " ::::::" )
818 main.log.error( traceback.print_exc() )
819 main.log.info( self.name + " ::::::" )
Jon Halle8217482014-10-17 13:49:14 -0400820 main.cleanup()
821 main.exit()
822
kelvin8ec71442015-01-15 16:57:00 -0800823 def roles( self, json_format=True ):
824 """
Jon Hall983a1702014-10-28 18:44:22 -0400825 Lists all devices and the controllers with roles assigned to them
826 Optional argument:
Jon Hallffb386d2014-11-21 13:43:38 -0800827 * json_format - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800828 """
andrewonlab7c211572014-10-15 16:45:20 -0400829 try:
kelvin9c3d4912015-01-15 17:36:47 -0800830<<<<<<< HEAD
Jon Hall983a1702014-10-28 18:44:22 -0400831 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -0800832 cmd_str = "roles -j"
833 handle = self.sendline( cmd_str )
Jon Hall983a1702014-10-28 18:44:22 -0400834 '''
Jon Halle3f39ff2015-01-13 11:50:53 -0800835 handle variable here contains some ANSI escape color code
836 sequences at the end which are invisible in the print command
837 output. To make that escape sequence visible, use repr()
838 function. The repr(handle) output when printed shows the ANSI
839 escape sequences. In json.loads(somestring), this somestring
840 variable is actually repr(somestring) and json.loads would
841 fail with the escape sequence.
Jon Hallb1290e82014-11-18 16:17:48 -0500842
Jon Halle3f39ff2015-01-13 11:50:53 -0800843 So we take off that escape sequence using the following
844 commads:
845
Jon Hall983a1702014-10-28 18:44:22 -0400846 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
Jon Hallb1290e82014-11-18 16:17:48 -0500847 handle1 = ansi_escape.sub('', handle)
Jon Hall983a1702014-10-28 18:44:22 -0400848 '''
Jon Hall983a1702014-10-28 18:44:22 -0400849 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
850 handle1 = ansi_escape.sub('', handle)
Jon Hall983a1702014-10-28 18:44:22 -0400851 return handle1
andrewonlab7c211572014-10-15 16:45:20 -0400852
andrewonlab7c211572014-10-15 16:45:20 -0400853 else:
Jon Halle3f39ff2015-01-13 11:50:53 -0800854 cmd_str = "roles"
855 handle = self.sendline( cmd_str )
kelvin9c3d4912015-01-15 17:36:47 -0800856=======
kelvin8ec71442015-01-15 16:57:00 -0800857 self.handle.sendline( "" )
858 self.handle.expect( "onos>" )
andrewonlab7c211572014-10-15 16:45:20 -0400859
860 if json_format:
kelvin8ec71442015-01-15 16:57:00 -0800861 self.handle.sendline( "roles -j" )
862 self.handle.expect( "roles -j" )
863 self.handle.expect( "onos>" )
andrewonlab7c211572014-10-15 16:45:20 -0400864 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800865 """
andrewonlab7c211572014-10-15 16:45:20 -0400866 handle variable here contains some ANSI escape color code sequences at the
867 end which are invisible in the print command output. To make that escape
kelvin8ec71442015-01-15 16:57:00 -0800868 sequence visible, use repr() function. The repr( handle ) output when printed
869 shows the ANSI escape sequences. In json.loads( somestring ), this somestring
870 variable is actually repr( somestring ) and json.loads would fail with the escape
andrewonlab7c211572014-10-15 16:45:20 -0400871 sequence.
872
873 So we take off that escape sequence using the following commads:
kelvin8ec71442015-01-15 16:57:00 -0800874 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
875 handle1 = ansi_escape.sub( '', handle )
876 """
877 # print "repr(handle) =", repr( handle )
878 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
879 handle1 = ansi_escape.sub( '', handle )
880 # print "repr(handle1) = ", repr( handle1 )
andrewonlab7c211572014-10-15 16:45:20 -0400881 return handle1
882
883 else:
kelvin8ec71442015-01-15 16:57:00 -0800884 self.handle.sendline( "roles" )
885 self.handle.expect( "onos>" )
886 self.handle.sendline( "" )
887 self.handle.expect( "onos>" )
Jon Hall983a1702014-10-28 18:44:22 -0400888 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800889 # print "handle =",handle
kelvin9c3d4912015-01-15 17:36:47 -0800890>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Hallffb386d2014-11-21 13:43:38 -0800891 return handle
Jon Hall983a1702014-10-28 18:44:22 -0400892 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800893 main.log.error( self.name + ": EOF exception found" )
894 main.log.error( self.name + ": " + self.handle.before )
Jon Hall983a1702014-10-28 18:44:22 -0400895 main.cleanup()
896 main.exit()
897 except:
kelvin8ec71442015-01-15 16:57:00 -0800898 main.log.info( self.name + " ::::::" )
899 main.log.error( traceback.print_exc() )
900 main.log.info( self.name + " ::::::" )
Jon Hall983a1702014-10-28 18:44:22 -0400901 main.cleanup()
902 main.exit()
903
kelvin9c3d4912015-01-15 17:36:47 -0800904<<<<<<< HEAD
Jon Hall983a1702014-10-28 18:44:22 -0400905 def get_role(self, device_id):
906 '''
Jon Halle3f39ff2015-01-13 11:50:53 -0800907 Given the a string containing the json representation of the "roles"
908 cli command and a partial or whole device id, returns a json object
909 containing the roles output for the first device whose id contains
910 "device_id"
Jon Hall983a1702014-10-28 18:44:22 -0400911
912 Returns:
Jon Halle3f39ff2015-01-13 11:50:53 -0800913 A dict of the role assignments for the given device or
914 None if no match
Jon Hall983a1702014-10-28 18:44:22 -0400915 '''
kelvin9c3d4912015-01-15 17:36:47 -0800916=======
kelvin8ec71442015-01-15 16:57:00 -0800917 def get_role( self, device_id ):
918 """
919 Given the a string containing the json representation of the "roles" cli command and a
Jon Hall983a1702014-10-28 18:44:22 -0400920 partial or whole device id, returns a json object containing the
921 roles output for the first device whose id contains "device_id"
922
923 Returns:
924 Dict of the role assignments for the given device or
925 None if not match
kelvin8ec71442015-01-15 16:57:00 -0800926 """
kelvin9c3d4912015-01-15 17:36:47 -0800927>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Hall983a1702014-10-28 18:44:22 -0400928 try:
929 import json
kelvin8ec71442015-01-15 16:57:00 -0800930 if device_id is None:
Jon Hall983a1702014-10-28 18:44:22 -0400931 return None
932 else:
933 raw_roles = self.roles()
kelvin8ec71442015-01-15 16:57:00 -0800934 roles_json = json.loads( raw_roles )
935 # search json for the device with id then return the device
Jon Hall983a1702014-10-28 18:44:22 -0400936 for device in roles_json:
kelvin8ec71442015-01-15 16:57:00 -0800937 # print device
938 if str( device_id ) in device[ 'id' ]:
Jon Hall983a1702014-10-28 18:44:22 -0400939 return device
940 return None
andrewonlab7c211572014-10-15 16:45:20 -0400941
andrewonlab86dc3082014-10-13 18:18:38 -0400942 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800943 main.log.error( self.name + ": EOF exception found" )
944 main.log.error( self.name + ": " + self.handle.before )
andrewonlab86dc3082014-10-13 18:18:38 -0400945 main.cleanup()
946 main.exit()
947 except:
kelvin8ec71442015-01-15 16:57:00 -0800948 main.log.info( self.name + " ::::::" )
949 main.log.error( traceback.print_exc() )
950 main.log.info( self.name + " ::::::" )
andrewonlab86dc3082014-10-13 18:18:38 -0400951 main.cleanup()
952 main.exit()
Jon Hall94fd0472014-12-08 11:52:42 -0800953
kelvin8ec71442015-01-15 16:57:00 -0800954 def roles_not_null( self ):
955 """
Jon Hall94fd0472014-12-08 11:52:42 -0800956 Iterates through each device and checks if there is a master assigned
957 Returns: main.TRUE if each device has a master
958 main.FALSE any device has no master
kelvin8ec71442015-01-15 16:57:00 -0800959 """
Jon Hall94fd0472014-12-08 11:52:42 -0800960 try:
961 import json
962 raw_roles = self.roles()
kelvin8ec71442015-01-15 16:57:00 -0800963 roles_json = json.loads( raw_roles )
964 # search json for the device with id then return the device
Jon Hall94fd0472014-12-08 11:52:42 -0800965 for device in roles_json:
kelvin8ec71442015-01-15 16:57:00 -0800966 # print device
967 if device[ 'master' ] == "none":
968 main.log.warn( "Device has no master: " + str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800969 return main.FALSE
970 return main.TRUE
971
972 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800973 main.log.error( self.name + ": EOF exception found" )
974 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -0800975 main.cleanup()
976 main.exit()
977 except:
kelvin8ec71442015-01-15 16:57:00 -0800978 main.log.info( self.name + " ::::::" )
979 main.log.error( traceback.print_exc() )
980 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -0800981 main.cleanup()
982 main.exit()
983
kelvin8ec71442015-01-15 16:57:00 -0800984 def paths( self, src_id, dst_id ):
985 """
andrewonlab3e15ead2014-10-15 14:21:34 -0400986 Returns string of paths, and the cost.
987 Issues command: onos:paths <src> <dst>
kelvin8ec71442015-01-15 16:57:00 -0800988 """
andrewonlab3e15ead2014-10-15 14:21:34 -0400989 try:
kelvin9c3d4912015-01-15 17:36:47 -0800990<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -0800991 cmd_str = "onos:paths " + str(src_id) + " " + str(dst_id)
992 handle = self.sendline( cmd_str )
993 if re.search( "Error", handle ):
andrewonlab3e15ead2014-10-15 14:21:34 -0400994 main.log.error("Error in getting paths")
andrewonlab7c211572014-10-15 16:45:20 -0400995 return (handle, "Error")
andrewonlab3e15ead2014-10-15 14:21:34 -0400996 else:
997 path = handle.split(";")[0]
998 cost = handle.split(";")[1]
999 return (path, cost)
kelvin9c3d4912015-01-15 17:36:47 -08001000=======
kelvin8ec71442015-01-15 16:57:00 -08001001 self.handle.sendline( "" )
1002 self.handle.expect( "onos>" )
andrewonlab3e15ead2014-10-15 14:21:34 -04001003
kelvin8ec71442015-01-15 16:57:00 -08001004 self.handle.sendline( "onos:paths " +
1005 str( src_id ) + " " + str( dst_id ) )
1006 i = self.handle.expect( [
andrewonlab3e15ead2014-10-15 14:21:34 -04001007 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001008 "onos>" ] )
1009
1010 self.handle.sendline( "" )
1011 self.handle.expect( "onos>" )
andrewonlab3e15ead2014-10-15 14:21:34 -04001012
1013 handle = self.handle.before
1014
1015 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001016 main.log.error( "Error in getting paths" )
1017 return ( handle, "Error" )
andrewonlab3e15ead2014-10-15 14:21:34 -04001018 else:
kelvin8ec71442015-01-15 16:57:00 -08001019 path = handle.split( ";" )[ 0 ]
1020 cost = handle.split( ";" )[ 1 ]
1021 return ( path, cost )
1022
kelvin9c3d4912015-01-15 17:36:47 -08001023>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab3e15ead2014-10-15 14:21:34 -04001024 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001025 main.log.error( self.name + ": EOF exception found" )
1026 main.log.error( self.name + ": " + self.handle.before )
andrewonlab3e15ead2014-10-15 14:21:34 -04001027 main.cleanup()
1028 main.exit()
1029 except:
kelvin8ec71442015-01-15 16:57:00 -08001030 main.log.info( self.name + " ::::::" )
1031 main.log.error( traceback.print_exc() )
1032 main.log.info( self.name + " ::::::" )
andrewonlab3e15ead2014-10-15 14:21:34 -04001033 main.cleanup()
1034 main.exit()
Jon Hallffb386d2014-11-21 13:43:38 -08001035
kelvin8ec71442015-01-15 16:57:00 -08001036 def hosts( self, json_format=True ):
1037 """
Jon Hallffb386d2014-11-21 13:43:38 -08001038 Lists all discovered hosts
Jon Hall42db6dc2014-10-24 19:03:48 -04001039 Optional argument:
Jon Hallffb386d2014-11-21 13:43:38 -08001040 * json_format - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -08001041 """
Jon Hall42db6dc2014-10-24 19:03:48 -04001042 try:
kelvin9c3d4912015-01-15 17:36:47 -08001043<<<<<<< HEAD
Jon Hall42db6dc2014-10-24 19:03:48 -04001044 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -08001045 cmd_str = "hosts -j"
1046 handle = self.sendline( cmd_str )
Jon Hall42db6dc2014-10-24 19:03:48 -04001047 '''
Jon Halle3f39ff2015-01-13 11:50:53 -08001048 handle variable here contains some ANSI escape color code
1049 sequences at the end which are invisible in the print command
1050 output. To make that escape sequence visible, use repr()
1051 function. The repr(handle) output when printed shows the ANSI
1052 escape sequences. In json.loads(somestring), this somestring
1053 variable is actually repr(somestring) and json.loads would
1054 fail with the escape sequence. So we take off that escape
1055 sequence using:
1056
Jon Hall42db6dc2014-10-24 19:03:48 -04001057 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
Jon Hallffb386d2014-11-21 13:43:38 -08001058 handle1 = ansi_escape.sub('', handle)
Jon Hall42db6dc2014-10-24 19:03:48 -04001059 '''
Jon Hall42db6dc2014-10-24 19:03:48 -04001060 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
1061 handle1 = ansi_escape.sub('', handle)
Jon Hall42db6dc2014-10-24 19:03:48 -04001062 return handle1
1063 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001064 cmd_str = "hosts"
1065 handle = self.sendline( cmd_str )
kelvin9c3d4912015-01-15 17:36:47 -08001066=======
kelvin8ec71442015-01-15 16:57:00 -08001067 self.handle.sendline( "" )
1068 self.handle.expect( "onos>" )
Jon Hall42db6dc2014-10-24 19:03:48 -04001069
1070 if json_format:
kelvin8ec71442015-01-15 16:57:00 -08001071 self.handle.sendline( "hosts -j" )
1072 self.handle.expect( "hosts -j" )
1073 self.handle.expect( "onos>" )
Jon Hall42db6dc2014-10-24 19:03:48 -04001074 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001075 """
Jon Hall42db6dc2014-10-24 19:03:48 -04001076 handle variable here contains some ANSI escape color code sequences at the end which are invisible in the print command output
kelvin8ec71442015-01-15 16:57:00 -08001077 To make that escape sequence visible, use repr() function. The repr( handle ) output when printed shows the ANSI escape sequences.
1078 In json.loads( somestring ), this somestring variable is actually repr( somestring ) and json.loads would fail with the escape sequence.
Jon Hall42db6dc2014-10-24 19:03:48 -04001079 So we take off that escape sequence using
kelvin8ec71442015-01-15 16:57:00 -08001080 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1081 handle1 = ansi_escape.sub( '', handle )
1082 """
1083 # print "repr(handle) =", repr( handle )
1084 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1085 handle1 = ansi_escape.sub( '', handle )
1086 # print "repr(handle1) = ", repr( handle1 )
Jon Hall42db6dc2014-10-24 19:03:48 -04001087 return handle1
1088 else:
kelvin8ec71442015-01-15 16:57:00 -08001089 self.handle.sendline( "hosts" )
1090 self.handle.expect( "onos>" )
Jon Hall42db6dc2014-10-24 19:03:48 -04001091 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001092 # print "handle =",handle
kelvin9c3d4912015-01-15 17:36:47 -08001093>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Hall42db6dc2014-10-24 19:03:48 -04001094 return handle
1095 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001096 main.log.error( self.name + ": EOF exception found" )
1097 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -04001098 main.cleanup()
1099 main.exit()
1100 except:
kelvin8ec71442015-01-15 16:57:00 -08001101 main.log.info( self.name + " ::::::" )
1102 main.log.error( traceback.print_exc() )
1103 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -04001104 main.cleanup()
1105 main.exit()
1106
kelvin8ec71442015-01-15 16:57:00 -08001107 def get_host( self, mac ):
1108 """
Jon Hall42db6dc2014-10-24 19:03:48 -04001109 Return the first host from the hosts api whose 'id' contains 'mac'
Jon Halle3f39ff2015-01-13 11:50:53 -08001110
1111 Note: mac must be a colon seperated mac address, but could be a
1112 partial mac address
1113
Jon Hall42db6dc2014-10-24 19:03:48 -04001114 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -08001115 """
Jon Hall42db6dc2014-10-24 19:03:48 -04001116 import json
1117 try:
kelvin8ec71442015-01-15 16:57:00 -08001118 if mac is None:
Jon Hall42db6dc2014-10-24 19:03:48 -04001119 return None
1120 else:
1121 mac = mac
1122 raw_hosts = self.hosts()
kelvin8ec71442015-01-15 16:57:00 -08001123 hosts_json = json.loads( raw_hosts )
1124 # search json for the host with mac then return the device
Jon Hall42db6dc2014-10-24 19:03:48 -04001125 for host in hosts_json:
kelvin8ec71442015-01-15 16:57:00 -08001126 # print "%s in %s?" % ( mac, host[ 'id' ] )
1127 if mac in host[ 'id' ]:
Jon Hall42db6dc2014-10-24 19:03:48 -04001128 return host
1129 return None
1130 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001131 main.log.error( self.name + ": EOF exception found" )
1132 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -04001133 main.cleanup()
1134 main.exit()
1135 except:
kelvin8ec71442015-01-15 16:57:00 -08001136 main.log.info( self.name + " ::::::" )
1137 main.log.error( traceback.print_exc() )
1138 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -04001139 main.cleanup()
1140 main.exit()
1141
kelvin8ec71442015-01-15 16:57:00 -08001142 def get_hosts_id( self, host_list ):
1143 """
1144 Obtain list of hosts
andrewonlab3f0a4af2014-10-17 12:25:14 -04001145 Issues command: 'onos> hosts'
kelvin8ec71442015-01-15 16:57:00 -08001146
andrewonlab3f0a4af2014-10-17 12:25:14 -04001147 Required:
1148 * host_list: List of hosts obtained by Mininet
1149 IMPORTANT:
1150 This function assumes that you started your
kelvin8ec71442015-01-15 16:57:00 -08001151 topology with the option '--mac'.
andrewonlab3f0a4af2014-10-17 12:25:14 -04001152 Furthermore, it assumes that value of VLAN is '-1'
1153 Description:
kelvin8ec71442015-01-15 16:57:00 -08001154 Converts mininet hosts ( h1, h2, h3... ) into
1155 ONOS format ( 00:00:00:00:00:01/-1 , ... )
1156 """
andrewonlab3f0a4af2014-10-17 12:25:14 -04001157 try:
andrewonlab3f0a4af2014-10-17 12:25:14 -04001158 onos_host_list = []
1159
1160 for host in host_list:
kelvin8ec71442015-01-15 16:57:00 -08001161 host = host.replace( "h", "" )
1162 host_hex = hex( int( host ) ).zfill( 12 )
1163 host_hex = str( host_hex ).replace( 'x', '0' )
1164 i = iter( str( host_hex ) )
1165 host_hex = ":".join( a + b for a, b in zip( i, i ) )
andrewonlab3f0a4af2014-10-17 12:25:14 -04001166 host_hex = host_hex + "/-1"
kelvin8ec71442015-01-15 16:57:00 -08001167 onos_host_list.append( host_hex )
andrewonlab3f0a4af2014-10-17 12:25:14 -04001168
kelvin8ec71442015-01-15 16:57:00 -08001169 return onos_host_list
andrewonlab3f0a4af2014-10-17 12:25:14 -04001170
1171 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001172 main.log.error( self.name + ": EOF exception found" )
1173 main.log.error( self.name + ": " + self.handle.before )
andrewonlab3f0a4af2014-10-17 12:25:14 -04001174 main.cleanup()
1175 main.exit()
1176 except:
kelvin8ec71442015-01-15 16:57:00 -08001177 main.log.info( self.name + " ::::::" )
1178 main.log.error( traceback.print_exc() )
1179 main.log.info( self.name + " ::::::" )
andrewonlab3f0a4af2014-10-17 12:25:14 -04001180 main.cleanup()
1181 main.exit()
andrewonlab3e15ead2014-10-15 14:21:34 -04001182
kelvin8ec71442015-01-15 16:57:00 -08001183 def add_host_intent( self, host_id_one, host_id_two ):
1184 """
andrewonlabe6745342014-10-17 14:29:13 -04001185 Required:
1186 * host_id_one: ONOS host id for host1
1187 * host_id_two: ONOS host id for host2
1188 Description:
kelvin8ec71442015-01-15 16:57:00 -08001189 Adds a host-to-host intent ( bidrectional ) by
Jon Hallb1290e82014-11-18 16:17:48 -05001190 specifying the two hosts.
kelvin8ec71442015-01-15 16:57:00 -08001191 """
andrewonlabe6745342014-10-17 14:29:13 -04001192 try:
kelvin9c3d4912015-01-15 17:36:47 -08001193<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08001194 cmd_str = "add-host-intent " + str(host_id_one) +\
1195 " " + str(host_id_two)
1196 handle = self.sendline( cmd_str )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001197 main.log.info("Host intent installed between "+
andrewonlabe6745342014-10-17 14:29:13 -04001198 str(host_id_one) + " and " + str(host_id_two))
kelvin9c3d4912015-01-15 17:36:47 -08001199=======
kelvin8ec71442015-01-15 16:57:00 -08001200 self.handle.sendline( "" )
1201 self.handle.expect( "onos>" )
andrewonlabe6745342014-10-17 14:29:13 -04001202
kelvin8ec71442015-01-15 16:57:00 -08001203 self.handle.sendline( "add-host-intent " +
1204 str( host_id_one ) + " " + str( host_id_two ) )
1205 self.handle.expect( "onos>" )
andrewonlabe6745342014-10-17 14:29:13 -04001206
1207 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001208 # print "handle =", handle
andrewonlabe6745342014-10-17 14:29:13 -04001209
kelvin8ec71442015-01-15 16:57:00 -08001210 main.log.info( "Host intent installed between " +
1211 str( host_id_one ) + " and " + str( host_id_two ) )
andrewonlabe6745342014-10-17 14:29:13 -04001212
kelvin9c3d4912015-01-15 17:36:47 -08001213>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlabe6745342014-10-17 14:29:13 -04001214 return handle
andrewonlabe6745342014-10-17 14:29:13 -04001215 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001216 main.log.error( self.name + ": EOF exception found" )
1217 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe6745342014-10-17 14:29:13 -04001218 main.cleanup()
1219 main.exit()
1220 except:
kelvin8ec71442015-01-15 16:57:00 -08001221 main.log.info( self.name + " ::::::" )
1222 main.log.error( traceback.print_exc() )
1223 main.log.info( self.name + " ::::::" )
andrewonlabe6745342014-10-17 14:29:13 -04001224 main.cleanup()
1225 main.exit()
1226
kelvin8ec71442015-01-15 16:57:00 -08001227 def add_optical_intent( self, ingress_device, egress_device ):
1228 """
andrewonlab7b31d232014-10-24 13:31:47 -04001229 Required:
1230 * ingress_device: device id of ingress device
1231 * egress_device: device id of egress device
1232 Optional:
1233 TODO: Still needs to be implemented via dev side
kelvin9c3d4912015-01-15 17:36:47 -08001234<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08001235 '''
andrewonlab7b31d232014-10-24 13:31:47 -04001236 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001237 cmd_str = "add-optical-intent " + str( ingress_device ) +\
1238 " " + str( egress_device )
1239 handle = self.sendline( cmd_str )
andrewonlab7b31d232014-10-24 13:31:47 -04001240 #If error, return error message
Jon Halle3f39ff2015-01-13 11:50:53 -08001241 if re.search( "Error", handle ):
andrewonlab7b31d232014-10-24 13:31:47 -04001242 return handle
1243 else:
1244 return main.TRUE
kelvin9c3d4912015-01-15 17:36:47 -08001245=======
kelvin8ec71442015-01-15 16:57:00 -08001246 """
andrewonlab7b31d232014-10-24 13:31:47 -04001247 try:
kelvin8ec71442015-01-15 16:57:00 -08001248 self.handle.sendline( "add-optical-intent " +
1249 str( ingress_device ) + " " + str( egress_device ) )
1250 self.handle.expect( "add-optical-intent" )
1251 i = self.handle.expect( [
andrewonlab7b31d232014-10-24 13:31:47 -04001252 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001253 "onos>" ] )
andrewonlab7b31d232014-10-24 13:31:47 -04001254
1255 handle = self.handle.before
1256
kelvin8ec71442015-01-15 16:57:00 -08001257 # If error, return error message
andrewonlab7b31d232014-10-24 13:31:47 -04001258 if i == 0:
1259 return handle
1260 else:
1261 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08001262
kelvin9c3d4912015-01-15 17:36:47 -08001263>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab7b31d232014-10-24 13:31:47 -04001264 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001265 main.log.error( self.name + ": EOF exception found" )
1266 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7b31d232014-10-24 13:31:47 -04001267 main.cleanup()
1268 main.exit()
1269 except:
kelvin8ec71442015-01-15 16:57:00 -08001270 main.log.info( self.name + " ::::::" )
1271 main.log.error( traceback.print_exc() )
1272 main.log.info( self.name + " ::::::" )
andrewonlab7b31d232014-10-24 13:31:47 -04001273 main.cleanup()
1274 main.exit()
1275
kelvin9c3d4912015-01-15 17:36:47 -08001276<<<<<<< HEAD
andrewonlab36af3822014-11-18 17:48:18 -05001277 def add_point_intent(self, ingress_device, egress_device,
1278 port_ingress="", port_egress="", ethType="", ethSrc="",
Jon Halle3f39ff2015-01-13 11:50:53 -08001279 ethDst="", bandwidth="", lambda_alloc=False,
andrewonlabfa4ff502014-11-11 16:41:30 -05001280 ipProto="", ipSrc="", ipDst="", tcpSrc="", tcpDst=""):
andrewonlab4dbb4d82014-10-17 18:22:31 -04001281 '''
kelvin9c3d4912015-01-15 17:36:47 -08001282=======
kelvin8ec71442015-01-15 16:57:00 -08001283 def add_point_intent( self, ingress_device, egress_device,
1284 port_ingress="", port_egress="", ethType="", ethSrc="",
1285 ethDst="", bandwidth="", lambda_alloc=False,
1286 ipProto="", ipSrc="", ipDst="", tcpSrc="", tcpDst="" ):
1287 """
kelvin9c3d4912015-01-15 17:36:47 -08001288>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab4dbb4d82014-10-17 18:22:31 -04001289 Required:
1290 * ingress_device: device id of ingress device
1291 * egress_device: device id of egress device
andrewonlab289e4b72014-10-21 21:24:18 -04001292 Optional:
1293 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -08001294 * ethSrc: specify ethSrc ( i.e. src mac addr )
1295 * ethDst: specify ethDst ( i.e. dst mac addr )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001296 * bandwidth: specify bandwidth capacity of link
Jon Halle3f39ff2015-01-13 11:50:53 -08001297 * lambda_alloc: if True, intent will allocate lambda
andrewonlab40ccd8b2014-11-06 16:23:34 -05001298 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -08001299 * ipProto: specify ip protocol
andrewonlabf77e0cb2014-11-11 17:17:59 -05001300 * ipSrc: specify ip source address
1301 * ipDst: specify ip destination address
1302 * tcpSrc: specify tcp source port
1303 * tcpDst: specify tcp destination port
andrewonlab4dbb4d82014-10-17 18:22:31 -04001304 Description:
kelvin8ec71442015-01-15 16:57:00 -08001305 Adds a point-to-point intent ( uni-directional ) by
andrewonlab289e4b72014-10-21 21:24:18 -04001306 specifying device id's and optional fields
1307
Jon Halle3f39ff2015-01-13 11:50:53 -08001308 NOTE: This function may change depending on the
andrewonlab4dbb4d82014-10-17 18:22:31 -04001309 options developers provide for point-to-point
1310 intent via cli
kelvin8ec71442015-01-15 16:57:00 -08001311 """
andrewonlab4dbb4d82014-10-17 18:22:31 -04001312 try:
andrewonlab289e4b72014-10-21 21:24:18 -04001313 cmd = ""
1314
kelvin8ec71442015-01-15 16:57:00 -08001315 # If there are no optional arguments
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001316 if not ethType and not ethSrc and not ethDst\
andrewonlabfa4ff502014-11-11 16:41:30 -05001317 and not bandwidth and not lambda_alloc \
1318 and not ipProto and not ipSrc and not ipDst \
1319 and not tcpSrc and not tcpDst:
andrewonlab36af3822014-11-18 17:48:18 -05001320 cmd = "add-point-intent"
kelvin9c3d4912015-01-15 17:36:47 -08001321<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08001322
kelvin9c3d4912015-01-15 17:36:47 -08001323=======
1324>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab36af3822014-11-18 17:48:18 -05001325
andrewonlab289e4b72014-10-21 21:24:18 -04001326 else:
andrewonlab36af3822014-11-18 17:48:18 -05001327 cmd = "add-point-intent"
Jon Halle3f39ff2015-01-13 11:50:53 -08001328
andrewonlab0c0a6772014-10-22 12:31:18 -04001329 if ethType:
kelvin8ec71442015-01-15 16:57:00 -08001330 cmd += " --ethType " + str( ethType )
andrewonlab289e4b72014-10-21 21:24:18 -04001331 if ethSrc:
kelvin9c3d4912015-01-15 17:36:47 -08001332<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08001333 cmd += " --ethSrc " + str(ethSrc)
1334 if ethDst:
1335 cmd += " --ethDst " + str(ethDst)
kelvin9c3d4912015-01-15 17:36:47 -08001336=======
kelvin8ec71442015-01-15 16:57:00 -08001337 cmd += " --ethSrc " + str( ethSrc )
1338 if ethDst:
1339 cmd += " --ethDst " + str( ethDst )
kelvin9c3d4912015-01-15 17:36:47 -08001340>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001341 if bandwidth:
kelvin8ec71442015-01-15 16:57:00 -08001342 cmd += " --bandwidth " + str( bandwidth )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001343 if lambda_alloc:
andrewonlabfa4ff502014-11-11 16:41:30 -05001344 cmd += " --lambda "
1345 if ipProto:
kelvin8ec71442015-01-15 16:57:00 -08001346 cmd += " --ipProto " + str( ipProto )
andrewonlabfa4ff502014-11-11 16:41:30 -05001347 if ipSrc:
kelvin8ec71442015-01-15 16:57:00 -08001348 cmd += " --ipSrc " + str( ipSrc )
andrewonlabfa4ff502014-11-11 16:41:30 -05001349 if ipDst:
kelvin8ec71442015-01-15 16:57:00 -08001350 cmd += " --ipDst " + str( ipDst )
andrewonlabfa4ff502014-11-11 16:41:30 -05001351 if tcpSrc:
kelvin8ec71442015-01-15 16:57:00 -08001352 cmd += " --tcpSrc " + str( tcpSrc )
andrewonlabfa4ff502014-11-11 16:41:30 -05001353 if tcpDst:
kelvin8ec71442015-01-15 16:57:00 -08001354 cmd += " --tcpDst " + str( tcpDst )
andrewonlab289e4b72014-10-21 21:24:18 -04001355
kelvin9c3d4912015-01-15 17:36:47 -08001356<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08001357 #Check whether the user appended the port
andrewonlab36af3822014-11-18 17:48:18 -05001358 #or provided it as an input
kelvin9c3d4912015-01-15 17:36:47 -08001359=======
kelvin8ec71442015-01-15 16:57:00 -08001360 # Check whether the user appended the port
1361 # or provided it as an input
kelvin9c3d4912015-01-15 17:36:47 -08001362>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab36af3822014-11-18 17:48:18 -05001363 if "/" in ingress_device:
kelvin8ec71442015-01-15 16:57:00 -08001364 cmd += " " + str( ingress_device )
andrewonlab36af3822014-11-18 17:48:18 -05001365 else:
1366 if not port_ingress:
kelvin8ec71442015-01-15 16:57:00 -08001367 main.log.error( "You must specify " +
1368 "the ingress port" )
1369 # TODO: perhaps more meaningful return
andrewonlab36af3822014-11-18 17:48:18 -05001370 return main.FALSE
1371
kelvin9c3d4912015-01-15 17:36:47 -08001372<<<<<<< HEAD
andrewonlab36af3822014-11-18 17:48:18 -05001373 cmd += " "+ \
1374 str(ingress_device) + "/" +\
Jon Halle3f39ff2015-01-13 11:50:53 -08001375 str(port_ingress) + " "
kelvin9c3d4912015-01-15 17:36:47 -08001376=======
kelvin8ec71442015-01-15 16:57:00 -08001377 cmd += " " + \
1378 str( ingress_device ) + "/" +\
1379 str( port_ingress ) + " "
kelvin9c3d4912015-01-15 17:36:47 -08001380>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab36af3822014-11-18 17:48:18 -05001381
1382 if "/" in egress_device:
kelvin8ec71442015-01-15 16:57:00 -08001383 cmd += " " + str( egress_device )
andrewonlab36af3822014-11-18 17:48:18 -05001384 else:
1385 if not port_egress:
kelvin8ec71442015-01-15 16:57:00 -08001386 main.log.error( "You must specify " +
1387 "the egress port" )
andrewonlab36af3822014-11-18 17:48:18 -05001388 return main.FALSE
Jon Halle3f39ff2015-01-13 11:50:53 -08001389
kelvin9c3d4912015-01-15 17:36:47 -08001390<<<<<<< HEAD
andrewonlab36af3822014-11-18 17:48:18 -05001391 cmd += " "+\
1392 str(egress_device) + "/" +\
Jon Halle3f39ff2015-01-13 11:50:53 -08001393 str(port_egress)
andrewonlab4dbb4d82014-10-17 18:22:31 -04001394
Jon Halle3f39ff2015-01-13 11:50:53 -08001395 handle = self.sendline(cmd)
1396 if re.search( "Error", handle ):
andrewonlab4dbb4d82014-10-17 18:22:31 -04001397 main.log.error("Error in adding point-to-point intent")
kelvin9c3d4912015-01-15 17:36:47 -08001398=======
kelvin8ec71442015-01-15 16:57:00 -08001399 cmd += " " +\
1400 str( egress_device ) + "/" +\
1401 str( port_egress )
1402
1403 self.handle.sendline( cmd )
1404
1405 main.log.info( cmd + " sent" )
1406 i = self.handle.expect( [
andrewonlab4dbb4d82014-10-17 18:22:31 -04001407 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001408 "onos>" ] )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001409
1410 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001411 main.log.error( "Error in adding point-to-point intent" )
kelvin9c3d4912015-01-15 17:36:47 -08001412>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Hall47a93fb2015-01-06 16:46:06 -08001413 return main.FALSE
andrewonlab4dbb4d82014-10-17 18:22:31 -04001414 else:
1415 return main.TRUE
andrewonlab4dbb4d82014-10-17 18:22:31 -04001416 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001417 main.log.error( self.name + ": EOF exception found" )
1418 main.log.error( self.name + ": " + self.handle.before )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001419 main.cleanup()
1420 main.exit()
1421 except:
kelvin8ec71442015-01-15 16:57:00 -08001422 main.log.info( self.name + " ::::::" )
1423 main.log.error( traceback.print_exc() )
1424 main.log.info( self.name + " ::::::" )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001425 main.cleanup()
1426 main.exit()
1427
kelvin9c3d4912015-01-15 17:36:47 -08001428<<<<<<< HEAD
shahshreyad0c80432014-12-04 16:56:05 -08001429
Jon Halle3f39ff2015-01-13 11:50:53 -08001430 def add_multipoint_to_singlepoint_intent(self, ingress_device1,
1431 ingress_device2, egress_device, port_ingress="", port_egress="",
1432 ethType="", ethSrc="", ethDst="", bandwidth="", lambda_alloc=False,
1433 ipProto="", ipSrc="", ipDst="", tcpSrc="", tcpDst="", setEthSrc="",
1434 setEthDst=""):
shahshreyad0c80432014-12-04 16:56:05 -08001435 '''
kelvin9c3d4912015-01-15 17:36:47 -08001436=======
kelvin8ec71442015-01-15 16:57:00 -08001437 def add_multipoint_to_singlepoint_intent(
1438 self, ingress_device1, ingress_device2, egress_device,
1439 port_ingress="", port_egress="", ethType="", ethSrc="",
1440 ethDst="", bandwidth="", lambda_alloc=False,
1441 ipProto="", ipSrc="", ipDst="", tcpSrc="", tcpDst="", setEthSrc="", setEthDst="" ):
1442 """
kelvin9c3d4912015-01-15 17:36:47 -08001443>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
shahshreyad0c80432014-12-04 16:56:05 -08001444 Note:
Jon Halle3f39ff2015-01-13 11:50:53 -08001445 This function assumes that there would be 2 ingress devices and
1446 one egress device. For more number of ingress devices, this
1447 function needs to be modified
shahshreyad0c80432014-12-04 16:56:05 -08001448 Required:
1449 * ingress_device1: device id of ingress device1
1450 * ingress_device2: device id of ingress device2
1451 * egress_device: device id of egress device
1452 Optional:
1453 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -08001454 * ethSrc: specify ethSrc ( i.e. src mac addr )
1455 * ethDst: specify ethDst ( i.e. dst mac addr )
shahshreyad0c80432014-12-04 16:56:05 -08001456 * bandwidth: specify bandwidth capacity of link
Jon Halle3f39ff2015-01-13 11:50:53 -08001457 * lambda_alloc: if True, intent will allocate lambda
shahshreyad0c80432014-12-04 16:56:05 -08001458 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -08001459 * ipProto: specify ip protocol
shahshreyad0c80432014-12-04 16:56:05 -08001460 * ipSrc: specify ip source address
1461 * ipDst: specify ip destination address
1462 * tcpSrc: specify tcp source port
1463 * tcpDst: specify tcp destination port
1464 * setEthSrc: action to Rewrite Source MAC Address
1465 * setEthDst: action to Rewrite Destination MAC Address
1466 Description:
kelvin8ec71442015-01-15 16:57:00 -08001467 Adds a multipoint-to-singlepoint intent ( uni-directional ) by
shahshreyad0c80432014-12-04 16:56:05 -08001468 specifying device id's and optional fields
1469
Jon Halle3f39ff2015-01-13 11:50:53 -08001470 NOTE: This function may change depending on the
shahshreyad0c80432014-12-04 16:56:05 -08001471 options developers provide for multipointpoint-to-singlepoint
1472 intent via cli
kelvin8ec71442015-01-15 16:57:00 -08001473 """
shahshreyad0c80432014-12-04 16:56:05 -08001474 try:
1475 cmd = ""
1476
kelvin8ec71442015-01-15 16:57:00 -08001477 # If there are no optional arguments
shahshreyad0c80432014-12-04 16:56:05 -08001478 if not ethType and not ethSrc and not ethDst\
Jon Halle3f39ff2015-01-13 11:50:53 -08001479 and not bandwidth and not lambda_alloc\
1480 and not ipProto and not ipSrc and not ipDst\
1481 and not tcpSrc and not tcpDst and not setEthSrc\
1482 and not setEthDst:
shahshreyad0c80432014-12-04 16:56:05 -08001483 cmd = "add-multi-to-single-intent"
shahshreyad0c80432014-12-04 16:56:05 -08001484
1485 else:
1486 cmd = "add-multi-to-single-intent"
Jon Halle3f39ff2015-01-13 11:50:53 -08001487
shahshreyad0c80432014-12-04 16:56:05 -08001488 if ethType:
kelvin8ec71442015-01-15 16:57:00 -08001489 cmd += " --ethType " + str( ethType )
shahshreyad0c80432014-12-04 16:56:05 -08001490 if ethSrc:
kelvin9c3d4912015-01-15 17:36:47 -08001491<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08001492 cmd += " --ethSrc " + str(ethSrc)
1493 if ethDst:
1494 cmd += " --ethDst " + str(ethDst)
kelvin9c3d4912015-01-15 17:36:47 -08001495=======
kelvin8ec71442015-01-15 16:57:00 -08001496 cmd += " --ethSrc " + str( ethSrc )
1497 if ethDst:
1498 cmd += " --ethDst " + str( ethDst )
kelvin9c3d4912015-01-15 17:36:47 -08001499>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
shahshreyad0c80432014-12-04 16:56:05 -08001500 if bandwidth:
kelvin8ec71442015-01-15 16:57:00 -08001501 cmd += " --bandwidth " + str( bandwidth )
shahshreyad0c80432014-12-04 16:56:05 -08001502 if lambda_alloc:
1503 cmd += " --lambda "
1504 if ipProto:
kelvin8ec71442015-01-15 16:57:00 -08001505 cmd += " --ipProto " + str( ipProto )
shahshreyad0c80432014-12-04 16:56:05 -08001506 if ipSrc:
kelvin8ec71442015-01-15 16:57:00 -08001507 cmd += " --ipSrc " + str( ipSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001508 if ipDst:
kelvin8ec71442015-01-15 16:57:00 -08001509 cmd += " --ipDst " + str( ipDst )
shahshreyad0c80432014-12-04 16:56:05 -08001510 if tcpSrc:
kelvin8ec71442015-01-15 16:57:00 -08001511 cmd += " --tcpSrc " + str( tcpSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001512 if tcpDst:
kelvin8ec71442015-01-15 16:57:00 -08001513 cmd += " --tcpDst " + str( tcpDst )
shahshreyad0c80432014-12-04 16:56:05 -08001514 if setEthSrc:
kelvin8ec71442015-01-15 16:57:00 -08001515 cmd += " --setEthSrc " + str( setEthSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001516 if setEthDst:
kelvin8ec71442015-01-15 16:57:00 -08001517 cmd += " --setEthDst " + str( setEthDst )
shahshreyad0c80432014-12-04 16:56:05 -08001518
kelvin9c3d4912015-01-15 17:36:47 -08001519<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08001520 #Check whether the user appended the port
shahshreyad0c80432014-12-04 16:56:05 -08001521 #or provided it as an input
1522 if "/" in ingress_device1:
Jon Halle3f39ff2015-01-13 11:50:53 -08001523 cmd += " "+str(ingress_device1)
kelvin9c3d4912015-01-15 17:36:47 -08001524=======
kelvin8ec71442015-01-15 16:57:00 -08001525 # Check whether the user appended the port
1526 # or provided it as an input
shahshreyad0c80432014-12-04 16:56:05 -08001527 if "/" in ingress_device1:
kelvin8ec71442015-01-15 16:57:00 -08001528 cmd += " " + str( ingress_device1 )
kelvin9c3d4912015-01-15 17:36:47 -08001529>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
shahshreyad0c80432014-12-04 16:56:05 -08001530 else:
1531 if not port_ingress1:
kelvin8ec71442015-01-15 16:57:00 -08001532 main.log.error( "You must specify " +
1533 "the ingress port1" )
1534 # TODO: perhaps more meaningful return
shahshreyad0c80432014-12-04 16:56:05 -08001535 return main.FALSE
1536
kelvin9c3d4912015-01-15 17:36:47 -08001537<<<<<<< HEAD
shahshreyad0c80432014-12-04 16:56:05 -08001538 cmd += " "+ \
1539 str(ingress_device1) + "/" +\
Jon Halle3f39ff2015-01-13 11:50:53 -08001540 str(port_ingress1) + " "
kelvin9c3d4912015-01-15 17:36:47 -08001541=======
kelvin8ec71442015-01-15 16:57:00 -08001542 cmd += " " + \
1543 str( ingress_device1 ) + "/" +\
1544 str( port_ingress1 ) + " "
kelvin9c3d4912015-01-15 17:36:47 -08001545>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
shahshreyad0c80432014-12-04 16:56:05 -08001546
1547 if "/" in ingress_device2:
kelvin8ec71442015-01-15 16:57:00 -08001548 cmd += " " + str( ingress_device2 )
shahshreyad0c80432014-12-04 16:56:05 -08001549 else:
1550 if not port_ingress2:
kelvin8ec71442015-01-15 16:57:00 -08001551 main.log.error( "You must specify " +
1552 "the ingress port2" )
1553 # TODO: perhaps more meaningful return
shahshreyad0c80432014-12-04 16:56:05 -08001554 return main.FALSE
1555
kelvin8ec71442015-01-15 16:57:00 -08001556 cmd += " " + \
1557 str( ingress_device2 ) + "/" +\
1558 str( port_ingress2 ) + " "
shahshreyad0c80432014-12-04 16:56:05 -08001559
1560 if "/" in egress_device:
kelvin8ec71442015-01-15 16:57:00 -08001561 cmd += " " + str( egress_device )
shahshreyad0c80432014-12-04 16:56:05 -08001562 else:
1563 if not port_egress:
kelvin8ec71442015-01-15 16:57:00 -08001564 main.log.error( "You must specify " +
1565 "the egress port" )
shahshreyad0c80432014-12-04 16:56:05 -08001566 return main.FALSE
Jon Halle3f39ff2015-01-13 11:50:53 -08001567
kelvin9c3d4912015-01-15 17:36:47 -08001568<<<<<<< HEAD
shahshreyad0c80432014-12-04 16:56:05 -08001569 cmd += " "+\
1570 str(egress_device) + "/" +\
Jon Halle3f39ff2015-01-13 11:50:53 -08001571 str(port_egress)
shahshreyad0c80432014-12-04 16:56:05 -08001572 print "cmd= ",cmd
Jon Halle3f39ff2015-01-13 11:50:53 -08001573 handle = self.sendline(cmd)
1574 if re.search( "Error", handle ):
shahshreyad0c80432014-12-04 16:56:05 -08001575 main.log.error("Error in adding point-to-point intent")
kelvin9c3d4912015-01-15 17:36:47 -08001576=======
kelvin8ec71442015-01-15 16:57:00 -08001577 cmd += " " +\
1578 str( egress_device ) + "/" +\
1579 str( port_egress )
1580 print "cmd= ", cmd
1581 self.handle.sendline( cmd )
1582
1583 main.log.info( cmd + " sent" )
1584 i = self.handle.expect( [
shahshreyad0c80432014-12-04 16:56:05 -08001585 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001586 "onos>" ] )
shahshreyad0c80432014-12-04 16:56:05 -08001587
1588 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001589 main.log.error( "Error in adding point-to-point intent" )
kelvin9c3d4912015-01-15 17:36:47 -08001590>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
shahshreyad0c80432014-12-04 16:56:05 -08001591 return self.handle
1592 else:
1593 return main.TRUE
shahshreyad0c80432014-12-04 16:56:05 -08001594 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001595 main.log.error( self.name + ": EOF exception found" )
1596 main.log.error( self.name + ": " + self.handle.before )
shahshreyad0c80432014-12-04 16:56:05 -08001597 main.cleanup()
1598 main.exit()
1599 except:
kelvin8ec71442015-01-15 16:57:00 -08001600 main.log.info( self.name + " ::::::" )
1601 main.log.error( traceback.print_exc() )
1602 main.log.info( self.name + " ::::::" )
shahshreyad0c80432014-12-04 16:56:05 -08001603 main.cleanup()
1604 main.exit()
1605
kelvin9c3d4912015-01-15 17:36:47 -08001606<<<<<<< HEAD
andrewonlab9a50dfe2014-10-17 17:22:31 -04001607 def remove_intent(self, intent_id):
1608 '''
1609 Remove intent for specified intent id
Jon Halle3f39ff2015-01-13 11:50:53 -08001610
1611 Returns:
1612 main.False on error and
1613 cli output otherwise
andrewonlab9a50dfe2014-10-17 17:22:31 -04001614 '''
1615 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001616 cmd_str = "remove-intent " + str( intent_id )
1617 handle = self.sendline( cmd_str )
1618 if re.search( "Error", handle ):
andrewonlab9a50dfe2014-10-17 17:22:31 -04001619 main.log.error("Error in removing intent")
Jon Halle3f39ff2015-01-13 11:50:53 -08001620 return main.FALSE
andrewonlab9a50dfe2014-10-17 17:22:31 -04001621 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001622 # TODO: Should this be main.TRUE
1623 return handle
kelvin9c3d4912015-01-15 17:36:47 -08001624=======
kelvin8ec71442015-01-15 16:57:00 -08001625 def remove_intent( self, intent_id ):
1626 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001627 Remove intent for specified intent id
kelvin8ec71442015-01-15 16:57:00 -08001628 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001629 try:
kelvin8ec71442015-01-15 16:57:00 -08001630 self.handle.sendline( "" )
1631 self.handle.expect( "onos>" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001632
kelvin8ec71442015-01-15 16:57:00 -08001633 self.handle.sendline( "remove-intent " + str( intent_id ) )
1634 i = self.handle.expect( [
andrewonlab9a50dfe2014-10-17 17:22:31 -04001635 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001636 "onos>" ] )
1637
andrewonlab9a50dfe2014-10-17 17:22:31 -04001638 handle = self.handle.before
1639
1640 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001641 main.log.error( "Error in removing intent" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001642 return handle
1643 else:
kelvin8ec71442015-01-15 16:57:00 -08001644 return handle
1645
kelvin9c3d4912015-01-15 17:36:47 -08001646>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab9a50dfe2014-10-17 17:22:31 -04001647 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001648 main.log.error( self.name + ": EOF exception found" )
1649 main.log.error( self.name + ": " + self.handle.before )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001650 main.cleanup()
1651 main.exit()
1652 except:
kelvin8ec71442015-01-15 16:57:00 -08001653 main.log.info( self.name + " ::::::" )
1654 main.log.error( traceback.print_exc() )
1655 main.log.info( self.name + " ::::::" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001656 main.cleanup()
1657 main.exit()
1658
kelvin9c3d4912015-01-15 17:36:47 -08001659<<<<<<< HEAD
pingping-lin8b306ac2014-11-17 18:13:51 -08001660 def routes(self, json_format=False):
1661 '''
Jon Halle3f39ff2015-01-13 11:50:53 -08001662 NOTE: This method should be used after installing application:
1663 onos-app-sdnip
kelvin9c3d4912015-01-15 17:36:47 -08001664=======
pingping-lin8b306ac2014-11-17 18:13:51 -08001665 # This method should be used after installing application: onos-app-sdnip
kelvin8ec71442015-01-15 16:57:00 -08001666 def routes( self, json_format=False ):
1667 """
kelvin9c3d4912015-01-15 17:36:47 -08001668>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
pingping-lin8b306ac2014-11-17 18:13:51 -08001669 Optional:
1670 * json_format: enable output formatting in json
1671 Description:
1672 Obtain all routes in the system
kelvin8ec71442015-01-15 16:57:00 -08001673 """
pingping-lin8b306ac2014-11-17 18:13:51 -08001674 try:
1675 if json_format:
kelvin9c3d4912015-01-15 17:36:47 -08001676<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08001677 cmd_str = "routes -j"
1678 handle_tmp = self.sendline( cmd_str )
pingping-lin8b306ac2014-11-17 18:13:51 -08001679 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
1680 handle = ansi_escape.sub('', handle_tmp)
pingping-lin8b306ac2014-11-17 18:13:51 -08001681 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001682 cmd_str = "routes"
1683 handle = self.sendline( cmd_str )
kelvin9c3d4912015-01-15 17:36:47 -08001684=======
kelvin8ec71442015-01-15 16:57:00 -08001685 self.handle.sendline( "routes -j" )
1686 self.handle.expect( "routes -j" )
1687 self.handle.expect( "onos>" )
pingping-lin8b306ac2014-11-17 18:13:51 -08001688 handle_tmp = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001689
1690 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1691 handle = ansi_escape.sub( '', handle_tmp )
pingping-lin8b306ac2014-11-17 18:13:51 -08001692
1693 else:
kelvin8ec71442015-01-15 16:57:00 -08001694 self.handle.sendline( "" )
1695 self.handle.expect( "onos>" )
pingping-lin8b306ac2014-11-17 18:13:51 -08001696
kelvin8ec71442015-01-15 16:57:00 -08001697 self.handle.sendline( "routes" )
1698 self.handle.expect( "onos>" )
pingping-lin8b306ac2014-11-17 18:13:51 -08001699 handle = self.handle.before
1700
kelvin9c3d4912015-01-15 17:36:47 -08001701>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
pingping-lin8b306ac2014-11-17 18:13:51 -08001702 return handle
pingping-lin8b306ac2014-11-17 18:13:51 -08001703 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001704 main.log.error( self.name + ": EOF exception found" )
1705 main.log.error( self.name + ": " + self.handle.before )
pingping-lin8b306ac2014-11-17 18:13:51 -08001706 main.cleanup()
1707 main.exit()
1708 except:
kelvin8ec71442015-01-15 16:57:00 -08001709 main.log.info( self.name + " ::::::" )
1710 main.log.error( traceback.print_exc() )
1711 main.log.info( self.name + " ::::::" )
pingping-lin8b306ac2014-11-17 18:13:51 -08001712 main.cleanup()
1713 main.exit()
1714
kelvin8ec71442015-01-15 16:57:00 -08001715 def intents( self, json_format=True ):
1716 """
andrewonlab377693f2014-10-21 16:00:30 -04001717 Optional:
1718 * json_format: enable output formatting in json
andrewonlabe6745342014-10-17 14:29:13 -04001719 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001720 Obtain intents currently installed
kelvin9c3d4912015-01-15 17:36:47 -08001721<<<<<<< HEAD
andrewonlabe6745342014-10-17 14:29:13 -04001722 '''
1723 try:
andrewonlab377693f2014-10-21 16:00:30 -04001724 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -08001725 cmd_str = "intents -j"
1726 handle = self.sendline( cmd_str )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001727 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
1728 handle = ansi_escape.sub('', handle)
andrewonlab377693f2014-10-21 16:00:30 -04001729 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001730 cmd_str = "intents"
1731 handle = self.sendline( cmd_str )
kelvin9c3d4912015-01-15 17:36:47 -08001732=======
kelvin8ec71442015-01-15 16:57:00 -08001733 """
andrewonlabe6745342014-10-17 14:29:13 -04001734 try:
1735 if json_format:
kelvin8ec71442015-01-15 16:57:00 -08001736 self.handle.sendline( "intents -j" )
1737 self.handle.expect( "intents -j" )
1738 self.handle.expect( "onos>" )
andrewonlabe6745342014-10-17 14:29:13 -04001739 handle = self.handle.before
andrewonlabe6745342014-10-17 14:29:13 -04001740
kelvin8ec71442015-01-15 16:57:00 -08001741 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1742 handle = ansi_escape.sub( '', handle )
1743 else:
1744 self.handle.sendline( "" )
1745 self.handle.expect( "onos>" )
1746
1747 self.handle.sendline( "intents" )
1748 self.handle.expect( "onos>" )
andrewonlab377693f2014-10-21 16:00:30 -04001749 handle = self.handle.before
andrewonlabe6745342014-10-17 14:29:13 -04001750
kelvin9c3d4912015-01-15 17:36:47 -08001751>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlabe6745342014-10-17 14:29:13 -04001752 return handle
andrewonlabe6745342014-10-17 14:29:13 -04001753 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001754 main.log.error( self.name + ": EOF exception found" )
1755 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe6745342014-10-17 14:29:13 -04001756 main.cleanup()
1757 main.exit()
1758 except:
kelvin8ec71442015-01-15 16:57:00 -08001759 main.log.info( self.name + " ::::::" )
1760 main.log.error( traceback.print_exc() )
1761 main.log.info( self.name + " ::::::" )
andrewonlabe6745342014-10-17 14:29:13 -04001762 main.cleanup()
1763 main.exit()
1764
kelvin8ec71442015-01-15 16:57:00 -08001765 def flows( self, json_format=True ):
1766 """
Shreya Shah0f01c812014-10-26 20:15:28 -04001767 Optional:
1768 * json_format: enable output formatting in json
1769 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001770 Obtain flows currently installed
kelvin9c3d4912015-01-15 17:36:47 -08001771<<<<<<< HEAD
Shreya Shah0f01c812014-10-26 20:15:28 -04001772 '''
1773 try:
1774 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -08001775 cmd_str = "flows -j"
1776 handle = self.sendline( cmd_str )
Jon Hallb1290e82014-11-18 16:17:48 -05001777 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
1778 handle = ansi_escape.sub('', handle)
Shreya Shah0f01c812014-10-26 20:15:28 -04001779 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001780 cmd_str = "flows"
1781 handle = self.sendline( cmd_str )
Jon Hallb1290e82014-11-18 16:17:48 -05001782 if re.search("Error\sexecuting\scommand:", handle):
Jon Halle3f39ff2015-01-13 11:50:53 -08001783 main.log.error( self.name + ".flows() response: " +
1784 str( handle ) )
kelvin9c3d4912015-01-15 17:36:47 -08001785=======
kelvin8ec71442015-01-15 16:57:00 -08001786 """
Shreya Shah0f01c812014-10-26 20:15:28 -04001787 try:
1788 if json_format:
kelvin8ec71442015-01-15 16:57:00 -08001789 self.handle.sendline( "flows -j" )
1790 self.handle.expect( "flows -j" )
1791 self.handle.expect( "onos>" )
Shreya Shah0f01c812014-10-26 20:15:28 -04001792 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001793 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1794 handle = ansi_escape.sub( '', handle )
Shreya Shah0f01c812014-10-26 20:15:28 -04001795
1796 else:
kelvin8ec71442015-01-15 16:57:00 -08001797 self.handle.sendline( "" )
1798 self.handle.expect( "onos>" )
1799 self.handle.sendline( "flows" )
1800 self.handle.expect( "onos>" )
Shreya Shah0f01c812014-10-26 20:15:28 -04001801 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001802 if re.search( "Error\sexecuting\scommand:", handle ):
1803 main.log.error(
1804 self.name + ".flows() response: " + str( handle ) )
Shreya Shah0f01c812014-10-26 20:15:28 -04001805
kelvin9c3d4912015-01-15 17:36:47 -08001806>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Shreya Shah0f01c812014-10-26 20:15:28 -04001807 return handle
Shreya Shah0f01c812014-10-26 20:15:28 -04001808 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001809 main.log.error( self.name + ": EOF exception found" )
1810 main.log.error( self.name + ": " + self.handle.before )
Shreya Shah0f01c812014-10-26 20:15:28 -04001811 main.cleanup()
1812 main.exit()
1813 except:
kelvin8ec71442015-01-15 16:57:00 -08001814 main.log.info( self.name + " ::::::" )
1815 main.log.error( traceback.print_exc() )
1816 main.log.info( self.name + " ::::::" )
Shreya Shah0f01c812014-10-26 20:15:28 -04001817 main.cleanup()
1818 main.exit()
1819
kelvin9c3d4912015-01-15 17:36:47 -08001820<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08001821 def push_test_intents(self, dpid_src, dpid_dst, num_intents,
andrewonlabb66dfa12014-12-02 15:51:10 -05001822 num_mult="", app_id="", report=True):
andrewonlab87852b02014-11-19 18:44:19 -05001823 '''
kelvin9c3d4912015-01-15 17:36:47 -08001824=======
kelvin8ec71442015-01-15 16:57:00 -08001825 def push_test_intents( self, dpid_src, dpid_dst, num_intents,
1826 num_mult="", app_id="", report=True ):
1827 """
kelvin9c3d4912015-01-15 17:36:47 -08001828>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab87852b02014-11-19 18:44:19 -05001829 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001830 Push a number of intents in a batch format to
andrewonlab87852b02014-11-19 18:44:19 -05001831 a specific point-to-point intent definition
1832 Required:
1833 * dpid_src: specify source dpid
1834 * dpid_dst: specify destination dpid
1835 * num_intents: specify number of intents to push
1836 Optional:
andrewonlabb66dfa12014-12-02 15:51:10 -05001837 * num_mult: number multiplier for multiplying
1838 the number of intents specified
1839 * app_id: specify the application id init to further
1840 modularize the intents
andrewonlab87852b02014-11-19 18:44:19 -05001841 * report: default True, returns latency information
kelvin8ec71442015-01-15 16:57:00 -08001842 """
andrewonlab87852b02014-11-19 18:44:19 -05001843 try:
kelvin9c3d4912015-01-15 17:36:47 -08001844<<<<<<< HEAD
andrewonlab87852b02014-11-19 18:44:19 -05001845 cmd = "push-test-intents "+\
1846 str(dpid_src)+" "+str(dpid_dst)+" "+\
1847 str(num_intents)
andrewonlabb66dfa12014-12-02 15:51:10 -05001848 if num_mult:
1849 cmd += " " + str(num_mult)
Jon Halle3f39ff2015-01-13 11:50:53 -08001850 #If app id is specified, then num_mult
andrewonlab042b3912014-12-10 16:40:50 -05001851 #must exist because of the way this command
1852 #takes in arguments
andrewonlabb66dfa12014-12-02 15:51:10 -05001853 if app_id:
1854 cmd += " " + str(app_id)
Jon Halle3f39ff2015-01-13 11:50:53 -08001855 handle = self.sendline( cmd )
andrewonlab87852b02014-11-19 18:44:19 -05001856 #Some color thing that we want to escape
1857 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
1858 handle = ansi_escape.sub('', handle)
kelvin9c3d4912015-01-15 17:36:47 -08001859=======
kelvin8ec71442015-01-15 16:57:00 -08001860 cmd = "push-test-intents " +\
1861 str( dpid_src ) + " " + str( dpid_dst ) + " " +\
1862 str( num_intents )
1863
andrewonlab87852b02014-11-19 18:44:19 -05001864 if num_mult:
kelvin8ec71442015-01-15 16:57:00 -08001865 cmd += " " + str( num_mult )
1866 # If app id is specified, then num_mult
1867 # must exist because of the way this command
1868 # takes in arguments
andrewonlab87852b02014-11-19 18:44:19 -05001869 if app_id:
kelvin8ec71442015-01-15 16:57:00 -08001870 cmd += " " + str( app_id )
1871
1872 self.handle.sendline( cmd )
1873 self.handle.expect( cmd )
1874 self.handle.expect( "onos>" )
1875
andrewonlab87852b02014-11-19 18:44:19 -05001876 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001877
1878 # Some color thing that we want to escape
1879 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1880 handle = ansi_escape.sub( '', handle )
1881
kelvin9c3d4912015-01-15 17:36:47 -08001882>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab87852b02014-11-19 18:44:19 -05001883 if report:
andrewonlabb66dfa12014-12-02 15:51:10 -05001884 lat_result = []
kelvin8ec71442015-01-15 16:57:00 -08001885 main.log.info( handle )
1886 # Split result by newline
1887 newline = handle.split( "\r\r\n" )
1888 # Ignore the first object of list, which is empty
1889 newline = newline[ 1: ]
1890 # Some sloppy parsing method to get the latency
andrewonlabb66dfa12014-12-02 15:51:10 -05001891 for result in newline:
kelvin9c3d4912015-01-15 17:36:47 -08001892<<<<<<< HEAD
andrewonlabb66dfa12014-12-02 15:51:10 -05001893 result = result.split(": ")
1894 #Append the first result of second parse
1895 lat_result.append(result[1].split(" ")[0])
Jon Halle3f39ff2015-01-13 11:50:53 -08001896 main.log.info(lat_result)
kelvin9c3d4912015-01-15 17:36:47 -08001897=======
kelvin8ec71442015-01-15 16:57:00 -08001898 result = result.split( ": " )
1899 # Append the first result of second parse
1900 lat_result.append( result[ 1 ].split( " " )[ 0 ] )
andrewonlabb66dfa12014-12-02 15:51:10 -05001901
kelvin8ec71442015-01-15 16:57:00 -08001902 main.log.info( lat_result )
kelvin9c3d4912015-01-15 17:36:47 -08001903>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Halle3f39ff2015-01-13 11:50:53 -08001904 return lat_result
andrewonlab87852b02014-11-19 18:44:19 -05001905 else:
1906 return main.TRUE
andrewonlab87852b02014-11-19 18:44:19 -05001907 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001908 main.log.error( self.name + ": EOF exception found" )
1909 main.log.error( self.name + ": " + self.handle.before )
andrewonlab87852b02014-11-19 18:44:19 -05001910 main.cleanup()
1911 main.exit()
1912 except:
kelvin8ec71442015-01-15 16:57:00 -08001913 main.log.info( self.name + " ::::::" )
1914 main.log.error( traceback.print_exc() )
1915 main.log.info( self.name + " ::::::" )
andrewonlab87852b02014-11-19 18:44:19 -05001916 main.cleanup()
1917 main.exit()
1918
kelvin9c3d4912015-01-15 17:36:47 -08001919<<<<<<< HEAD
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001920 def intents_events_metrics(self, json_format=True):
1921 '''
kelvin9c3d4912015-01-15 17:36:47 -08001922=======
kelvin8ec71442015-01-15 16:57:00 -08001923 def intents_events_metrics( self, json_format=True ):
1924 """
kelvin9c3d4912015-01-15 17:36:47 -08001925>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Halle3f39ff2015-01-13 11:50:53 -08001926 Description:Returns topology metrics
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001927 Optional:
1928 * json_format: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08001929 """
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001930 try:
1931 if json_format:
kelvin9c3d4912015-01-15 17:36:47 -08001932<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08001933 cmd_str = "intents-events-metrics -j"
1934 handle = self.sendline( cmd_str )
1935 # Some color thing that we want to escape
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001936 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
1937 handle = ansi_escape.sub('', handle)
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001938 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001939 cmd_str = "intents-events-metrics"
1940 handle = self.sendline( cmd_str )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001941 return handle
kelvin9c3d4912015-01-15 17:36:47 -08001942=======
kelvin8ec71442015-01-15 16:57:00 -08001943 self.handle.sendline( "intents-events-metrics -j" )
1944 self.handle.expect( "intents-events-metrics -j" )
1945 self.handle.expect( "onos>" )
1946
Shreya Shah0f01c812014-10-26 20:15:28 -04001947 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001948
1949 # Some color thing that we want to escape
1950 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
1951 handle = ansi_escape.sub( '', handle )
1952
Shreya Shah0f01c812014-10-26 20:15:28 -04001953 else:
kelvin8ec71442015-01-15 16:57:00 -08001954 self.handle.sendline( "intents-events-metrics" )
1955 self.handle.expect( "intents-events-metrics" )
1956 self.handle.expect( "onos>" )
1957
Shreya Shah0f01c812014-10-26 20:15:28 -04001958 handle = self.handle.before
1959
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001960 return handle
kelvin8ec71442015-01-15 16:57:00 -08001961
kelvin9c3d4912015-01-15 17:36:47 -08001962>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001963 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001964 main.log.error( self.name + ": EOF exception found" )
1965 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001966 main.cleanup()
1967 main.exit()
1968 except:
kelvin8ec71442015-01-15 16:57:00 -08001969 main.log.info( self.name + " ::::::" )
1970 main.log.error( traceback.print_exc() )
1971 main.log.info( self.name + " ::::::" )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001972 main.cleanup()
1973 main.exit()
Shreya Shah0f01c812014-10-26 20:15:28 -04001974
kelvin8ec71442015-01-15 16:57:00 -08001975 def topology_events_metrics( self, json_format=True ):
1976 """
1977 Description:Returns topology metrics
andrewonlab867212a2014-10-22 20:13:38 -04001978 Optional:
1979 * json_format: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08001980 """
andrewonlab867212a2014-10-22 20:13:38 -04001981 try:
1982 if json_format:
kelvin9c3d4912015-01-15 17:36:47 -08001983<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08001984 cmd_str = "topology-events-metrics -j"
1985 handle = self.sendline( cmd_str )
andrewonlab867212a2014-10-22 20:13:38 -04001986 #Some color thing that we want to escape
1987 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
1988 handle = ansi_escape.sub('', handle)
andrewonlab867212a2014-10-22 20:13:38 -04001989 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001990 cmd_str = "topology-events-metrics"
1991 handle = self.sendline( cmd_str )
andrewonlab867212a2014-10-22 20:13:38 -04001992 return handle
kelvin9c3d4912015-01-15 17:36:47 -08001993=======
kelvin8ec71442015-01-15 16:57:00 -08001994 self.handle.sendline( "topology-events-metrics -j" )
1995 self.handle.expect( "topology-events-metrics -j" )
1996 self.handle.expect( "onos>" )
1997
andrewonlab867212a2014-10-22 20:13:38 -04001998 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001999
2000 # Some color thing that we want to escape
2001 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
2002 handle = ansi_escape.sub( '', handle )
2003
andrewonlab867212a2014-10-22 20:13:38 -04002004 else:
kelvin8ec71442015-01-15 16:57:00 -08002005 self.handle.sendline( "topology-events-metrics" )
2006 self.handle.expect( "topology-events-metrics" )
2007 self.handle.expect( "onos>" )
2008
andrewonlab867212a2014-10-22 20:13:38 -04002009 handle = self.handle.before
2010
2011 return handle
kelvin8ec71442015-01-15 16:57:00 -08002012
kelvin9c3d4912015-01-15 17:36:47 -08002013>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab867212a2014-10-22 20:13:38 -04002014 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002015 main.log.error( self.name + ": EOF exception found" )
2016 main.log.error( self.name + ": " + self.handle.before )
andrewonlab867212a2014-10-22 20:13:38 -04002017 main.cleanup()
2018 main.exit()
2019 except:
kelvin8ec71442015-01-15 16:57:00 -08002020 main.log.info( self.name + " ::::::" )
2021 main.log.error( traceback.print_exc() )
2022 main.log.info( self.name + " ::::::" )
andrewonlab867212a2014-10-22 20:13:38 -04002023 main.cleanup()
2024 main.exit()
2025
kelvin8ec71442015-01-15 16:57:00 -08002026 # Wrapper functions ****************
2027 # Wrapper functions use existing driver
2028 # functions and extends their use case.
2029 # For example, we may use the output of
2030 # a normal driver function, and parse it
2031 # using a wrapper function
andrewonlabc2d05aa2014-10-13 16:51:10 -04002032
kelvin8ec71442015-01-15 16:57:00 -08002033 def get_all_intents_id( self ):
2034 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04002035 Description:
2036 Obtain all intent id's in a list
kelvin8ec71442015-01-15 16:57:00 -08002037 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04002038 try:
kelvin8ec71442015-01-15 16:57:00 -08002039 # Obtain output of intents function
andrewonlab9a50dfe2014-10-17 17:22:31 -04002040 intents_str = self.intents()
2041 all_intent_list = []
2042 intent_id_list = []
2043
kelvin8ec71442015-01-15 16:57:00 -08002044 # Parse the intents output for ID's
2045 intents_list = [ s.strip() for s in intents_str.splitlines() ]
andrewonlab9a50dfe2014-10-17 17:22:31 -04002046 for intents in intents_list:
2047 if "onos>" in intents:
2048 continue
2049 elif "intents" in intents:
2050 continue
2051 else:
kelvin8ec71442015-01-15 16:57:00 -08002052 line_list = intents.split( " " )
2053 all_intent_list.append( line_list[ 0 ] )
2054
2055 all_intent_list = all_intent_list[ 1:-2 ]
andrewonlab9a50dfe2014-10-17 17:22:31 -04002056
2057 for intents in all_intent_list:
2058 if not intents:
2059 continue
2060 else:
kelvin8ec71442015-01-15 16:57:00 -08002061 intent_id_list.append( intents )
andrewonlab9a50dfe2014-10-17 17:22:31 -04002062
2063 return intent_id_list
2064
2065 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002066 main.log.error( self.name + ": EOF exception found" )
2067 main.log.error( self.name + ": " + self.handle.before )
andrewonlab9a50dfe2014-10-17 17:22:31 -04002068 main.cleanup()
2069 main.exit()
2070 except:
kelvin8ec71442015-01-15 16:57:00 -08002071 main.log.info( self.name + " ::::::" )
2072 main.log.error( traceback.print_exc() )
2073 main.log.info( self.name + " ::::::" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04002074 main.cleanup()
2075 main.exit()
2076
kelvin8ec71442015-01-15 16:57:00 -08002077 def get_all_devices_id( self ):
2078 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04002079 Use 'devices' function to obtain list of all devices
2080 and parse the result to obtain a list of all device
2081 id's. Returns this list. Returns empty list if no
2082 devices exist
kelvin8ec71442015-01-15 16:57:00 -08002083 List is ordered sequentially
2084
andrewonlab3e15ead2014-10-15 14:21:34 -04002085 This function may be useful if you are not sure of the
kelvin8ec71442015-01-15 16:57:00 -08002086 device id, and wish to execute other commands using
andrewonlab3e15ead2014-10-15 14:21:34 -04002087 the ids. By obtaining the list of device ids on the fly,
2088 you can iterate through the list to get mastership, etc.
kelvin8ec71442015-01-15 16:57:00 -08002089 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04002090 try:
kelvin8ec71442015-01-15 16:57:00 -08002091 # Call devices and store result string
2092 devices_str = self.devices( json_format=False )
andrewonlab7e4d2d32014-10-15 13:23:21 -04002093 id_list = []
kelvin8ec71442015-01-15 16:57:00 -08002094
andrewonlab7e4d2d32014-10-15 13:23:21 -04002095 if not devices_str:
kelvin8ec71442015-01-15 16:57:00 -08002096 main.log.info( "There are no devices to get id from" )
andrewonlab7e4d2d32014-10-15 13:23:21 -04002097 return id_list
kelvin8ec71442015-01-15 16:57:00 -08002098
2099 # Split the string into list by comma
2100 device_list = devices_str.split( "," )
2101 # Get temporary list of all arguments with string 'id='
2102 temp_list = [ dev for dev in device_list if "id=" in dev ]
2103 # Split list further into arguments before and after string
2104 # 'id='. Get the latter portion ( the actual device id ) and
andrewonlab7e4d2d32014-10-15 13:23:21 -04002105 # append to id_list
2106 for arg in temp_list:
kelvin8ec71442015-01-15 16:57:00 -08002107 id_list.append( arg.split( "id=" )[ 1 ] )
andrewonlab7e4d2d32014-10-15 13:23:21 -04002108 return id_list
2109
2110 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002111 main.log.error( self.name + ": EOF exception found" )
2112 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7e4d2d32014-10-15 13:23:21 -04002113 main.cleanup()
2114 main.exit()
2115 except:
kelvin8ec71442015-01-15 16:57:00 -08002116 main.log.info( self.name + " ::::::" )
2117 main.log.error( traceback.print_exc() )
2118 main.log.info( self.name + " ::::::" )
andrewonlab7e4d2d32014-10-15 13:23:21 -04002119 main.cleanup()
2120 main.exit()
2121
kelvin8ec71442015-01-15 16:57:00 -08002122 def get_all_nodes_id( self ):
2123 """
andrewonlab7c211572014-10-15 16:45:20 -04002124 Uses 'nodes' function to obtain list of all nodes
2125 and parse the result of nodes to obtain just the
kelvin8ec71442015-01-15 16:57:00 -08002126 node id's.
andrewonlab7c211572014-10-15 16:45:20 -04002127 Returns:
2128 list of node id's
kelvin8ec71442015-01-15 16:57:00 -08002129 """
andrewonlab7c211572014-10-15 16:45:20 -04002130 try:
2131 nodes_str = self.nodes()
2132 id_list = []
2133
2134 if not nodes_str:
kelvin8ec71442015-01-15 16:57:00 -08002135 main.log.info( "There are no nodes to get id from" )
andrewonlab7c211572014-10-15 16:45:20 -04002136 return id_list
2137
kelvin8ec71442015-01-15 16:57:00 -08002138 # Sample nodes_str output
2139 # id=local, address=127.0.0.1:9876, state=ACTIVE *
andrewonlab7c211572014-10-15 16:45:20 -04002140
kelvin8ec71442015-01-15 16:57:00 -08002141 # Split the string into list by comma
2142 nodes_list = nodes_str.split( "," )
2143 temp_list = [ node for node in nodes_list if "id=" in node ]
andrewonlab7c211572014-10-15 16:45:20 -04002144 for arg in temp_list:
kelvin8ec71442015-01-15 16:57:00 -08002145 id_list.append( arg.split( "id=" )[ 1 ] )
andrewonlab7c211572014-10-15 16:45:20 -04002146
2147 return id_list
kelvin8ec71442015-01-15 16:57:00 -08002148
andrewonlab7c211572014-10-15 16:45:20 -04002149 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002150 main.log.error( self.name + ": EOF exception found" )
2151 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -04002152 main.cleanup()
2153 main.exit()
2154 except:
kelvin8ec71442015-01-15 16:57:00 -08002155 main.log.info( self.name + " ::::::" )
2156 main.log.error( traceback.print_exc() )
2157 main.log.info( self.name + " ::::::" )
andrewonlab7c211572014-10-15 16:45:20 -04002158 main.cleanup()
2159 main.exit()
andrewonlab7e4d2d32014-10-15 13:23:21 -04002160
kelvin8ec71442015-01-15 16:57:00 -08002161 def get_device( self, dpid=None ):
2162 """
Jon Halla91c4dc2014-10-22 12:57:04 -04002163 Return the first device from the devices api whose 'id' contains 'dpid'
2164 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -08002165 """
Jon Halla91c4dc2014-10-22 12:57:04 -04002166 import json
2167 try:
kelvin8ec71442015-01-15 16:57:00 -08002168 if dpid is None:
Jon Halla91c4dc2014-10-22 12:57:04 -04002169 return None
2170 else:
kelvin8ec71442015-01-15 16:57:00 -08002171 dpid = dpid.replace( ':', '' )
Jon Halla91c4dc2014-10-22 12:57:04 -04002172 raw_devices = self.devices()
kelvin8ec71442015-01-15 16:57:00 -08002173 devices_json = json.loads( raw_devices )
2174 # search json for the device with dpid then return the device
Jon Halla91c4dc2014-10-22 12:57:04 -04002175 for device in devices_json:
kelvin8ec71442015-01-15 16:57:00 -08002176 # print "%s in %s?" % ( dpid, device[ 'id' ] )
2177 if dpid in device[ 'id' ]:
Jon Halla91c4dc2014-10-22 12:57:04 -04002178 return device
2179 return None
2180 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002181 main.log.error( self.name + ": EOF exception found" )
2182 main.log.error( self.name + ": " + self.handle.before )
Jon Halla91c4dc2014-10-22 12:57:04 -04002183 main.cleanup()
2184 main.exit()
2185 except:
kelvin8ec71442015-01-15 16:57:00 -08002186 main.log.info( self.name + " ::::::" )
2187 main.log.error( traceback.print_exc() )
2188 main.log.info( self.name + " ::::::" )
Jon Halla91c4dc2014-10-22 12:57:04 -04002189 main.cleanup()
2190 main.exit()
2191
kelvin8ec71442015-01-15 16:57:00 -08002192 def check_status( self, ip, numoswitch, numolink, log_level="info" ):
2193 """
2194 Checks the number of swithes & links that ONOS sees against the
2195 supplied values. By default this will report to main.log, but the
Jon Hall42db6dc2014-10-24 19:03:48 -04002196 log level can be specifid.
kelvin8ec71442015-01-15 16:57:00 -08002197
Jon Hall42db6dc2014-10-24 19:03:48 -04002198 Params: ip = ip used for the onos cli
2199 numoswitch = expected number of switches
2200 numlink = expected number of links
2201 log_level = level to log to. Currently accepts 'info', 'warn' and 'report'
2202
2203
2204 log_level can
2205
kelvin8ec71442015-01-15 16:57:00 -08002206 Returns: main.TRUE if the number of switchs and links are correct,
Jon Hall42db6dc2014-10-24 19:03:48 -04002207 main.FALSE if the numer of switches and links is incorrect,
2208 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08002209 """
Jon Hall42db6dc2014-10-24 19:03:48 -04002210 try:
kelvin8ec71442015-01-15 16:57:00 -08002211 topology = self.get_topology( ip )
Jon Hall42db6dc2014-10-24 19:03:48 -04002212 if topology == {}:
2213 return main.ERROR
2214 output = ""
kelvin8ec71442015-01-15 16:57:00 -08002215 # Is the number of switches is what we expected
2216 devices = topology.get( 'devices', False )
2217 links = topology.get( 'links', False )
Jon Hall42db6dc2014-10-24 19:03:48 -04002218 if devices == False or links == False:
2219 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -08002220 switch_check = ( int( devices ) == int( numoswitch ) )
2221 # Is the number of links is what we expected
2222 link_check = ( int( links ) == int( numolink ) )
2223 if ( switch_check and link_check ):
2224 # We expected the correct numbers
Jon Hall42db6dc2014-10-24 19:03:48 -04002225 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08002226 + "what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04002227 result = main.TRUE
2228 else:
2229 output = output + \
kelvin8ec71442015-01-15 16:57:00 -08002230 "The number of links and switches does not match what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04002231 result = main.FALSE
2232 output = output + "\n ONOS sees %i devices (%i expected) and %i links (%i expected)"\
kelvin8ec71442015-01-15 16:57:00 -08002233 % ( int( devices ), int( numoswitch ), int( links ), int( numolink ) )
Jon Hall42db6dc2014-10-24 19:03:48 -04002234 if log_level == "report":
kelvin8ec71442015-01-15 16:57:00 -08002235 main.log.report( output )
Jon Hall42db6dc2014-10-24 19:03:48 -04002236 elif log_level == "warn":
kelvin8ec71442015-01-15 16:57:00 -08002237 main.log.warn( output )
Jon Hall42db6dc2014-10-24 19:03:48 -04002238 else:
kelvin8ec71442015-01-15 16:57:00 -08002239 main.log.info( output )
2240 return result
Jon Hall42db6dc2014-10-24 19:03:48 -04002241 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002242 main.log.error( self.name + ": EOF exception found" )
2243 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -04002244 main.cleanup()
2245 main.exit()
2246 except:
kelvin8ec71442015-01-15 16:57:00 -08002247 main.log.info( self.name + " ::::::" )
2248 main.log.error( traceback.print_exc() )
2249 main.log.info( self.name + " ::::::" )
Jon Hall42db6dc2014-10-24 19:03:48 -04002250 main.cleanup()
2251 main.exit()
Jon Hall1c9e8732014-10-27 19:29:27 -04002252
kelvin8ec71442015-01-15 16:57:00 -08002253 def device_role( self, device_id, onos_node, role="master" ):
2254 """
Jon Hall1c9e8732014-10-27 19:29:27 -04002255 Calls the device-role cli command.
2256 device_id must be the id of a device as seen in the onos devices command
2257 onos_node is the ip of one of the onos nodes in the cluster
2258 role must be either master, standby, or none
2259
kelvin9c3d4912015-01-15 17:36:47 -08002260<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08002261 Returns:
2262 main.TRUE or main.FALSE based on argument verification and
2263 main.ERROR if command returns and error
Jon Hall1c9e8732014-10-27 19:29:27 -04002264 '''
Jon Hall1c9e8732014-10-27 19:29:27 -04002265 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08002266 if role.lower() == "master" or role.lower() == "standby" or\
Jon Hall1c9e8732014-10-27 19:29:27 -04002267 role.lower() == "none":
Jon Halle3f39ff2015-01-13 11:50:53 -08002268 cmd_str = "device-role " +\
2269 str(device_id) + " " +\
2270 str(onos_node) + " " +\
2271 str(role)
2272 handle = self.sendline( cmd_str )
2273 if re.search( "Error", handle ):
2274 # end color output to escape any colours
2275 # from the cli
2276 main.log.error( self.name + ": " +\
2277 handle + '\033[0m' )
Jon Hall983a1702014-10-28 18:44:22 -04002278 return main.ERROR
Jon Hall1c9e8732014-10-27 19:29:27 -04002279 return main.TRUE
kelvin9c3d4912015-01-15 17:36:47 -08002280=======
andrewonlab95ce8322014-10-13 14:12:04 -04002281 Returns main.TRUE or main.FALSE based on argument verification.
2282 When device-role supports errors this should be extended to
2283 support that output
kelvin8ec71442015-01-15 16:57:00 -08002284 """
andrewonlab95ce8322014-10-13 14:12:04 -04002285 try:
kelvin8ec71442015-01-15 16:57:00 -08002286 # print "beginning device_role... \n\tdevice_id:" + device_id
2287 # print "\tonos_node: " + onos_node
2288 # print "\trole: "+ role
andrewonlab95ce8322014-10-13 14:12:04 -04002289 if role.lower() == "master" or \
2290 role.lower() == "standby" or \
2291 role.lower() == "none":
kelvin8ec71442015-01-15 16:57:00 -08002292 self.handle.sendline( "" )
2293 self.handle.expect( "onos>" )
2294 self.handle.sendline( "device-role " +
2295 str( device_id ) + " " +
2296 str( onos_node ) + " " +
2297 str( role ) )
2298 i = self.handle.expect( [ "Error", "onos>" ] )
2299 if i == 0:
2300 output = str( self.handle.before )
2301 self.handle.expect( "onos>" )
2302 output = output + str( self.handle.before )
2303 main.log.error( self.name + ": " +
2304 output + '\033[0m' ) # end color output to escape any colours from the cli
2305 return main.ERROR
2306 self.handle.sendline( "" )
2307 self.handle.expect( "onos>" )
2308 return main.TRUE
kelvin9c3d4912015-01-15 17:36:47 -08002309>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab95ce8322014-10-13 14:12:04 -04002310 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002311 main.log.error("Invalid 'role' given to device_role(). " +
2312 "Value was '" + str( role ) + "'.")
andrewonlab95ce8322014-10-13 14:12:04 -04002313 return main.FALSE
andrewonlab95ce8322014-10-13 14:12:04 -04002314 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002315 main.log.error( self.name + ": EOF exception found" )
2316 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -04002317 main.cleanup()
2318 main.exit()
2319 except:
kelvin8ec71442015-01-15 16:57:00 -08002320 main.log.info( self.name + " ::::::" )
2321 main.log.error( traceback.print_exc() )
2322 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -04002323 main.cleanup()
2324 main.exit()
2325
kelvin8ec71442015-01-15 16:57:00 -08002326 def clusters( self, json_format=True ):
2327 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08002328 Lists all clusters
Jon Hallffb386d2014-11-21 13:43:38 -08002329 Optional argument:
2330 * json_format - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -08002331 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08002332 try:
kelvin9c3d4912015-01-15 17:36:47 -08002333<<<<<<< HEAD
Jon Hall73cf9cc2014-11-20 22:28:38 -08002334 if json_format:
Jon Halle3f39ff2015-01-13 11:50:53 -08002335 cmd_str = "clusters -j"
2336 handle = self.sendline( cmd_str )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002337 '''
2338 handle variable here contains some ANSI escape color code
2339 sequences at the end which are invisible in the print command
Jon Halle3f39ff2015-01-13 11:50:53 -08002340 output. To make that escape sequence visible, use repr()
2341 function. The repr(handle) output when printed shows the ANSI
2342 escape sequences. In json.loads(somestring), this somestring
2343 variable is actually repr(somestring) and json.loads would fail
2344 with the escape sequence. So we take off that escape sequence
2345 using:
2346
Jon Hall73cf9cc2014-11-20 22:28:38 -08002347 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
2348 handle1 = ansi_escape.sub('', handle)
2349 '''
Jon Hall73cf9cc2014-11-20 22:28:38 -08002350 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
2351 handle1 = ansi_escape.sub('', handle)
Jon Hall73cf9cc2014-11-20 22:28:38 -08002352 return handle1
2353 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002354 cmd_str = "clusters"
2355 handle = self.sendline( cmd_str )
kelvin9c3d4912015-01-15 17:36:47 -08002356=======
kelvin8ec71442015-01-15 16:57:00 -08002357 self.handle.sendline( "" )
2358 self.handle.expect( "onos>" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002359
2360 if json_format:
kelvin8ec71442015-01-15 16:57:00 -08002361 self.handle.sendline( "clusters -j" )
2362 self.handle.expect( "clusters -j" )
2363 self.handle.expect( "onos>" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002364 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08002365 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08002366 handle variable here contains some ANSI escape color code
2367 sequences at the end which are invisible in the print command
2368 output. To make that escape sequence visible, use repr() function.
kelvin8ec71442015-01-15 16:57:00 -08002369 The repr( handle ) output when printed shows the ANSI escape sequences.
2370 In json.loads( somestring ), this somestring variable is actually
2371 repr( somestring ) and json.loads would fail with the escape sequence.
Jon Hall73cf9cc2014-11-20 22:28:38 -08002372 So we take off that escape sequence using
kelvin8ec71442015-01-15 16:57:00 -08002373 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
2374 handle1 = ansi_escape.sub( '', handle )
2375 """
2376 # print "repr(handle) =", repr( handle )
2377 ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' )
2378 handle1 = ansi_escape.sub( '', handle )
2379 # print "repr(handle1) = ", repr( handle1 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002380 return handle1
2381 else:
kelvin8ec71442015-01-15 16:57:00 -08002382 self.handle.sendline( "clusters" )
2383 self.handle.expect( "onos>" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002384 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08002385 # print "handle =",handle
kelvin9c3d4912015-01-15 17:36:47 -08002386>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Hall73cf9cc2014-11-20 22:28:38 -08002387 return handle
2388 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002389 main.log.error( self.name + ": EOF exception found" )
2390 main.log.error( self.name + ": " + self.handle.before )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002391 main.cleanup()
2392 main.exit()
2393 except:
kelvin8ec71442015-01-15 16:57:00 -08002394 main.log.info( self.name + " ::::::" )
2395 main.log.error( traceback.print_exc() )
2396 main.log.info( self.name + " ::::::" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002397 main.cleanup()
2398 main.exit()
2399
kelvin9c3d4912015-01-15 17:36:47 -08002400<<<<<<< HEAD
Jon Hall94fd0472014-12-08 11:52:42 -08002401 def election_test_leader(self):
2402 '''
Jon Halle3f39ff2015-01-13 11:50:53 -08002403 CLI command to get the current leader for the Election test application
2404 NOTE: Requires installation of the onos-app-election feature
2405 Returns: Node IP of the leader if one exists
2406 None if none exists
2407 Main.FALSE on error
Jon Hall94fd0472014-12-08 11:52:42 -08002408 '''
2409 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08002410 cmd_str = "election-test-leader"
2411 response = self.sendline( cmd_str )
2412 # Leader
2413 leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\
2414 "app\sis\s(?P<node>.+)\."
2415 node_search = re.search(leaderPattern, response)
Jon Hall94fd0472014-12-08 11:52:42 -08002416 if node_search:
2417 node = node_search.group('node')
Jon Halle3f39ff2015-01-13 11:50:53 -08002418 main.log.info( "Election-test-leader on " + str( self.name ) +
2419 " found " + node + " as the leader" )
Jon Hall94fd0472014-12-08 11:52:42 -08002420 return node
Jon Halle3f39ff2015-01-13 11:50:53 -08002421 # no leader
2422 nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\
2423 "the\sElection\sapp"
2424 null_search = re.search(nullPattern, response)
Jon Hall94fd0472014-12-08 11:52:42 -08002425 if null_search:
Jon Halle3f39ff2015-01-13 11:50:53 -08002426 main.log.info( "Election-test-leader found no leader on " +
2427 self.name )
Jon Hall94fd0472014-12-08 11:52:42 -08002428 return None
2429 #error
Jon Halle3f39ff2015-01-13 11:50:53 -08002430 errorPattern = "Command\snot\sfound"
2431 if re.search(errorPattern, response):
Jon Hall669173b2014-12-17 11:36:30 -08002432 main.log.error("Election app is not loaded on " + self.name)
Jon Halle3f39ff2015-01-13 11:50:53 -08002433 # TODO: Should this be main.ERROR?
Jon Hall669173b2014-12-17 11:36:30 -08002434 return main.FALSE
2435 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002436 main.log.error("Error in election_test_leader: " +
2437 "unexpected response")
Jon Hall669173b2014-12-17 11:36:30 -08002438 main.log.error( repr(response) )
kelvin9c3d4912015-01-15 17:36:47 -08002439=======
kelvin8ec71442015-01-15 16:57:00 -08002440 def election_test_leader( self ):
2441 """
Jon Hall94fd0472014-12-08 11:52:42 -08002442 * CLI command to get the current leader for the Election test application.
2443 #NOTE: Requires installation of the onos-app-election feature
2444 Returns: Node IP of the leader if one exists
2445 None if none exists
2446 Main.FALSE on error
kelvin8ec71442015-01-15 16:57:00 -08002447 """
Jon Hall94fd0472014-12-08 11:52:42 -08002448 try:
kelvin8ec71442015-01-15 16:57:00 -08002449 self.handle.sendline( "election-test-leader" )
2450 self.handle.expect( "election-test-leader" )
2451 self.handle.expect( "onos>" )
Jon Hall94fd0472014-12-08 11:52:42 -08002452 response = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08002453 # Leader
2454 node_search = re.search(
2455 "The\scurrent\sleader\sfor\sthe\sElection\sapp\sis\s(?P<node>.+)\.",
2456 response )
Jon Hall94fd0472014-12-08 11:52:42 -08002457 if node_search:
kelvin8ec71442015-01-15 16:57:00 -08002458 node = node_search.group( 'node' )
2459 main.log.info( "Election-test-leader on " + str(
2460 self.name ) + " found " + node + " as the leader" )
Jon Hall94fd0472014-12-08 11:52:42 -08002461 return node
kelvin8ec71442015-01-15 16:57:00 -08002462 # no leader
2463 null_search = re.search(
2464 "There\sis\scurrently\sno\sleader\selected\sfor\sthe\sElection\sapp",
2465 response )
Jon Hall94fd0472014-12-08 11:52:42 -08002466 if null_search:
kelvin8ec71442015-01-15 16:57:00 -08002467 main.log.info(
2468 "Election-test-leader found no leader on " +
2469 self.name )
Jon Hall94fd0472014-12-08 11:52:42 -08002470 return None
kelvin8ec71442015-01-15 16:57:00 -08002471 # error
2472 if re.search( "Command\snot\sfound", response ):
2473 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08002474 return main.FALSE
2475 else:
kelvin8ec71442015-01-15 16:57:00 -08002476 main.log.error(
2477 "Error in election_test_leader: unexpected response" )
2478 main.log.error( repr( response ) )
kelvin9c3d4912015-01-15 17:36:47 -08002479>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Hall669173b2014-12-17 11:36:30 -08002480 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08002481 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002482 main.log.error( self.name + ": EOF exception found" )
2483 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08002484 main.cleanup()
2485 main.exit()
2486 except:
kelvin8ec71442015-01-15 16:57:00 -08002487 main.log.info( self.name + " ::::::" )
2488 main.log.error( traceback.print_exc() )
2489 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08002490 main.cleanup()
2491 main.exit()
2492
kelvin9c3d4912015-01-15 17:36:47 -08002493<<<<<<< HEAD
Jon Hall94fd0472014-12-08 11:52:42 -08002494 def election_test_run(self):
2495 '''
Jon Halle3f39ff2015-01-13 11:50:53 -08002496 CLI command to run for leadership of the Election test application.
2497 NOTE: Requires installation of the onos-app-election feature
2498 Returns: Main.TRUE on success
2499 Main.FALSE on error
Jon Hall94fd0472014-12-08 11:52:42 -08002500 '''
2501 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08002502 cmd_str = "election-test-run"
2503 response = self.sendline( cmd_str )
Jon Hall94fd0472014-12-08 11:52:42 -08002504 #success
Jon Halle3f39ff2015-01-13 11:50:53 -08002505 successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\
2506 "Election\sapp."
2507 search = re.search( successPattern, response )
Jon Hall94fd0472014-12-08 11:52:42 -08002508 if search:
Jon Halle3f39ff2015-01-13 11:50:53 -08002509 main.log.info( self.name + " entering leadership elections " +
2510 "for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08002511 return main.TRUE
2512 #error
Jon Halle3f39ff2015-01-13 11:50:53 -08002513 errorPattern = "Command\snot\sfound"
2514 if re.search( errorPattern, response ):
2515 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08002516 return main.FALSE
2517 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002518 main.log.error( "Error in election_test_run: " +
2519 "unexpected response" )
kelvin9c3d4912015-01-15 17:36:47 -08002520=======
kelvin8ec71442015-01-15 16:57:00 -08002521 def election_test_run( self ):
2522 """
Jon Hall94fd0472014-12-08 11:52:42 -08002523 * CLI command to run for leadership of the Election test application.
2524 #NOTE: Requires installation of the onos-app-election feature
2525 Returns: Main.TRUE on success
2526 Main.FALSE on error
kelvin8ec71442015-01-15 16:57:00 -08002527 """
Jon Hall94fd0472014-12-08 11:52:42 -08002528 try:
kelvin8ec71442015-01-15 16:57:00 -08002529 self.handle.sendline( "election-test-run" )
2530 self.handle.expect( "election-test-run" )
2531 self.handle.expect( "onos>" )
Jon Hall94fd0472014-12-08 11:52:42 -08002532 response = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08002533 # success
2534 search = re.search(
2535 "Entering\sleadership\selections\sfor\sthe\sElection\sapp.",
2536 response )
Jon Hall94fd0472014-12-08 11:52:42 -08002537 if search:
kelvin8ec71442015-01-15 16:57:00 -08002538 main.log.info(
2539 self.name +
2540 " entering leadership elections for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08002541 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08002542 # error
2543 if re.search( "Command\snot\sfound", response ):
2544 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08002545 return main.FALSE
2546 else:
kelvin8ec71442015-01-15 16:57:00 -08002547 main.log.error(
2548 "Error in election_test_run: unexpected response" )
kelvin9c3d4912015-01-15 17:36:47 -08002549>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Jon Halle3f39ff2015-01-13 11:50:53 -08002550 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08002551 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08002552 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002553 main.log.error( self.name + ": EOF exception found" )
2554 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08002555 main.cleanup()
2556 main.exit()
2557 except:
kelvin8ec71442015-01-15 16:57:00 -08002558 main.log.info( self.name + " ::::::" )
2559 main.log.error( traceback.print_exc() )
2560 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08002561 main.cleanup()
2562 main.exit()
2563
kelvin8ec71442015-01-15 16:57:00 -08002564 def election_test_withdraw( self ):
2565 """
Jon Hall94fd0472014-12-08 11:52:42 -08002566 * CLI command to withdraw the local node from leadership election for
2567 * the Election test application.
2568 #NOTE: Requires installation of the onos-app-election feature
2569 Returns: Main.TRUE on success
2570 Main.FALSE on error
kelvin8ec71442015-01-15 16:57:00 -08002571 """
Jon Hall94fd0472014-12-08 11:52:42 -08002572 try:
kelvin9c3d4912015-01-15 17:36:47 -08002573<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08002574 cmd_str = "election-test-withdraw"
2575 response = self.sendline( cmd_str )
Jon Hall94fd0472014-12-08 11:52:42 -08002576 #success
Jon Halle3f39ff2015-01-13 11:50:53 -08002577 successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\
2578 "\sthe\sElection\sapp."
2579 if re.search( successPattern, response ):
2580 main.log.info( self.name + " withdrawing from leadership " +
2581 "elections for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08002582 return main.TRUE
2583 #error
Jon Halle3f39ff2015-01-13 11:50:53 -08002584 errorPattern = "Command\snot\sfound"
2585 if re.search( errorPattern, response ):
2586 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08002587 return main.FALSE
2588 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002589 main.log.error( "Error in election_test_withdraw: " +
2590 "unexpected response" )
2591 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08002592 return main.FALSE
kelvin9c3d4912015-01-15 17:36:47 -08002593=======
kelvin8ec71442015-01-15 16:57:00 -08002594 self.handle.sendline( "election-test-withdraw" )
2595 self.handle.expect( "election-test-withdraw" )
2596 self.handle.expect( "onos>" )
Jon Hall94fd0472014-12-08 11:52:42 -08002597 response = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08002598 # success
2599 search = re.search(
2600 "Withdrawing\sfrom\sleadership\selections\sfor\sthe\sElection\sapp.",
2601 response )
Jon Hall94fd0472014-12-08 11:52:42 -08002602 if search:
kelvin8ec71442015-01-15 16:57:00 -08002603 main.log.info(
2604 self.name +
2605 " withdrawing from leadership elections for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08002606 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08002607 # error
2608 if re.search( "Command\snot\sfound", response ):
2609 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall94fd0472014-12-08 11:52:42 -08002610 return main.FALSE
2611 else:
kelvin8ec71442015-01-15 16:57:00 -08002612 main.log.error(
2613 "Error in election_test_withdraw: unexpected response" )
2614 main.log.error( repr( response ) )
Jon Hall94fd0472014-12-08 11:52:42 -08002615 return main.FALSE
2616
kelvin9c3d4912015-01-15 17:36:47 -08002617>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
andrewonlab95ce8322014-10-13 14:12:04 -04002618 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002619 main.log.error( self.name + ": EOF exception found" )
2620 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -04002621 main.cleanup()
2622 main.exit()
2623 except:
kelvin8ec71442015-01-15 16:57:00 -08002624 main.log.info( self.name + " ::::::" )
2625 main.log.error( traceback.print_exc() )
2626 main.log.info( self.name + " ::::::" )
andrewonlab95ce8322014-10-13 14:12:04 -04002627 main.cleanup()
2628 main.exit()
andrewonlab95ce8322014-10-13 14:12:04 -04002629
2630 #***********************************
kelvin8ec71442015-01-15 16:57:00 -08002631 def getDevicePortsEnabledCount( self, dpid ):
2632 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002633 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08002634 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002635 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08002636 dpid = str( dpid )
kelvin9c3d4912015-01-15 17:36:47 -08002637<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08002638 cmd_str = "onos:ports -e " + dpid + " | wc -l"
2639 output = self.sendline( cmd_str )
2640 if re.search( "No such device", output ):
2641 main.log.error( "Error in getting ports" )
2642 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002643 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002644 return output
kelvin9c3d4912015-01-15 17:36:47 -08002645=======
kelvin8ec71442015-01-15 16:57:00 -08002646 self.handle.sendline( "" )
2647 self.handle.expect( "onos>" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002648
kelvin8ec71442015-01-15 16:57:00 -08002649 self.handle.sendline( "onos:ports -e " + dpid + " | wc -l" )
2650 i = self.handle.expect( [
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002651 "No such device",
kelvin8ec71442015-01-15 16:57:00 -08002652 "onos>" ] )
2653
2654 # self.handle.sendline( "" )
2655 # self.handle.expect( "onos>" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002656
2657 output = self.handle.before
2658
2659 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08002660 main.log.error( "Error in getting ports" )
2661 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002662 else:
2663 result = output
2664 return result
kelvin8ec71442015-01-15 16:57:00 -08002665
kelvin9c3d4912015-01-15 17:36:47 -08002666>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002667 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002668 main.log.error( self.name + ": EOF exception found" )
2669 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002670 main.cleanup()
2671 main.exit()
2672 except:
kelvin8ec71442015-01-15 16:57:00 -08002673 main.log.info( self.name + " ::::::" )
2674 main.log.error( traceback.print_exc() )
2675 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002676 main.cleanup()
2677 main.exit()
2678
kelvin8ec71442015-01-15 16:57:00 -08002679 def getDeviceLinksActiveCount( self, dpid ):
2680 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002681 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08002682 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002683 try:
kelvin9c3d4912015-01-15 17:36:47 -08002684<<<<<<< HEAD
Hari Krishna2bbaa702014-12-19 14:46:12 -08002685 dpid = str(dpid)
Jon Halle3f39ff2015-01-13 11:50:53 -08002686 cmd_str = "onos:links " + dpid + " | grep ACTIVE | wc -l"
2687 output = self.sendline( cmd_str )
2688 if re.search( "No such device", output ):
2689 main.log.error( "Error in getting ports ")
2690 return ( output, "Error ")
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002691 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002692 return output
kelvin9c3d4912015-01-15 17:36:47 -08002693=======
kelvin8ec71442015-01-15 16:57:00 -08002694 dpid = str( dpid )
2695 self.handle.sendline( "" )
2696 self.handle.expect( "onos>" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002697
kelvin8ec71442015-01-15 16:57:00 -08002698 self.handle.sendline(
2699 "onos:links " +
2700 dpid +
2701 " | grep ACTIVE | wc -l" )
2702 i = self.handle.expect( [
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002703 "No such device",
kelvin8ec71442015-01-15 16:57:00 -08002704 "onos>" ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002705
2706 output = self.handle.before
2707
2708 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08002709 main.log.error( "Error in getting ports" )
2710 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002711 else:
2712 result = output
2713 return result
kelvin8ec71442015-01-15 16:57:00 -08002714
kelvin9c3d4912015-01-15 17:36:47 -08002715>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002716 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002717 main.log.error( self.name + ": EOF exception found" )
2718 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002719 main.cleanup()
2720 main.exit()
2721 except:
kelvin8ec71442015-01-15 16:57:00 -08002722 main.log.info( self.name + " ::::::" )
2723 main.log.error( traceback.print_exc() )
2724 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002725 main.cleanup()
2726 main.exit()
2727
kelvin8ec71442015-01-15 16:57:00 -08002728 def getAllIntentIds( self ):
2729 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002730 Return a list of all Intent IDs
kelvin8ec71442015-01-15 16:57:00 -08002731 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002732 try:
kelvin9c3d4912015-01-15 17:36:47 -08002733<<<<<<< HEAD
Jon Halle3f39ff2015-01-13 11:50:53 -08002734 cmd_str = "onos:intents | grep id="
2735 output = self.sendline( cmd_str )
2736 if re.search( "Error", output ):
2737 main.log.error( "Error in getting ports" )
2738 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002739 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002740 return output
kelvin9c3d4912015-01-15 17:36:47 -08002741=======
kelvin8ec71442015-01-15 16:57:00 -08002742 self.handle.sendline( "" )
2743 self.handle.expect( "onos>" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002744
kelvin8ec71442015-01-15 16:57:00 -08002745 self.handle.sendline( "onos:intents | grep id=" )
2746 i = self.handle.expect( [
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002747 "Error",
kelvin8ec71442015-01-15 16:57:00 -08002748 "onos>" ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002749
2750 output = self.handle.before
2751
2752 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08002753 main.log.error( "Error in getting ports" )
2754 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002755 else:
2756 result = output
2757 return result
kelvin8ec71442015-01-15 16:57:00 -08002758
kelvin9c3d4912015-01-15 17:36:47 -08002759>>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002760 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002761 main.log.error( self.name + ": EOF exception found" )
2762 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002763 main.cleanup()
2764 main.exit()
2765 except:
kelvin8ec71442015-01-15 16:57:00 -08002766 main.log.info( self.name + " ::::::" )
2767 main.log.error( traceback.print_exc() )
2768 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002769 main.cleanup()
2770 main.exit()
kelvin8ec71442015-01-15 16:57:00 -08002771