blob: 2b3b721d0971dea02fcba4758a82bb647be8c6f4 [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 Ronquillob27ce4c2017-07-17 12:41:28 -07004Copyright 2016 Open Networking Foundation (ONF)
5
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 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 ):
Devin Lim58046fa2017-07-05 16:55:00 -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:
alisone4121a92016-11-22 16:31:36 -0800133 main.log.info(
acsmars51a7fe02015-10-29 18:33:32 -0700134 self.name +
135 ": PACKET LOST, HOST IS NOT REACHABLE" )
136 main.lastResult = main.FALSE
137 return main.FALSE