Merge branch 'datamodel' into 'devel'

Added support for IP Diagnostics Data Model

See merge request bbf/tr143d!1
This commit is contained in:
Amin Ben Romdhane
2024-05-18 19:39:29 +00:00
8 changed files with 4030 additions and 0 deletions

223
scripts/bbf_diag/ipping Executable file
View File

@@ -0,0 +1,223 @@
#!/bin/sh
# Copyright (C) 2022 iopsys Software Solutions AB
# Author: MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
# Author: AMIN Ben Romdhane <amin.benromdhane@iopsys.eu>
. /usr/share/libubox/jshn.sh
. /usr/share/bbfdm/scripts/bbf_api
ipping_list() {
json_add_object "ipping"
json_add_string "host" "str"
json_add_string "iface" "str"
json_add_string "ip_proto" "str"
json_add_string "nbr_of_rep" "str"
json_add_string "timeout" "str"
json_add_string "data_size" "str"
json_add_string "dscp" "str"
json_add_string "proto" "str"
json_add_string "cancel" "str"
json_close_object
}
ipping_error() {
json_init
json_add_string "Status" "$1"
json_add_string "IPAddressUsed" ""
json_add_int "MinimumResponseTime" "9999"
json_add_int "AverageResponseTime" "0"
json_add_int "MaximumResponseTime" "0"
json_add_int "MinimumResponseTimeDetailed" "999999999"
json_add_int "AverageResponseTimeDetailed" "0"
json_add_int "MaximumResponseTimeDetailed" "0"
json_add_int "SuccessCount" "0"
json_add_int "FailureCount" "$2"
json_dump
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "$3" = "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState="$1"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.IPAddressUsed=""
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.SuccessCount=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.FailureCount="$2"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTime=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTime=9999
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTime=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTimeDetailed=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTimeDetailed=999999999
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTimeDetailed=0
$UCI_COMMIT_BBF_DMMAP
}
}
ipping_launch() {
input="$1"
json_load "${input}"
json_get_var host host
json_get_var iface iface
json_get_var ip_proto ip_proto
json_get_var nbr_of_rep nbr_of_rep
json_get_var timeout timeout
json_get_var dsize data_size
json_get_var dscp dscp
json_get_var proto proto
json_get_var cancel cancel
if [ "${proto}" = "both_proto" ]; then
old_pid=$(cat /tmp/ipping_pid)
[ -n "${old_pid}" ] && {
cmd=$(cat /proc/$old_pid/cmdline)
}
if [[ "${cmd}" = *ipping* ]]; then
kill -9 $old_pid
fi
if [ "${cancel}" -eq "1" ]; then
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState="None"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.IPAddressUsed=""
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.SuccessCount=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.FailureCount="0"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTime=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTime=9999
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTime=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTimeDetailed=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTimeDetailed=999999999
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTimeDetailed=0
$UCI_COMMIT_BBF_DMMAP
json_init
json_add_string "Status" "None"
json_add_string "IPAddressUsed" ""
json_add_int "MinimumResponseTime" "9999"
json_add_int "AverageResponseTime" "0"
json_add_int "MaximumResponseTime" "0"
json_add_int "MinimumResponseTimeDetailed" "999999999"
json_add_int "AverageResponseTimeDetailed" "0"
json_add_int "MaximumResponseTimeDetailed" "0"
json_add_int "SuccessCount" "0"
json_add_int "FailureCount" "0"
json_dump
return
else
echo $$ > /tmp/ipping_pid
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState="Requested_running"
$UCI_COMMIT_BBF_DMMAP
fi
fi
# Assign default value
[ -z "${nbr_of_rep}" ] && nbr_of_rep=3
[ -z "${dsize}" ] && dsize=64
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) && device="-I $device" || device=""
ip_addr_used=$(get_ip_addr_used "${ip_proto}" "${iface}")
if [ "$ip_proto" = "IPv4" ]; then ip_proto="-4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="-6"; else ip_proto=""; fi
[ -z "${timeout}" ] && timeout=1 || timeout=$((timeout/1000))
# Fail if host is empty
[ -z "${host}" ] && {
ipping_error "Error_Internal" "${nbr_of_rep}" "${proto}"
return
}
micros=1000
success_count=0
avg_time_sum=0
avg_time_sum_det=0
min=9999999
min_det=999999999
max=0
max_det=0
idx=0
while [ $idx -lt "${nbr_of_rep}" ]; do
idx=$((idx+1))
res=$(ping -q ${ip_proto} -c 1 -s ${dsize} -W ${timeout} ${device} "${host}" 2>&1)
ba=$(echo "$res" | grep -E "bad address|unknown host|Name does not resolve")
[ -n "$ba" ] && {
ipping_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
return
}
stc=$(echo "$res" | grep "received")
[ -z "$stc" ] && {
ipping_error "Error_Other" "${nbr_of_rep}" "${proto}"
return
}
times=$(echo "$res" | grep "min/avg/max")
[ -z "$times" ] && continue
sc1=$(echo "$stc" | awk '{print $4}')
sc1=${sc1:-0}
success_count=$((success_count+sc1))
times=$(echo "$times" | awk -F'=' '{ print $2 }')
min_time=$(echo "$times" | awk -F'[=/ ]' '{ print $2 }')
avg_time=$(echo "$times" | awk -F'[=/ ]' '{ print $3 }')
max_time=$(echo "$times" | awk -F'[=/ ]' '{ print $4 }')
min_time=${min_time:-0}
avg_time=${avg_time:-0}
max_time=${max_time:-0}
min_time_det=$(echo "$min_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
avg_time_det=$(echo "$avg_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
max_time_det=$(echo "$max_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
min_time=$(awk "BEGIN{print $min_time * 1000}")
avg_time=$(awk "BEGIN{print $avg_time * 1000}")
max_time=$(awk "BEGIN{print $max_time * 1000}")
[ "$min_time" -lt $min ] && min=$min_time
[ "$max_time" -gt $max ] && max=$max_time
avg_time_sum=$((avg_time_sum+avg_time))
[ "$min_time_det" -lt $min_det ] && min_det=$min_time_det
[ "$max_time_det" -gt $max_det ] && max_det=$max_time_det
avg_time_sum_det=$((avg_time_sum_det+avg_time_det))
done
failure_count=$((nbr_of_rep-success_count))
[ $success_count -gt 0 ] && avg_time=$((avg_time_sum/success_count)) || avg_time=0
[ $success_count -gt 0 ] && avg_time_det=$((avg_time_sum_det/success_count)) || avg_time_det=0
avg_time=$(awk "BEGIN{print int($avg_time / 1000)}")
min_time=$(awk "BEGIN{print int($min / 1000)}")
max_time=$(awk "BEGIN{print int($max / 1000)}")
min_time_det=$min_det
max_time_det=$max_det
json_init
json_add_string "Status" "Complete"
json_add_string "IPAddressUsed" "${ip_addr_used}"
json_add_int "MinimumResponseTime" "${min_time}"
json_add_int "AverageResponseTime" "${avg_time}"
json_add_int "MaximumResponseTime" "${max_time}"
json_add_int "MinimumResponseTimeDetailed" "${min_time_det}"
json_add_int "AverageResponseTimeDetailed" "${avg_time_det}"
json_add_int "MaximumResponseTimeDetailed" "${max_time_det}"
json_add_int "SuccessCount" "${success_count}"
json_add_int "FailureCount" "${failure_count}"
json_dump
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "${proto}" = "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState="Complete"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.IPAddressUsed="${ip_addr_used}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.SuccessCount="${success_count}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.FailureCount="${failure_count}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTime="${min_time}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTime="${avg_time}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTime="${max_time}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTimeDetailed="${min_time_det}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTimeDetailed="${avg_time_det}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTimeDetailed="${max_time_det}"
$UCI_COMMIT_BBF_DMMAP
}
}
if [ "$1" = "list" ]; then
ipping_list
elif [ -n "$1" ]; then
ipping_launch "$1"
else
ipping_error "Error_Internal" "1"
fi

243
scripts/bbf_diag/serverselection Executable file
View File

@@ -0,0 +1,243 @@
#!/bin/sh
# Copyright (C) 2022 iopsys Software Solutions AB
# Author: AMIN Ben Romdhane <amin.benromdhane@iopsys.eu>
. /usr/share/libubox/jshn.sh
. /usr/share/bbfdm/scripts/bbf_api
serverselection_list() {
json_add_object "serverselection"
json_add_string "hostlist" "str"
json_add_string "port" "str"
json_add_string "iface" "str"
json_add_string "ip_proto" "str"
json_add_string "nbr_of_rep" "str"
json_add_string "timeout" "str"
json_add_string "protocol_used" "str"
json_add_string "proto" "str"
json_add_string "cancel" "str"
json_close_object
}
serverselection_error() {
json_init
json_add_string "Status" "$1"
json_add_string "FastestHost" ""
json_add_string "IPAddressUsed" ""
json_add_int "MinimumResponseTime" "9999"
json_add_int "AverageResponseTime" "0"
json_add_int "MaximumResponseTime" "0"
json_dump
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "$3" = "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState="$1"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.FastestHost=""
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MinimumResponseTime=9999
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.AverageResponseTime=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MaximumResponseTime=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.IPAddressUsed=""
$UCI_COMMIT_BBF_DMMAP
}
}
serverselection_launch() {
input="$1"
json_load "${input}"
json_get_var hostlist hostlist
json_get_var port port
json_get_var iface iface
json_get_var ip_proto ip_proto
json_get_var nbr_of_rep nbr_of_rep
json_get_var timeout timeout
json_get_var protocol_used protocol_used
json_get_var proto proto
json_get_var cancel cancel
if [ "${proto}" = "both_proto" ]; then
old_pid=$(cat /tmp/serverselection_pid)
[ -n "${old_pid}" ] && {
cmd=$(cat /proc/$old_pid/cmdline)
}
if [[ "${cmd}" = *serverselection* ]]; then
kill -9 $old_pid
fi
if [ "${cancel}" -eq "1" ]; then
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState="None"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.FastestHost=""
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MinimumResponseTime=9999
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.AverageResponseTime=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MaximumResponseTime=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.IPAddressUsed=""
$UCI_COMMIT_BBF_DMMAP
json_init
json_add_string "Status" "None"
json_add_string "FastestHost" ""
json_add_string "IPAddressUsed" ""
json_add_int "MinimumResponseTime" "9999"
json_add_int "AverageResponseTime" "0"
json_add_int "MaximumResponseTime" "0"
json_dump
return
else
echo $$ > /tmp/serverselection_pid
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState="Requested_running"
$UCI_COMMIT_BBF_DMMAP
fi
fi
# Assign default value
[ -z "${nbr_of_rep}" ] && nbr_of_rep=3
[ -z "${port}" ] && port=7
[ -z "${protocol_used}" ] && protocol_used="ICMP"
ip_addr_used=$(get_ip_addr_used "${ip_proto}" "${iface}")
[ -z "${timeout}" ] && timeout=1 || timeout=$((timeout/1000))
# Fail if hostlist is empty
[ -z "${hostlist}" ] && {
serverselection_error "Error_Internal" "${nbr_of_rep}" "${proto}"
return
}
micros=1000
success_count=0
avg_time_sum=0
avg_time_host=9999999
min=9999999
max=0
i=0
for host in $(echo "$hostlist" | tr "," "\n"); do
if [ "$protocol_used" = "ICMP" ]; then
if [ "$ip_proto" = "IPv4" ]; then ip_proto="-4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="-6"; else ip_proto=""; fi
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) && device="-I $device" || device=""
while [ $i -lt "$nbr_of_rep" ]; do
i=$((i+1))
res=$(ping -q ${ip_proto} -c 1 -W ${timeout} ${device} "${host}" 2>&1)
ba=$(echo "$res" | grep "bad address")
[ -n "$ba" ] && {
serverselection_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
return
}
ba=$(echo "$res" | grep "unknown host")
[ -n "$ba" ] && {
serverselection_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
return
}
stc=$(echo "$res" | grep "received")
[ -z "$stc" ] && {
serverselection_error "Error_Other" "${nbr_of_rep}" "${proto}"
return
}
times=$(echo "$res" | grep "min/avg/max")
[ -z "$times" ] && break
sc1=$(echo "$stc" | awk '{print $4}')
sc1=${sc1:-0}
success_count=$((success_count+sc1))
times=$(echo "$times" | awk -F'=' '{ print $2 }')
min_time=$(echo "$times" | awk -F'[=/ ]' '{ print $2 }')
avg_time=$(echo "$times" | awk -F'[=/ ]' '{ print $3 }')
max_time=$(echo "$times" | awk -F'[=/ ]' '{ print $4 }')
min_time=${min_time:-0}
avg_time=${avg_time:-0}
max_time=${max_time:-0}
min_time=$(echo "$min_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
avg_time=$(echo "$avg_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
max_time=$(echo "$max_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
[ "$min_time" -lt "$min" ] && min="$min_time"
[ "$max_time" -gt "$max" ] && max="$max_time"
avg_time_sum=$((avg_time_sum+avg_time))
done
else
if [ "$ip_proto" = "IPv4" ]; then ip_proto="--protocol 4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="--protocol 6"; else ip_proto=""; fi
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) && device="-i $device" || device=""
while [ $i -lt "$nbr_of_rep" ]; do
i=$((i+1))
res=$(udpechoclientd -c 1 -t $timeout --host "$host" --port "$port" $ip_proto $device 2>&1)
ba=$(echo "$res" | grep "Can't Resolve Host Name")
[ -n "$ba" ] && {
serverselection_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
return
}
ba=$(echo "$res" | grep "RCVD")
[ -z "$ba" ] && {
serverselection_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
return
}
times=$(echo "$res" | grep "rtt")
[ -z "$times" ] && continue
sc1=$(echo "$res" | grep "Rcvd" | awk -F': ' '{print $3}' | awk -F'(' '{ print $1 }')
sc1=${sc1:-0}
success_count=$((success_count+sc1))
max_time=$(echo "$times" | awk -F': ' '{ print $2 }' | awk -F'ms' '{ print $1 }')
min_time=$(echo "$times" | awk -F': ' '{ print $3 }' | awk -F'ms' '{ print $1 }')
avg_time=$(echo "$times" | awk -F': ' '{ print $4 }' | awk -F'ms' '{ print $1 }')
min_time=${min_time:-0}
avg_time=${avg_time:-0}
max_time=${max_time:-0}
min_time=$(echo "$min_time" $micros | awk '{printf "%3.0f\n",$1*$2}')
avg_time=$(echo "$avg_time" $micros | awk '{printf "%3.0f\n",$1*$2}')
max_time=$(echo "$max_time" $micros | awk '{printf "%3.0f\n",$1*$2}')
[ "$min_time" -lt "$min" ] && min="$min_time"
[ "$max_time" -gt "$max" ] && max="$max_time"
avg_time_sum=$((avg_time_sum+avg_time))
done
fi
[ $success_count -gt 0 ] && avg_time=$((avg_time_sum/success_count)) || avg_time=0
[ "$avg_time" != "0" ] && [ $avg_time -lt $avg_time_host ] && avg_time_host="$avg_time" && min_time_host="$min" && max_time_host="$max" && fasthost="$host"
success_count=0
avg_time_sum=0
min=9999999
max=0
i=0
done
json_init
json_add_string "Status" "Complete"
json_add_string "FastestHost" "${fasthost}"
json_add_string "IPAddressUsed" "${ip_addr_used}"
json_add_int "MinimumResponseTime" "${min_time}"
json_add_int "AverageResponseTime" "${avg_time}"
json_add_int "MaximumResponseTime" "${max_time}"
json_dump
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "${proto}" = "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState="Complete"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.FastestHost="${fasthost}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.IPAddressUsed="${ip_addr_used}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MinimumResponseTime="${min_time_host}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.AverageResponseTime="${avg_time_host}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MaximumResponseTime="${max_time_host}"
$UCI_COMMIT_BBF_DMMAP
}
}
if [ "$1" = "list" ]; then
serverselection_list
elif [ -n "$1" ]; then
serverselection_launch "$1"
else
serverselection_error "Error_Internal" "1"
fi

