diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2017-01-17 22:05:56 +0100 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2017-01-23 18:26:28 +0100 |
commit | cbf3e3eb3a6452b898b4a082b81e8ec4f9dddb26 (patch) | |
tree | afa9c6337979b47513117287cfc2a82509992e0c /ospfd/ospf_lsa.c | |
parent | lib: time: add new monotime() helpers (diff) | |
download | frr-cbf3e3eb3a6452b898b4a082b81e8ec4f9dddb26.tar.xz frr-cbf3e3eb3a6452b898b4a082b81e8ec4f9dddb26.zip |
ospfd: time: replace local helpers with monotime
This ditches tv_add, tv_sub, tv_cmp, etc. in favour of
monotime{,_since,_until}() which actually makes the code much more
readable in some locations.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'ospfd/ospf_lsa.c')
-rw-r--r-- | ospfd/ospf_lsa.c | 87 |
1 files changed, 12 insertions, 75 deletions
diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 916d4d01c..94575d594 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -22,6 +22,7 @@ #include <zebra.h> +#include "monotime.h" #include "linklist.h" #include "prefix.h" #include "if.h" @@ -63,40 +64,6 @@ get_metric (u_char *metric) struct timeval -tv_adjust (struct timeval a) -{ - while (a.tv_usec >= 1000000) - { - a.tv_usec -= 1000000; - a.tv_sec++; - } - - while (a.tv_usec < 0) - { - a.tv_usec += 1000000; - a.tv_sec--; - } - - return a; -} - -int -tv_ceil (struct timeval a) -{ - a = tv_adjust (a); - - return (a.tv_usec ? a.tv_sec + 1 : a.tv_sec); -} - -int -tv_floor (struct timeval a) -{ - a = tv_adjust (a); - - return a.tv_sec; -} - -struct timeval int2tv (int a) { struct timeval ret; @@ -115,50 +82,22 @@ msec2tv (int a) ret.tv_sec = a/1000; ret.tv_usec = (a%1000) * 1000; - return tv_adjust (ret); -} - -struct timeval -tv_add (struct timeval a, struct timeval b) -{ - struct timeval ret; - - ret.tv_sec = a.tv_sec + b.tv_sec; - ret.tv_usec = a.tv_usec + b.tv_usec; - - return tv_adjust (ret); -} - -struct timeval -tv_sub (struct timeval a, struct timeval b) -{ - struct timeval ret; - - ret.tv_sec = a.tv_sec - b.tv_sec; - ret.tv_usec = a.tv_usec - b.tv_usec; - - return tv_adjust (ret); -} - -int -tv_cmp (struct timeval a, struct timeval b) -{ - return (a.tv_sec == b.tv_sec ? - a.tv_usec - b.tv_usec : a.tv_sec - b.tv_sec); + return ret; } int ospf_lsa_refresh_delay (struct ospf_lsa *lsa) { - struct timeval delta, now; + struct timeval delta; int delay = 0; - quagga_gettime (QUAGGA_CLK_MONOTONIC, &now); - delta = tv_sub (now, lsa->tv_orig); - - if (tv_cmp (delta, msec2tv (OSPF_MIN_LS_INTERVAL)) < 0) + if (monotime_since (&lsa->tv_orig, &delta) < OSPF_MIN_LS_INTERVAL * 1000LL) { - delay = tv_ceil (tv_sub (msec2tv (OSPF_MIN_LS_INTERVAL), delta)); + struct timeval minv = msec2tv (OSPF_MIN_LS_INTERVAL); + timersub (&minv, &delta, &minv); + + /* TBD: remove padding to full sec, return timeval instead */ + delay = minv.tv_sec + !!minv.tv_usec; if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) zlog_debug ("LSA[Type%d:%s]: Refresh timer delay %d seconds", @@ -174,12 +113,10 @@ ospf_lsa_refresh_delay (struct ospf_lsa *lsa) int get_age (struct ospf_lsa *lsa) { - int age; - - age = ntohs (lsa->data->ls_age) - + tv_floor (tv_sub (recent_relative_time (), lsa->tv_recv)); + struct timeval rel; - return age; + monotime_since (&lsa->tv_recv, &rel); + return ntohs (lsa->data->ls_age) + rel.tv_sec; } |