acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | """ |
| 3 | |
| 4 | TestON is free software: you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation, either version 2 of the License, or |
| 7 | ( at your option ) any later version. |
| 8 | |
| 9 | TestON is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | |
| 18 | LincOEMininetDriver is an extension of the mininetclidriver to handle linc oe |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 19 | |
| 20 | Modified 2016 by ON.Lab |
| 21 | |
| 22 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 23 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 24 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 25 | """ |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 26 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 27 | import pexpect |
| 28 | import re |
| 29 | import sys |
| 30 | import os |
| 31 | from drivers.common.cli.emulator.mininetclidriver import MininetCliDriver |
| 32 | |
| 33 | |
| 34 | class LincOEMininetDriver( MininetCliDriver ): |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 35 | def runOpticalMnScript( self,onosDirectory = 'onos', ctrllerIP = None, topology = 'opticalTest' ): |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 36 | import time |
| 37 | import types |
| 38 | """ |
| 39 | Description: |
| 40 | This function is only meant for Packet Optical. |
| 41 | It runs python script "opticalTest.py" to create the |
| 42 | packet layer( mn ) and optical topology |
| 43 | Optional: |
| 44 | name - Name of onos directory. (ONOS | onos) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 45 | topology - Name of optical topology to activate, defaults to opticalTest.py |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 46 | Required: |
| 47 | ctrllerIP = Controller(s) IP address |
| 48 | TODO: If no ctrllerIP is provided, a default |
| 49 | $OC1 can be accepted |
| 50 | """ |
| 51 | try: |
| 52 | if ctrllerIP == None: |
| 53 | main.log.error( "You need to specify the IP" ) |
| 54 | return main.FALSE |
| 55 | else: |
| 56 | controller = '' |
| 57 | if isinstance( ctrllerIP, types.ListType ): |
| 58 | for i in xrange( len( ctrllerIP ) ): |
| 59 | controller += ctrllerIP[i] + ' ' |
| 60 | main.log.info( "Mininet topology is being loaded with " + |
| 61 | "controllers: " + controller ) |
| 62 | elif isinstance( ctrllerIP, types.StringType ): |
| 63 | controller = ctrllerIP |
| 64 | main.log.info( "Mininet topology is being loaded with " + |
| 65 | "controller: " + controller ) |
| 66 | else: |
| 67 | main.log.info( "You need to specify a valid IP" ) |
| 68 | return main.FALSE |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 69 | topoFile = "~/{0}/tools/test/topos/{1}.py".format( onosDirectory, topology ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 70 | cmd = "sudo -E python {0} {1}".format( topoFile, controller ) |
| 71 | main.log.info( self.name + ": cmd = " + cmd ) |
| 72 | self.handle.sendline( cmd ) |
| 73 | lincStart = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ],timeout=120 ) |
| 74 | if lincStart == 1: |
| 75 | self.handle.sendline( "\x03" ) |
| 76 | self.handle.sendline( "sudo mn -c" ) |
| 77 | self.handle.sendline( cmd ) |
| 78 | lincStart = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ],timeout=120 ) |
| 79 | if lincStart == 1: |
| 80 | main.log.error( "OpticalTest.py failed to start." ) |
| 81 | return main.FALSE |
| 82 | return main.TRUE |
| 83 | except pexpect.EOF: |
| 84 | main.log.error( self.name + ": EOF exception found" ) |
| 85 | main.log.error( self.name + ": " + self.handle.before ) |
| 86 | return main.FALSE |
Ming Yan Shu | 404f7e7 | 2016-07-22 14:37:03 -0700 | [diff] [blame] | 87 | except Exception: |
| 88 | main.log.exception(self.name + ": Uncaught exception!") |
| 89 | main.cleanup() |
| 90 | return main.FALSE |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 91 | |
| 92 | def pingHostOptical( self, **pingParams ): |
| 93 | """ |
| 94 | This function is only for Packet Optical related ping |
| 95 | Use the next pingHost() function for all normal scenarios ) |
| 96 | Ping from one mininet host to another |
| 97 | Currently the only supported Params: SRC and TARGET |
| 98 | """ |
| 99 | args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams ) |
| 100 | command = args[ "SRC" ] + " ping " + \ |
| 101 | args[ "TARGET" ] + " -c 1 -i 1 -W 8" |
| 102 | try: |
| 103 | main.log.warn( "Sending: " + command ) |
| 104 | self.handle.sendline( command ) |
| 105 | i = self.handle.expect( [ command, pexpect.TIMEOUT ] ) |
| 106 | if i == 1: |
| 107 | main.log.error( |
| 108 | self.name + |
| 109 | ": timeout when waiting for response from mininet" ) |
| 110 | main.log.error( "response: " + str( self.handle.before ) ) |
| 111 | i = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ] ) |
| 112 | if i == 1: |
| 113 | main.log.error( |
| 114 | self.name + |
| 115 | ": timeout when waiting for response from mininet" ) |
| 116 | main.log.error( "response: " + str( self.handle.before ) ) |
| 117 | response = self.handle.before |
| 118 | except pexpect.EOF: |
| 119 | main.log.error( self.name + ": EOF exception found" ) |
| 120 | main.log.error( self.name + ": " + self.handle.before ) |
| 121 | main.cleanup() |
| 122 | main.exit() |
Ming Yan Shu | 404f7e7 | 2016-07-22 14:37:03 -0700 | [diff] [blame] | 123 | except Exception: |
| 124 | main.log.exception(self.name + ": Uncaught exception!") |
| 125 | main.cleanup() |
| 126 | main.exit() |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 127 | main.log.info( self.name + ": Ping Response: " + response ) |
| 128 | if re.search( ',\s0\%\spacket\sloss', response ): |
| 129 | main.log.info( self.name + ": no packets lost, host is reachable" ) |
| 130 | main.lastResult = main.TRUE |
| 131 | return main.TRUE |
| 132 | else: |
| 133 | main.log.error( |
| 134 | self.name + |
| 135 | ": PACKET LOST, HOST IS NOT REACHABLE" ) |
| 136 | main.lastResult = main.FALSE |
| 137 | return main.FALSE |