blob: 5839e188bcbb3ea31ff2b5c9ef1f8bf3e3524dea [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
kelvin-onlabb87672e2015-01-16 10:58:34 -08002"""
adminbae64d82013-08-01 10:50:15 -07003Created on 26-Mar-2013
Jeremy Songsterae01bba2016-07-11 15:39:17 -07004Modified 2015 by ON.Lab
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>
adminbae64d82013-08-01 10:50:15 -07009
kelvin-onlabb87672e2015-01-16 10:58:34 -080010author:: Anil Kumar ( anilkumar.s@paxterrasolutions.com )
adminbae64d82013-08-01 10:50:15 -070011
12
13 TestON is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 2 of the License, or
kelvin-onlabb87672e2015-01-16 10:58:34 -080016 ( at your option ) any later version.
adminbae64d82013-08-01 10:50:15 -070017
18 TestON is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
kelvin-onlabb87672e2015-01-16 10:58:34 -080024 along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070025
26
27FlowVisorDriver is the basic driver which will handle the Mininet functions
kelvin-onlabb87672e2015-01-16 10:58:34 -080028"""
adminbae64d82013-08-01 10:50:15 -070029import re
30import sys
adminbae64d82013-08-01 10:50:15 -070031from drivers.common.cli.emulatordriver import Emulator
adminbae64d82013-08-01 10:50:15 -070032
adminbae64d82013-08-01 10:50:15 -070033
kelvin-onlabb87672e2015-01-16 10:58:34 -080034class FlowVisorDriver( Emulator ):
35
36 """
37 FlowVisorDriver is the basic driver which will handle the Mininet functions
38 """
39 def __init__( self ):
Devin Limdc78e202017-06-09 18:30:07 -070040 super( FlowVisorDriver, self ).__init__()
kelvin-onlabb87672e2015-01-16 10:58:34 -080041 self.handle = self
42 self.wrapped = sys.modules[ __name__ ]
43
44 def connect( self, **connectargs ):
45 #,user_name, ip_address, pwd,options ):
46 # Here the main is the TestON instance after creating all the log
47 # handles.
adminbae64d82013-08-01 10:50:15 -070048 for key in connectargs:
kelvin-onlabb87672e2015-01-16 10:58:34 -080049 vars( self )[ key ] = connectargs[ key ]
50
51 self.name = self.options[ 'name' ]
52 self.handle = super(
53 FlowVisorDriver,
54 self ).connect(
55 user_name=self.user_name,
56 ip_address=self.ip_address,
57 port=None,
58 pwd=self.pwd )
59
adminbae64d82013-08-01 10:50:15 -070060 self.ssh_handle = self.handle
kelvin-onlabb87672e2015-01-16 10:58:34 -080061
62 # Copying the readme file to process the
63 if self.handle:
Devin Limdc78e202017-06-09 18:30:07 -070064 self.execute( cmd='\r', prompt=self.prompt, timeout=10 )
kelvin-onlabb87672e2015-01-16 10:58:34 -080065 self.options[ 'path' ] = '/home/openflow/flowvisor/scripts/'
adminbae64d82013-08-01 10:50:15 -070066 #self.handle.logfile = sys.stdout
kelvin-onlabb87672e2015-01-16 10:58:34 -080067 self.execute(
68 cmd='cd ' +
69 self.options[ 'path' ],
Devin Limdc78e202017-06-09 18:30:07 -070070 prompt=self.prompt,
kelvin-onlabb87672e2015-01-16 10:58:34 -080071 timeout=10 )
72 main.log.info( "Starting FlowVisor " )
73
74 response = self.execute(
75 cmd='./flowvisor.sh &',
76 prompt='---\sSetting\slogging\slevel\sto\sNOTE',
77 timeout=10 )
78
adminbae64d82013-08-01 10:50:15 -070079 pattern = '\d+'
kelvin-onlabb87672e2015-01-16 10:58:34 -080080
81 process_id_search = re.search( "\[\d+\]\s+(\d+)", str( response ) )
adminbae64d82013-08-01 10:50:15 -070082 self.fvprocess_id = "None"
83 if process_id_search:
kelvin-onlabb87672e2015-01-16 10:58:34 -080084 self.fvprocess_id = process_id_search.group( 1 )
85
86 utilities.assert_matches(
87 expect=pattern,
88 actual=response,
89 onpass="FlowVisor Started Successfully : Proceess Id :" +
90 self.fvprocess_id,
91 onfail="Failed to start FlowVisor" )
92 main.log.info( response )
adminbae64d82013-08-01 10:50:15 -070093 #import time
kelvin-onlabb87672e2015-01-16 10:58:34 -080094 # time.sleep( 10 )
Devin Limdc78e202017-06-09 18:30:07 -070095 #response = self.execute( cmd='./start_visualizer.sh & \r',prompt=self.prompt,timeout=10 )
kelvin-onlabb87672e2015-01-16 10:58:34 -080096
adminbae64d82013-08-01 10:50:15 -070097 return main.TRUE
kelvin-onlabb87672e2015-01-16 10:58:34 -080098 else:
99 main.log.error(
100 "Connection failed to the host " +
101 self.user_name +
102 "@" +
103 self.ip_address )
104 main.log.error( "Failed to connect to the FlowVisor" )
adminbae64d82013-08-01 10:50:15 -0700105 return main.FALSE
kelvin-onlabb87672e2015-01-16 10:58:34 -0800106
107 def removeFlowSpace( self, id ):
adminbae64d82013-08-01 10:50:15 -0700108 if id == "all":
109 flow_space = self.listFlowSpace()
kelvin-onlabb87672e2015-01-16 10:58:34 -0800110 flow_ids = re.findall( "\,id=\[(\d+)\]", flow_space )
111 for id in flow_ids:
112 self.removeFlowSpace( id )
113 else:
Devin Limdc78e202017-06-09 18:30:07 -0700114 self.execute( cmd="clear", prompt=self.prompt, timeout=10 )
kelvin-onlabb87672e2015-01-16 10:58:34 -0800115 self.execute(
116 cmd="./fvctl.sh removeFlowSpace " +
117 id,
118 prompt="passwd:",
119 timeout=10 )
Devin Limdc78e202017-06-09 18:30:07 -0700120 self.execute( cmd="\n", prompt=self.prompt, timeout=10 )
kelvin-onlabb87672e2015-01-16 10:58:34 -0800121 main.log.info( "Removed flowSpace which is having id :" + id )
122
adminbae64d82013-08-01 10:50:15 -0700123 return main.TRUE
kelvin-onlabb87672e2015-01-16 10:58:34 -0800124
125 def addFlowSpace( self, **flowspace_args ):
adminbae64d82013-08-01 10:50:15 -0700126 temp_string = None
127 for key in flowspace_args:
kelvin-onlabb87672e2015-01-16 10:58:34 -0800128 if temp_string:
129 temp_string = temp_string + ',' + \
130 key + '=' + flowspace_args[ key ]
131 else:
adminbae64d82013-08-01 10:50:15 -0700132 temp_string = ''
kelvin-onlabb87672e2015-01-16 10:58:34 -0800133 temp_string = temp_string + key + '=' + flowspace_args[ key ]
134
135 src_search = re.search( 'dl_src', temp_string )
136 if src_search:
137 flowspace = "any 100 dl_type=0x806,nw_proto=6," + \
138 temp_string + " Slice:SSH=4"
139 else:
140 flowspace = "any 100 dl_type=0x800,nw_proto=6," + \
141 temp_string + " Slice:SSH=4"
142
143 """
adminbae64d82013-08-01 10:50:15 -0700144 try :
145 if self.dl_src and self.nw_dst:
146 flowspace = "any 100 dl_type=0x806,dl_src="+self.dl_src+",nw_dst="+self.nw_dst+" Slice:"+self.Slice+"=4"
Jon Hallfebb1c72015-03-05 13:30:09 -0800147 except Exception:
adminbae64d82013-08-01 10:50:15 -0700148 try :
149 if self.nw_src and self.tp_dst:
kelvin-onlabb87672e2015-01-16 10:58:34 -0800150 flowspace = "any 100 dl_type=0x800,nw_proto=6,nw_src="+self.nw_src+",tp_dst="+self.tp_dst+" Slice:"+self.Slice+"=4"
Jon Hallfebb1c72015-03-05 13:30:09 -0800151 except Exception:
adminbae64d82013-08-01 10:50:15 -0700152 try :
153 if self.nw_src and self.tp_src:
154 flowspace = "any 100 dl_type=0x800,nw_proto=6,nw_src="+self.nw_src+",tp_src="+self.tp_dst+" Slice:"+self.Slice+"=4"
Jon Hallfebb1c72015-03-05 13:30:09 -0800155 except Exception:
kelvin-onlabb87672e2015-01-16 10:58:34 -0800156 main.log.error( "Please specify flowspace properly" )
157 """
Devin Limdc78e202017-06-09 18:30:07 -0700158 # self.execute( cmd="clear",prompt=self.prompt,timeout=10 )
kelvin-onlabb87672e2015-01-16 10:58:34 -0800159 self.execute(
160 cmd="./fvctl.sh addFlowSpace " +
161 flowspace,
162 prompt="passwd:",
163 timeout=10 )
Devin Limdc78e202017-06-09 18:30:07 -0700164 self.execute( cmd="\n", prompt=self.prompt, timeout=10 )
kelvin-onlabb87672e2015-01-16 10:58:34 -0800165 sucess_match = re.search( "success\:\s+(\d+)", main.last_response )
166 if sucess_match:
167 main.log.info(
168 "Added flow Space and id is " +
169 sucess_match.group( 1 ) )
adminbae64d82013-08-01 10:50:15 -0700170 return main.TRUE
kelvin-onlabb87672e2015-01-16 10:58:34 -0800171 else:
adminbae64d82013-08-01 10:50:15 -0700172 return main.FALSE
kelvin-onlabb87672e2015-01-16 10:58:34 -0800173
174 def listFlowSpace( self ):
Devin Limdc78e202017-06-09 18:30:07 -0700175 self.execute( cmd="clear", prompt=self.prompt, timeout=10 )
kelvin-onlabb87672e2015-01-16 10:58:34 -0800176 self.execute(
177 cmd="./fvctl.sh listFlowSpace ",
178 prompt="passwd:",
179 timeout=10 )
Devin Limdc78e202017-06-09 18:30:07 -0700180 self.execute( cmd="\n", prompt=self.prompt, timeout=10 )
adminbae64d82013-08-01 10:50:15 -0700181 flow_space = main.last_response
kelvin-onlabb87672e2015-01-16 10:58:34 -0800182 flow_space = self.remove_contol_chars( flow_space )
183 flow_space = re.sub(
184 "rule\s(\d+)\:",
185 "\nrule " +
186 r'\1' +
187 ":",
188 flow_space )
189 main.log.info( flow_space )
190
adminbae64d82013-08-01 10:50:15 -0700191 return flow_space
kelvin-onlabb87672e2015-01-16 10:58:34 -0800192
193 def listDevices( self ):
Devin Limdc78e202017-06-09 18:30:07 -0700194 # self.execute( cmd="clear",prompt=self.prompt,timeout=10 )
kelvin-onlabb87672e2015-01-16 10:58:34 -0800195 #self.execute( cmd="./fvctl.sh listDevices ",prompt="passwd:",timeout=10 )
Devin Limdc78e202017-06-09 18:30:07 -0700196 # self.execute( cmd="\n",prompt=self.prompt,timeout=10 )
adminbae64d82013-08-01 10:50:15 -0700197 devices_list = ''
kelvin-onlabb87672e2015-01-16 10:58:34 -0800198 last_response = re.findall(
199 "(Device\s\d+\:\s((\d|[a-z])(\d|[a-z])\:)+(\d|[a-z])(\d|[a-z]))",
200 main.last_response )
201
202 for resp in last_response:
203 devices_match = re.search(
204 "(Device\s\d+\:\s((\d|[a-z])(\d|[a-z])\:)+(\d|[a-z])(\d|[a-z]))",
205 str( resp ) )
adminbae64d82013-08-01 10:50:15 -0700206 if devices_match:
kelvin-onlabb87672e2015-01-16 10:58:34 -0800207 devices_list = devices_list + devices_match.group( 0 ) + "\n"
adminbae64d82013-08-01 10:50:15 -0700208 devices_list = "Device 0: 00:00:00:00:00:00:00:02 \n Device 1: 00:00:00:00:00:00:00:03"
kelvin-onlabb87672e2015-01-16 10:58:34 -0800209 main.log.info( "List of Devices \n" + devices_list )
210
adminbae64d82013-08-01 10:50:15 -0700211 return main.TRUE
kelvin-onlabb87672e2015-01-16 10:58:34 -0800212
213 def disconnect( self ):
214
adminbae64d82013-08-01 10:50:15 -0700215 response = ''
kelvin-onlabb87672e2015-01-16 10:58:34 -0800216 main.log.info( "Stopping the FlowVisor" )
adminbae64d82013-08-01 10:50:15 -0700217 if self.handle:
kelvin-onlabb87672e2015-01-16 10:58:34 -0800218 self.handle.sendline( "kill -9 " + str( self.fvprocess_id ) )
219 else:
220 main.log.error( "Connection failed to the host" )
adminbae64d82013-08-01 10:50:15 -0700221 response = main.FALSE
kelvin-onlabb87672e2015-01-16 10:58:34 -0800222 return response