andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 3 | """ |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 4 | This driver handles the optical switch emulator linc-oe. |
| 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 | andrew@onlab.us |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 13 | shreya@onlab.us |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 14 | |
| 15 | OCT 20 2014 |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 16 | """ |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 17 | import traceback |
| 18 | import pexpect |
| 19 | import struct |
| 20 | import fcntl |
| 21 | import os |
| 22 | import signal |
| 23 | import re |
| 24 | import sys |
| 25 | import core.teston |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 26 | import time |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 27 | sys.path.append( "../" ) |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 28 | from math import pow |
| 29 | from drivers.common.cli.emulatordriver import Emulator |
| 30 | from drivers.common.clidriver import CLI |
| 31 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 32 | |
| 33 | class LincOEDriver( Emulator ): |
| 34 | |
| 35 | """ |
| 36 | LincOEDriver class will handle all emulator functions |
| 37 | """ |
| 38 | def __init__( self ): |
| 39 | super( Emulator, self ).__init__() |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 40 | self.handle = self |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 41 | self.wrapped = sys.modules[ __name__ ] |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 42 | self.flag = 0 |
| 43 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 44 | def connect( self, **connectargs ): |
| 45 | """ |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 46 | Create ssh handle for Linc-OE cli |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 47 | """ |
andrewonlab | a85a776 | 2014-10-22 18:05:52 -0400 | [diff] [blame] | 48 | import time |
| 49 | |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 50 | for key in connectargs: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 51 | vars( self )[ key ] = connectargs[ key ] |
| 52 | |
| 53 | self.name = self.options[ 'name' ] |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 54 | self.handle = \ |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 55 | super( LincOEDriver, self ).connect( |
| 56 | user_name=self.user_name, |
| 57 | ip_address=self.ip_address, |
| 58 | port=None, |
| 59 | pwd=self.pwd ) |
| 60 | |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 61 | self.ssh_handle = self.handle |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 62 | |
| 63 | if self.handle: |
| 64 | main.log.info( "Handle successfully created" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 65 | self.home = "~/linc-oe" |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 66 | |
| 67 | self.handle.sendline( "cd " + self.home ) |
| 68 | self.handle.expect( "oe$" ) |
| 69 | |
| 70 | #self.handle.sendline( "pgrep -g linc" ) |
| 71 | # self.handle.expect( "\$" ) |
| 72 | print "handle = ", self.handle.before |
| 73 | |
| 74 | return main.TRUE |
| 75 | """ |
| 76 | main.log.info( "Building Linc-OE" ) |
| 77 | self.handle.sendline( "make rel" ) |
| 78 | i = self.handle.expect( [ "ERROR","linc-oe\$" ],timeout=60 ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 79 | if i == 0: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 80 | self.handle.sendline( "sudo pkill -9 epmd" ) |
| 81 | self.handle.expect( "\$" ) |
| 82 | self.handle.sendline( "make rel" ) |
| 83 | x = self.handle.expect( [ "\$",pexpect.EOF,pexpect.TIMEOUT ] ) |
| 84 | main.log.info( "make rel returned: "+ str( x ) ) |
| 85 | else: |
| 86 | |
| 87 | main.log.info( self.name+": Starting Linc-OE CLI.. This may take a while" ) |
| 88 | time.sleep( 30 ) |
| 89 | self.handle.sendline( "sudo ./rel/linc/bin/linc console" ) |
| 90 | j = self.handle.expect( [ "linc@",pexpect.EOF,pexpect.TIMEOUT ] ) |
andrewonlab | a85a776 | 2014-10-22 18:05:52 -0400 | [diff] [blame] | 91 | if j == 0: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 92 | main.log.info( "Linc-OE CLI started" ) |
andrewonlab | a85a776 | 2014-10-22 18:05:52 -0400 | [diff] [blame] | 93 | return main.TRUE |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 94 | """ |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 95 | else: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 96 | main.log.error( self.name + |
| 97 | ": Connection failed to the host " + |
| 98 | self.user_name + "@" + self.ip_address ) |
| 99 | main.log.error( self.name + |
| 100 | ": Failed to connect to Linc-OE" ) |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 101 | return main.FALSE |
| 102 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 103 | def start_console( self ): |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 104 | import time |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 105 | main.log.info( |
| 106 | self.name + |
| 107 | ": Starting Linc-OE CLI.. This may take a while" ) |
| 108 | time.sleep( 30 ) |
| 109 | self.handle.sendline( "sudo ./rel/linc/bin/linc console" ) |
| 110 | j = self.handle.expect( [ "linc@", pexpect.EOF, pexpect.TIMEOUT ] ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 111 | start_result = self.handle.before |
| 112 | if j == 0: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 113 | main.log.info( "Linc-OE CLI started" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 114 | return main.TRUE |
| 115 | else: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 116 | main.log.error( |
| 117 | self.name + |
| 118 | ": Connection failed to the host " + |
| 119 | self.user_name + |
| 120 | "@" + |
| 121 | self.ip_address ) |
| 122 | main.log.error( self.name + |
| 123 | ": Failed to connect to Linc-OE" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 124 | return main.FALSE |
| 125 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 126 | def build( self ): |
| 127 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 128 | Build Linc-OE with the specified settings |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 129 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 130 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 131 | self.handle.sendline( "make rel" ) |
| 132 | i = self.handle.expect( [ |
andrewonlab | c6d1fa6 | 2014-10-22 16:28:04 -0400 | [diff] [blame] | 133 | "ERROR", |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 134 | "\$" ] ) |
andrewonlab | c6d1fa6 | 2014-10-22 16:28:04 -0400 | [diff] [blame] | 135 | |
| 136 | if i == 0: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 137 | # If error, try to resolve the most common error |
| 138 | #( epmd running and cannot compile ) |
| 139 | self.handle.sendline( "sudo pkill -9 epmd" ) |
| 140 | self.handle.sendline( "make rel" ) |
| 141 | self.handle.expect( "\$" ) |
| 142 | |
andrewonlab | c6d1fa6 | 2014-10-22 16:28:04 -0400 | [diff] [blame] | 143 | handle = self.handle.before |
| 144 | return handle |
| 145 | |
| 146 | else: |
| 147 | return main.TRUE |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 148 | |
| 149 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 150 | main.log.error( self.name + ": EOF exception" ) |
| 151 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 152 | main.cleanup() |
| 153 | main.exit() |
| 154 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 155 | main.log.info( self.name + " :::::::" ) |
| 156 | main.log.error( traceback.print_exc() ) |
| 157 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 158 | main.cleanup() |
| 159 | main.exit() |
| 160 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 161 | def set_interface_up( self, intfs ): |
| 162 | """ |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 163 | Specify interface to bring up. |
| 164 | When Linc-OE is started, tap interfaces should |
| 165 | be created. They must be brought up manually |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 166 | """ |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 167 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 168 | self.handle.sendline( "ifconfig " + str( intfs ) + " up" ) |
| 169 | self.handle.expect( "linc@" ) |
| 170 | |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 171 | handle = self.handle.before |
| 172 | |
| 173 | return handle |
| 174 | |
| 175 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 176 | main.log.error( self.name + ": EOF exception" ) |
| 177 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 178 | main.cleanup() |
| 179 | main.exit() |
| 180 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 181 | main.log.info( self.name + " :::::::" ) |
| 182 | main.log.error( traceback.print_exc() ) |
| 183 | main.log.info( self.name + " :::::::" ) |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 184 | main.cleanup() |
| 185 | main.exit() |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 186 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 187 | def start_switch( self, sw_id ): |
| 188 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 189 | Start a logical switch using switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 190 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 191 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 192 | self.handle.sendline( "linc:start_switch(" + str( sw_id ) + ")." ) |
| 193 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 194 | |
| 195 | handle = self.handle.before |
| 196 | |
| 197 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 198 | main.log.error( self.name + ": EOF exception" ) |
| 199 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 200 | main.cleanup() |
| 201 | main.exit() |
| 202 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 203 | main.log.info( self.name + " :::::::" ) |
| 204 | main.log.error( traceback.print_exc() ) |
| 205 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 206 | main.cleanup() |
| 207 | main.exit() |
| 208 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 209 | def stop_switch( self, sw_id ): |
| 210 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 211 | Stop a logical switch using switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 212 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 213 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 214 | self.handle.sendline( "linc:stop_switch(" + str( sw_id ) + ")." ) |
| 215 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 216 | |
| 217 | handle = self.handle.before |
| 218 | |
| 219 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 220 | main.log.error( self.name + ": EOF exception" ) |
| 221 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 222 | main.cleanup() |
| 223 | main.exit() |
| 224 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 225 | main.log.info( self.name + " :::::::" ) |
| 226 | main.log.error( traceback.print_exc() ) |
| 227 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 228 | main.cleanup() |
| 229 | main.exit() |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 230 | |
| 231 | def get_datapath_id( self, sw_id ): |
| 232 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 233 | Get datapath id of a specific switch by switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 234 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 235 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 236 | self.handle.sendline( "linc_logic:get_datapath_id(" + |
| 237 | str( sw_id ) + ")." ) |
| 238 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 239 | |
| 240 | handle = self.handle.before |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 241 | |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 242 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 243 | main.log.error( self.name + ": EOF exception" ) |
| 244 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 245 | main.cleanup() |
| 246 | main.exit() |
| 247 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 248 | main.log.info( self.name + " :::::::" ) |
| 249 | main.log.error( traceback.print_exc() ) |
| 250 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 251 | main.cleanup() |
| 252 | main.exit() |
| 253 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 254 | def list_ports( self, sw_id ): |
| 255 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 256 | List all ports of a switch by switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 257 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 258 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 259 | self.handle.sendline( "linc:ports(" + str( sw_id ) + ")." ) |
| 260 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 261 | |
| 262 | handle = self.handle.before |
| 263 | |
| 264 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 265 | main.log.error( self.name + ": EOF exception" ) |
| 266 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 267 | main.cleanup() |
| 268 | main.exit() |
| 269 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 270 | main.log.info( self.name + " :::::::" ) |
| 271 | main.log.error( traceback.print_exc() ) |
| 272 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 273 | main.cleanup() |
| 274 | main.exit() |
| 275 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 276 | def port_up( self, sw_id, pt_id ): |
| 277 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 278 | Bring port up using switch id and port id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 279 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 280 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 281 | self.handle.sendline( "linc:port_up(" + |
| 282 | str( sw_id ) + ", " + str( pt_id ) + ")." ) |
| 283 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 284 | |
| 285 | handle = self.handle.before |
| 286 | |
| 287 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 288 | main.log.error( self.name + ": EOF exception" ) |
| 289 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 290 | main.cleanup() |
| 291 | main.exit() |
| 292 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 293 | main.log.info( self.name + " :::::::" ) |
| 294 | main.log.error( traceback.print_exc() ) |
| 295 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 296 | main.cleanup() |
| 297 | main.exit() |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 298 | |
| 299 | def port_down( self, sw_id, pt_id ): |
| 300 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 301 | Bring port down using switch id and port id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 302 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 303 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 304 | self.handle.sendline( "linc:port_down(" + |
| 305 | str( sw_id ) + ", " + str( pt_id ) + ")." ) |
| 306 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 307 | |
| 308 | handle = self.handle.before |
| 309 | |
| 310 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 311 | main.log.error( self.name + ": EOF exception" ) |
| 312 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 313 | main.cleanup() |
| 314 | main.exit() |
| 315 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 316 | main.log.info( self.name + " :::::::" ) |
| 317 | main.log.error( traceback.print_exc() ) |
| 318 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 319 | main.cleanup() |
| 320 | main.exit() |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 321 | |
| 322 | def stopLincOEConsole( self ): |
| 323 | """ |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 324 | This function is only used for packet optical testing |
| 325 | Send disconnect prompt to Linc-OE CLI |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 326 | ( CTRL+C ) and kill the linc process |
| 327 | """ |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 328 | try: |
| 329 | cmd = "pgrep -f linc" |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 330 | self.handle.sendline( "pgrep -f linc" ) |
| 331 | self.handle.expect( "linc" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 332 | print "stophandle = ", self.handle.before |
| 333 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 334 | main.log.error( self.name + ": EOF exception" ) |
| 335 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 336 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 337 | def disconnect( self ): |
| 338 | """ |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 339 | Send disconnect prompt to Linc-OE CLI |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 340 | ( CTRL+C ) and kill the linc process |
| 341 | """ |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 342 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 343 | # Send CTRL+C twice to exit CLI |
| 344 | self.handle.send( "\x03" ) |
| 345 | self.handle.send( "\x03" ) |
| 346 | self.handle.expect( "\$" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 347 | handle1 = self.handle.before |
| 348 | cmd = "pgrep -f linc" |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 349 | self.handle.sendline( cmd ) |
| 350 | self.handle.expect( "\$" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 351 | handle2 = self.handle.before |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 352 | main.log.info( "pid's = " + handle2 ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 353 | cmd = "sudo kill -9 `pgrep -f linc`" |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 354 | self.handle.sendline( cmd ) |
| 355 | self.handle.expect( "\$" ) |
| 356 | |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 357 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 358 | main.log.error( self.name + ": EOF exception" ) |
| 359 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 360 | main.cleanup() |
| 361 | main.exit() |
| 362 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 363 | main.log.info( self.name + " :::::::" ) |
| 364 | main.log.error( traceback.print_exc() ) |
| 365 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 366 | main.cleanup() |
| 367 | main.exit() |
| 368 | |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 369 | if __name__ != "__main__": |
| 370 | import sys |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 371 | sys.modules[ __name__ ] = LincOEDriver() |