From d82cf370873233dfc6b9707f6b804b6e9a875e68 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 18 Jun 2010 21:00:24 +0200 Subject: [PATCH] network: New function beautify_time. This functions does pretty printing for the topology change time. (No very precise but okay as far as I can see.) EDIT: Also committed STP_PRIORITY by accident. --- functions.util | 26 ++++++++++++++++++++++++++ hooks/bridge | 17 +++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/functions.util b/functions.util index a953a27e..c7385416 100644 --- a/functions.util +++ b/functions.util @@ -235,3 +235,29 @@ function uppercase() { read input echo "${input^^}" } + +function beautify_time() { + local value=${1} + + local unit + local limit + for unit in s m h d w; do + case "${unit}" in + s|m|h) + limit=60 + ;; + d) + limit=24 + ;; + w) + limit=7 + ;; + esac + + [ ${value} -lt ${limit} ] && break + + value=$(( ${value} / ${limit} )) + done + + echo "${value}${unit}" +} diff --git a/hooks/bridge b/hooks/bridge index fe21b552..9b98d482 100755 --- a/hooks/bridge +++ b/hooks/bridge @@ -21,7 +21,8 @@ . /lib/network/header-zone -HOOK_SETTINGS="HOOK STP STP_FORWARD_DELAY STP_HELLO STP_MAXAGE MAC MTU" +HOOK_SETTINGS="HOOK STP STP_FORWARD_DELAY STP_HELLO STP_MAXAGE STP_PRIORITY" +HOOK_SETTINGS="${HOOK_SETTINGS} MAC MTU" # Default values MAC=$(mac_generate) @@ -30,12 +31,14 @@ STP="on" STP_FORWARD_DELAY=0 STP_HELLO=2 STP_MAXAGE=20 +STP_PRIORITY=512 # XXX check out better value function _check() { assert ismac MAC assert isbool STP assert isinteger STP_HELLO assert isinteger STP_FORWARD_DELAY + assert isinteger STP_PRIORITY assert isinteger MTU } @@ -51,6 +54,9 @@ function _parse_cmdline() { --stp-forward-delay=*) STP_FORWARD_DELAY=${1#--stp-forward-delay=} ;; + --stp-priority=*) + STP_PRIORITY=${1#--stp-priority=} + ;; --mtu=*) MTU=${1#--mtu=} ;; @@ -93,6 +99,10 @@ function _up() { if [ -n "${STP_MAXAGE}" ]; then brctl setmaxage ${zone} ${STP_MAXAGE} fi + + if [ -n "${STP_PRIORITY}" ]; then + brctl setbridgeprio ${zone} ${STP_PRIORITY} + fi else brctl stp ${zone} off fi @@ -147,6 +157,9 @@ function _status() { exit ${EXIT_ERROR} fi + # XXX Add bridge stp priority here + # brctl does not give any information about that + cli_headline " Spanning Tree Protocol information:" echo " Bridge ID : $(stp_bridge_id ${zone})" echo " Designated root : $(stp_designated_root ${zone})" @@ -155,7 +168,7 @@ function _status() { # Topology information printf " Topology changing : %6s\n" $(stp_topology_change ${zone}) - printf " Topology change time : %6s\n" $(stp_topology_change_time ${zone}) + printf " Topology change time : %6s\n" $(beautify_time $(stp_topology_change_time ${zone})) printf " Topology change count : %6s\n" $(stp_topology_change_count ${zone}) cli_headline " Ports:" -- 2.39.2