Browse Source

[tools]add upload and mtu_test scripts

balbekova 4 years ago
parent
commit
fa179e19cf
2 changed files with 215 additions and 0 deletions
  1. 40 0
      tools/test_mtu.sh
  2. 175 0
      tools/upload.sh

+ 40 - 0
tools/test_mtu.sh

@@ -0,0 +1,40 @@
+#!/bin/bash
+# Run script with sudo!
+# NOTE: Rebuild IAP with DUMMY_PROG option enabled to skip any read/write ioperations during the test.
+
+ETH=enp5s0
+IP=$1
+MTU_MIN=400
+MTU_MAX=1500
+
+total=()
+failed=()
+success=()
+
+echo "Test MTUs: $MTU_MIN - $MTU_MAX"
+for (( size=$MTU_MIN; size<=$MTU_MAX; size++ ))
+do
+	ifconfig enp5s0 mtu $size
+	MTU=$(ifconfig $ETH | grep MTU | awk '{print $5}' | awk -F ":" '{print $2}')
+	total+=($MTU)
+	./tools/upload.sh $IP > /dev/null 2>&1
+	if [ $? -eq 0 ]
+	then
+		echo "MTU $MTU - OK"
+		success+=($MTU)
+	else
+		echo "MTU $MTU - Error"
+		failed+=($MTU)
+		# IAP will reboot automaticaly by timeout
+		echo "Waiting IAP reboot timeout..."
+		sleep 25
+	fi
+	sleep 5
+done
+
+echo "Success: ${#success[@]}/${#total[@]}"
+if [ ${#failed[@]} -ne 0 ]
+then
+	echo "Failed: ${#failed[@]}/${#total[@]}"
+	echo "Failed MTUs: ${failed[@]}"
+fi

+ 175 - 0
tools/upload.sh

@@ -0,0 +1,175 @@
+#!/bin/bash
+
+DEFMODE=main
+
+MODE=${2:-$DEFMODE}
+
+IAPPASS=rotekucn
+LOGIN=admin
+PASS=12345
+
+DB_FW=""
+#MAIN_FW=./output/RTPS_05502xx.bin
+MAIN_FW=./output/IBP.bin
+SERVICE_FW=./output/SERVICE_05502xx.bin
+
+function usage {
+    echo -e "Usage: upload.sh {ip|mac} {full|main|db|service}\n\
+    \tmain - update main firmware\n\
+    \tdb - update doughter board firmware\n\
+    \service - upload service firmware\n\
+    \tfull - update both main and doughter boards firmware"
+}
+
+function wait_ip {
+	while ! ping -c1 -W1 $IP > /dev/null
+	do
+		echo "Waiting IP.."	
+		sleep 1
+		((i++))
+		if [ $i == 10 ]
+		then
+			echo -e "\r\nError. IP not found!"
+			exit 1
+		fi
+	done
+}
+
+function need_login {
+	curl -s --compressed -b /tmp/cookies.txt -c /tmp/cookies.txt http://$IP/index.html | grep -q "Авторизация"
+}
+
+function need_iap {
+	curl -s --compressed -b /tmp/cookies.txt -c /tmp/cookies.txt http://$IP/index.html | grep -q "Параметры"
+}
+
+function log_out {
+	curl -s -b /tmp/cookies.txt -c /tmp/cookies.txt http://$IP/logout.cgi > /dev/null
+}
+
+function log_in {
+	curl -s -b /tmp/cookies.txt -c /tmp/cookies.txt -d "login=$LOGIN&password=$PASS" http://$IP/login.cgi > /dev/null
+}
+
+function boot_iap {
+	curl -s -X GET -b /tmp/cookies.txt -c /tmp/cookies.txt http://$IP/fw_update.cgi > /dev/null
+}
+
+function upload_db_fw {
+	echo $(curl --compressed http://$IP/upload.cgi -H 'Expect:' -F filedata=@$DB_FW --progress-bar)
+}
+
+function upload_main_fw {
+	echo $(curl --compressed http://$IP/upload.cgi -H 'Expect:' -F filedata=@$MAIN_FW --progress-bar)
+}
+
+function upload_service_fw {
+	TMP_FILE=$(mktemp -d /tmp/upload.XXXXX)/$(basename $MAIN_FW)
+	cp $SERVICE_FW $TMP_FILE
+	echo $(curl --compressed http://$IP/upload.cgi -H 'Expect:' -F filedata=@$TMP_FILE --progress-bar)
+}
+
+function goback {
+	curl -s http://$IP/goback.cgi 
+}
+
+
+if [ $# -lt 1 ]
+then
+    echo "Error: Not enough parameters" 
+    usage
+    exit 1
+fi
+
+#Check passed parameter
+if [[ "$1" =~ ^([a-fA-F0-9]{2}[:-]){5}[a-fA-F0-9]{2}$ ]]
+then
+    #Passed MAC
+    MAC=$(echo $1 | tr '[:upper:]' '[:lower:]' | tr '-' ':')
+    IP=$(sudo arp-scan -l | grep $MAC | cut -d$'\t' -f1)
+elif [[ "$1" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]
+then
+    #Passed IP
+    IP=$1
+else
+    echo "Error: Invalid parameter"
+    usage
+    exit 1
+fi
+
+ping -c1 -W1 $IP 2>/dev/null 1>/dev/null
+if [ "$?" = 0 ]
+then
+  echo "Host found ($IP)"
+else
+  echo "Error: Host not found ($IP)"
+  exit 1
+fi
+
+
+if need_login 
+then
+	echo "Logging in.."
+	log_in
+fi	
+if need_iap
+then
+	echo "Reboot to IAP.."
+	boot_iap
+	sleep 10
+	wait_ip
+fi	
+
+if [[ $MODE = "full" || $MODE = "db" ]]
+then
+	echo "Prog db firmware.."
+	db_res=$(upload_db_fw)
+	if [[ $db_res == "1" ]]
+	then 
+		echo "OK"
+	else
+		echo "Error"
+		echo "Update failed!"
+		exit 1
+	fi
+	sleep 1
+fi
+
+if [[ $MODE = "db" ]]
+then
+	goback
+	echo "Successfully updated"
+	exit 0
+fi
+
+if [[ $MODE = "full" || $MODE = "main" ]]
+then
+	echo "Prog main firmware.."
+	main_res=$(upload_main_fw)
+	if [[ $main_res == "1" ]]
+	then 
+		echo "OK"
+	else 
+		echo "Error"
+		echo "Update failed!"
+		exit 1
+	fi
+fi
+
+if [[ $MODE = "service" ]]
+then
+	echo "Prog service firmware.."
+	res=$(upload_service_fw)
+	if [[ $res == "1" ]]
+	then 
+		echo "OK"
+	else 
+		echo "Error"
+		echo "Update failed!"
+		exit 1
+	fi
+	rm -rf $TMP_FILE
+fi
+
+echo "Successfully updated"
+exit 0