201
scripts/bbf_diag/udpecho Executable file
View File

@@ -0,0 +1,201 @@
#!/bin/sh
# Copyright (C) 2022 iopsys Software Solutions AB
# Author: AMIN Ben Romdhane <amin.benromdhane@iopsys.eu>
. /usr/share/libubox/jshn.sh
. /usr/share/bbfdm/scripts/bbf_api
udpecho_list() {
json_add_object "udpecho"
json_add_string "host" "str"
json_add_string "port" "str"
json_add_string "iface" "str"
json_add_string "ip_proto" "str"
json_add_string "nbr_of_rep" "str"
json_add_string "timeout" "str"
json_add_string "data_size" "str"
json_add_string "dscp" "str"
json_add_string "inter_trans_time" "str"
json_add_string "proto" "str"
json_add_string "cancel" "str"
json_close_object
}
udpecho_error() {
json_init
json_add_string "Status" "$1"
json_add_string "IPAddressUsed" ""
json_add_int "SuccessCount" "0"
json_add_int "FailureCount" "$2"
json_add_int "MinimumResponseTime" "9999"
json_add_int "AverageResponseTime" "0"
json_add_int "MaximumResponseTime" "0"
json_dump
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "$3" = "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState="$1"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.SuccessCount=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.FailureCount="$2"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MinimumResponseTime=9999
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.AverageResponseTime=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MaximumResponseTime=0
$UCI_COMMIT_BBF_DMMAP
}
}
udpecho_launch() {
input="$1"
json_load "${input}"
json_get_var host host
json_get_var port port
json_get_var iface iface
json_get_var ip_proto ip_proto
json_get_var nbr_of_rep nbr_of_rep
json_get_var timeout timeout
json_get_var dsize data_size
json_get_var dscp dscp
json_get_var inter_time inter_trans_time
json_get_var proto proto
json_get_var cancel cancel
[ "${proto}" = "both_proto" ] && {
old_pid=$(cat /tmp/udpecho_pid)
[ -n "${old_pid}" ] && {
cmd=$(cat /proc/$old_pid/cmdline)
}
if [[ "${cmd}" = *udpecho* ]]; then
kill -9 $old_pid
fi
if [ "${cancel}" -eq "1" ]; then
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState="None"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.SuccessCount="0"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.FailureCount="0"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MinimumResponseTime="9999"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.AverageResponseTime="0"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MaximumResponseTime="0"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.IPAddressUsed=""
$UCI_COMMIT_BBF_DMMAP
json_init
json_add_string "Status" "None"
json_add_string "IPAddressUsed" ""
json_add_int "SuccessCount" "0"
json_add_int "FailureCount" "0"
json_add_int "MinimumResponseTime" "9999"
json_add_int "AverageResponseTime" "0"
json_add_int "MaximumResponseTime" "0"
json_dump
return
else
echo $$ > /tmp/udpecho_pid
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState="Requested_running"
$UCI_COMMIT_BBF_DMMAP
fi
}
# Assign default value
[ -z "${nbr_of_rep}" ] && nbr_of_rep=1
[ -z "${port}" ] && port=7
[ -z "${dsize}" ] && dsize=24
[ -z "${dscp}" ] && dscp=0
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) && device="-i $device" || device=""
ip_addr_used=$(get_ip_addr_used "${ip_proto}" "${iface}")
if [ "$ip_proto" = "IPv4" ]; then ip_proto="--protocol 4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="--protocol 6"; else ip_proto=""; fi
[ -z "${timeout}" ] && timeout=1 || timeout=$((timeout/1000))
[ -z "${inter_time}" ] && inter_time=1 || inter_time=$((inter_time/1000))
tos=$((dscp<<2))
# Fail if host is empty
[ -z "${host}" ] && {
udpecho_error "Error_Internal" "${nbr_of_rep}" "${proto}"
return
}
micros=1000
success_count=0
avg_time_sum=0
min=9999999
max=0
i=0
while [ $i -lt "$nbr_of_rep" ]; do
i=$((i+1))
res=$(udpechoclientd -c 1 -t $timeout --host "$host" --data-length "$dsize" --port "$port" $ip_proto $device 2>&1)
ba=$(echo "$res" | grep "Can't Resolve Host Name")
[ -n "$ba" ] && {
udpecho_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
return
}
ba=$(echo "$res" | grep "RCVD")
[[ -z "$ba" && $((nbr_of_rep-i)) == 0 ]] && {
udpecho_error "Complete" "${nbr_of_rep}" "${proto}"
return
}
times=$(echo "$res" | grep "rtt")
[ -z "$times" ] && continue
sc1=$(echo "$res" | grep "Rcvd" | awk -F': ' '{print $3}' | awk -F'(' '{ print $1 }')
[ "$sc1" != 0 ] && sc1=1 || sc1=0
success_count=$((success_count+sc1))
max_time=$(echo "$times" | awk -F': ' '{ print $2 }' | awk -F'ms' '{ print $1 }')
min_time=$(echo "$times" | awk -F': ' '{ print $3 }' | awk -F'ms' '{ print $1 }')
avg_time=$(echo "$times" | awk -F': ' '{ print $4 }' | awk -F'ms' '{ print $1 }')
min_time=${min_time:-0}
avg_time=${avg_time:-0}
max_time=${max_time:-0}
min_time=$(echo "$min_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
avg_time=$(echo "$avg_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
max_time=$(echo "$max_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
[ "$min_time" -lt "$min" ] && min="$min_time"
[ "$max_time" -gt "$max" ] && max="$max_time"
avg_time_sum=$((avg_time_sum+avg_time))
sleep $inter_time
done
failure_count=$((nbr_of_rep-success_count))
[ $success_count -gt 0 ] && avg_time=$((avg_time_sum/success_count)) || avg_time=0
min_time=$min
max_time=$max
json_init
json_add_string "Status" "Complete"
json_add_string "IPAddressUsed" "${ip_addr_used}"
json_add_int "SuccessCount" "${success_count}"
json_add_int "FailureCount" "${failure_count}"
json_add_int "MinimumResponseTime" "${min_time}"
json_add_int "AverageResponseTime" "${avg_time}"
json_add_int "MaximumResponseTime" "${max_time}"
json_dump
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "${proto}" = "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState="Complete"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.IPAddressUsed="${ip_addr_used}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.SuccessCount="${success_count}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.FailureCount="${failure_count}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MinimumResponseTime="${min_time}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.AverageResponseTime="${avg_time}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MaximumResponseTime="${max_time}"
$UCI_COMMIT_BBF_DMMAP
}
}
if [ "$1" = "list" ]; then
udpecho_list
elif [ -n "$1" ]; then
udpecho_launch "$1"
else
udpecho_error "Error_Internal" "1"
fi

235
scripts/download Executable file
View File

@@ -0,0 +1,235 @@
#!/bin/sh
# Copyright (C) 2022 iopsys Software Solutions AB
# Author: IMEN Bhiri <imen.bhiri@pivasoftware.com>
# Author: AMIN Ben Romdhane <amin.benromdhane@iopsys.eu>
. /usr/share/libubox/jshn.sh
ROOT="$(dirname "${0}")"
. "${ROOT}"/bbf_api
DOWNLOAD_TIMEOUT=1800
download_error() {
json_init
json_add_string "Status" "$1"
json_dump
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "$2" = "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState="$1"
}
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.Status="complete"
$UCI_COMMIT_BBF_DMMAP
}
download_launch() {
input="$1"
json_load "${input}"
json_get_var url url
json_get_var iface iface
json_get_var dscp dscp
json_get_var eth_prio eth_prio
json_get_var ip_proto ip_proto
json_get_var num_of_con num_of_con
json_get_var enable_per_con enable_per_con
json_get_var proto proto
# Check if a download process is already running
download_s=$(uci_get_bbf_dmmap dmmap_diagnostics.download)
if [ -z "${download_s}" ]; then
[ ! -f /etc/bbfdm/dmmap/dmmap_diagnostics ] && touch /etc/bbfdm/dmmap/dmmap_diagnostics
$UCI_ADD_BBF_DMMAP dmmap_diagnostics download
$UCI_RENAME_BBF_DMMAP dmmap_diagnostics.@download[0]='download'
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.Status="running"
$UCI_COMMIT_BBF_DMMAP
else
Status=$(uci_get_bbf_dmmap dmmap_diagnostics.download.Status)
[ "${Status}" = "running" ] && {
return
}
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.Status="running"
$UCI_COMMIT_BBF_DMMAP
fi
# Assign default value
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) || device=$(route -n | grep 'UG[ \t]' | awk '{print $8}')
ip_addr_used=$(get_ip_addr_used "${ip_proto}" "${iface}")
if [ "$ip_proto" = "IPv4" ]; then ip_proto="--ipv4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="--ipv6"; else ip_proto=""; fi
# Fail if url is empty
[ -z "${url}" ] && {
download_error "Error_InitConnectionFailed" "${proto}"
return
}
[ "${url:0:7}" != "http://" ] && [ "${url:0:6}" != "ftp://" ] && {
download_error "Error_Other" "${proto}"
return
}
format='{ "size_download": "%{size_download}",
"size_header": "%{size_header}",
"time_appconnect": "%{time_appconnect}",
"time_connect": "%{time_connect}",
"time_pretransfer": "%{time_pretransfer}",
"time_starttransfer": "%{time_starttransfer}",
"time_total": "%{time_total}",
"exitcode": "%{exitcode}" }'
tx_bytes_start=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
rx_bytes_start=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
time_start=$(date +"%s.282646") # It should be like that time_start=$(date +"%s.%6N") but since OpenWrt busybox has limitations and doesn't support nonoseconds so keep it hardcoded
res=$(curl ${ip_proto} --fail --silent --max-time ${DOWNLOAD_TIMEOUT} -w "${format}" "${url}" --output /dev/null)
time_end=$(date +"%s.282646") # It should be like that time_end=$(date +"%s.%6N") but since OpenWrt busybox has limitations and doesn't support nonoseconds so keep it hardcoded
tx_bytes_end=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
rx_bytes_end=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
logger -t "bbf_download" "########### ${url} ==> ${res} ###########"
json_load "${res}"
json_get_var size_download size_download
json_get_var size_header size_header
json_get_var time_appconnect time_appconnect
json_get_var time_connect time_connect
json_get_var time_pretransfer time_pretransfer
json_get_var time_starttransfer time_starttransfer
json_get_var time_total time_total
json_get_var exitcode exitcode
[ "$exitcode" = "6" ] && {
download_error "Error_CannotResolveHostName" "${proto}"
return
}
[ "$exitcode" = "7" ] && {
download_error "Error_InitConnectionFailed" "${proto}"
return
}
[ "$exitcode" = "22" ] && {
download_error "Error_NoResponse" "${proto}"
return
}
[ "$exitcode" = "27" ] && {
download_error "Error_IncorrectSize" "${proto}"
return
}
[ "$exitcode" = "28" ] && {
download_error "Error_Timeout" "${proto}"
return
}
[ "$exitcode" != "0" ] && {
download_error "Error_Other" "${proto}"
return
}
tcp_open_request_time=$(echo "${time_start}" "${time_appconnect}" | awk '{printf "%.6f", $1 + $2}')
tcp_open_response_time=$(echo "${time_start}" "${time_connect}" | awk '{printf "%.6f", $1 + $2}')
rom_time=$(echo "${time_start}" "${time_pretransfer}" | awk '{printf "%.6f", $1 + $2}')
bom_time=$(echo "${time_start}" "${time_starttransfer}" | awk '{printf "%.6f", $1 + $2}')
eom_time=$(echo "${time_start}" "${time_total}" | awk '{printf "%.6f", $1 + $2}')
separator_idx=$(expr index "${tcp_open_request_time}" .)
TCPOpenRequestTime_MicroSec=${tcp_open_request_time:$separator_idx}
TCPOpenRequestTime_Sec=${tcp_open_request_time:0:$((separator_idx-1))}
separator_idx=$(expr index "${tcp_open_response_time}" .)
TCPOpenResponseTime_MicroSec=${tcp_open_response_time:$separator_idx}
TCPOpenResponseTime_Sec=${tcp_open_response_time:0:$((separator_idx-1))}
separator_idx=$(expr index "${rom_time}" .)
ROMTime_MicroSec=${rom_time:$separator_idx}
ROMTime_Sec=${rom_time:0:$((separator_idx-1))}
separator_idx=$(expr index "${bom_time}" .)
BOMTime_MicroSec=${bom_time:$separator_idx}
BOMTime_Sec=${bom_time:0:$((separator_idx-1))}
separator_idx=$(expr index "${eom_time}" .)
EOMTime_MicroSec=${eom_time:$separator_idx}
EOMTime_Sec=${eom_time:0:$((separator_idx-1))}
TCPOpenRequestTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${TCPOpenRequestTime_MicroSec}Z" -d @"${TCPOpenRequestTime_Sec}")
TCPOpenResponseTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${TCPOpenResponseTime_MicroSec}Z" -d @"${TCPOpenResponseTime_Sec}")
ROMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${ROMTime_MicroSec}Z" -d @"${ROMTime_Sec}")
BOMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${BOMTime_MicroSec}Z" -d @"${BOMTime_Sec}")
EOMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${EOMTime_MicroSec}Z" -d @"${EOMTime_Sec}")
tx_bytes=$((tx_bytes_end-tx_bytes_start))
rx_bytes=$((rx_bytes_end-rx_bytes_start))
test_rx_bytes=$((size_download+size_header))
period_time=$(echo "${time_end}" "${time_start}" | awk '{printf ($1 - $2) * 1000000}')
json_init
json_add_string "Status" "Complete"
json_add_string "IPAddressUsed" "${ip_addr_used}"
json_add_string "ROMTime" "${ROMTime}"
json_add_string "BOMTime" "${BOMTime}"
json_add_string "EOMTime" "${EOMTime}"
json_add_int "TestBytesReceived" "${test_rx_bytes}"
json_add_int "TotalBytesReceived" "${rx_bytes}"
json_add_int "TotalBytesSent" "${tx_bytes}"
json_add_int "PeriodOfFullLoading" "${period_time}"
json_add_string "TCPOpenRequestTime" "${TCPOpenRequestTime}"
json_add_string "TCPOpenResponseTime" "${TCPOpenResponseTime}"
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
json_add_array "DownloadPerConnection"
json_add_object ""
json_add_string "ROMTime" "${ROMTime}"
json_add_string "BOMTime" "${BOMTime}"
json_add_string "EOMTime" "${EOMTime}"
json_add_int "TestBytesReceived" "${test_rx_bytes}"
json_add_int "TotalBytesReceived" "${rx_bytes}"
json_add_int "TotalBytesSent" "${tx_bytes}"
json_add_string "TCPOpenRequestTime" "${TCPOpenRequestTime}"
json_add_string "TCPOpenResponseTime" "${TCPOpenResponseTime}"
json_close_object
fi
json_dump
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "${proto}" == "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState="Complete"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.IPAddressUsed="${ip_addr_used}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.ROMTime="${ROMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.BOMTime="${BOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.EOMTime="${EOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TestBytesReceived="${test_rx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TotalBytesReceived="${rx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TotalBytesSent="${tx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.PeriodOfFullLoading="${period_time}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TCPOpenRequestTime="${TCPOpenRequestTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TCPOpenResponseTime="${TCPOpenResponseTime}"
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
$UCI_ADD_BBF_DMMAP dmmap_diagnostics DownloadPerConnection
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].ROMTime="${ROMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].BOMTime="${BOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].EOMTime="${EOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TestBytesReceived="${test_rx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesReceived="${rx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesSent="${tx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TCPOpenRequestTime="${TCPOpenRequestTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TCPOpenResponseTime="${TCPOpenResponseTime}"
else
$UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0]
fi
}
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.Status="complete"
$UCI_COMMIT_BBF_DMMAP
}
if [ -n "$1" ]; then
download_launch "$1"
else
download_error "Error_Internal"
fi

180
scripts/traceroute Executable file
View File

@@ -0,0 +1,180 @@
#!/bin/sh
# Copyright (C) 2022 iopsys Software Solutions AB
# Author: AMIN Ben Romdhane <amin.benromdhane@iopsys.eu>
. /usr/share/libubox/jshn.sh
ROOT="$(dirname "${0}")"
. "${ROOT}"/bbf_api
get_traceroute_log_file() {
IDX=1
LOG_FILE="/tmp/traceroute_$IDX.log"
while [ -e ${LOG_FILE} ]; do
IDX=$((IDX+1))
LOG_FILE="/tmp/traceroute_$IDX.log";
done
echo ${LOG_FILE}
}
traceroute_error() {
json_init
json_add_string "Status" "$1"
json_add_string "IPAddressUsed" "$2"
json_add_int "ResponseTime" "0"
json_dump
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "$3" = "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState="$1"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.IPAddressUsed="$2"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.ResponseTime=0
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.NumberOfHops=0
$UCI_COMMIT_BBF_DMMAP
}
}
traceroute_launch() {
input="$1"
json_load "${input}"
json_get_var host host
json_get_var iface iface
json_get_var ip_proto ip_proto
json_get_var cnt nbr_of_tries
json_get_var timeout timeout
json_get_var dsize data_size
json_get_var dscp dscp
json_get_var maxhop max_hop_cnt
json_get_var proto proto
json_get_var cancel cancel
LOG_FILE=$(get_traceroute_log_file)
# Assign default value
[ -z "${cnt}" ] && cnt=1
[ -z "${maxhop}" ] && maxhop=30
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) && device="-i $device" || device=""
ip_addr_used=$(get_ip_addr_used "${ip_proto}" "${iface}")
if [ "$ip_proto" = "IPv4" ]; then ip_proto="-4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="-6"; else ip_proto=""; fi
[ -z "${timeout}" ] && timeout=5 || timeout=$((timeout/1000))
# Clear all route hops instances
[ "$proto" = "both_proto" ] && {
old_pid=$(cat /tmp/traceroute_pid)
[ -n "${old_pid}" ] && {
cmd=$(cat /proc/$old_pid/cmdline)
}
if [[ "${cmd}" = *traceroute* ]]; then
kill -9 ${old_pid}
fi
res=$($UCI_SHOW_BBF_DMMAP dmmap_diagnostics | grep -E "=RouteHops$" | cut -d= -f 1)
for i in $res; do
$UCI_DELETE_BBF_DMMAP "${i}"
done
if [ "${cancel}" -eq "1" ]; then
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState="None"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.IPAddressUsed=""
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.NumberOfHops="0"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.ResponseTime="0"
$UCI_COMMIT_BBF_DMMAP
json_init
json_add_string "Status" "None"
json_add_string "IPAddressUsed" ""
json_add_int "ResponseTime" "0"
json_dump
return
else
echo $$ > /tmp/traceroute_pid
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState="Requested_running"
$UCI_COMMIT_BBF_DMMAP
fi
}
# Fail if host is empty
[ -z "${host}" ] && {
traceroute_error "Error_Internal" "${ip_addr_used}" "${proto}"
return
}
[ -z "${dsize}" ] && dsize="38"
res=$(traceroute -m ${maxhop} -w ${timeout} -q ${cnt} ${ip_proto} ${device} "${host}" "${dsize}" 2>&1 >"${LOG_FILE}")
error_code="$?"
ba=$(echo "$res" | grep "bad address")
[ -n "$ba" ] && {
traceroute_error "Error_CannotResolveHostName" "${ip_addr_used}" "${proto}"
return
}
[ "$error_code" != "0" ] && {
traceroute_error "Error_Other" "${ip_addr_used}" "${proto}"
return
}
i=-2
resp_time=0
json_init
json_add_array "RouteHops"
while read _ host ip time _; do
[ "$host" = "*" ] || [ "$ip" = "*" ] && continue
i=$((i+1))
[ "$i" = "-1" ] && continue;
ip=${ip#(}; ip=${ip%)}
time=${time%.*}
resp_time="${time}"
json_add_object ""
json_add_string "Host" "${host}"
json_add_string "HostAddress" "${ip}"
json_add_int "RTTimes" "${time}"
json_add_int "ErrorCode" "0"
json_close_object
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "$proto" = "both_proto" ] && {
$UCI_ADD_BBF_DMMAP dmmap_diagnostics RouteHops
$UCI_RENAME_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i]="route_hops_${i}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i].host="${host}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i].ip="${ip}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i].time="${time}"
}
done < "${LOG_FILE}"
rm -f "${LOG_FILE}"
i=$((i+1))
json_close_array
json_add_string "Status" "Complete"
json_add_string "IPAddressUsed" "${ip_addr_used}"
json_add_int "ResponseTime" "${resp_time}"
json_dump
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "$proto" = "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState="Complete"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.IPAddressUsed="${ip_addr_used}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.NumberOfHops="${i}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.ResponseTime="${resp_time}"
$UCI_COMMIT_BBF_DMMAP
}
}
if [ -n "$1" ]; then
traceroute_launch "$1"
else
traceroute_error "Error_Internal"
fi

