admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 2 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 3 | Created on 26-Mar-2013 |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 4 | Modified 2015 by ON.Lab |
| 5 | |
| 6 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 7 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 8 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 9 | |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 10 | author:: Anil Kumar ( anilkumar.s@paxterrasolutions.com ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 11 | |
| 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-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 16 | ( at your option ) any later version. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 17 | |
| 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-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 24 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 25 | |
| 26 | |
| 27 | FlowVisorDriver is the basic driver which will handle the Mininet functions |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 28 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 29 | import re |
| 30 | import sys |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 31 | from drivers.common.cli.emulatordriver import Emulator |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 32 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 33 | |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 34 | class FlowVisorDriver( Emulator ): |
| 35 | |
| 36 | """ |
| 37 | FlowVisorDriver is the basic driver which will handle the Mininet functions |
| 38 | """ |
| 39 | def __init__( self ): |
| 40 | super( Emulator, self ).__init__() |
| 41 | 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. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 48 | for key in connectargs: |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 49 | 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 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 60 | self.ssh_handle = self.handle |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 61 | |
| 62 | # Copying the readme file to process the |
| 63 | if self.handle: |
| 64 | self.execute( cmd='\r', prompt='\$', timeout=10 ) |
| 65 | self.options[ 'path' ] = '/home/openflow/flowvisor/scripts/' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 66 | #self.handle.logfile = sys.stdout |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 67 | self.execute( |
| 68 | cmd='cd ' + |
| 69 | self.options[ 'path' ], |
| 70 | prompt='\$', |
| 71 | 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 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 79 | pattern = '\d+' |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 80 | |
| 81 | process_id_search = re.search( "\[\d+\]\s+(\d+)", str( response ) ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 82 | self.fvprocess_id = "None" |
| 83 | if process_id_search: |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 84 | 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 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 93 | #import time |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 94 | # time.sleep( 10 ) |
| 95 | #response = self.execute( cmd='./start_visualizer.sh & \r',prompt='\$',timeout=10 ) |
| 96 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 97 | return main.TRUE |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 98 | 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" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 105 | return main.FALSE |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 106 | |
| 107 | def removeFlowSpace( self, id ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 108 | if id == "all": |
| 109 | flow_space = self.listFlowSpace() |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 110 | flow_ids = re.findall( "\,id=\[(\d+)\]", flow_space ) |
| 111 | for id in flow_ids: |
| 112 | self.removeFlowSpace( id ) |
| 113 | else: |
| 114 | self.execute( cmd="clear", prompt="\$", timeout=10 ) |
| 115 | self.execute( |
| 116 | cmd="./fvctl.sh removeFlowSpace " + |
| 117 | id, |
| 118 | prompt="passwd:", |
| 119 | timeout=10 ) |
| 120 | self.execute( cmd="\n", prompt="\$", timeout=10 ) |
| 121 | main.log.info( "Removed flowSpace which is having id :" + id ) |
| 122 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 123 | return main.TRUE |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 124 | |
| 125 | def addFlowSpace( self, **flowspace_args ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 126 | temp_string = None |
| 127 | for key in flowspace_args: |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 128 | if temp_string: |
| 129 | temp_string = temp_string + ',' + \ |
| 130 | key + '=' + flowspace_args[ key ] |
| 131 | else: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 132 | temp_string = '' |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 133 | 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 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 144 | 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 Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 147 | except Exception: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 148 | try : |
| 149 | if self.nw_src and self.tp_dst: |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 150 | flowspace = "any 100 dl_type=0x800,nw_proto=6,nw_src="+self.nw_src+",tp_dst="+self.tp_dst+" Slice:"+self.Slice+"=4" |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 151 | except Exception: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 152 | 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 Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 155 | except Exception: |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 156 | main.log.error( "Please specify flowspace properly" ) |
| 157 | """ |
| 158 | # self.execute( cmd="clear",prompt="\$",timeout=10 ) |
| 159 | self.execute( |
| 160 | cmd="./fvctl.sh addFlowSpace " + |
| 161 | flowspace, |
| 162 | prompt="passwd:", |
| 163 | timeout=10 ) |
| 164 | self.execute( cmd="\n", prompt="\$", timeout=10 ) |
| 165 | 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 ) ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 170 | return main.TRUE |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 171 | else: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 172 | return main.FALSE |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 173 | |
| 174 | def listFlowSpace( self ): |
| 175 | self.execute( cmd="clear", prompt="\$", timeout=10 ) |
| 176 | self.execute( |
| 177 | cmd="./fvctl.sh listFlowSpace ", |
| 178 | prompt="passwd:", |
| 179 | timeout=10 ) |
| 180 | self.execute( cmd="\n", prompt="\$", timeout=10 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 181 | flow_space = main.last_response |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 182 | 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 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 191 | return flow_space |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 192 | |
| 193 | def listDevices( self ): |
| 194 | # self.execute( cmd="clear",prompt="\$",timeout=10 ) |
| 195 | #self.execute( cmd="./fvctl.sh listDevices ",prompt="passwd:",timeout=10 ) |
| 196 | # self.execute( cmd="\n",prompt="\$",timeout=10 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 197 | devices_list = '' |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 198 | 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 ) ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 206 | if devices_match: |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 207 | devices_list = devices_list + devices_match.group( 0 ) + "\n" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 208 | devices_list = "Device 0: 00:00:00:00:00:00:00:02 \n Device 1: 00:00:00:00:00:00:00:03" |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 209 | main.log.info( "List of Devices \n" + devices_list ) |
| 210 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 211 | return main.TRUE |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 212 | |
| 213 | def disconnect( self ): |
| 214 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 215 | response = '' |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 216 | main.log.info( "Stopping the FlowVisor" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 217 | if self.handle: |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 218 | self.handle.sendline( "kill -9 " + str( self.fvprocess_id ) ) |
| 219 | else: |
| 220 | main.log.error( "Connection failed to the host" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 221 | response = main.FALSE |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 222 | return response |