#include <zebra.h>
+#include "monotime.h"
#include "linklist.h"
#include "thread.h"
#include "prefix.h"
struct timeval result;
if (!t)
return "inactive";
-
- result = tv_sub (t->u.sands, recent_relative_time());
+
+ monotime_until (&t->u.sands, &result);
return ospf_timeval_dump (&result, buf, size);
}
#include <zebra.h>
+#include "monotime.h"
#include "linklist.h"
#include "prefix.h"
#include "if.h"
"while local one is initial instance.");
; /* Accept this LSA for quick LSDB resynchronization. */
}
- else if (tv_cmp (tv_sub (recent_relative_time (), current->tv_recv),
- msec2tv (ospf->min_ls_arrival)) < 0)
+ else if (monotime_since (¤t->tv_recv, NULL)
+ < ospf->min_ls_arrival * 1000LL)
{
if (IS_DEBUG_OSPF_EVENT)
zlog_debug ("LSA[Flooding]: LSA is received recently.");
#include <zebra.h>
+#include "monotime.h"
#include "linklist.h"
#include "prefix.h"
#include "if.h"
}
-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)
{
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",
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;
}
/* Prototypes. */
/* XXX: Eek, time functions, similar are in lib/thread.c */
-extern struct timeval tv_adjust (struct timeval);
-extern int tv_ceil (struct timeval);
-extern int tv_floor (struct timeval);
extern struct timeval int2tv (int);
extern struct timeval msec2tv (int);
-extern struct timeval tv_add (struct timeval, struct timeval);
-extern struct timeval tv_sub (struct timeval, struct timeval);
-extern int tv_cmp (struct timeval, struct timeval);
extern int get_age (struct ospf_lsa *);
extern u_int16_t ospf_lsa_checksum (struct lsa_header *);
#include <zebra.h>
+#include "monotime.h"
#include "thread.h"
#include "memory.h"
#include "linklist.h"
struct ospf_lsa *lsa;
if ((lsa = rn->info) != NULL)
- /* Don't retransmit an LSA if we received it within
- the last RxmtInterval seconds - this is to allow the
- neighbour a chance to acknowledge the LSA as it may
- have ben just received before the retransmit timer
- fired. This is a small tweak to what is in the RFC,
- but it will cut out out a lot of retransmit traffic
- - MAG */
- if (tv_cmp (tv_sub (recent_relative_time (), lsa->tv_recv),
- int2tv (retransmit_interval)) >= 0)
- listnode_add (update, rn->info);
+ {
+ /* Don't retransmit an LSA if we received it within
+ the last RxmtInterval seconds - this is to allow the
+ neighbour a chance to acknowledge the LSA as it may
+ have ben just received before the retransmit timer
+ fired. This is a small tweak to what is in the RFC,
+ but it will cut out out a lot of retransmit traffic
+ - MAG */
+ if (monotime_since (&lsa->tv_recv, NULL)
+ >= retransmit_interval * 1000000LL)
+ listnode_add (update, rn->info);
+ }
}
}
}
else
{
- struct timeval t, now;
- quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
- t = tv_sub (now, nbr->last_send_ts);
- if (tv_cmp (t, int2tv (nbr->v_inactivity)) < 0)
+ if (monotime_since (&nbr->last_send_ts, NULL)
+ < nbr->v_inactivity * 1000000LL)
{
/* In states Loading and Full the slave must resend
its last Database Description packet in response to
recent) LSA instance. */
else
{
- struct timeval now;
-
- quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
-
- if (tv_cmp (tv_sub (now, current->tv_orig),
- msec2tv (ospf->min_ls_arrival)) >= 0)
+ if (monotime_since (¤t->tv_orig, NULL)
+ >= ospf->min_ls_arrival * 1000LL)
/* Trap NSSA type later.*/
ospf_ls_upd_send_lsa (nbr, current, OSPF_SEND_PACKET_DIRECT);
DISCARD_LSA (lsa, 8);
#include <zebra.h>
+#include "monotime.h"
#include "thread.h"
#include "memory.h"
#include "hash.h"
ospf_spf_calculate_schedule (struct ospf *ospf, ospf_spf_reason_t reason)
{
unsigned long delay, elapsed, ht;
- struct timeval result;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug ("SPF: calculation timer scheduled");
(void *)ospf->t_spf_calc);
return;
}
-
- /* XXX Monotic timers: we only care about relative time here. */
- result = tv_sub (recent_relative_time (), ospf->ts_spf);
-
- elapsed = (result.tv_sec * 1000) + (result.tv_usec / 1000);
+
+ elapsed = monotime_since (&ospf->ts_spf, NULL) / 1000;
+
ht = ospf->spf_holdtime * ospf->spf_hold_multiplier;
if (ht > ospf->spf_max_holdtime)
#include <zebra.h>
#include <string.h>
+#include "monotime.h"
#include "memory.h"
#include "thread.h"
#include "prefix.h"
json_object_boolean_true_add(json_area, "indefiniteActiveAdmin");
if (area->t_stub_router)
{
- struct timeval result;
- unsigned long time_store = 0;
- result = tv_sub (area->t_stub_router->u.sands, recent_relative_time());
- time_store = (1000 * result.tv_sec) + (result.tv_usec / 1000);
+ long time_store;
+ time_store = monotime_until(&area->t_stub_router->u.sands, NULL) / 1000LL;
json_object_int_add(json_area, "activeStartupRemainderMsecs", time_store);
}
}
{
if (use_json)
{
- unsigned long time_store = 0;
- result = tv_sub (ospf->t_deferred_shutdown->u.sands, recent_relative_time());
- time_store = (1000 * result.tv_sec) + (result.tv_usec / 1000);
+ long time_store;
+ time_store = monotime_until(&ospf->t_deferred_shutdown->u.sands, NULL) / 1000LL;
json_object_int_add(json, "deferredShutdownMsecs", time_store);
}
else
{
if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec)
{
- unsigned long time_store = 0;
+ long time_store = 0;
- result = tv_sub (recent_relative_time(), ospf->ts_spf);
- result = tv_sub (result, recent_relative_time());
- time_store = (1000 * result.tv_sec) + (result.tv_usec / 1000);
+ time_store = monotime_since(&ospf->ts_spf, NULL) / 1000LL;
json_object_int_add(json, "spfLastExecutedMsecs", time_store);
time_store = (1000 * ospf->ts_spf_duration.tv_sec) + (ospf->ts_spf_duration.tv_usec / 1000);
vty_out (vty, " SPF algorithm ");
if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec)
{
- result = tv_sub (recent_relative_time(), ospf->ts_spf);
+ monotime_since(&ospf->ts_spf, &result);
vty_out (vty, "last executed %s ago%s",
ospf_timeval_dump (&result, timebuf, sizeof (timebuf)),
VTY_NEWLINE);
if (use_json)
{
- struct timeval temp_time;
- unsigned long time_store = 0;
-
if (ospf->t_spf_calc)
{
- temp_time = tv_sub (ospf->t_spf_calc->u.sands, recent_relative_time());
- time_store = (1000 * temp_time.tv_sec) + (temp_time.tv_usec / 1000);
+ long time_store;
+ time_store = monotime_until(&ospf->t_spf_calc->u.sands, NULL) / 1000LL;
json_object_int_add(json, "spfTimerDueInMsecs", time_store);
}
char timebuf[OSPF_TIME_DUMP_SIZE];
if (use_json)
{
- struct timeval result;
- unsigned long time_store = 0;
- if (oi->t_hello)
- result = tv_sub (oi->t_hello->u.sands, recent_relative_time());
- else
- {
- result.tv_sec = 0;
- result.tv_usec = 0;
- }
- time_store = (1000 * result.tv_sec) + (result.tv_usec / 1000);
+ long time_store = 0;
+ if (oi->t_hello)
+ time_store = monotime_until(&oi->t_hello->u.sands, NULL) / 1000LL;
json_object_int_add(json_interface_sub, "timerHelloInMsecs", time_store);
}
else
json_neighbor = json_object_new_object();
ospf_nbr_state_message (nbr, msgbuf, 16);
- struct timeval result;
- unsigned long time_store = 0;
+ long time_store;
- result = tv_sub (nbr->t_inactivity->u.sands, recent_relative_time());
- time_store = (1000 * result.tv_sec) + (result.tv_usec / 1000);
+ time_store = monotime_until(&nbr->t_inactivity->u.sands, NULL) / 1000LL;
json_object_int_add (json_neighbor, "priority", nbr->priority);
json_object_string_add (json_neighbor, "state", msgbuf);
/* Show poll-interval timer. */
if (use_json)
{
- struct timeval res = tv_sub (nbr_nbma->t_poll->u.sands, recent_relative_time ());
- unsigned long time_store = 0;
- time_store = (1000 * res.tv_sec) + (res.tv_usec / 1000);
+ long time_store;
+ time_store = monotime_until(&nbr_nbma->t_poll->u.sands, NULL) / 1000LL;
json_object_int_add(json_sub, "pollIntervalTimerDueMsec", time_store);
}
else
if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec)
{
- struct timeval res = tv_sub (recent_relative_time (), nbr->ts_last_progress);
+ struct timeval res;
+ long time_store;
+
+ time_store = monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
if (use_json)
{
- unsigned long time_store = 0;
- time_store = (1000 * res.tv_sec) + (res.tv_usec / 1000);
json_object_int_add(json_sub, "lastPrgrsvChangeMsec", time_store);
}
else
if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec)
{
- struct timeval res = tv_sub (recent_relative_time (), nbr->ts_last_regress);
+ struct timeval res;
+ long time_store;
+
+ time_store = monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
if (use_json)
{
- unsigned long time_store = 0;
- time_store = (1000 * res.tv_sec) + (res.tv_usec / 1000);
json_object_int_add(json_sub, "lastRegressiveChangeMsec", time_store);
if (nbr->last_regress_str)
json_object_string_add(json_sub, "lastRegressiveChangeReason", nbr->last_regress_str);
{
if (nbr->t_inactivity)
{
- struct timeval res = tv_sub (nbr->t_inactivity->u.sands, recent_relative_time ());
- unsigned long time_store = 0;
- time_store = (1000 * res.tv_sec) + (res.tv_usec / 1000);
+ long time_store;
+ time_store = monotime_until(&nbr->t_inactivity->u.sands, NULL) / 1000LL;
json_object_int_add(json_sub, "routerDeadIntervalTimerDueMsec", time_store);
}
else