andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | ''' |
| 4 | This driver enters the onos> prompt to issue commands. |
| 5 | |
| 6 | Please follow the coding style demonstrated by existing |
| 7 | functions and document properly. |
| 8 | |
| 9 | If you are a contributor to the driver, please |
| 10 | list your email here for future contact: |
| 11 | |
| 12 | jhall@onlab.us |
| 13 | andrew@onlab.us |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 14 | shreya@onlab.us |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 15 | |
| 16 | OCT 13 2014 |
| 17 | |
| 18 | ''' |
| 19 | |
| 20 | import sys |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 21 | import pexpect |
| 22 | import re |
| 23 | import traceback |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 24 | #import os.path |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 25 | sys.path.append("../") |
| 26 | from drivers.common.clidriver import CLI |
| 27 | |
| 28 | class OnosCliDriver(CLI): |
| 29 | |
| 30 | def __init__(self): |
| 31 | ''' |
| 32 | Initialize client |
| 33 | ''' |
| 34 | super(CLI, self).__init__() |
| 35 | |
| 36 | def connect(self,**connectargs): |
| 37 | ''' |
| 38 | Creates ssh handle for ONOS cli. |
| 39 | ''' |
| 40 | try: |
| 41 | for key in connectargs: |
| 42 | vars(self)[key] = connectargs[key] |
| 43 | self.home = "~/ONOS" |
| 44 | for key in self.options: |
| 45 | if key == "home": |
| 46 | self.home = self.options['home'] |
| 47 | break |
| 48 | |
| 49 | |
| 50 | self.name = self.options['name'] |
| 51 | self.handle = super(OnosCliDriver,self).connect( |
| 52 | user_name = self.user_name, |
| 53 | ip_address = self.ip_address, |
| 54 | port = self.port, |
| 55 | pwd = self.pwd, |
| 56 | home = self.home) |
| 57 | |
| 58 | self.handle.sendline("cd "+ self.home) |
| 59 | self.handle.expect("\$") |
| 60 | if self.handle: |
| 61 | return self.handle |
| 62 | else : |
| 63 | main.log.info("NO ONOS HANDLE") |
| 64 | return main.FALSE |
| 65 | except pexpect.EOF: |
| 66 | main.log.error(self.name + ": EOF exception found") |
| 67 | main.log.error(self.name + ": " + self.handle.before) |
| 68 | main.cleanup() |
| 69 | main.exit() |
| 70 | except: |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 71 | main.log.info(self.name + ":::::::::::::::::::::::") |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 72 | main.log.error( traceback.print_exc() ) |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 73 | main.log.info(":::::::::::::::::::::::") |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 74 | main.cleanup() |
| 75 | main.exit() |
| 76 | |
| 77 | def disconnect(self): |
| 78 | ''' |
| 79 | Called when Test is complete to disconnect the ONOS handle. |
| 80 | ''' |
| 81 | response = '' |
| 82 | try: |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 83 | self.handle.sendline("") |
Jon Hall | 7e5b917 | 2014-10-22 12:32:47 -0400 | [diff] [blame] | 84 | i = self.handle.expect(["onos>","\$"]) |
| 85 | if i == 0: |
| 86 | self.handle.sendline("system:shutdown") |
| 87 | self.handle.expect("Confirm") |
| 88 | self.handle.sendline("yes") |
| 89 | self.handle.expect("\$") |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 90 | self.handle.sendline("") |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 91 | self.handle.expect("\$") |
Jon Hall | 7e5b917 | 2014-10-22 12:32:47 -0400 | [diff] [blame] | 92 | self.handle.sendline("exit") |
| 93 | self.handle.expect("closed") |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 94 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 95 | except pexpect.EOF: |
| 96 | main.log.error(self.name + ": EOF exception found") |
| 97 | main.log.error(self.name + ": " + self.handle.before) |
| 98 | except: |
| 99 | main.log.error(self.name + ": Connection failed to the host") |
| 100 | response = main.FALSE |
| 101 | return response |
| 102 | |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 103 | def logout(self): |
| 104 | ''' |
| 105 | Sends 'logout' command to ONOS cli |
| 106 | ''' |
| 107 | try: |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 108 | self.handle.sendline("") |
| 109 | i = self.handle.expect([ |
| 110 | "onos>", |
| 111 | "\$"], timeout=10) |
| 112 | if i == 0: |
| 113 | self.handle.sendline("logout") |
| 114 | self.handle.expect("\$") |
| 115 | elif i == 1: |
| 116 | return main.TRUE |
| 117 | |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 118 | except pexpect.EOF: |
| 119 | main.log.error(self.name + ": eof exception found") |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 120 | main.log.error(self.name + ": " + |
| 121 | self.handle.before) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 122 | main.cleanup() |
| 123 | main.exit() |
| 124 | except: |
| 125 | main.log.info(self.name+" ::::::") |
| 126 | main.log.error( traceback.print_exc()) |
| 127 | main.log.info(self.name+" ::::::") |
| 128 | main.cleanup() |
| 129 | main.exit() |
| 130 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 131 | def set_cell(self, cellname): |
| 132 | ''' |
| 133 | Calls 'cell <name>' to set the environment variables on ONOSbench |
| 134 | |
| 135 | Before issuing any cli commands, set the environment variable first. |
| 136 | ''' |
| 137 | try: |
| 138 | if not cellname: |
| 139 | main.log.error("Must define cellname") |
| 140 | main.cleanup() |
| 141 | main.exit() |
| 142 | else: |
| 143 | self.handle.sendline("cell "+str(cellname)) |
| 144 | #Expect the cellname in the ONOS_CELL variable. |
| 145 | #Note that this variable name is subject to change |
| 146 | # and that this driver will have to change accordingly |
| 147 | self.handle.expect("ONOS_CELL="+str(cellname)) |
| 148 | handle_before = self.handle.before |
| 149 | handle_after = self.handle.after |
| 150 | #Get the rest of the handle |
| 151 | self.handle.sendline("") |
| 152 | self.handle.expect("\$") |
| 153 | handle_more = self.handle.before |
| 154 | |
| 155 | main.log.info("Cell call returned: "+handle_before+ |
| 156 | handle_after + handle_more) |
| 157 | |
| 158 | return main.TRUE |
| 159 | |
| 160 | except pexpect.EOF: |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 161 | main.log.error(self.name + ": eof exception found") |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 162 | main.log.error(self.name + ": " + self.handle.before) |
| 163 | main.cleanup() |
| 164 | main.exit() |
| 165 | except: |
| 166 | main.log.info(self.name+" ::::::") |
| 167 | main.log.error( traceback.print_exc()) |
| 168 | main.log.info(self.name+" ::::::") |
| 169 | main.cleanup() |
| 170 | main.exit() |
| 171 | |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 172 | def start_onos_cli(self, ONOS_ip, karafTimeout=""): |
Hari Krishna | d7b9c20 | 2015-01-05 10:38:14 -0800 | [diff] [blame] | 173 | ''' |
| 174 | karafTimeout is an optional arugument. karafTimeout value passed by user would be used to set the |
| 175 | current karaf shell idle timeout. Note that when ever this property is modified the shell will exit and |
| 176 | the subsequent login would reflect new idle timeout. |
Hari Krishna | 25d42f7 | 2015-01-05 15:08:28 -0800 | [diff] [blame] | 177 | Below is an example to start a session with 60 seconds idle timeout (input value is in milliseconds): |
| 178 | |
| 179 | tValue = "60000" |
| 180 | main.ONOScli1.start_onos_cli(ONOS_ip, karafTimeout=tValue) |
| 181 | |
| 182 | Note: karafTimeout is left as str so that this could be read and passed to start_onos_cli from PARAMS file as str. |
Hari Krishna | d7b9c20 | 2015-01-05 10:38:14 -0800 | [diff] [blame] | 183 | ''' |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 184 | try: |
| 185 | self.handle.sendline("") |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 186 | x = self.handle.expect([ |
| 187 | "\$", "onos>"], timeout=10) |
| 188 | |
| 189 | if x == 1: |
| 190 | main.log.info("ONOS cli is already running") |
| 191 | return main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 192 | |
| 193 | #Wait for onos start (-w) and enter onos cli |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 194 | self.handle.sendline("onos -w "+str(ONOS_ip)) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 195 | i = self.handle.expect([ |
| 196 | "onos>", |
| 197 | pexpect.TIMEOUT],timeout=60) |
| 198 | |
| 199 | if i == 0: |
| 200 | main.log.info(str(ONOS_ip)+" CLI Started successfully") |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 201 | if karafTimeout: |
| 202 | self.handle.sendline("config:property-set -p org.apache.karaf.shell sshIdleTimeout "+karafTimeout) |
| 203 | self.handle.expect("\$") |
| 204 | self.handle.sendline("onos -w "+str(ONOS_ip)) |
| 205 | self.handle.expect("onos>") |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 206 | return main.TRUE |
| 207 | else: |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 208 | #If failed, send ctrl+c to process and try again |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 209 | main.log.info("Starting CLI failed. Retrying...") |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 210 | self.handle.send("\x03") |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 211 | self.handle.sendline("onos -w "+str(ONOS_ip)) |
| 212 | i = self.handle.expect(["onos>",pexpect.TIMEOUT], |
| 213 | timeout=30) |
| 214 | if i == 0: |
andrewonlab | 28ca4b2 | 2014-11-20 13:15:59 -0500 | [diff] [blame] | 215 | main.log.info(str(ONOS_ip)+" CLI Started "+ |
| 216 | "successfully after retry attempt") |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 217 | if karafTimeout: |
| 218 | self.handle.sendline("config:property-set -p org.apache.karaf.shell sshIdleTimeout "+karafTimeout) |
| 219 | self.handle.expect("\$") |
| 220 | self.handle.sendline("onos -w "+str(ONOS_ip)) |
| 221 | self.handle.expect("onos>") |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 222 | return main.TRUE |
| 223 | else: |
| 224 | main.log.error("Connection to CLI "+\ |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 225 | str(ONOS_ip)+" timeout") |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 226 | return main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 227 | |
| 228 | except pexpect.EOF: |
| 229 | main.log.error(self.name + ": EOF exception found") |
| 230 | main.log.error(self.name + ": " + self.handle.before) |
| 231 | main.cleanup() |
| 232 | main.exit() |
| 233 | except: |
| 234 | main.log.info(self.name+" ::::::") |
| 235 | main.log.error( traceback.print_exc()) |
| 236 | main.log.info(self.name+" ::::::") |
| 237 | main.cleanup() |
| 238 | main.exit() |
| 239 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 240 | def sendline(self, cmd_str): |
| 241 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 242 | Send a completely user specified string to |
| 243 | the onos> prompt. Use this function if you have |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 244 | a very specific command to send. |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 245 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 246 | Warning: There are no sanity checking to commands |
| 247 | sent using this method. |
| 248 | ''' |
| 249 | try: |
| 250 | self.handle.sendline("") |
| 251 | self.handle.expect("onos>") |
| 252 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 253 | self.handle.sendline("log:log \"Sending CLI command: '" |
| 254 | + cmd_str + "'\"") |
| 255 | self.handle.expect("onos>") |
| 256 | self.handle.sendline( cmd_str ) |
| 257 | self.handle.expect( cmd_str ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 258 | self.handle.expect("onos>") |
| 259 | |
| 260 | handle = self.handle.before |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 261 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 262 | self.handle.sendline("") |
| 263 | self.handle.expect("onos>") |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 264 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 265 | #handle += self.handle.before |
| 266 | #handle += self.handle.after |
| 267 | |
| 268 | main.log.info("Command '" + str( cmd_str ) + "' sent to " |
| 269 | + self.name + ".") |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 270 | ansi_escape = re.compile(r'\x1b[^m]*m') |
| 271 | handle = ansi_escape.sub('', handle) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 272 | |
| 273 | return handle |
| 274 | except pexpect.EOF: |
| 275 | main.log.error(self.name + ": EOF exception found") |
| 276 | main.log.error(self.name + ": " + self.handle.before) |
| 277 | main.cleanup() |
| 278 | main.exit() |
| 279 | except: |
| 280 | main.log.info(self.name+" ::::::") |
| 281 | main.log.error( traceback.print_exc()) |
| 282 | main.log.info(self.name+" ::::::") |
| 283 | main.cleanup() |
| 284 | main.exit() |
| 285 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 286 | #IMPORTANT NOTE: |
| 287 | #For all cli commands, naming convention should match |
| 288 | #the cli command replacing ':' with '_'. |
| 289 | #Ex) onos:topology > onos_topology |
| 290 | # onos:links > onos_links |
| 291 | # feature:list > feature_list |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 292 | |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 293 | def add_node(self, node_id, ONOS_ip, tcp_port=""): |
| 294 | ''' |
| 295 | Adds a new cluster node by ID and address information. |
| 296 | Required: |
| 297 | * node_id |
| 298 | * ONOS_ip |
| 299 | Optional: |
| 300 | * tcp_port |
| 301 | ''' |
| 302 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 303 | cmd_str = "add-node " + str(node_id) + " " +\ |
| 304 | str(ONOS_ip) + " " + str(tcp_port) |
| 305 | handle = self.sendline( cmd_str ) |
| 306 | if re.search("Error", handle): |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 307 | main.log.error("Error in adding node") |
| 308 | main.log.error(handle) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 309 | return main.FALSE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 310 | else: |
| 311 | main.log.info("Node "+str(ONOS_ip)+" added") |
| 312 | return main.TRUE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 313 | except pexpect.EOF: |
| 314 | main.log.error(self.name + ": EOF exception found") |
| 315 | main.log.error(self.name + ": " + self.handle.before) |
| 316 | main.cleanup() |
| 317 | main.exit() |
| 318 | except: |
| 319 | main.log.info(self.name+" ::::::") |
| 320 | main.log.error( traceback.print_exc()) |
| 321 | main.log.info(self.name+" ::::::") |
| 322 | main.cleanup() |
| 323 | main.exit() |
| 324 | |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 325 | def remove_node(self, node_id): |
| 326 | ''' |
| 327 | Removes a cluster by ID |
| 328 | Issues command: 'remove-node [<node-id>]' |
| 329 | Required: |
| 330 | * node_id |
| 331 | ''' |
| 332 | try: |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 333 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 334 | cmd_str = "remove-node " + str(node_id) |
| 335 | self.sendline( cmd_str ) |
| 336 | # TODO: add error checking. Does ONOS give any errors? |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 337 | |
| 338 | return main.TRUE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 339 | |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 340 | except pexpect.EOF: |
| 341 | main.log.error(self.name + ": EOF exception found") |
| 342 | main.log.error(self.name + ": " + self.handle.before) |
| 343 | main.cleanup() |
| 344 | main.exit() |
| 345 | except: |
| 346 | main.log.info(self.name+" ::::::") |
| 347 | main.log.error( traceback.print_exc()) |
| 348 | main.log.info(self.name+" ::::::") |
| 349 | main.cleanup() |
| 350 | main.exit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 351 | |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 352 | def nodes(self): |
| 353 | ''' |
| 354 | List the nodes currently visible |
| 355 | Issues command: 'nodes' |
| 356 | Returns: entire handle of list of nodes |
| 357 | ''' |
| 358 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 359 | cmd_str = "nodes" |
| 360 | handle = self.sendline( cmd_str ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 361 | return handle |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 362 | except pexpect.EOF: |
| 363 | main.log.error(self.name + ": EOF exception found") |
| 364 | main.log.error(self.name + ": " + self.handle.before) |
| 365 | main.cleanup() |
| 366 | main.exit() |
| 367 | except: |
| 368 | main.log.info(self.name+" ::::::") |
| 369 | main.log.error( traceback.print_exc()) |
| 370 | main.log.info(self.name+" ::::::") |
| 371 | main.cleanup() |
| 372 | main.exit() |
| 373 | |
andrewonlab | 38d6ae2 | 2014-10-15 14:23:45 -0400 | [diff] [blame] | 374 | def topology(self): |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 375 | ''' |
| 376 | Shows the current state of the topology |
| 377 | by issusing command: 'onos> onos:topology' |
| 378 | ''' |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 379 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 380 | # either onos:topology or 'topology' will work in CLI |
| 381 | cmd_str = "onos:topology" |
| 382 | handle = self.sendline( cmd_str ) |
| 383 | main.log.info( "onos:topology returned: " + str( handle ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 384 | return handle |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 385 | except pexpect.EOF: |
| 386 | main.log.error(self.name + ": EOF exception found") |
| 387 | main.log.error(self.name + ": " + self.handle.before) |
| 388 | main.cleanup() |
| 389 | main.exit() |
| 390 | except: |
| 391 | main.log.info(self.name+" ::::::") |
| 392 | main.log.error( traceback.print_exc()) |
| 393 | main.log.info(self.name+" ::::::") |
| 394 | main.cleanup() |
| 395 | main.exit() |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 396 | |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 397 | def feature_install(self, feature_str): |
| 398 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 399 | Installs a specified feature |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 400 | by issuing command: 'onos> feature:install <feature_str>' |
| 401 | ''' |
| 402 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 403 | cmd_str = "feature:install " + str( feature_str ) |
| 404 | self.sendline( cmd_str ) |
| 405 | # TODO: Check for possible error responses from karaf |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 406 | return main.TRUE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 407 | except pexpect.EOF: |
| 408 | main.log.error(self.name + ": EOF exception found") |
| 409 | main.log.error(self.name + ": " + self.handle.before) |
andrewonlab | bf225b0 | 2014-11-12 12:14:05 -0500 | [diff] [blame] | 410 | main.log.report("Failed to install feature") |
| 411 | main.log.report("Exiting test") |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 412 | main.cleanup() |
| 413 | main.exit() |
| 414 | except: |
| 415 | main.log.info(self.name+" ::::::") |
| 416 | main.log.error( traceback.print_exc()) |
andrewonlab | bf225b0 | 2014-11-12 12:14:05 -0500 | [diff] [blame] | 417 | main.log.report("Failed to install feature") |
| 418 | main.log.report("Exiting test") |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 419 | main.log.info(self.name+" ::::::") |
| 420 | main.cleanup() |
| 421 | main.exit() |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 422 | |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 423 | def feature_uninstall(self, feature_str): |
| 424 | ''' |
| 425 | Uninstalls a specified feature |
| 426 | by issuing command: 'onos> feature:uninstall <feature_str>' |
| 427 | ''' |
| 428 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 429 | cmd_str = "feature:uninstall " + str( feature_str ) |
| 430 | self.sendline( cmd_str ) |
| 431 | # TODO: Check for possible error responses from karaf |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 432 | return main.TRUE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 433 | except pexpect.EOF: |
| 434 | main.log.error(self.name + ": EOF exception found") |
| 435 | main.log.error(self.name + ": " + self.handle.before) |
| 436 | main.cleanup() |
| 437 | main.exit() |
| 438 | except: |
| 439 | main.log.info(self.name+" ::::::") |
| 440 | main.log.error( traceback.print_exc()) |
| 441 | main.log.info(self.name+" ::::::") |
| 442 | main.cleanup() |
| 443 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 444 | |
| 445 | def devices(self, json_format=True): |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 446 | ''' |
Jon Hall | 7b02d95 | 2014-10-17 20:14:54 -0400 | [diff] [blame] | 447 | Lists all infrastructure devices or switches |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 448 | Optional argument: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 449 | * json_format - boolean indicating if you want output in json |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 450 | ''' |
| 451 | try: |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 452 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 453 | cmd_str = "devices -j" |
| 454 | handle = self.sendline( cmd_str ) |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 455 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 456 | handle variable here contains some ANSI escape color code |
| 457 | sequences at the end which are invisible in the print command |
| 458 | output. To make that escape sequence visible, use repr() |
| 459 | function. The repr(handle) output when printed shows the |
| 460 | ANSI escape sequences. In json.loads(somestring), this |
| 461 | somestring variable is actually repr(somestring) and |
| 462 | json.loads would fail with the escape sequence. So we take off |
| 463 | that escape sequence using: |
| 464 | |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 465 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 466 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 467 | ''' |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 468 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 469 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 470 | return handle1 |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 471 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 472 | cmd_str = "devices" |
| 473 | handle = self.sendline( cmd_str ) |
Jon Hall | cd70729 | 2014-10-17 19:06:17 -0400 | [diff] [blame] | 474 | return handle |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 475 | except pexpect.EOF: |
| 476 | main.log.error(self.name + ": EOF exception found") |
| 477 | main.log.error(self.name + ": " + self.handle.before) |
| 478 | main.cleanup() |
| 479 | main.exit() |
| 480 | except: |
| 481 | main.log.info(self.name+" ::::::") |
| 482 | main.log.error( traceback.print_exc()) |
| 483 | main.log.info(self.name+" ::::::") |
| 484 | main.cleanup() |
| 485 | main.exit() |
| 486 | |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 487 | def balance_masters(self): |
| 488 | ''' |
| 489 | This balances the devices across all controllers |
| 490 | by issuing command: 'onos> onos:balance-masters' |
| 491 | If required this could be extended to return devices balanced output. |
| 492 | ''' |
| 493 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 494 | cmd_str = "onos:balance-masters" |
| 495 | self.sendline( cmd_str ) |
| 496 | # TODO: Check for error responses from ONOS |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 497 | return main.TRUE |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 498 | except pexpect.EOF: |
| 499 | main.log.error(self.name + ": EOF exception found") |
| 500 | main.log.error(self.name + ": " + self.handle.before) |
| 501 | main.cleanup() |
| 502 | main.exit() |
| 503 | except: |
| 504 | main.log.info(self.name+" ::::::") |
| 505 | main.log.error( traceback.print_exc()) |
| 506 | main.log.info(self.name+" ::::::") |
| 507 | main.cleanup() |
| 508 | main.exit() |
| 509 | |
Hari Krishna | 2bbaa70 | 2014-12-19 14:46:12 -0800 | [diff] [blame] | 510 | def links(self, json_format=True): |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 511 | ''' |
| 512 | Lists all core links |
| 513 | Optional argument: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 514 | * json_format - boolean indicating if you want output in json |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 515 | ''' |
| 516 | try: |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 517 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 518 | cmd_str = "links -j" |
| 519 | handle = self.sendline( cmd_str ) |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 520 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 521 | handle variable here contains some ANSI escape color code |
| 522 | sequences at the end which are invisible in the print command |
| 523 | output. To make that escape sequence visible, use repr() |
| 524 | function. The repr(handle) output when printed shows the ANSI |
| 525 | escape sequences. In json.loads(somestring), this somestring |
| 526 | variable is actually repr(somestring) and json.loads would |
| 527 | fail with the escape sequence. So we take off that escape |
| 528 | sequence using: |
| 529 | |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 530 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 531 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 532 | ''' |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 533 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 534 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 535 | return handle1 |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 536 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 537 | cmd_str = "links" |
| 538 | handle = self.sendline( cmd_str ) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 539 | return handle |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 540 | except pexpect.EOF: |
| 541 | main.log.error(self.name + ": EOF exception found") |
| 542 | main.log.error(self.name + ": " + self.handle.before) |
| 543 | main.cleanup() |
| 544 | main.exit() |
| 545 | except: |
| 546 | main.log.info(self.name+" ::::::") |
| 547 | main.log.error( traceback.print_exc()) |
| 548 | main.log.info(self.name+" ::::::") |
| 549 | main.cleanup() |
| 550 | main.exit() |
| 551 | |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 552 | def ports(self, json_format=True): |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 553 | ''' |
| 554 | Lists all ports |
| 555 | Optional argument: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 556 | * json_format - boolean indicating if you want output in json |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 557 | ''' |
| 558 | try: |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 559 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 560 | cmd_str = "ports -j" |
| 561 | handle = self.sendline( cmd_str ) |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 562 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 563 | handle variable here contains some ANSI escape color code |
| 564 | sequences at the end which are invisible in the print command |
| 565 | output. To make that escape sequence visible, use repr() |
| 566 | function. The repr(handle) output when printed shows the ANSI |
| 567 | escape sequences. In json.loads(somestring), this somestring |
| 568 | variable is actually repr(somestring) and json.loads would |
| 569 | fail with the escape sequence. So we take off that escape |
| 570 | sequence using the following commads: |
| 571 | |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 572 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 573 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 574 | ''' |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 575 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 576 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 577 | return handle1 |
| 578 | |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 579 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 580 | cmd_str = "ports" |
| 581 | handle = self.sendline( cmd_str ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 582 | return handle |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 583 | except pexpect.EOF: |
| 584 | main.log.error(self.name + ": EOF exception found") |
| 585 | main.log.error(self.name + ": " + self.handle.before) |
| 586 | main.cleanup() |
| 587 | main.exit() |
| 588 | except: |
| 589 | main.log.info(self.name+" ::::::") |
| 590 | main.log.error( traceback.print_exc()) |
| 591 | main.log.info(self.name+" ::::::") |
| 592 | main.cleanup() |
| 593 | main.exit() |
| 594 | |
| 595 | |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 596 | def roles(self, json_format=True): |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 597 | ''' |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 598 | Lists all devices and the controllers with roles assigned to them |
| 599 | Optional argument: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 600 | * json_format - boolean indicating if you want output in json |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 601 | ''' |
| 602 | try: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 603 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 604 | cmd_str = "roles -j" |
| 605 | handle = self.sendline( cmd_str ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 606 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 607 | handle variable here contains some ANSI escape color code |
| 608 | sequences at the end which are invisible in the print command |
| 609 | output. To make that escape sequence visible, use repr() |
| 610 | function. The repr(handle) output when printed shows the ANSI |
| 611 | escape sequences. In json.loads(somestring), this somestring |
| 612 | variable is actually repr(somestring) and json.loads would |
| 613 | fail with the escape sequence. |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 614 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 615 | So we take off that escape sequence using the following |
| 616 | commads: |
| 617 | |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 618 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 619 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 620 | ''' |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 621 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 622 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 623 | return handle1 |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 624 | |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 625 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 626 | cmd_str = "roles" |
| 627 | handle = self.sendline( cmd_str ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 628 | return handle |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 629 | except pexpect.EOF: |
| 630 | main.log.error(self.name + ": EOF exception found") |
| 631 | main.log.error(self.name + ": " + self.handle.before) |
| 632 | main.cleanup() |
| 633 | main.exit() |
| 634 | except: |
| 635 | main.log.info(self.name+" ::::::") |
| 636 | main.log.error( traceback.print_exc()) |
| 637 | main.log.info(self.name+" ::::::") |
| 638 | main.cleanup() |
| 639 | main.exit() |
| 640 | |
| 641 | def get_role(self, device_id): |
| 642 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 643 | Given the a string containing the json representation of the "roles" |
| 644 | cli command and a partial or whole device id, returns a json object |
| 645 | containing the roles output for the first device whose id contains |
| 646 | "device_id" |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 647 | |
| 648 | Returns: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 649 | A dict of the role assignments for the given device or |
| 650 | None if no match |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 651 | ''' |
| 652 | try: |
| 653 | import json |
| 654 | if device_id == None: |
| 655 | return None |
| 656 | else: |
| 657 | raw_roles = self.roles() |
| 658 | roles_json = json.loads(raw_roles) |
| 659 | #search json for the device with id then return the device |
| 660 | for device in roles_json: |
Jon Hall | 720653a | 2014-10-28 19:02:37 -0400 | [diff] [blame] | 661 | #print device |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 662 | if str(device_id) in device['id']: |
| 663 | return device |
| 664 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 665 | |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 666 | except pexpect.EOF: |
| 667 | main.log.error(self.name + ": EOF exception found") |
| 668 | main.log.error(self.name + ": " + self.handle.before) |
| 669 | main.cleanup() |
| 670 | main.exit() |
| 671 | except: |
| 672 | main.log.info(self.name+" ::::::") |
| 673 | main.log.error( traceback.print_exc()) |
| 674 | main.log.info(self.name+" ::::::") |
| 675 | main.cleanup() |
| 676 | main.exit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 677 | |
| 678 | def roles_not_null(self): |
| 679 | ''' |
| 680 | Iterates through each device and checks if there is a master assigned |
| 681 | Returns: main.TRUE if each device has a master |
| 682 | main.FALSE any device has no master |
| 683 | ''' |
| 684 | try: |
| 685 | import json |
| 686 | raw_roles = self.roles() |
| 687 | roles_json = json.loads(raw_roles) |
| 688 | #search json for the device with id then return the device |
| 689 | for device in roles_json: |
| 690 | #print device |
| 691 | if device['master'] == "none": |
| 692 | main.log.warn("Device has no master: " + str(device) ) |
| 693 | return main.FALSE |
| 694 | return main.TRUE |
| 695 | |
| 696 | except pexpect.EOF: |
| 697 | main.log.error(self.name + ": EOF exception found") |
| 698 | main.log.error(self.name + ": " + self.handle.before) |
| 699 | main.cleanup() |
| 700 | main.exit() |
| 701 | except: |
| 702 | main.log.info(self.name+" ::::::") |
| 703 | main.log.error( traceback.print_exc()) |
| 704 | main.log.info(self.name+" ::::::") |
| 705 | main.cleanup() |
| 706 | main.exit() |
| 707 | |
| 708 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 709 | def paths(self, src_id, dst_id): |
| 710 | ''' |
| 711 | Returns string of paths, and the cost. |
| 712 | Issues command: onos:paths <src> <dst> |
| 713 | ''' |
| 714 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 715 | cmd_str = "onos:paths " + str(src_id) + " " + str(dst_id) |
| 716 | handle = self.sendline( cmd_str ) |
| 717 | if re.search( "Error", handle ): |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 718 | main.log.error("Error in getting paths") |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 719 | return (handle, "Error") |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 720 | else: |
| 721 | path = handle.split(";")[0] |
| 722 | cost = handle.split(";")[1] |
| 723 | return (path, cost) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 724 | except pexpect.EOF: |
| 725 | main.log.error(self.name + ": EOF exception found") |
| 726 | main.log.error(self.name + ": " + self.handle.before) |
| 727 | main.cleanup() |
| 728 | main.exit() |
| 729 | except: |
| 730 | main.log.info(self.name+" ::::::") |
| 731 | main.log.error( traceback.print_exc()) |
| 732 | main.log.info(self.name+" ::::::") |
| 733 | main.cleanup() |
| 734 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 735 | |
| 736 | def hosts(self, json_format=True): |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 737 | ''' |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 738 | Lists all discovered hosts |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 739 | Optional argument: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 740 | * json_format - boolean indicating if you want output in json |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 741 | ''' |
| 742 | try: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 743 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 744 | cmd_str = "hosts -j" |
| 745 | handle = self.sendline( cmd_str ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 746 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 747 | handle variable here contains some ANSI escape color code |
| 748 | sequences at the end which are invisible in the print command |
| 749 | output. To make that escape sequence visible, use repr() |
| 750 | function. The repr(handle) output when printed shows the ANSI |
| 751 | escape sequences. In json.loads(somestring), this somestring |
| 752 | variable is actually repr(somestring) and json.loads would |
| 753 | fail with the escape sequence. So we take off that escape |
| 754 | sequence using: |
| 755 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 756 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 757 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 758 | ''' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 759 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 760 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 761 | return handle1 |
| 762 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 763 | cmd_str = "hosts" |
| 764 | handle = self.sendline( cmd_str ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 765 | return handle |
| 766 | except pexpect.EOF: |
| 767 | main.log.error(self.name + ": EOF exception found") |
| 768 | main.log.error(self.name + ": " + self.handle.before) |
| 769 | main.cleanup() |
| 770 | main.exit() |
| 771 | except: |
| 772 | main.log.info(self.name+" ::::::") |
| 773 | main.log.error( traceback.print_exc()) |
| 774 | main.log.info(self.name+" ::::::") |
| 775 | main.cleanup() |
| 776 | main.exit() |
| 777 | |
| 778 | def get_host(self, mac): |
| 779 | ''' |
| 780 | Return the first host from the hosts api whose 'id' contains 'mac' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 781 | |
| 782 | Note: mac must be a colon seperated mac address, but could be a |
| 783 | partial mac address |
| 784 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 785 | Return None if there is no match |
| 786 | ''' |
| 787 | import json |
| 788 | try: |
| 789 | if mac == None: |
| 790 | return None |
| 791 | else: |
| 792 | mac = mac |
| 793 | raw_hosts = self.hosts() |
| 794 | hosts_json = json.loads(raw_hosts) |
| 795 | #search json for the host with mac then return the device |
| 796 | for host in hosts_json: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 797 | #print "%s in %s?" % (mac, host['id']) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 798 | if mac in host['id']: |
| 799 | return host |
| 800 | return None |
| 801 | except pexpect.EOF: |
| 802 | main.log.error(self.name + ": EOF exception found") |
| 803 | main.log.error(self.name + ": " + self.handle.before) |
| 804 | main.cleanup() |
| 805 | main.exit() |
| 806 | except: |
| 807 | main.log.info(self.name+" ::::::") |
| 808 | main.log.error( traceback.print_exc()) |
| 809 | main.log.info(self.name+" ::::::") |
| 810 | main.cleanup() |
| 811 | main.exit() |
| 812 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 813 | |
| 814 | def get_hosts_id(self, host_list): |
| 815 | ''' |
| 816 | Obtain list of hosts |
| 817 | Issues command: 'onos> hosts' |
| 818 | |
| 819 | Required: |
| 820 | * host_list: List of hosts obtained by Mininet |
| 821 | IMPORTANT: |
| 822 | This function assumes that you started your |
| 823 | topology with the option '--mac'. |
| 824 | Furthermore, it assumes that value of VLAN is '-1' |
| 825 | Description: |
| 826 | Converts mininet hosts (h1, h2, h3...) into |
| 827 | ONOS format (00:00:00:00:00:01/-1 , ...) |
| 828 | ''' |
| 829 | |
| 830 | try: |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 831 | onos_host_list = [] |
| 832 | |
| 833 | for host in host_list: |
| 834 | host = host.replace("h", "") |
| 835 | host_hex = hex(int(host)).zfill(12) |
| 836 | host_hex = str(host_hex).replace('x','0') |
| 837 | i = iter(str(host_hex)) |
| 838 | host_hex = ":".join(a+b for a,b in zip(i,i)) |
| 839 | host_hex = host_hex + "/-1" |
| 840 | onos_host_list.append(host_hex) |
| 841 | |
| 842 | return onos_host_list |
| 843 | |
| 844 | except pexpect.EOF: |
| 845 | main.log.error(self.name + ": EOF exception found") |
| 846 | main.log.error(self.name + ": " + self.handle.before) |
| 847 | main.cleanup() |
| 848 | main.exit() |
| 849 | except: |
| 850 | main.log.info(self.name+" ::::::") |
| 851 | main.log.error( traceback.print_exc()) |
| 852 | main.log.info(self.name+" ::::::") |
| 853 | main.cleanup() |
| 854 | main.exit() |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 855 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 856 | def add_host_intent(self, host_id_one, host_id_two): |
| 857 | ''' |
| 858 | Required: |
| 859 | * host_id_one: ONOS host id for host1 |
| 860 | * host_id_two: ONOS host id for host2 |
| 861 | Description: |
| 862 | Adds a host-to-host intent (bidrectional) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 863 | specifying the two hosts. |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 864 | ''' |
| 865 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 866 | cmd_str = "add-host-intent " + str(host_id_one) +\ |
| 867 | " " + str(host_id_two) |
| 868 | handle = self.sendline( cmd_str ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 869 | main.log.info("Host intent installed between "+ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 870 | str(host_id_one) + " and " + str(host_id_two)) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 871 | return handle |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 872 | except pexpect.EOF: |
| 873 | main.log.error(self.name + ": EOF exception found") |
| 874 | main.log.error(self.name + ": " + self.handle.before) |
| 875 | main.cleanup() |
| 876 | main.exit() |
| 877 | except: |
| 878 | main.log.info(self.name+" ::::::") |
| 879 | main.log.error( traceback.print_exc()) |
| 880 | main.log.info(self.name+" ::::::") |
| 881 | main.cleanup() |
| 882 | main.exit() |
| 883 | |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 884 | def add_optical_intent(self, ingress_device, egress_device): |
| 885 | ''' |
| 886 | Required: |
| 887 | * ingress_device: device id of ingress device |
| 888 | * egress_device: device id of egress device |
| 889 | Optional: |
| 890 | TODO: Still needs to be implemented via dev side |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 891 | ''' |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 892 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 893 | cmd_str = "add-optical-intent " + str( ingress_device ) +\ |
| 894 | " " + str( egress_device ) |
| 895 | handle = self.sendline( cmd_str ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 896 | #If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 897 | if re.search( "Error", handle ): |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 898 | return handle |
| 899 | else: |
| 900 | return main.TRUE |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 901 | except pexpect.EOF: |
| 902 | main.log.error(self.name + ": EOF exception found") |
| 903 | main.log.error(self.name + ": " + self.handle.before) |
| 904 | main.cleanup() |
| 905 | main.exit() |
| 906 | except: |
| 907 | main.log.info(self.name+" ::::::") |
| 908 | main.log.error( traceback.print_exc()) |
| 909 | main.log.info(self.name+" ::::::") |
| 910 | main.cleanup() |
| 911 | main.exit() |
| 912 | |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 913 | def add_point_intent(self, ingress_device, egress_device, |
| 914 | port_ingress="", port_egress="", ethType="", ethSrc="", |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 915 | ethDst="", bandwidth="", lambda_alloc=False, |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 916 | ipProto="", ipSrc="", ipDst="", tcpSrc="", tcpDst=""): |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 917 | ''' |
| 918 | Required: |
| 919 | * ingress_device: device id of ingress device |
| 920 | * egress_device: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 921 | Optional: |
| 922 | * ethType: specify ethType |
| 923 | * ethSrc: specify ethSrc (i.e. src mac addr) |
| 924 | * ethDst: specify ethDst (i.e. dst mac addr) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 925 | * bandwidth: specify bandwidth capacity of link |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 926 | * lambda_alloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 927 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 928 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 929 | * ipSrc: specify ip source address |
| 930 | * ipDst: specify ip destination address |
| 931 | * tcpSrc: specify tcp source port |
| 932 | * tcpDst: specify tcp destination port |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 933 | Description: |
| 934 | Adds a point-to-point intent (uni-directional) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 935 | specifying device id's and optional fields |
| 936 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 937 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 938 | options developers provide for point-to-point |
| 939 | intent via cli |
| 940 | ''' |
| 941 | try: |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 942 | cmd = "" |
| 943 | |
| 944 | #If there are no optional arguments |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 945 | if not ethType and not ethSrc and not ethDst\ |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 946 | and not bandwidth and not lambda_alloc \ |
| 947 | and not ipProto and not ipSrc and not ipDst \ |
| 948 | and not tcpSrc and not tcpDst: |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 949 | cmd = "add-point-intent" |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 950 | |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 951 | |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 952 | else: |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 953 | cmd = "add-point-intent" |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 954 | |
andrewonlab | 0c0a677 | 2014-10-22 12:31:18 -0400 | [diff] [blame] | 955 | if ethType: |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 956 | cmd += " --ethType " + str(ethType) |
| 957 | if ethSrc: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 958 | cmd += " --ethSrc " + str(ethSrc) |
| 959 | if ethDst: |
| 960 | cmd += " --ethDst " + str(ethDst) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 961 | if bandwidth: |
| 962 | cmd += " --bandwidth " + str(bandwidth) |
| 963 | if lambda_alloc: |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 964 | cmd += " --lambda " |
| 965 | if ipProto: |
| 966 | cmd += " --ipProto " + str(ipProto) |
| 967 | if ipSrc: |
| 968 | cmd += " --ipSrc " + str(ipSrc) |
| 969 | if ipDst: |
| 970 | cmd += " --ipDst " + str(ipDst) |
| 971 | if tcpSrc: |
| 972 | cmd += " --tcpSrc " + str(tcpSrc) |
| 973 | if tcpDst: |
| 974 | cmd += " --tcpDst " + str(tcpDst) |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 975 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 976 | #Check whether the user appended the port |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 977 | #or provided it as an input |
| 978 | if "/" in ingress_device: |
| 979 | cmd += " "+str(ingress_device) |
| 980 | else: |
| 981 | if not port_ingress: |
| 982 | main.log.error("You must specify "+ |
| 983 | "the ingress port") |
| 984 | #TODO: perhaps more meaningful return |
| 985 | return main.FALSE |
| 986 | |
| 987 | cmd += " "+ \ |
| 988 | str(ingress_device) + "/" +\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 989 | str(port_ingress) + " " |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 990 | |
| 991 | if "/" in egress_device: |
| 992 | cmd += " "+str(egress_device) |
| 993 | else: |
| 994 | if not port_egress: |
| 995 | main.log.error("You must specify "+ |
| 996 | "the egress port") |
| 997 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 998 | |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 999 | cmd += " "+\ |
| 1000 | str(egress_device) + "/" +\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1001 | str(port_egress) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1002 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1003 | handle = self.sendline(cmd) |
| 1004 | if re.search( "Error", handle ): |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1005 | main.log.error("Error in adding point-to-point intent") |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 1006 | return main.FALSE |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1007 | else: |
| 1008 | return main.TRUE |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1009 | except pexpect.EOF: |
| 1010 | main.log.error(self.name + ": EOF exception found") |
| 1011 | main.log.error(self.name + ": " + self.handle.before) |
| 1012 | main.cleanup() |
| 1013 | main.exit() |
| 1014 | except: |
| 1015 | main.log.info(self.name+" ::::::") |
| 1016 | main.log.error( traceback.print_exc()) |
| 1017 | main.log.info(self.name+" ::::::") |
| 1018 | main.cleanup() |
| 1019 | main.exit() |
| 1020 | |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1021 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1022 | def add_multipoint_to_singlepoint_intent(self, ingress_device1, |
| 1023 | ingress_device2, egress_device, port_ingress="", port_egress="", |
| 1024 | ethType="", ethSrc="", ethDst="", bandwidth="", lambda_alloc=False, |
| 1025 | ipProto="", ipSrc="", ipDst="", tcpSrc="", tcpDst="", setEthSrc="", |
| 1026 | setEthDst=""): |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1027 | ''' |
| 1028 | Note: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1029 | This function assumes that there would be 2 ingress devices and |
| 1030 | one egress device. For more number of ingress devices, this |
| 1031 | function needs to be modified |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1032 | Required: |
| 1033 | * ingress_device1: device id of ingress device1 |
| 1034 | * ingress_device2: device id of ingress device2 |
| 1035 | * egress_device: device id of egress device |
| 1036 | Optional: |
| 1037 | * ethType: specify ethType |
| 1038 | * ethSrc: specify ethSrc (i.e. src mac addr) |
| 1039 | * ethDst: specify ethDst (i.e. dst mac addr) |
| 1040 | * bandwidth: specify bandwidth capacity of link |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1041 | * lambda_alloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1042 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1043 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1044 | * ipSrc: specify ip source address |
| 1045 | * ipDst: specify ip destination address |
| 1046 | * tcpSrc: specify tcp source port |
| 1047 | * tcpDst: specify tcp destination port |
| 1048 | * setEthSrc: action to Rewrite Source MAC Address |
| 1049 | * setEthDst: action to Rewrite Destination MAC Address |
| 1050 | Description: |
| 1051 | Adds a multipoint-to-singlepoint intent (uni-directional) by |
| 1052 | specifying device id's and optional fields |
| 1053 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1054 | NOTE: This function may change depending on the |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1055 | options developers provide for multipointpoint-to-singlepoint |
| 1056 | intent via cli |
| 1057 | ''' |
| 1058 | try: |
| 1059 | cmd = "" |
| 1060 | |
| 1061 | #If there are no optional arguments |
| 1062 | if not ethType and not ethSrc and not ethDst\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1063 | and not bandwidth and not lambda_alloc\ |
| 1064 | and not ipProto and not ipSrc and not ipDst\ |
| 1065 | and not tcpSrc and not tcpDst and not setEthSrc\ |
| 1066 | and not setEthDst: |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1067 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1068 | |
| 1069 | else: |
| 1070 | cmd = "add-multi-to-single-intent" |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1071 | |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1072 | if ethType: |
| 1073 | cmd += " --ethType " + str(ethType) |
| 1074 | if ethSrc: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1075 | cmd += " --ethSrc " + str(ethSrc) |
| 1076 | if ethDst: |
| 1077 | cmd += " --ethDst " + str(ethDst) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1078 | if bandwidth: |
| 1079 | cmd += " --bandwidth " + str(bandwidth) |
| 1080 | if lambda_alloc: |
| 1081 | cmd += " --lambda " |
| 1082 | if ipProto: |
| 1083 | cmd += " --ipProto " + str(ipProto) |
| 1084 | if ipSrc: |
| 1085 | cmd += " --ipSrc " + str(ipSrc) |
| 1086 | if ipDst: |
| 1087 | cmd += " --ipDst " + str(ipDst) |
| 1088 | if tcpSrc: |
| 1089 | cmd += " --tcpSrc " + str(tcpSrc) |
| 1090 | if tcpDst: |
| 1091 | cmd += " --tcpDst " + str(tcpDst) |
| 1092 | if setEthSrc: |
| 1093 | cmd += " --setEthSrc "+ str(setEthSrc) |
| 1094 | if setEthDst: |
| 1095 | cmd += " --setEthDst "+ str(setEthDst) |
| 1096 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1097 | #Check whether the user appended the port |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1098 | #or provided it as an input |
| 1099 | if "/" in ingress_device1: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1100 | cmd += " "+str(ingress_device1) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1101 | else: |
| 1102 | if not port_ingress1: |
| 1103 | main.log.error("You must specify "+ |
| 1104 | "the ingress port1") |
| 1105 | #TODO: perhaps more meaningful return |
| 1106 | return main.FALSE |
| 1107 | |
| 1108 | cmd += " "+ \ |
| 1109 | str(ingress_device1) + "/" +\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1110 | str(port_ingress1) + " " |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1111 | |
| 1112 | if "/" in ingress_device2: |
| 1113 | cmd += " "+str(ingress_device2) |
| 1114 | else: |
| 1115 | if not port_ingress2: |
| 1116 | main.log.error("You must specify "+ |
| 1117 | "the ingress port2") |
| 1118 | #TODO: perhaps more meaningful return |
| 1119 | return main.FALSE |
| 1120 | |
| 1121 | cmd += " "+ \ |
| 1122 | str(ingress_device2) + "/" +\ |
| 1123 | str(port_ingress2) + " " |
| 1124 | |
| 1125 | if "/" in egress_device: |
| 1126 | cmd += " "+str(egress_device) |
| 1127 | else: |
| 1128 | if not port_egress: |
| 1129 | main.log.error("You must specify "+ |
| 1130 | "the egress port") |
| 1131 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1132 | |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1133 | cmd += " "+\ |
| 1134 | str(egress_device) + "/" +\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1135 | str(port_egress) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1136 | print "cmd= ",cmd |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1137 | handle = self.sendline(cmd) |
| 1138 | if re.search( "Error", handle ): |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1139 | main.log.error("Error in adding point-to-point intent") |
| 1140 | return self.handle |
| 1141 | else: |
| 1142 | return main.TRUE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1143 | except pexpect.EOF: |
| 1144 | main.log.error(self.name + ": EOF exception found") |
| 1145 | main.log.error(self.name + ": " + self.handle.before) |
| 1146 | main.cleanup() |
| 1147 | main.exit() |
| 1148 | except: |
| 1149 | main.log.info(self.name+" ::::::") |
| 1150 | main.log.error( traceback.print_exc()) |
| 1151 | main.log.info(self.name+" ::::::") |
| 1152 | main.cleanup() |
| 1153 | main.exit() |
| 1154 | |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1155 | def remove_intent(self, intent_id): |
| 1156 | ''' |
| 1157 | Remove intent for specified intent id |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1158 | |
| 1159 | Returns: |
| 1160 | main.False on error and |
| 1161 | cli output otherwise |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1162 | ''' |
| 1163 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1164 | cmd_str = "remove-intent " + str( intent_id ) |
| 1165 | handle = self.sendline( cmd_str ) |
| 1166 | if re.search( "Error", handle ): |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1167 | main.log.error("Error in removing intent") |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1168 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1169 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1170 | # TODO: Should this be main.TRUE |
| 1171 | return handle |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1172 | except pexpect.EOF: |
| 1173 | main.log.error(self.name + ": EOF exception found") |
| 1174 | main.log.error(self.name + ": " + self.handle.before) |
| 1175 | main.cleanup() |
| 1176 | main.exit() |
| 1177 | except: |
| 1178 | main.log.info(self.name+" ::::::") |
| 1179 | main.log.error( traceback.print_exc()) |
| 1180 | main.log.info(self.name+" ::::::") |
| 1181 | main.cleanup() |
| 1182 | main.exit() |
| 1183 | |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1184 | def routes(self, json_format=False): |
| 1185 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1186 | NOTE: This method should be used after installing application: |
| 1187 | onos-app-sdnip |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1188 | Optional: |
| 1189 | * json_format: enable output formatting in json |
| 1190 | Description: |
| 1191 | Obtain all routes in the system |
| 1192 | ''' |
| 1193 | try: |
| 1194 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1195 | cmd_str = "routes -j" |
| 1196 | handle_tmp = self.sendline( cmd_str ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1197 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1198 | handle = ansi_escape.sub('', handle_tmp) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1199 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1200 | cmd_str = "routes" |
| 1201 | handle = self.sendline( cmd_str ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1202 | return handle |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1203 | except pexpect.EOF: |
| 1204 | main.log.error(self.name + ": EOF exception found") |
| 1205 | main.log.error(self.name + ": " + self.handle.before) |
| 1206 | main.cleanup() |
| 1207 | main.exit() |
| 1208 | except: |
| 1209 | main.log.info(self.name + " ::::::") |
| 1210 | main.log.error(traceback.print_exc()) |
| 1211 | main.log.info(self.name + " ::::::") |
| 1212 | main.cleanup() |
| 1213 | main.exit() |
| 1214 | |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1215 | def intents(self, json_format = True): |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1216 | ''' |
andrewonlab | 377693f | 2014-10-21 16:00:30 -0400 | [diff] [blame] | 1217 | Optional: |
| 1218 | * json_format: enable output formatting in json |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1219 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1220 | Obtain intents currently installed |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1221 | ''' |
| 1222 | try: |
andrewonlab | 377693f | 2014-10-21 16:00:30 -0400 | [diff] [blame] | 1223 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1224 | cmd_str = "intents -j" |
| 1225 | handle = self.sendline( cmd_str ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1226 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1227 | handle = ansi_escape.sub('', handle) |
andrewonlab | 377693f | 2014-10-21 16:00:30 -0400 | [diff] [blame] | 1228 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1229 | cmd_str = "intents" |
| 1230 | handle = self.sendline( cmd_str ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1231 | return handle |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1232 | except pexpect.EOF: |
| 1233 | main.log.error(self.name + ": EOF exception found") |
| 1234 | main.log.error(self.name + ": " + self.handle.before) |
| 1235 | main.cleanup() |
| 1236 | main.exit() |
| 1237 | except: |
| 1238 | main.log.info(self.name+" ::::::") |
| 1239 | main.log.error( traceback.print_exc()) |
| 1240 | main.log.info(self.name+" ::::::") |
| 1241 | main.cleanup() |
| 1242 | main.exit() |
| 1243 | |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1244 | def flows(self, json_format = True): |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1245 | ''' |
| 1246 | Optional: |
| 1247 | * json_format: enable output formatting in json |
| 1248 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1249 | Obtain flows currently installed |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1250 | ''' |
| 1251 | try: |
| 1252 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1253 | cmd_str = "flows -j" |
| 1254 | handle = self.sendline( cmd_str ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1255 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1256 | handle = ansi_escape.sub('', handle) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1257 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1258 | cmd_str = "flows" |
| 1259 | handle = self.sendline( cmd_str ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1260 | if re.search("Error\sexecuting\scommand:", handle): |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1261 | main.log.error( self.name + ".flows() response: " + |
| 1262 | str( handle ) ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1263 | return handle |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1264 | except pexpect.EOF: |
| 1265 | main.log.error(self.name + ": EOF exception found") |
| 1266 | main.log.error(self.name + ": " + self.handle.before) |
| 1267 | main.cleanup() |
| 1268 | main.exit() |
| 1269 | except: |
| 1270 | main.log.info(self.name+" ::::::") |
| 1271 | main.log.error( traceback.print_exc()) |
| 1272 | main.log.info(self.name+" ::::::") |
| 1273 | main.cleanup() |
| 1274 | main.exit() |
| 1275 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1276 | def push_test_intents(self, dpid_src, dpid_dst, num_intents, |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1277 | num_mult="", app_id="", report=True): |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1278 | ''' |
| 1279 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1280 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1281 | a specific point-to-point intent definition |
| 1282 | Required: |
| 1283 | * dpid_src: specify source dpid |
| 1284 | * dpid_dst: specify destination dpid |
| 1285 | * num_intents: specify number of intents to push |
| 1286 | Optional: |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1287 | * num_mult: number multiplier for multiplying |
| 1288 | the number of intents specified |
| 1289 | * app_id: specify the application id init to further |
| 1290 | modularize the intents |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1291 | * report: default True, returns latency information |
| 1292 | ''' |
| 1293 | try: |
| 1294 | cmd = "push-test-intents "+\ |
| 1295 | str(dpid_src)+" "+str(dpid_dst)+" "+\ |
| 1296 | str(num_intents) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1297 | if num_mult: |
| 1298 | cmd += " " + str(num_mult) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1299 | #If app id is specified, then num_mult |
andrewonlab | 042b391 | 2014-12-10 16:40:50 -0500 | [diff] [blame] | 1300 | #must exist because of the way this command |
| 1301 | #takes in arguments |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1302 | if app_id: |
| 1303 | cmd += " " + str(app_id) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1304 | handle = self.sendline( cmd ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1305 | #Some color thing that we want to escape |
| 1306 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1307 | handle = ansi_escape.sub('', handle) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1308 | if report: |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1309 | lat_result = [] |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1310 | main.log.info(handle) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1311 | #Split result by newline |
| 1312 | newline = handle.split("\r\r\n") |
| 1313 | #Ignore the first object of list, which is empty |
| 1314 | newline = newline[1:] |
| 1315 | #Some sloppy parsing method to get the latency |
| 1316 | for result in newline: |
| 1317 | result = result.split(": ") |
| 1318 | #Append the first result of second parse |
| 1319 | lat_result.append(result[1].split(" ")[0]) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1320 | main.log.info(lat_result) |
| 1321 | return lat_result |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1322 | else: |
| 1323 | return main.TRUE |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1324 | except pexpect.EOF: |
| 1325 | main.log.error(self.name + ": EOF exception found") |
| 1326 | main.log.error(self.name + ": " + self.handle.before) |
| 1327 | main.cleanup() |
| 1328 | main.exit() |
| 1329 | except: |
| 1330 | main.log.info(self.name+" ::::::") |
| 1331 | main.log.error( traceback.print_exc()) |
| 1332 | main.log.info(self.name+" ::::::") |
| 1333 | main.cleanup() |
| 1334 | main.exit() |
| 1335 | |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1336 | def intents_events_metrics(self, json_format=True): |
| 1337 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1338 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1339 | Optional: |
| 1340 | * json_format: enable json formatting of output |
| 1341 | ''' |
| 1342 | try: |
| 1343 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1344 | cmd_str = "intents-events-metrics -j" |
| 1345 | handle = self.sendline( cmd_str ) |
| 1346 | # Some color thing that we want to escape |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1347 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1348 | handle = ansi_escape.sub('', handle) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1349 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1350 | cmd_str = "intents-events-metrics" |
| 1351 | handle = self.sendline( cmd_str ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1352 | return handle |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1353 | except pexpect.EOF: |
| 1354 | main.log.error(self.name + ": EOF exception found") |
| 1355 | main.log.error(self.name + ": " + self.handle.before) |
| 1356 | main.cleanup() |
| 1357 | main.exit() |
| 1358 | except: |
| 1359 | main.log.info(self.name+" ::::::") |
| 1360 | main.log.error( traceback.print_exc()) |
| 1361 | main.log.info(self.name+" ::::::") |
| 1362 | main.cleanup() |
| 1363 | main.exit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1364 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1365 | def topology_events_metrics(self, json_format=True): |
| 1366 | ''' |
| 1367 | Description:Returns topology metrics |
| 1368 | Optional: |
| 1369 | * json_format: enable json formatting of output |
| 1370 | ''' |
| 1371 | try: |
| 1372 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1373 | cmd_str = "topology-events-metrics -j" |
| 1374 | handle = self.sendline( cmd_str ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1375 | #Some color thing that we want to escape |
| 1376 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1377 | handle = ansi_escape.sub('', handle) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1378 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1379 | cmd_str = "topology-events-metrics" |
| 1380 | handle = self.sendline( cmd_str ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1381 | return handle |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1382 | except pexpect.EOF: |
| 1383 | main.log.error(self.name + ": EOF exception found") |
| 1384 | main.log.error(self.name + ": " + self.handle.before) |
| 1385 | main.cleanup() |
| 1386 | main.exit() |
| 1387 | except: |
| 1388 | main.log.info(self.name+" ::::::") |
| 1389 | main.log.error( traceback.print_exc()) |
| 1390 | main.log.info(self.name+" ::::::") |
| 1391 | main.cleanup() |
| 1392 | main.exit() |
| 1393 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1394 | #Wrapper functions **************** |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1395 | #Wrapper functions use existing driver |
| 1396 | #functions and extends their use case. |
| 1397 | #For example, we may use the output of |
| 1398 | #a normal driver function, and parse it |
| 1399 | #using a wrapper function |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 1400 | |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1401 | def get_all_intents_id(self): |
| 1402 | ''' |
| 1403 | Description: |
| 1404 | Obtain all intent id's in a list |
| 1405 | ''' |
| 1406 | try: |
| 1407 | #Obtain output of intents function |
| 1408 | intents_str = self.intents() |
| 1409 | all_intent_list = [] |
| 1410 | intent_id_list = [] |
| 1411 | |
| 1412 | #Parse the intents output for ID's |
| 1413 | intents_list = [s.strip() for s in intents_str.splitlines()] |
| 1414 | for intents in intents_list: |
| 1415 | if "onos>" in intents: |
| 1416 | continue |
| 1417 | elif "intents" in intents: |
| 1418 | continue |
| 1419 | else: |
| 1420 | line_list = intents.split(" ") |
| 1421 | all_intent_list.append(line_list[0]) |
| 1422 | |
| 1423 | all_intent_list = all_intent_list[1:-2] |
| 1424 | |
| 1425 | for intents in all_intent_list: |
| 1426 | if not intents: |
| 1427 | continue |
| 1428 | else: |
| 1429 | intent_id_list.append(intents) |
| 1430 | |
| 1431 | return intent_id_list |
| 1432 | |
| 1433 | except pexpect.EOF: |
| 1434 | main.log.error(self.name + ": EOF exception found") |
| 1435 | main.log.error(self.name + ": " + self.handle.before) |
| 1436 | main.cleanup() |
| 1437 | main.exit() |
| 1438 | except: |
| 1439 | main.log.info(self.name+" ::::::") |
| 1440 | main.log.error( traceback.print_exc()) |
| 1441 | main.log.info(self.name+" ::::::") |
| 1442 | main.cleanup() |
| 1443 | main.exit() |
| 1444 | |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1445 | def get_all_devices_id(self): |
| 1446 | ''' |
| 1447 | Use 'devices' function to obtain list of all devices |
| 1448 | and parse the result to obtain a list of all device |
| 1449 | id's. Returns this list. Returns empty list if no |
| 1450 | devices exist |
| 1451 | List is ordered sequentially |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1452 | |
| 1453 | This function may be useful if you are not sure of the |
| 1454 | device id, and wish to execute other commands using |
| 1455 | the ids. By obtaining the list of device ids on the fly, |
| 1456 | you can iterate through the list to get mastership, etc. |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1457 | ''' |
| 1458 | try: |
| 1459 | #Call devices and store result string |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1460 | devices_str = self.devices(json_format=False) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1461 | id_list = [] |
| 1462 | |
| 1463 | if not devices_str: |
| 1464 | main.log.info("There are no devices to get id from") |
| 1465 | return id_list |
| 1466 | |
| 1467 | #Split the string into list by comma |
| 1468 | device_list = devices_str.split(",") |
| 1469 | #Get temporary list of all arguments with string 'id=' |
| 1470 | temp_list = [dev for dev in device_list if "id=" in dev] |
| 1471 | #Split list further into arguments before and after string |
| 1472 | # 'id='. Get the latter portion (the actual device id) and |
| 1473 | # append to id_list |
| 1474 | for arg in temp_list: |
| 1475 | id_list.append(arg.split("id=")[1]) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1476 | return id_list |
| 1477 | |
| 1478 | except pexpect.EOF: |
| 1479 | main.log.error(self.name + ": EOF exception found") |
| 1480 | main.log.error(self.name + ": " + self.handle.before) |
| 1481 | main.cleanup() |
| 1482 | main.exit() |
| 1483 | except: |
| 1484 | main.log.info(self.name+" ::::::") |
| 1485 | main.log.error( traceback.print_exc()) |
| 1486 | main.log.info(self.name+" ::::::") |
| 1487 | main.cleanup() |
| 1488 | main.exit() |
| 1489 | |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1490 | def get_all_nodes_id(self): |
| 1491 | ''' |
| 1492 | Uses 'nodes' function to obtain list of all nodes |
| 1493 | and parse the result of nodes to obtain just the |
| 1494 | node id's. |
| 1495 | Returns: |
| 1496 | list of node id's |
| 1497 | ''' |
| 1498 | try: |
| 1499 | nodes_str = self.nodes() |
| 1500 | id_list = [] |
| 1501 | |
| 1502 | if not nodes_str: |
| 1503 | main.log.info("There are no nodes to get id from") |
| 1504 | return id_list |
| 1505 | |
| 1506 | #Sample nodes_str output |
| 1507 | #id=local, address=127.0.0.1:9876, state=ACTIVE * |
| 1508 | |
| 1509 | #Split the string into list by comma |
| 1510 | nodes_list = nodes_str.split(",") |
| 1511 | temp_list = [node for node in nodes_list if "id=" in node] |
| 1512 | for arg in temp_list: |
| 1513 | id_list.append(arg.split("id=")[1]) |
| 1514 | |
| 1515 | return id_list |
| 1516 | |
| 1517 | except pexpect.EOF: |
| 1518 | main.log.error(self.name + ": EOF exception found") |
| 1519 | main.log.error(self.name + ": " + self.handle.before) |
| 1520 | main.cleanup() |
| 1521 | main.exit() |
| 1522 | except: |
| 1523 | main.log.info(self.name+" ::::::") |
| 1524 | main.log.error( traceback.print_exc()) |
| 1525 | main.log.info(self.name+" ::::::") |
| 1526 | main.cleanup() |
| 1527 | main.exit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1528 | |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1529 | def get_device(self, dpid=None): |
| 1530 | ''' |
| 1531 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 1532 | Return None if there is no match |
| 1533 | ''' |
| 1534 | import json |
| 1535 | try: |
| 1536 | if dpid == None: |
| 1537 | return None |
| 1538 | else: |
| 1539 | dpid = dpid.replace(':', '') |
| 1540 | raw_devices = self.devices() |
| 1541 | devices_json = json.loads(raw_devices) |
| 1542 | #search json for the device with dpid then return the device |
| 1543 | for device in devices_json: |
| 1544 | #print "%s in %s?" % (dpid, device['id']) |
| 1545 | if dpid in device['id']: |
| 1546 | return device |
| 1547 | return None |
| 1548 | except pexpect.EOF: |
| 1549 | main.log.error(self.name + ": EOF exception found") |
| 1550 | main.log.error(self.name + ": " + self.handle.before) |
| 1551 | main.cleanup() |
| 1552 | main.exit() |
| 1553 | except: |
| 1554 | main.log.info(self.name+" ::::::") |
| 1555 | main.log.error( traceback.print_exc()) |
| 1556 | main.log.info(self.name+" ::::::") |
| 1557 | main.cleanup() |
| 1558 | main.exit() |
| 1559 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1560 | def check_status(self, ip, numoswitch, numolink, log_level="info"): |
| 1561 | ''' |
| 1562 | Checks the number of swithes & links that ONOS sees against the |
| 1563 | supplied values. By default this will report to main.log, but the |
| 1564 | log level can be specifid. |
| 1565 | |
| 1566 | Params: ip = ip used for the onos cli |
| 1567 | numoswitch = expected number of switches |
| 1568 | numlink = expected number of links |
| 1569 | log_level = level to log to. Currently accepts 'info', 'warn' and 'report' |
| 1570 | |
| 1571 | |
| 1572 | log_level can |
| 1573 | |
| 1574 | Returns: main.TRUE if the number of switchs and links are correct, |
| 1575 | main.FALSE if the numer of switches and links is incorrect, |
| 1576 | and main.ERROR otherwise |
| 1577 | ''' |
| 1578 | |
| 1579 | try: |
| 1580 | topology = self.get_topology(ip) |
| 1581 | if topology == {}: |
| 1582 | return main.ERROR |
| 1583 | output = "" |
| 1584 | #Is the number of switches is what we expected |
| 1585 | devices = topology.get('devices',False) |
| 1586 | links = topology.get('links',False) |
| 1587 | if devices == False or links == False: |
| 1588 | return main.ERROR |
| 1589 | switch_check = ( int(devices) == int(numoswitch) ) |
| 1590 | #Is the number of links is what we expected |
| 1591 | link_check = ( int(links) == int(numolink) ) |
| 1592 | if (switch_check and link_check): |
| 1593 | #We expected the correct numbers |
| 1594 | output = output + "The number of links and switches match "\ |
| 1595 | + "what was expected" |
| 1596 | result = main.TRUE |
| 1597 | else: |
| 1598 | output = output + \ |
| 1599 | "The number of links and switches does not match what was expected" |
| 1600 | result = main.FALSE |
| 1601 | output = output + "\n ONOS sees %i devices (%i expected) and %i links (%i expected)"\ |
| 1602 | % ( int(devices), int(numoswitch), int(links), int(numolink) ) |
| 1603 | if log_level == "report": |
| 1604 | main.log.report(output) |
| 1605 | elif log_level == "warn": |
| 1606 | main.log.warn(output) |
| 1607 | else: |
| 1608 | main.log.info(output) |
| 1609 | return result |
| 1610 | except pexpect.EOF: |
| 1611 | main.log.error(self.name + ": EOF exception found") |
| 1612 | main.log.error(self.name + ": " + self.handle.before) |
| 1613 | main.cleanup() |
| 1614 | main.exit() |
| 1615 | except: |
| 1616 | main.log.info(self.name+" ::::::") |
| 1617 | main.log.error( traceback.print_exc()) |
| 1618 | main.log.info(self.name+" ::::::") |
| 1619 | main.cleanup() |
| 1620 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1621 | |
| 1622 | def device_role(self, device_id, onos_node, role="master"): |
| 1623 | ''' |
| 1624 | Calls the device-role cli command. |
| 1625 | device_id must be the id of a device as seen in the onos devices command |
| 1626 | onos_node is the ip of one of the onos nodes in the cluster |
| 1627 | role must be either master, standby, or none |
| 1628 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1629 | Returns: |
| 1630 | main.TRUE or main.FALSE based on argument verification and |
| 1631 | main.ERROR if command returns and error |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1632 | ''' |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1633 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1634 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1635 | role.lower() == "none": |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1636 | cmd_str = "device-role " +\ |
| 1637 | str(device_id) + " " +\ |
| 1638 | str(onos_node) + " " +\ |
| 1639 | str(role) |
| 1640 | handle = self.sendline( cmd_str ) |
| 1641 | if re.search( "Error", handle ): |
| 1642 | # end color output to escape any colours |
| 1643 | # from the cli |
| 1644 | main.log.error( self.name + ": " +\ |
| 1645 | handle + '\033[0m' ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1646 | return main.ERROR |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1647 | return main.TRUE |
| 1648 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1649 | main.log.error("Invalid 'role' given to device_role(). " + |
| 1650 | "Value was '" + str( role ) + "'.") |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1651 | return main.FALSE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1652 | except pexpect.EOF: |
| 1653 | main.log.error(self.name + ": EOF exception found") |
| 1654 | main.log.error(self.name + ": " + self.handle.before) |
| 1655 | main.cleanup() |
| 1656 | main.exit() |
| 1657 | except: |
| 1658 | main.log.info(self.name+" ::::::") |
| 1659 | main.log.error( traceback.print_exc()) |
| 1660 | main.log.info(self.name+" ::::::") |
| 1661 | main.cleanup() |
| 1662 | main.exit() |
| 1663 | |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1664 | def clusters(self, json_format=True): |
| 1665 | ''' |
| 1666 | Lists all clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1667 | Optional argument: |
| 1668 | * json_format - boolean indicating if you want output in json |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1669 | ''' |
| 1670 | try: |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1671 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1672 | cmd_str = "clusters -j" |
| 1673 | handle = self.sendline( cmd_str ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1674 | ''' |
| 1675 | handle variable here contains some ANSI escape color code |
| 1676 | sequences at the end which are invisible in the print command |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1677 | output. To make that escape sequence visible, use repr() |
| 1678 | function. The repr(handle) output when printed shows the ANSI |
| 1679 | escape sequences. In json.loads(somestring), this somestring |
| 1680 | variable is actually repr(somestring) and json.loads would fail |
| 1681 | with the escape sequence. So we take off that escape sequence |
| 1682 | using: |
| 1683 | |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1684 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1685 | handle1 = ansi_escape.sub('', handle) |
| 1686 | ''' |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1687 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1688 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1689 | return handle1 |
| 1690 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1691 | cmd_str = "clusters" |
| 1692 | handle = self.sendline( cmd_str ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1693 | return handle |
| 1694 | except pexpect.EOF: |
| 1695 | main.log.error(self.name + ": EOF exception found") |
| 1696 | main.log.error(self.name + ": " + self.handle.before) |
| 1697 | main.cleanup() |
| 1698 | main.exit() |
| 1699 | except: |
| 1700 | main.log.info(self.name+" ::::::") |
| 1701 | main.log.error( traceback.print_exc()) |
| 1702 | main.log.info(self.name+" ::::::") |
| 1703 | main.cleanup() |
| 1704 | main.exit() |
| 1705 | |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1706 | def election_test_leader(self): |
| 1707 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1708 | CLI command to get the current leader for the Election test application |
| 1709 | NOTE: Requires installation of the onos-app-election feature |
| 1710 | Returns: Node IP of the leader if one exists |
| 1711 | None if none exists |
| 1712 | Main.FALSE on error |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1713 | ''' |
| 1714 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1715 | cmd_str = "election-test-leader" |
| 1716 | response = self.sendline( cmd_str ) |
| 1717 | # Leader |
| 1718 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
| 1719 | "app\sis\s(?P<node>.+)\." |
| 1720 | node_search = re.search(leaderPattern, response) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1721 | if node_search: |
| 1722 | node = node_search.group('node') |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1723 | main.log.info( "Election-test-leader on " + str( self.name ) + |
| 1724 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1725 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1726 | # no leader |
| 1727 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
| 1728 | "the\sElection\sapp" |
| 1729 | null_search = re.search(nullPattern, response) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1730 | if null_search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1731 | main.log.info( "Election-test-leader found no leader on " + |
| 1732 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1733 | return None |
| 1734 | #error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1735 | errorPattern = "Command\snot\sfound" |
| 1736 | if re.search(errorPattern, response): |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1737 | main.log.error("Election app is not loaded on " + self.name) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1738 | # TODO: Should this be main.ERROR? |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1739 | return main.FALSE |
| 1740 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1741 | main.log.error("Error in election_test_leader: " + |
| 1742 | "unexpected response") |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1743 | main.log.error( repr(response) ) |
| 1744 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1745 | except pexpect.EOF: |
| 1746 | main.log.error(self.name + ": EOF exception found") |
| 1747 | main.log.error(self.name + ": " + self.handle.before) |
| 1748 | main.cleanup() |
| 1749 | main.exit() |
| 1750 | except: |
| 1751 | main.log.info(self.name+" ::::::") |
| 1752 | main.log.error( traceback.print_exc()) |
| 1753 | main.log.info(self.name+" ::::::") |
| 1754 | main.cleanup() |
| 1755 | main.exit() |
| 1756 | |
| 1757 | def election_test_run(self): |
| 1758 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1759 | CLI command to run for leadership of the Election test application. |
| 1760 | NOTE: Requires installation of the onos-app-election feature |
| 1761 | Returns: Main.TRUE on success |
| 1762 | Main.FALSE on error |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1763 | ''' |
| 1764 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1765 | cmd_str = "election-test-run" |
| 1766 | response = self.sendline( cmd_str ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1767 | #success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1768 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
| 1769 | "Election\sapp." |
| 1770 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1771 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1772 | main.log.info( self.name + " entering leadership elections " + |
| 1773 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1774 | return main.TRUE |
| 1775 | #error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1776 | errorPattern = "Command\snot\sfound" |
| 1777 | if re.search( errorPattern, response ): |
| 1778 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1779 | return main.FALSE |
| 1780 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1781 | main.log.error( "Error in election_test_run: " + |
| 1782 | "unexpected response" ) |
| 1783 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1784 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1785 | except pexpect.EOF: |
| 1786 | main.log.error(self.name + ": EOF exception found") |
| 1787 | main.log.error(self.name + ": " + self.handle.before) |
| 1788 | main.cleanup() |
| 1789 | main.exit() |
| 1790 | except: |
| 1791 | main.log.info(self.name+" ::::::") |
| 1792 | main.log.error( traceback.print_exc()) |
| 1793 | main.log.info(self.name+" ::::::") |
| 1794 | main.cleanup() |
| 1795 | main.exit() |
| 1796 | |
| 1797 | def election_test_withdraw(self): |
| 1798 | ''' |
| 1799 | * CLI command to withdraw the local node from leadership election for |
| 1800 | * the Election test application. |
| 1801 | #NOTE: Requires installation of the onos-app-election feature |
| 1802 | Returns: Main.TRUE on success |
| 1803 | Main.FALSE on error |
| 1804 | ''' |
| 1805 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1806 | cmd_str = "election-test-withdraw" |
| 1807 | response = self.sendline( cmd_str ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1808 | #success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1809 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
| 1810 | "\sthe\sElection\sapp." |
| 1811 | if re.search( successPattern, response ): |
| 1812 | main.log.info( self.name + " withdrawing from leadership " + |
| 1813 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1814 | return main.TRUE |
| 1815 | #error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1816 | errorPattern = "Command\snot\sfound" |
| 1817 | if re.search( errorPattern, response ): |
| 1818 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1819 | return main.FALSE |
| 1820 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1821 | main.log.error( "Error in election_test_withdraw: " + |
| 1822 | "unexpected response" ) |
| 1823 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1824 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1825 | except pexpect.EOF: |
| 1826 | main.log.error(self.name + ": EOF exception found") |
| 1827 | main.log.error(self.name + ": " + self.handle.before) |
| 1828 | main.cleanup() |
| 1829 | main.exit() |
| 1830 | except: |
| 1831 | main.log.info(self.name+" ::::::") |
| 1832 | main.log.error( traceback.print_exc()) |
| 1833 | main.log.info(self.name+" ::::::") |
| 1834 | main.cleanup() |
| 1835 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1836 | |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1837 | #*********************************** |
Hari Krishna | 416c3ca | 2014-12-19 15:39:31 -0800 | [diff] [blame] | 1838 | def getDevicePortsEnabledCount(self,dpid): |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1839 | ''' |
| 1840 | Get the count of all enabled ports on a particular device/switch |
| 1841 | ''' |
| 1842 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1843 | dpid = str( dpid ) |
| 1844 | cmd_str = "onos:ports -e " + dpid + " | wc -l" |
| 1845 | output = self.sendline( cmd_str ) |
| 1846 | if re.search( "No such device", output ): |
| 1847 | main.log.error( "Error in getting ports" ) |
| 1848 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1849 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1850 | return output |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1851 | except pexpect.EOF: |
| 1852 | main.log.error(self.name + ": EOF exception found") |
| 1853 | main.log.error(self.name + ": " + self.handle.before) |
| 1854 | main.cleanup() |
| 1855 | main.exit() |
| 1856 | except: |
| 1857 | main.log.info(self.name+" ::::::") |
| 1858 | main.log.error( traceback.print_exc()) |
| 1859 | main.log.info(self.name+" ::::::") |
| 1860 | main.cleanup() |
| 1861 | main.exit() |
| 1862 | |
| 1863 | def getDeviceLinksActiveCount(self,dpid): |
| 1864 | ''' |
| 1865 | Get the count of all enabled ports on a particular device/switch |
| 1866 | ''' |
| 1867 | try: |
Hari Krishna | 2bbaa70 | 2014-12-19 14:46:12 -0800 | [diff] [blame] | 1868 | dpid = str(dpid) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1869 | cmd_str = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
| 1870 | output = self.sendline( cmd_str ) |
| 1871 | if re.search( "No such device", output ): |
| 1872 | main.log.error( "Error in getting ports ") |
| 1873 | return ( output, "Error ") |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1874 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1875 | return output |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1876 | except pexpect.EOF: |
| 1877 | main.log.error(self.name + ": EOF exception found") |
| 1878 | main.log.error(self.name + ": " + self.handle.before) |
| 1879 | main.cleanup() |
| 1880 | main.exit() |
| 1881 | except: |
| 1882 | main.log.info(self.name+" ::::::") |
| 1883 | main.log.error( traceback.print_exc()) |
| 1884 | main.log.info(self.name+" ::::::") |
| 1885 | main.cleanup() |
| 1886 | main.exit() |
| 1887 | |
| 1888 | def getAllIntentIds(self): |
| 1889 | ''' |
| 1890 | Return a list of all Intent IDs |
| 1891 | ''' |
| 1892 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1893 | cmd_str = "onos:intents | grep id=" |
| 1894 | output = self.sendline( cmd_str ) |
| 1895 | if re.search( "Error", output ): |
| 1896 | main.log.error( "Error in getting ports" ) |
| 1897 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1898 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1899 | return output |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1900 | except pexpect.EOF: |
| 1901 | main.log.error(self.name + ": EOF exception found") |
| 1902 | main.log.error(self.name + ": " + self.handle.before) |
| 1903 | main.cleanup() |
| 1904 | main.exit() |
| 1905 | except: |
| 1906 | main.log.info(self.name+" ::::::") |
| 1907 | main.log.error( traceback.print_exc()) |
| 1908 | main.log.info(self.name+" ::::::") |
| 1909 | main.cleanup() |
| 1910 | main.exit() |