From dddfebf3661b2d99d3483f5b9503364dd891e013 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 7 Oct 2012 03:56:38 +0200 Subject: Send periodic updates --- ffd/ffd.c | 29 +++++++++++++++++++++-------- ffd/ffd.h | 2 +- ffd/util.h | 15 +++++++++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/ffd/ffd.c b/ffd/ffd.c index 592281a..1a31298 100644 --- a/ffd/ffd.c +++ b/ffd/ffd.c @@ -463,11 +463,14 @@ static void receive_packet(void) { } } -void add_interval(struct timespec *time, int interval) { - int cs = time->tv_nsec/1e7 + interval; - - time->tv_sec += cs/100; - time->tv_nsec = time->tv_nsec%(long)1e7 + (cs%100)*1e7; +static void send_updates(void) { + ffd_iface_t *iface; + for (iface = iface_list; iface; iface = iface->next) { + ffd_neigh_t *neigh; + for (neigh = iface->neigh_list; neigh; neigh = neigh->next) { + ffd_send_update(iface, neigh, NULL, false); + } + } } int main() { @@ -483,25 +486,35 @@ int main() { update_time(); struct timespec next_hello = now; + struct timespec next_update = now; while (true) { update_netifs(); - int timeout = timespec_diff(&next_hello, &now); + int hello_timeout = timespec_diff(&next_hello, &now); + int update_timeout = timespec_diff(&next_update, &now); - if (timeout <= 0) { + if (hello_timeout <= 0) { ffd_send_hellos(); add_interval(&next_hello, FFD_HELLO_INTERVAL); continue; } + if (update_timeout <= 0) { + fprintf(stderr, "Sending periodic update.\n"); + send_updates(); + + add_interval(&next_update, FFD_UPDATE_INTERVAL); + continue; + } + struct pollfd fds[1]; fds[0].fd = sockfd; fds[0].events = POLLIN; - poll(fds, 1, timeout); + poll(fds, 1, min(hello_timeout, update_timeout)); update_time(); diff --git a/ffd/ffd.h b/ffd/ffd.h index f498f4e..3a4b9e0 100644 --- a/ffd/ffd.h +++ b/ffd/ffd.h @@ -40,7 +40,7 @@ #define FFD_HELLO_INTERVAL 400 #define FFD_IHU_INTERVAL (3*FFD_HELLO_INTERVAL) -#define FFD_UPDATE_INTERVAL 400 +#define FFD_UPDATE_INTERVAL 6000 #define FFD_UPDATE_WITH_DATA 0x01 diff --git a/ffd/util.h b/ffd/util.h index 9fd6d66..cf29311 100644 --- a/ffd/util.h +++ b/ffd/util.h @@ -58,4 +58,19 @@ static inline int timespec_diff(const struct timespec *tp1, const struct timespe return ((tp1->tv_sec - tp2->tv_sec))*1000 + (tp1->tv_nsec - tp2->tv_nsec)/1e6; } +static inline int max(int a, int b) { + return (a > b) ? a : b; +} + +static inline int min(int a, int b) { + return (a < b) ? a : b; +} + +static inline void add_interval(struct timespec *time, int interval) { + int cs = time->tv_nsec/1e7 + interval; + + time->tv_sec += cs/100; + time->tv_nsec = time->tv_nsec%(long)1e7 + (cs%100)*1e7; +} + #endif /* _FFD_UTIL_H_ */ -- cgit v1.2.3