blob: ba54a75a3d4806f713cf3fbbc4217a2acc07f684 [file] [log] [blame]
acsmars51a7fe02015-10-29 18:33:32 -07001#!/usr/bin/env python
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002
acsmars51a7fe02015-10-29 18:33:32 -07003"""
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004Copyright 2016 Open Networking Foundation (ONF)
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07005
6Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
7the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
8or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
acsmars51a7fe02015-10-29 18:33:32 -07009
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
24LincOEMininetDriver is an extension of the mininetclidriver to handle linc oe
25"""
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000026
acsmars51a7fe02015-10-29 18:33:32 -070027import pexpect
28import re
29import sys
30import os
31from drivers.common.cli.emulator.mininetclidriver import MininetCliDriver
32
33
34class LincOEMininetDriver( MininetCliDriver ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -070035
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000036 def runOpticalMnScript( self, onosDirectory = 'onos', ctrllerIP = None, topology = 'opticalTest' ):
acsmars51a7fe02015-10-29 18:33:32 -070037 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 Ronquillo4d5f1d02017-10-13 20:23:57 +000045 name - Name of onos directory. (ONOS | onos)
Jeremy Songster5665f1b2016-06-20 14:38:22 -070046 topology - Name of optical topology to activate, defaults to opticalTest.py
acsmars51a7fe02015-10-29 18:33:32 -070047 Required:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000048 ctrllerIP = Controller(s) IP address
acsmars51a7fe02015-10-29 18:33:32 -070049 TODO: If no ctrllerIP is provided, a default
50 $OC1 can be accepted
51 """
52 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -070053 if ctrllerIP is None:
acsmars51a7fe02015-10-29 18:33:32 -070054 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 Ronquillo82705492017-10-18 14:19:55 -070060 controller += ctrllerIP[ i ] + ' '
acsmars51a7fe02015-10-29 18:33:32 -070061 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 Songster5665f1b2016-06-20 14:38:22 -070070 topoFile = "~/{0}/tools/test/topos/{1}.py".format( onosDirectory, topology )
acsmars51a7fe02015-10-29 18:33:32 -070071 cmd = "sudo -E python {0} {1}".format( topoFile, controller )
72 main.log.info( self.name + ": cmd = " + cmd )
73 self.handle.sendline( cmd )
Jeremy Ronquillo82705492017-10-18 14:19:55 -070074 lincStart = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ], timeout=120 )
acsmars51a7fe02015-10-29 18:33:32 -070075 if lincStart == 1:
Jon Hall2c5ac942018-03-23 11:26:54 -070076 self.handle.send( "\x03" )
acsmars51a7fe02015-10-29 18:33:32 -070077 self.handle.sendline( "sudo mn -c" )
78 self.handle.sendline( cmd )
Jeremy Ronquillo82705492017-10-18 14:19:55 -070079 lincStart = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ], timeout=120 )
acsmars51a7fe02015-10-29 18:33:32 -070080 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 Shu404f7e72016-07-22 14:37:03 -070088 except Exception:
Jeremy Ronquillo82705492017-10-18 14:19:55 -070089 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -070090 main.cleanAndExit()
Ming Yan Shu404f7e72016-07-22 14:37:03 -070091 return main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -070092
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 Lim44075962017-08-11 10:56:37 -0700122 main.cleanAndExit()
Ming Yan Shu404f7e72016-07-22 14:37:03 -0700123 except Exception:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700124 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700125 main.cleanAndExit()
acsmars51a7fe02015-10-29 18:33:32 -0700126 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:
alisone4121a92016-11-22 16:31:36 -0800132 main.log.info(
acsmars51a7fe02015-10-29 18:33:32 -0700133 self.name +
134 ": PACKET LOST, HOST IS NOT REACHABLE" )
135 main.lastResult = main.FALSE
136 return main.FALSE