[packages] olsrd: init: parse new var 'speed', which translates to several other...
authorSaverio Proto <zioproto@gmail.com>
Wed, 10 Apr 2013 10:48:35 +0000 (10:48 +0000)
committerSaverio Proto <zioproto@gmail.com>
Wed, 10 Apr 2013 10:48:35 +0000 (10:48 +0000)
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 <bittorf@bluebottle.com>
git-svn-id: svn://svn.openwrt.org/openwrt/packages/net/olsrd@36299 3c298f89-4303-0410-b956-a3cf2f4a3e73

files/olsrd.init

index 6ed369f..aab85eb 100644 (file)
@@ -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='+'