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( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 56 | userName=self.userName, |
| 57 | ipAddress=self.ipAddress, |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 58 | port=None, |
| 59 | pwd=self.pwd ) |
| 60 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 61 | self.sshHandle = 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 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 70 | print "handle = ", self.handle.before |
| 71 | |
| 72 | return main.TRUE |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 73 | else: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 74 | main.log.error( self.name + |
| 75 | ": Connection failed to the host " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 76 | self.userName + "@" + self.ipAddress ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 77 | main.log.error( self.name + |
| 78 | ": Failed to connect to Linc-OE" ) |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 79 | return main.FALSE |
| 80 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 81 | def startConsole( self ): |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 82 | import time |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 83 | main.log.info( |
| 84 | self.name + |
| 85 | ": Starting Linc-OE CLI.. This may take a while" ) |
| 86 | time.sleep( 30 ) |
| 87 | self.handle.sendline( "sudo ./rel/linc/bin/linc console" ) |
| 88 | j = self.handle.expect( [ "linc@", pexpect.EOF, pexpect.TIMEOUT ] ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 89 | startResult = self.handle.before |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 90 | if j == 0: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 91 | main.log.info( "Linc-OE CLI started" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 92 | return main.TRUE |
| 93 | else: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 94 | main.log.error( |
| 95 | self.name + |
| 96 | ": Connection failed to the host " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 97 | self.userName + |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 98 | "@" + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 99 | self.ipAddress ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 100 | main.log.error( self.name + |
| 101 | ": Failed to connect to Linc-OE" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 102 | return main.FALSE |
| 103 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 104 | def build( self ): |
| 105 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 106 | Build Linc-OE with the specified settings |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 107 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 108 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 109 | self.handle.sendline( "make rel" ) |
| 110 | i = self.handle.expect( [ |
andrewonlab | c6d1fa6 | 2014-10-22 16:28:04 -0400 | [diff] [blame] | 111 | "ERROR", |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 112 | "\$" ] ) |
andrewonlab | c6d1fa6 | 2014-10-22 16:28:04 -0400 | [diff] [blame] | 113 | |
| 114 | if i == 0: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 115 | self.handle.sendline( "sudo pkill -9 epmd" ) |
| 116 | self.handle.sendline( "make rel" ) |
| 117 | self.handle.expect( "\$" ) |
| 118 | |
andrewonlab | c6d1fa6 | 2014-10-22 16:28:04 -0400 | [diff] [blame] | 119 | handle = self.handle.before |
| 120 | return handle |
| 121 | |
| 122 | else: |
| 123 | return main.TRUE |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 124 | |
| 125 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 126 | main.log.error( self.name + ": EOF exception" ) |
| 127 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 128 | main.cleanup() |
| 129 | main.exit() |
| 130 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 131 | main.log.info( self.name + " :::::::" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 132 | main.log.error( traceback.printExc() ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 133 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 134 | main.cleanup() |
| 135 | main.exit() |
| 136 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 137 | def setInterfaceUp( self, intfs ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 138 | """ |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 139 | Specify interface to bring up. |
| 140 | When Linc-OE is started, tap interfaces should |
| 141 | be created. They must be brought up manually |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 142 | """ |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 143 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 144 | self.handle.sendline( "ifconfig " + str( intfs ) + " up" ) |
| 145 | self.handle.expect( "linc@" ) |
| 146 | |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 147 | handle = self.handle.before |
| 148 | |
| 149 | return handle |
| 150 | |
| 151 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 152 | main.log.error( self.name + ": EOF exception" ) |
| 153 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 154 | main.cleanup() |
| 155 | main.exit() |
| 156 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 157 | main.log.info( self.name + " :::::::" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 158 | main.log.error( traceback.printExc() ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 159 | main.log.info( self.name + " :::::::" ) |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 160 | main.cleanup() |
| 161 | main.exit() |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 162 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 163 | def startSwitch( self, swId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 164 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 165 | Start a logical switch using switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 166 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 167 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 168 | self.handle.sendline( "linc:start_switch(" + str( swId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 169 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 170 | |
| 171 | handle = self.handle.before |
| 172 | |
| 173 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 174 | main.log.error( self.name + ": EOF exception" ) |
| 175 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 176 | main.cleanup() |
| 177 | main.exit() |
| 178 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 179 | main.log.info( self.name + " :::::::" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 180 | main.log.error( traceback.printExc() ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 181 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 182 | main.cleanup() |
| 183 | main.exit() |
| 184 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 185 | def stopSwitch( self, swId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 186 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 187 | Stop a logical switch using switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 188 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 189 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 190 | self.handle.sendline( "linc:stop_switch(" + str( swId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 191 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 192 | |
| 193 | handle = self.handle.before |
| 194 | |
| 195 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 196 | main.log.error( self.name + ": EOF exception" ) |
| 197 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 198 | main.cleanup() |
| 199 | main.exit() |
| 200 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 201 | main.log.info( self.name + " :::::::" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 202 | main.log.error( traceback.printExc() ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 203 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 204 | main.cleanup() |
| 205 | main.exit() |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 206 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 207 | def getDatapathId( self, swId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 208 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 209 | Get datapath id of a specific switch by switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 210 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 211 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 212 | self.handle.sendline( "linc_logic:get_datapath_id(" + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 213 | str( swId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 214 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 215 | |
| 216 | handle = self.handle.before |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 217 | |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 218 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 219 | main.log.error( self.name + ": EOF exception" ) |
| 220 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 221 | main.cleanup() |
| 222 | main.exit() |
| 223 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 224 | main.log.info( self.name + " :::::::" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 225 | main.log.error( traceback.printExc() ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 226 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 227 | main.cleanup() |
| 228 | main.exit() |
| 229 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 230 | def listPorts( self, swId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 231 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 232 | List all ports of a switch by switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 233 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 234 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 235 | self.handle.sendline( "linc:ports(" + str( swId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 236 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 237 | |
| 238 | handle = self.handle.before |
| 239 | |
| 240 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 241 | main.log.error( self.name + ": EOF exception" ) |
| 242 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 243 | main.cleanup() |
| 244 | main.exit() |
| 245 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 246 | main.log.info( self.name + " :::::::" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 247 | main.log.error( traceback.printExc() ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 248 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 249 | main.cleanup() |
| 250 | main.exit() |
| 251 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 252 | def portUp( self, swId, ptId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 253 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 254 | Bring port up using switch id and port id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 255 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 256 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 257 | self.handle.sendline( "linc:port_up(" + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 258 | str( swId ) + ", " + str( ptId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 259 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 260 | |
| 261 | handle = self.handle.before |
| 262 | |
| 263 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 264 | main.log.error( self.name + ": EOF exception" ) |
| 265 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 266 | main.cleanup() |
| 267 | main.exit() |
| 268 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 269 | main.log.info( self.name + " :::::::" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 270 | main.log.error( traceback.printExc() ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 271 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 272 | main.cleanup() |
| 273 | main.exit() |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 274 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 275 | def portDown( self, swId, ptId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 276 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 277 | Bring port down using switch id and port id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 278 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 279 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 280 | self.handle.sendline( "linc:port_down(" + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 281 | str( swId ) + ", " + str( ptId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 282 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 283 | |
| 284 | handle = self.handle.before |
| 285 | |
| 286 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 287 | main.log.error( self.name + ": EOF exception" ) |
| 288 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 289 | main.cleanup() |
| 290 | main.exit() |
| 291 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 292 | main.log.info( self.name + " :::::::" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 293 | main.log.error( traceback.printExc() ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 294 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 295 | main.cleanup() |
| 296 | main.exit() |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 297 | |
| 298 | def stopLincOEConsole( self ): |
| 299 | """ |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 300 | This function is only used for packet optical testing |
| 301 | Send disconnect prompt to Linc-OE CLI |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 302 | ( CTRL+C ) and kill the linc process |
| 303 | """ |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 304 | try: |
| 305 | cmd = "pgrep -f linc" |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 306 | self.handle.sendline( "pgrep -f linc" ) |
| 307 | self.handle.expect( "linc" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 308 | print "stophandle = ", self.handle.before |
| 309 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 310 | main.log.error( self.name + ": EOF exception" ) |
| 311 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 312 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 313 | def disconnect( self ): |
| 314 | """ |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 315 | Send disconnect prompt to Linc-OE CLI |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 316 | ( CTRL+C ) and kill the linc process |
| 317 | """ |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 318 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 319 | # Send CTRL+C twice to exit CLI |
| 320 | self.handle.send( "\x03" ) |
| 321 | self.handle.send( "\x03" ) |
| 322 | self.handle.expect( "\$" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 323 | handle1 = self.handle.before |
| 324 | cmd = "pgrep -f linc" |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 325 | self.handle.sendline( cmd ) |
| 326 | self.handle.expect( "\$" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 327 | handle2 = self.handle.before |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 328 | main.log.info( "pid's = " + handle2 ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 329 | cmd = "sudo kill -9 `pgrep -f linc`" |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 330 | self.handle.sendline( cmd ) |
| 331 | self.handle.expect( "\$" ) |
| 332 | |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 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 | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 336 | main.cleanup() |
| 337 | main.exit() |
| 338 | except: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 339 | main.log.info( self.name + " :::::::" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 340 | main.log.error( traceback.printExc() ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 341 | main.log.info( self.name + " :::::::" ) |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 342 | main.cleanup() |
| 343 | main.exit() |
| 344 | |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 345 | if __name__ != "__main__": |
| 346 | import sys |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 347 | sys.modules[ __name__ ] = LincOEDriver() |