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