blob: 9372a545614b3105de75a3aa190bb1c0729f6750 [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 ):
28 def runOpticalMnScript( self,onosDirectory = 'onos', ctrllerIP = None ):
29 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)
38 Required:
39 ctrllerIP = Controller(s) IP address
40 TODO: If no ctrllerIP is provided, a default
41 $OC1 can be accepted
42 """
43 try:
44 if ctrllerIP == None:
45 main.log.error( "You need to specify the IP" )
46 return main.FALSE
47 else:
48 controller = ''
49 if isinstance( ctrllerIP, types.ListType ):
50 for i in xrange( len( ctrllerIP ) ):
51 controller += ctrllerIP[i] + ' '
52 main.log.info( "Mininet topology is being loaded with " +
53 "controllers: " + controller )
54 elif isinstance( ctrllerIP, types.StringType ):
55 controller = ctrllerIP
56 main.log.info( "Mininet topology is being loaded with " +
57 "controller: " + controller )
58 else:
59 main.log.info( "You need to specify a valid IP" )
60 return main.FALSE
61 topoFile = "~/{0}/tools/test/topos/opticalTest.py".format( onosDirectory )
62 cmd = "sudo -E python {0} {1}".format( topoFile, controller )
63 main.log.info( self.name + ": cmd = " + cmd )
64 self.handle.sendline( cmd )
65 lincStart = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ],timeout=120 )
66 if lincStart == 1:
67 self.handle.sendline( "\x03" )
68 self.handle.sendline( "sudo mn -c" )
69 self.handle.sendline( cmd )
70 lincStart = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ],timeout=120 )
71 if lincStart == 1:
72 main.log.error( "OpticalTest.py failed to start." )
73 return main.FALSE
74 return main.TRUE
75 except pexpect.EOF:
76 main.log.error( self.name + ": EOF exception found" )
77 main.log.error( self.name + ": " + self.handle.before )
78 return main.FALSE
79
80 def pingHostOptical( self, **pingParams ):
81 """
82 This function is only for Packet Optical related ping
83 Use the next pingHost() function for all normal scenarios )
84 Ping from one mininet host to another
85 Currently the only supported Params: SRC and TARGET
86 """
87 args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams )
88 command = args[ "SRC" ] + " ping " + \
89 args[ "TARGET" ] + " -c 1 -i 1 -W 8"
90 try:
91 main.log.warn( "Sending: " + command )
92 self.handle.sendline( command )
93 i = self.handle.expect( [ command, pexpect.TIMEOUT ] )
94 if i == 1:
95 main.log.error(
96 self.name +
97 ": timeout when waiting for response from mininet" )
98 main.log.error( "response: " + str( self.handle.before ) )
99 i = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ] )
100 if i == 1:
101 main.log.error(
102 self.name +
103 ": timeout when waiting for response from mininet" )
104 main.log.error( "response: " + str( self.handle.before ) )
105 response = self.handle.before
106 except pexpect.EOF:
107 main.log.error( self.name + ": EOF exception found" )
108 main.log.error( self.name + ": " + self.handle.before )
109 main.cleanup()
110 main.exit()
111 main.log.info( self.name + ": Ping Response: " + response )
112 if re.search( ',\s0\%\spacket\sloss', response ):
113 main.log.info( self.name + ": no packets lost, host is reachable" )
114 main.lastResult = main.TRUE
115 return main.TRUE
116 else:
117 main.log.error(
118 self.name +
119 ": PACKET LOST, HOST IS NOT REACHABLE" )
120 main.lastResult = main.FALSE
121 return main.FALSE