Send periodic updates

This commit is contained in:
Matthias Schiffer 2012-10-07 03:56:38 +02:00
parent 7601e58284
commit dddfebf366
3 changed files with 37 additions and 9 deletions

View file

@ -463,11 +463,14 @@ static void receive_packet(void) {
} }
} }
void add_interval(struct timespec *time, int interval) { static void send_updates(void) {
int cs = time->tv_nsec/1e7 + interval; ffd_iface_t *iface;
for (iface = iface_list; iface; iface = iface->next) {
time->tv_sec += cs/100; ffd_neigh_t *neigh;
time->tv_nsec = time->tv_nsec%(long)1e7 + (cs%100)*1e7; for (neigh = iface->neigh_list; neigh; neigh = neigh->next) {
ffd_send_update(iface, neigh, NULL, false);
}
}
} }
int main() { int main() {
@ -483,25 +486,35 @@ int main() {
update_time(); update_time();
struct timespec next_hello = now; struct timespec next_hello = now;
struct timespec next_update = now;
while (true) { while (true) {
update_netifs(); 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(); ffd_send_hellos();
add_interval(&next_hello, FFD_HELLO_INTERVAL); add_interval(&next_hello, FFD_HELLO_INTERVAL);
continue; 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]; struct pollfd fds[1];
fds[0].fd = sockfd; fds[0].fd = sockfd;
fds[0].events = POLLIN; fds[0].events = POLLIN;
poll(fds, 1, timeout); poll(fds, 1, min(hello_timeout, update_timeout));
update_time(); update_time();

View file

@ -40,7 +40,7 @@
#define FFD_HELLO_INTERVAL 400 #define FFD_HELLO_INTERVAL 400
#define FFD_IHU_INTERVAL (3*FFD_HELLO_INTERVAL) #define FFD_IHU_INTERVAL (3*FFD_HELLO_INTERVAL)
#define FFD_UPDATE_INTERVAL 400 #define FFD_UPDATE_INTERVAL 6000
#define FFD_UPDATE_WITH_DATA 0x01 #define FFD_UPDATE_WITH_DATA 0x01

View file

@ -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; 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_ */ #endif /* _FFD_UTIL_H_ */