From: Saverio Proto Date: Wed, 10 Apr 2013 10:48:35 +0000 (+0000) Subject: olsrd: init: parse new var 'speed', which translates to several other vars X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=93f48607dc6c6f7dc6ff4398b43e07e5463081e3;p=openwrt%2Fsvn-archive%2Fpackages.git olsrd: init: parse new var 'speed', which translates to several other vars Range is 1...20 where 1 is fastest protocol speed and 20 is the slowest protocol speed Like in the Freifunk-Firmware from sven-ola we accept now a per-interface option 'speed', which should range from 1...20 and is sanitized. when the value is not in valid range, it defaults to 6 which allows the daemon to start and behave like in a city-wide mesh. (same default like in freifunk firmware) The value 'speed' overrides the normal values for emission intervals like Hello-, Tc-, Mid-, Hna-Interval/ValidityTime or sets them explicitely. this makes it much easier to play with intervals on several routers: Instead of changes eight values, we only have to alter 1 value. The value-calculation is tested since several years. Signed-off-by: Bastian Bittorf SVN-Revision: 36299 --- diff --git a/net/olsrd/files/olsrd.init b/net/olsrd/files/olsrd.init index 6ed369fc4..aab85eb15 100644 --- a/net/olsrd/files/olsrd.init +++ b/net/olsrd/files/olsrd.init @@ -225,6 +225,7 @@ config_update_schema() { } config_write_options() { + local funcname="config_write_options" unset IFS local schema="$1" local cfg="$2" @@ -244,6 +245,8 @@ config_write_options() { local list_value local i local position + local speed + local list_speed_vars="HelloInterval HelloValidityTime TcInterval TcValidityTime MidInterval MidValidityTime HnaInterval HnaValidityTime" get_value_for_entry() { @@ -262,12 +265,90 @@ config_write_options() { [ "$option_type" = internal ] && return 1 config_get value "$cfg" "$option" + [ "$option" = "speed" ] && return 1 return 0 } + case " $schema " in + *" speed "*) + get_value_for_entry "speed" + + if [ 2>/dev/null $value -gt 0 -a $value -le 20 ]; then + speed="$value" + else + log "$funcname() Warning: invalid speed-value: '$value' - allowed integers: 1...20, fallback to 6" + speed=6 + fi + + already_in_schema() + { + case " $schema " in + *" $1 "*) + return 0 + ;; + *) + return 1 + ;; + esac + } + + for schema_entry in $list_speed_vars; do { + already_in_schema "$schema_entry" || schema="$schema $schema_entry" + } done + ;; + esac + for schema_entry in $schema; do - get_value_for_entry "$schema_entry" || continue + if [ -n "$speed" ]; then # like sven-ola freifunk firmware fff-1.7.4 + case "$schema_entry" in + HelloInterval) + value="$(( $speed / 2 + 1 )).0" + ;; + HelloValidityTime) + value="$(( $speed * 25 )).0" + ;; + TcInterval) # todo: not fisheye? -> $(( $speed * 2 )) + value=$(( $speed / 2 )) + [ $value -eq 0 ] && value=1 + value="$value.0" + ;; + TcValidityTime) + value="$(( $speed * 100 )).0" + ;; + MidInterval) + value="$(( $speed * 5 )).0" + ;; + MidValidityTime) + value="$(( $speed * 100 )).0" + ;; + HnaInterval) + value="$(( $speed * 2 )).0" + ;; + HnaValidityTime) + value="$(( $speed * 25 )).0" + ;; + *) + get_value_for_entry "$schema_entry" || continue + ;; + esac + + is_speed_var() + { + case " $list_speed_vars " in + *" $1 "*) + return 0 + ;; + *) + return 1 + ;; + esac + } + + is_speed_var "$schema_entry" && option="$schema_entry" + else + get_value_for_entry "$schema_entry" || continue + fi if [ -z "$value" ]; then IFS='+'