2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
15 sdwan_pod_name=sdwan-ovn-pod
20 login_url=http://$1/cgi-bin/luci/
21 echo $(wget -S --spider --post-data "luci_username=root&luci_password=" $login_url 2>&1 | grep sysauth= | sed -r 's/.*sysauth=([^;]+);.*/\1/')
24 function disable_ping {
25 command_url=http://$2/cgi-bin/luci/admin/config/command
26 command="uci set firewall.@rule[1].target='REJECT';fw3 reload"
27 echo $(wget -S --spider --header="Cookie:sysauth=$1" --post-data "command=$command" $command_url 2>&1)
30 function enable_ping {
31 command_url=http://$2/cgi-bin/luci/admin/config/command
32 command="uci set firewall.@rule[1].target='ACCEPT';fw3 reload"
33 echo $(wget -S --spider --header="Cookie:sysauth=$1" --post-data "command=$command" $command_url 2>&1)
36 function wait_for_pod {
38 while [[ "$status_phase" != "Running" ]]; do
39 new_phase="$(kubectl get pods -o wide | grep ^$1 | awk '{print $3}')"
40 if [[ "$new_phase" != "$status_phase" ]]; then
41 status_phase="$new_phase"
43 if [[ "$new_phase" == "Err"* ]]; then
50 function wait_for_pod_namespace {
52 while [[ "$status_phase" != "Running" ]]; do
53 new_phase="$(kubectl get pods -o wide -n $2 | grep ^$1 | awk '{print $3}')"
54 if [[ "$new_phase" != "$status_phase" ]]; then
55 status_phase="$new_phase"
57 if [[ "$new_phase" == "Err"* ]]; then
64 echo "Waiting for pods to be ready ..."
65 wait_for_pod $ovn_pod_name
66 wait_for_pod $sdwan_pod_name
67 echo "* Create pods success"
69 sdwan_pod_ip=$(kubectl get pods -o wide | grep ^$sdwan_pod_name | awk '{print $6}')
70 ovn_pod_ip=$(kubectl get pods -o wide | grep ^$ovn_pod_name | awk '{print $6}')
71 echo "SDWAN pod ip:"$sdwan_pod_ip
72 echo "OVN pod ip:"$ovn_pod_ip
74 echo "Login to sdwan ..."
76 while [[ "$security_token" == "" ]]; do
77 echo "Get Security Token ..."
78 security_token=$(login $sdwan_pod_ip)
81 echo "* Security Token: "$security_token
83 kubectl exec $sdwan_pod_name ifconfig
85 sdwan_pod_wan_ip=$(kubectl exec $sdwan_pod_name ifconfig $wan_interface | awk '/inet/{print $2}' | cut -f2 -d ":" | awk 'NR==1 {print $1}')
86 echo "Verify ping is work through wan interface between $sdwan_pod_name and $ovn_pod_name"
87 ping_result=$(kubectl exec $ovn_pod_name -- ping -c 3 $sdwan_pod_wan_ip)
88 if [[ $ping_result == *", 0% packet loss"* ]]; then
89 echo "* Ping is work through wan interface"
95 echo "Disable ping rule of wan interface ..."
96 ret=$(disable_ping $security_token $sdwan_pod_ip)
98 echo "Verify ping is not work through wan interface after ping rule disabled"
99 ping_result=$(kubectl exec $ovn_pod_name -- ping -c 3 $sdwan_pod_wan_ip 2>&1 || true)
100 if [[ $ping_result == *", 100% packet loss"* ]]; then
101 echo "* Ping is disabled"
103 echo "* Test failed!"
107 echo "Enable ping rule of wan interface ..."
108 ret=$(enable_ping $security_token $sdwan_pod_ip)
110 echo "Verify ping is work through wan interface after ping rule enabled"
111 ping_result=$(kubectl exec $ovn_pod_name -- ping -c 3 $sdwan_pod_wan_ip)
112 if [[ $ping_result == *", 0% packet loss"* ]]; then
113 echo "* Ping is enabled"
115 echo "* Test failed!"
120 echo "Test Completed!"