236
scripts/upload Executable file
View File

@@ -0,0 +1,236 @@
#!/bin/sh
# Copyright (C) 2022 iopsys Software Solutions AB
# Author: IMEN Bhiri <imen.bhiri@pivasoftware.com>
# Author: AMIN Ben Romdhane <amin.benromdhane@iopsys.eu>
. /usr/share/libubox/jshn.sh
ROOT="$(dirname "${0}")"
. "${ROOT}"/bbf_api
UPLOAD_TIMEOUT=1800
upload_error() {
json_init
json_add_string "Status" "$1"
json_dump
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "$2" = "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState="$1"
}
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.Status="complete"
$UCI_COMMIT_BBF_DMMAP
}
upload_launch() {
input="$1"
json_load "${input}"
json_get_var url url
json_get_var iface iface
json_get_var dscp dscp
json_get_var eth_prio eth_prio
json_get_var file_length file_length
json_get_var ip_proto ip_proto
json_get_var num_of_con num_of_con
json_get_var enable_per_con enable_per_con
json_get_var proto proto
# Check if an upload process is already running
upload_s=$(uci_get_bbf_dmmap dmmap_diagnostics.upload)
if [ -z "${upload_s}" ]; then
[ ! -f /etc/bbfdm/dmmap/dmmap_diagnostics ] && touch /etc/bbfdm/dmmap/dmmap_diagnostics
$UCI_ADD_BBF_DMMAP dmmap_diagnostics upload
$UCI_RENAME_BBF_DMMAP dmmap_diagnostics.@upload[0]='upload'
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.Status="running"
$UCI_COMMIT_BBF_DMMAP
else
Status=$(uci_get_bbf_dmmap dmmap_diagnostics.upload.Status)
[ "${Status}" = "running" ] && {
return
}
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.Status="running"
$UCI_COMMIT_BBF_DMMAP
fi
# Assign default value
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) || device=$(route -n | grep 'UG[ \t]' | awk '{print $8}')
ip_addr_used=$(get_ip_addr_used "${ip_proto}" "${iface}")
if [ "$ip_proto" = "IPv4" ]; then ip_proto="--ipv4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="--ipv6"; else ip_proto=""; fi
# Fail if url is empty
[ -z "${url}" ] && {
upload_error "Error_InitConnectionFailed" "${proto}"
return
}
[ "${url:0:7}" != "http://" ] && [ "${url:0:6}" != "ftp://" ] && {
upload_error "Error_Other" "${proto}"
return
}
format='{ "size_upload":"%{size_upload}", "time_appconnect":"%{time_appconnect}", "time_connect":"%{time_connect}", "time_pretransfer":"%{time_pretransfer}", "time_starttransfer":"%{time_starttransfer}", "time_total":"%{time_total}", "exitcode":"%{exitcode}" }'
len_mb=$((file_length/(1000*1000)))
if [ $len_mb -gt 0 ]; then
bs="1MB"
count="$len_mb"
else
bs="$file_length"
count="1"
fi
tx_bytes_start=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
rx_bytes_start=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
time_start=$(date +"%s.282646") # It should be like that time_start=$(date +"%s.%6N") but since OpenWrt busybox has limitations and doesn't support nonoseconds so keep it hardcoded
res=$(dd if=/dev/zero bs="${bs}" count=${count} 2>/dev/null | curl ${ip_proto} --fail --silent --max-time ${UPLOAD_TIMEOUT} -T - "${url}" -w "${format}"|grep -wo '{.*}')
time_end=$(date +"%s.282646") # It should be like that time_end=$(date +"%s.%6N") but since OpenWrt busybox has limitations and doesn't support nonoseconds so keep it hardcoded
tx_bytes_end=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
rx_bytes_end=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
logger -t "bbf_upload" "# ${url} => ${res} #"
json_load "${res}"
json_get_var size_upload size_upload
json_get_var time_appconnect time_appconnect
json_get_var time_connect time_connect
json_get_var time_pretransfer time_pretransfer
json_get_var time_starttransfer time_starttransfer
json_get_var time_total time_total
json_get_var exitcode exitcode
[ "$exitcode" = "6" ] && {
upload_error "Error_CannotResolveHostName" "${proto}"
return
}
[ "$exitcode" = "7" ] && {
upload_error "Error_InitConnectionFailed" "${proto}"
return
}
[ "$exitcode" = "22" ] && {
upload_error "Error_NoResponse" "${proto}"
return
}
[ "$exitcode" = "27" ] && {
upload_error "Error_IncorrectSize" "${proto}"
return
}
[ "$exitcode" = "28" ] && {
upload_error "Error_Timeout" "${proto}"
return
}
[ "$exitcode" != "0" ] && {
upload_error "Error_Other" "${proto}"
return
}
tcp_open_request_time=$(echo "${time_start}" "${time_appconnect}" | awk '{printf "%.6f", $1 + $2}')
tcp_open_response_time=$(echo "${time_start}" "${time_connect}" | awk '{printf "%.6f", $1 + $2}')
rom_time=$(echo "${time_start}" "${time_pretransfer}" | awk '{printf "%.6f", $1 + $2}')
bom_time=$(echo "${time_start}" "${time_starttransfer}" | awk '{printf "%.6f", $1 + $2}')
eom_time=$(echo "${time_start}" "${time_total}" | awk '{printf "%.6f", $1 + $2}')
separator_idx=$(expr index "${tcp_open_request_time}" .)
TCPOpenRequestTime_MicroSec=${tcp_open_request_time:$separator_idx}
TCPOpenRequestTime_Sec=${tcp_open_request_time:0:$((separator_idx-1))}
separator_idx=$(expr index "${tcp_open_response_time}" .)
TCPOpenResponseTime_MicroSec=${tcp_open_response_time:$separator_idx}
TCPOpenResponseTime_Sec=${tcp_open_response_time:0:$((separator_idx-1))}
separator_idx=$(expr index "${rom_time}" .)
ROMTime_MicroSec=${rom_time:$separator_idx}
ROMTime_Sec=${rom_time:0:$((separator_idx-1))}
separator_idx=$(expr index "${bom_time}" .)
BOMTime_MicroSec=${bom_time:$separator_idx}
BOMTime_Sec=${bom_time:0:$((separator_idx-1))}
separator_idx=$(expr index "${eom_time}" .)
EOMTime_MicroSec=${eom_time:$separator_idx}
EOMTime_Sec=${eom_time:0:$((separator_idx-1))}
TCPOpenRequestTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${TCPOpenRequestTime_MicroSec}Z" -d @"${TCPOpenRequestTime_Sec}")
TCPOpenResponseTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${TCPOpenResponseTime_MicroSec}Z" -d @"${TCPOpenResponseTime_Sec}")
ROMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${ROMTime_MicroSec}Z" -d @"${ROMTime_Sec}")
BOMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${BOMTime_MicroSec}Z" -d @"${BOMTime_Sec}")
EOMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${EOMTime_MicroSec}Z" -d @"${EOMTime_Sec}")
tx_bytes=$((tx_bytes_end-tx_bytes_start))
rx_bytes=$((rx_bytes_end-rx_bytes_start))
period_time=$(echo "${time_end}" "${time_start}" | awk '{printf ($1 - $2) * 1000000}')
json_init
json_add_string "Status" "Complete"
json_add_string "IPAddressUsed" "${ip_addr_used}"
json_add_string "ROMTime" "${ROMTime}"
json_add_string "BOMTime" "${BOMTime}"
json_add_string "EOMTime" "${EOMTime}"
json_add_int "TestBytesSent" "${size_upload}"
json_add_int "TotalBytesReceived" "${rx_bytes}"
json_add_int "TotalBytesSent" "${tx_bytes}"
json_add_int "PeriodOfFullLoading" "${period_time}"
json_add_string "TCPOpenRequestTime" "${TCPOpenRequestTime}"
json_add_string "TCPOpenResponseTime" "${TCPOpenResponseTime}"
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
json_add_array "UploadPerConnection"
json_add_object ""
json_add_string "ROMTime" "${ROMTime}"
json_add_string "BOMTime" "${BOMTime}"
json_add_string "EOMTime" "${EOMTime}"
json_add_int "TestBytesSent" "${size_upload}"
json_add_int "TotalBytesReceived" "${rx_bytes}"
json_add_int "TotalBytesSent" "${tx_bytes}"
json_add_string "TCPOpenRequestTime" "${TCPOpenRequestTime}"
json_add_string "TCPOpenResponseTime" "${TCPOpenResponseTime}"
json_close_object
fi
json_dump
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "${proto}" = "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState="Complete"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.IPAddressUsed="${ip_addr_used}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.ROMTime="${ROMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.BOMTime="${BOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.EOMTime="${EOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TestBytesSent="${size_upload}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TotalBytesReceived="${rx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TotalBytesSent="${tx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.PeriodOfFullLoading="${period_time}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TCPOpenRequestTime="${TCPOpenRequestTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TCPOpenResponseTime="${TCPOpenResponseTime}"
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
$UCI_ADD_BBF_DMMAP dmmap_diagnostics UploadPerConnection
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].ROMTime="${ROMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].BOMTime="${BOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].EOMTime="${EOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TestBytesSent="${size_upload}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesReceived="${rx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesSent="${tx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TCPOpenRequestTime="${TCPOpenRequestTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TCPOpenResponseTime="${TCPOpenResponseTime}"
else
$UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0]
fi
}
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.Status="complete"
$UCI_COMMIT_BBF_DMMAP
}
if [ -n "$1" ]; then
upload_launch "$1"
else
upload_error "Error_Internal"
fi

21
src/Makefile Normal file
View File

@@ -0,0 +1,21 @@
LIBOUT := libtr143d.so
LIBOBJS := diagnostics.o
LIB_CFLAGS = $(CFLAGS) -Wall -Werror -fstrict-aliasing -g
LIB_LDFLAGS = $(LDFLAGS)
FPIC := -fPIC
.PHONY: all
%.o: %.c
$(CC) $(LIB_CFLAGS) $(FPIC) -c -o $@ $<
all: $(LIBOUT)
$(LIBOUT): $(LIBOBJS)
$(CC) $(LIB_CFLAGS) $(LIB_LDFLAGS) -shared -o $@ $^
clean:
rm -f *.o $(LIBOUT)

2691
src/diagnostics.c Normal file

File diff suppressed because it is too large Load Diff