Send periodic updates
This commit is contained in:
parent
7601e58284
commit
dddfebf366
3 changed files with 37 additions and 9 deletions
29
ffd/ffd.c
29
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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
15
ffd/util.h
15
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_ */
|
||||
|
|
Reference in a new issue