blob: bcdbf339f6f0d7d33776b9ac157e072eacc93420 [file] [log] [blame]
acsmars51a7fe02015-10-29 18:33:32 -07001#!/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
18LincOEMininetDriver is an extension of the mininetclidriver to handle linc oe
Jeremy Songsterae01bba2016-07-11 15:39:17 -070019
20Modified 2016 by ON.Lab
21
22Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
23the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
24or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
acsmars51a7fe02015-10-29 18:33:32 -070025"""
Jeremy Songsterae01bba2016-07-11 15:39:17 -070026
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 Songster5665f1b2016-06-20 14:38:22 -070035 def runOpticalMnScript( self,onosDirectory = 'onos', ctrllerIP = None, topology = 'opticalTest' ):
acsmars51a7fe02015-10-29 18:33:32 -070036 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 Songster5665f1b2016-06-20 14:38:22 -070045 topology - Name of optical topology to activate, defaults to opticalTest.py
acsmars51a7fe02015-10-29 18:33:32 -070046 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 Songster5665f1b2016-06-20 14:38:22 -070069 topoFile = "~/{0}/tools/test/topos/{1}.py".format( onosDirectory, topology )
acsmars51a7fe02015-10-29 18:33:32 -070070 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 Shu404f7e72016-07-22 14:37:03 -070087 except Exception:
88 main.log.exception(self.name + ": Uncaught exception!")
89 main.cleanup()
90 return main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -070091
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 Shu404f7e72016-07-22 14:37:03 -0700123 except Exception:
124 main.log.exception(self.name + ": Uncaught exception!")
125 main.cleanup()
126 main.exit()
acsmars51a7fe02015-10-29 18:33:32 -0700127 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