blob: 7dfcb1e2168d7fc55101646222ccfdaf0511a5a0 [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
19"""
20import pexpect
21import re
22import sys
23import os
24from drivers.common.cli.emulator.mininetclidriver import MininetCliDriver
25
26
27class LincOEMininetDriver( MininetCliDriver ):
Jeremy Songster5665f1b2016-06-20 14:38:22 -070028 def runOpticalMnScript( self,onosDirectory = 'onos', ctrllerIP = None, topology = 'opticalTest' ):
acsmars51a7fe02015-10-29 18:33:32 -070029 import time
30 import types
31 """
32 Description:
33 This function is only meant for Packet Optical.
34 It runs python script "opticalTest.py" to create the
35 packet layer( mn ) and optical topology
36 Optional:
37 name - Name of onos directory. (ONOS | onos)
Jeremy Songster5665f1b2016-06-20 14:38:22 -070038 topology - Name of optical topology to activate, defaults to opticalTest.py
acsmars51a7fe02015-10-29 18:33:32 -070039 Required:
40 ctrllerIP = Controller(s) IP address
41 TODO: If no ctrllerIP is provided, a default
42 $OC1 can be accepted
43 """
44 try:
45 if ctrllerIP == None:
46 main.log.error( "You need to specify the IP" )
47 return main.FALSE
48 else:
49 controller = ''
50 if isinstance( ctrllerIP, types.ListType ):
51 for i in xrange( len( ctrllerIP ) ):
52 controller += ctrllerIP[i] + ' '
53 main.log.info( "Mininet topology is being loaded with " +
54 "controllers: " + controller )
55 elif isinstance( ctrllerIP, types.StringType ):
56 controller = ctrllerIP
57 main.log.info( "Mininet topology is being loaded with " +
58 "controller: " + controller )
59 else:
60 main.log.info( "You need to specify a valid IP" )
61 return main.FALSE
Jeremy Songster5665f1b2016-06-20 14:38:22 -070062 topoFile = "~/{0}/tools/test/topos/{1}.py".format( onosDirectory, topology )
acsmars51a7fe02015-10-29 18:33:32 -070063 cmd = "sudo -E python {0} {1}".format( topoFile, controller )
64 main.log.info( self.name + ": cmd = " + cmd )
65 self.handle.sendline( cmd )
66 lincStart = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ],timeout=120 )
67 if lincStart == 1:
68 self.handle.sendline( "\x03" )
69 self.handle.sendline( "sudo mn -c" )
70 self.handle.sendline( cmd )
71 lincStart = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ],timeout=120 )
72 if lincStart == 1:
73 main.log.error( "OpticalTest.py failed to start." )
74 return main.FALSE
75 return main.TRUE
76 except pexpect.EOF:
77 main.log.error( self.name + ": EOF exception found" )
78 main.log.error( self.name + ": " + self.handle.before )
79 return main.FALSE
80
81 def pingHostOptical( self, **pingParams ):
82 """
83 This function is only for Packet Optical related ping
84 Use the next pingHost() function for all normal scenarios )
85 Ping from one mininet host to another
86 Currently the only supported Params: SRC and TARGET
87 """
88 args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams )
89 command = args[ "SRC" ] + " ping " + \
90 args[ "TARGET" ] + " -c 1 -i 1 -W 8"
91 try:
92 main.log.warn( "Sending: " + command )
93 self.handle.sendline( command )
94 i = self.handle.expect( [ command, pexpect.TIMEOUT ] )
95 if i == 1:
96 main.log.error(
97 self.name +
98 ": timeout when waiting for response from mininet" )
99 main.log.error( "response: " + str( self.handle.before ) )
100 i = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ] )
101 if i == 1:
102 main.log.error(
103 self.name +
104 ": timeout when waiting for response from mininet" )
105 main.log.error( "response: " + str( self.handle.before ) )
106 response = self.handle.before
107 except pexpect.EOF:
108 main.log.error( self.name + ": EOF exception found" )
109 main.log.error( self.name + ": " + self.handle.before )
110 main.cleanup()
111 main.exit()
112 main.log.info( self.name + ": Ping Response: " + response )
113 if re.search( ',\s0\%\spacket\sloss', response ):
114 main.log.info( self.name + ": no packets lost, host is reachable" )
115 main.lastResult = main.TRUE
116 return main.TRUE
117 else:
118 main.log.error(
119 self.name +
120 ": PACKET LOST, HOST IS NOT REACHABLE" )
121 main.lastResult = main.FALSE
122 return main.FALSE