4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openvim
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
25 #author Alfonso Tierno
27 #script to test openflow connector with the creation of rules
31 echo -e "usage: ${BASH_SOURCE[0]} [OPTIONS] \n test openflow connector "
33 echo -e " -f --force does not prompt for confirmation"
34 echo -e " -v --same-vlan use this if the parameter 'of_controller_nets_with_same_vlan'"
35 echo -e " is not false at openvimd.cfg to avoid test unrealizable openflow nets"
36 echo -e " -d --debug show debug information at each command. It is quite verbose"
37 echo -e " -h --help shows this help"
41 function delete_and_exit
(){
43 [[ $force != y
]] && read -e -p " Press enter to delete the deployed things " kk
47 if [[ $f == restore
]]
49 printf "%-50s" "restoring back old rules: "
50 result
=`openflow install ./test_openflow_old_rules.bk $debug `
53 echo "FAIL cannot install old rules:"
56 rm .
/test_openflow_old_rules.bk
57 echo OK
"./test_openflow_old_rules.bk deleted"
60 printf "%-50s" "removing $f rule: "
61 result
=`openflow delete $f -f $debug`
62 [[ $?
!= 0 ]] && echo "FAIL cannot delete" && echo "$result" ||
echo OK
72 #detect if is called with a source to use the 'exit'/'return' command for exiting
73 [[ ${BASH_SOURCE[0]} != $0 ]] && echo "Do not execute this script as SOURCE" >&2 && return 1
75 #check correct arguments
78 if [[ $param == -h ]] ||
[[ $param == --help ]]
82 elif [[ $param == -d ]] ||
[[ $param == --debug ]]
85 elif [[ $param == -v ]] ||
[[ $param == --same-vlan ]]
88 elif [[ $param == -f ]] ||
[[ $param == --force ]]
92 echo "invalid argument '$param'?. See $0 --help" && exit 1
96 #detect if environment variables are set
98 [[ -z $OF_CONTROLLER_TYPE ]] && echo "OF_CONTROLLER_TYPE not defined" >&2 && fail
=1
99 [[ -z $OF_CONTROLLER_IP ]] && echo "OF_CONTROLLER_IP not defined" >&2 && fail
=1
100 [[ -z $OF_CONTROLLER_PORT ]] && echo "OF_CONTROLLER_PORT not defined" >&2 && fail
=1
101 [[ -z $OF_CONTROLLER_DPID ]] && echo "OF_CONTROLLER_DPID not defined" >&2 && fail
=1
102 [[ -n $fail ]] && exit 1
105 export _exit
=delete_and_exit
108 echo " This will remove temporally the existing openflow rules and restored back a the end"
109 read -e -p "Press enter to continue, CTRL+C to abort " kk
113 printf "%-50s" "obtain port list: "
114 result
=`openflow port-list $debug | gawk '/^ /{print substr($1,0,length($1)-1)}'`
115 [[ $?
!= 0 ]] && echo "FAIL" && echo "$result" && $_exit 1
116 ports
=`echo $result | wc -w`
117 [[ $ports -lt 4 ]] && echo "FAIL not enough ports managed by this DPID, needed at least 4" && $_exit 1
119 port0
=`echo $result | cut -d" " -f1`
120 port1
=`echo $result | cut -d" " -f2`
121 port2
=`echo $result | cut -d" " -f3`
122 port3
=`echo $result | cut -d" " -f4`
125 printf "%-50s" "saving the current rules: "
126 openflow list
$debug > .
/test_openflow_old_rules.bk
127 [[ $?
!= 0 ]] && echo "FAIL cannot obtain existing rules" && $_exit 1
128 echo OK
"> ./test_openflow_old_rules.bk"
130 printf "%-50s" "clearing all current rules: "
131 openflow
clear -f $debug
132 [[ $?
!= 0 ]] && echo "FAIL cannot clear existing rules" && $_exit 1
133 result
=`openflow list | wc -l`
134 [[ $result != 1 ]] && echo "FAIL rules not completely cleared" && $_exit 1
138 printf "%-50s" "clearing again all rules: "
139 openflow
clear -f $debug
140 [[ $?
!= 0 ]] && echo "FAIL when there are not any rules" && $_exit 1
141 result
=`openflow list | wc -l`
142 [[ $result != 1 ]] && echo "FAIL rules not completely cleared" && $_exit 1
147 printf "%-50s" "new rule vlan,mac -> no vlan: "
148 rule_name
=fromVlanMac_to_NoVlan1
149 openflow add
$rule_name --priority 1000 --matchmac "aa:bb:cc:dd:ee:ff" --matchvlan 500 --inport $port0 --stripvlan --out $port1 $debug
150 [[ $?
!= 0 ]] && echo "FAIL cannot insert new rule" && $_exit 1
151 expected
="$OF_CONTROLLER_DPID 1000 $rule_name $port0 aa:bb:cc:dd:ee:ff 500 vlan=None,out=$port1"
152 result
=`openflow list | grep $rule_name`
153 [[ $?
!= 0 ]] && echo "FAIL rule bad inserted" && $_exit 1
154 result
=`echo $result` #remove blanks
155 [[ "$result" != "$expected" ]] && echo "FAIL" && echo " expected: $expected\n obtained: $result" && $_exit 1
157 TODELETE
="$rule_name $TODELETE"
159 printf "%-50s" "new rule mac -> vlan: "
160 rule_name
=fromMac_to_Vlan2
161 openflow add
$rule_name --priority 1001 --matchmac "ff:ff:ff:ff:ff:ff" --inport $port1 --setvlan 501 --out $port2 --out $port3 $debug
162 [[ $?
!= 0 ]] && echo "FAIL cannot insert new rule" && $_exit 1
163 expected
="$OF_CONTROLLER_DPID 1001 $rule_name $port1 ff:ff:ff:ff:ff:ff any vlan=501,out=$port2,out=$port3"
164 result
=`openflow list | grep $rule_name`
165 [[ $?
!= 0 ]] && echo "FAIL rule bad inserted" && $_exit 1
166 result
=`echo $result` #remove blanks
167 [[ "$result" != "$expected" ]] && echo "FAIL" && echo " expected: $expected\n obtained: $result" && $_exit 1
169 TODELETE
="$rule_name $TODELETE"
171 printf "%-50s" "new rule None -> None: "
172 rule_name
=fromNone_to_None
173 openflow add
$rule_name --priority 1002 --inport $port2 --out $port0 $debug
174 [[ $?
!= 0 ]] && echo "FAIL cannot insert new rule" && $_exit 1
175 expected
="$OF_CONTROLLER_DPID 1002 $rule_name $port2 any any out=$port0"
176 result
=`openflow list | grep $rule_name`
177 [[ $?
!= 0 ]] && echo "FAIL rule bad inserted" && $_exit 1
178 result
=`echo $result` #remove blanks
179 [[ "$result" != "$expected" ]] && echo "FAIL" && echo " expected: $expected\n obtained: $result" && $_exit 1
181 TODELETE
="$rule_name $TODELETE"
183 printf "%-50s" "new rule vlan -> vlan: "
184 rule_name
=fromVlan_to_Vlan1
185 openflow add
$rule_name --priority 1003 --matchvlan 504 --inport $port3 --setvlan 505 --out $port0 $debug
186 [[ $?
!= 0 ]] && echo "FAIL cannot insert new rule" && $_exit 1
187 expected
="$OF_CONTROLLER_DPID 1003 $rule_name $port3 any 504 vlan=505,out=$port0"
188 result
=`openflow list | grep $rule_name`
189 [[ $?
!= 0 ]] && echo "FAIL rule bad inserted" && $_exit 1
190 result
=`echo $result` #remove blanks
191 [[ "$result" != "$expected" ]] && echo "FAIL" && echo " expected: $expected\n obtained: $result" && $_exit 1
193 TODELETE
="$rule_name $TODELETE"
196 if [[ $same_vlan == n
]]
199 printf "%-50s" "new rule Vlan -> Vlan_Vlan: "
200 rule_name
=fromVlan_to_Vlan1Vlan1
201 openflow add
$rule_name --priority 1005 --inport $port3 --matchvlan 505 --setvlan 510 --out $port0 --setvlan 511 --out $port1 --stripvlan --out=$port2 $debug
202 [[ $?
!= 0 ]] && echo "FAIL cannot insert new rule" && $_exit 1
203 expected
="$OF_CONTROLLER_DPID 1005 $rule_name $port3 any 505 vlan=510,out=$port0,vlan=511,out=$port1,vlan=None,out=$port2"
204 result
=`openflow list | grep $rule_name`
205 [[ $?
!= 0 ]] && echo "FAIL rule bad inserted" && $_exit 1
206 result
=`echo $result` #remove blanks
207 [[ "$result" != "$expected" ]] && echo "FAIL" && echo " expected: $expected\n obtained: $result" && $_exit 1
209 TODELETE
="$rule_name $TODELETE"