icwmp/init/cwmpd.init
Mohamed Kallel 27b73d5af7 PIVA::DELIVERY 8
script optimization
Voice parameters: AddObject/DeleteObject
Voice parameters: Vendor specific parameter

Concerning what we did in the optimization task:
1)  The main script  (freecwmp) is loaded only 1 time during the session. the load is done just before the start of the session. the function scripts are loaded within the load of the main script (freecwmp) only one time. The old behaviour consist to load the main script (freecwmp) and the function scripts for each parameter treatment. Core code (C) and Scripts are changed
2) Optimize the preparing of inform message. old script take ~30s and now it takes ~2s. Core code (C) and Scripts are changed
3) Execute only the function related to the parameter. For example if the requested parameter is "InternetGatewayDevice.ManagementServer.URL" then the main script freecwmp will execute only the related function of this parameter which is get_management_server(). The old behaviour consist to execute all get functions: get_wan_device(), get_lan_device(), get_device_info()...
4) Minimize the size of the script files: Replace some blocks o othe source code by a functions
2013-07-24 16:05:32 +01:00

145 lines
3.5 KiB
Bash

#!/bin/sh /etc/rc.common
# Copyright (C) 2012 Inteno
include /lib/network
. /usr/share/libubox/jshn.sh
START=60
STOP=40
EXTRA_HELP=" start [GetRPCMethods] Start cwmpd service and send GetRPCMethods"
check_url_format() {
# SCHEMA_LIST: contain list of possible schemas that could be present in the acs url
# Example: SCHEMA_LIST="http https"
SCHEMA_LIST="http"
for schema in $SCHEMA_LIST; do
dest=`echo $1|sed 's/$schema:\/\///g'|cut -f1 -d \/|cut -f1 -d:`
if [ "_$dest" != "_" ]; then
return 0
fi
done
return 1
}
check_acs_url() {
default_acs="http://10.10.1.6:8000/openacs/acs"
acs_dhcp_discovery=`uci -q get cwmp.acs.dhcp_discovery`
url=`uci -q get cwmp.acs.url`
dhcp_url_path=`uci -q get cwmp.acs.dhcp_url_path`
if [ \( "_$acs_dhcp_discovery" = "_enable" \) -o \( "_$url" = "_" \) ];then
url=`uci -P /var/state -q get $dhcp_url_path`
echo "ACS URL from dhcp: $url"
elif [ "_$url" != "_" ];then
url=`uci -q get cwmp.acs.url`
echo "ACS URL from configuration: $url"
else
url=$default_acs
echo "Using default ACS URL: $url"
fi
check_url_format $url
if [ "$?" != "0" ];then
echo "Invalid ACS URL: $url"
exit 1
fi
}
check_dhcp() {
i=0
dhcp_discovery=`uci -q get cwmp.acs.dhcp_discovery`
url=`uci -q get cwmp.acs.url`
dhcp_url_path=`uci -q get cwmp.acs.dhcp_url_path`
if [ \( "_$acs_dhcp_discovery" = "_enable" \) -o \( "_$url" = "_" \) ]
then
while [ $i -le 10 ]
do
acs_url=`uci -P /var/state -q get $dhcp_url_path`
if [ "$acs_url" != "" ]
then
break
else
echo "Waiting for discovery of acs url from dhcp server ..."
sleep 10
fi
i=`expr $i + 1`
done
fi
}
set_wan_interface() {
local l3_device=""
local default_wan_interface=""
config_load cwmp
config_get default_wan_interface cpe default_wan_interface
json_load "$(ifstatus $default_wan_interface)"
json_get_var l3_device l3_device
if [ "$l3_device" != "" ];then
uci_set cwmp cpe interface "$l3_device"
uci_commit
fi
}
start_msg="Start cwmpd ..."
stop_msg="Stop cwmpd ..."
run() {
echo $start_msg;printf "\033[A" ;sleep 1
set_wan_interface
check_dhcp
check_acs_url
if [ "_$1" = "_boot" ];then
opt=$opt"-b "
fi
if [ "_$1" = "_GetRPCMethods" ];then
opt=$opt"-g "
fi
[ -f /etc/config/cwmp ] && /usr/sbin/cwmpd $opt &
while [ "`ps aux|grep /usr/sbin/cwmpd|grep -v grep|grep -v rc.common`" = "" ];do
sleep 1
done
}
boot() {
touch /etc/cwmpd/.cwmpd_boot
}
start() {
run=$(ps aux|grep /usr/sbin/cwmpd|grep -v grep|grep -v rc.common)
if [ "$run" = "" ]
then
if [ "$1" = "GetRPCMethods" ];then
run "GetRPCMethods"
else
if [ ! -f /etc/cwmpd/.cwmpd_boot ]; then
run
else
run "boot"
rm -f /etc/cwmpd/.cwmpd_boot 2>/dev/null
fi
fi
else
echo "cwmpd is currently running ..."
fi
}
stop() {
echo $stop_msg;printf "\033[A" ;sleep 1
ubus call tr069 command '{"command": "exit"}' -t 3 &> /dev/null
pids="`ps aux|grep /usr/sbin/cwmpd|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v \" Z \"|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
while [ "_$pids" != "_" ];do
kill -9 $pids 2> /dev/null
pids="`ps aux|grep /usr/sbin/cwmpd|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v \" Z \"|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
done
pids="`ps aux|grep /usr/sbin/freecwmp|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
while [ "_$pids" != "_" ];do
kill -9 $pids 2> /dev/null
pids="`ps aux|grep /usr/sbin/freecwmp|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
done
}
restart() {
stop
start
}