Add a neighbour packet timeout to prevent new neighbours to be purged right after a route request has been received

This commit is contained in:
Matthias Schiffer 2013-08-03 03:18:54 +02:00
parent 48f77c26dc
commit b63b1bef96
4 changed files with 24 additions and 10 deletions

View file

@ -60,7 +60,15 @@ static void maintain_neighbours(gmrf_context_t *ctx) {
gp_babel_neigh_t *neigh = *cur; gp_babel_neigh_t *neigh = *cur;
next = &neigh->next; next = &neigh->next;
if (gp_babel_neigh_get_rxcost(ctx, neigh) == GP_BABEL_INFINITY && gp_babel_neigh_get_txcost(ctx, neigh) == GP_BABEL_INFINITY && !neigh->ref) { if ((gp_babel_neigh_get_rxcost(ctx, neigh) == GP_BABEL_INFINITY)
&& (gp_babel_neigh_get_txcost(ctx, neigh) == GP_BABEL_INFINITY)
&& (gp_babel_since(ctx, neigh->last_packet) > GP_BABEL_NEIGH_PACKET_TIMEOUT)
&& !neigh->ref) {
gmrf_logf(ctx->gmrf, LOG_DEBUG, "maintenance: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x[%s]: expired (%ims since last packet)",
neigh->addr.d[0], neigh->addr.d[1], neigh->addr.d[2], neigh->addr.d[3],
neigh->addr.d[4], neigh->addr.d[5], neigh->addr.d[6], neigh->addr.d[7],
gmrf_iface_get_name(ctx->gmrf, iface->gmrf_iface), (int)gp_babel_since(ctx, neigh->last_packet)*10);
*cur = *next; *cur = *next;
next = cur; next = cur;
free(neigh); free(neigh);

View file

@ -45,6 +45,7 @@
#define GP_BABEL_UPDATE_REQUEST_TIMEOUT(interval) ((interval)*13/4) /* 3.25 intervals */ #define GP_BABEL_UPDATE_REQUEST_TIMEOUT(interval) ((interval)*13/4) /* 3.25 intervals */
#define GP_BABEL_MAINTENANCE_INTERVAL GP_BABEL_HELLO_INTERVAL #define GP_BABEL_MAINTENANCE_INTERVAL GP_BABEL_HELLO_INTERVAL
#define GP_BABEL_NEIGH_PACKET_TIMEOUT 6000
#define GP_BABEL_SEQNO_REQ_HOP_LIMIT 127 #define GP_BABEL_SEQNO_REQ_HOP_LIMIT 127
@ -75,6 +76,7 @@ struct gp_babel_neigh {
gp_babel_neigh_t *next; gp_babel_neigh_t *next;
unsigned ref; unsigned ref;
gmrf_time_t last_packet;
gmrf_iface_state_t *iface; gmrf_iface_state_t *iface;
gmrf_addr_t addr; gmrf_addr_t addr;

View file

@ -36,6 +36,7 @@ gp_babel_neigh_t* gp_babel_neigh_get(gmrf_iface_state_t *iface, const gmrf_addr_
neigh->next = iface->neighbours; neigh->next = iface->neighbours;
neigh->iface = iface; neigh->iface = iface;
iface->neighbours = neigh; iface->neighbours = neigh;
neigh->last_packet = gmrf_time_unspec;
neigh->last_hello = gmrf_time_unspec; neigh->last_hello = gmrf_time_unspec;
neigh->last_ihu = gmrf_time_unspec; neigh->last_ihu = gmrf_time_unspec;
neigh->addr = *addr; neigh->addr = *addr;
@ -106,5 +107,6 @@ uint16_t gp_babel_neigh_get_cost(gmrf_context_t *ctx, const gp_babel_neigh_t *ne
} }
void gp_babel_neigh_reset(gmrf_context_t *ctx, gmrf_iface_state_t *iface, gp_babel_neigh_t *neigh) { void gp_babel_neigh_reset(gmrf_context_t *ctx, gmrf_iface_state_t *iface, gp_babel_neigh_t *neigh) {
gp_babel_send_route_request(ctx, iface, neigh, NULL);
//gp_babel_send_route_request(ctx, iface, neigh, NULL);
} }

View file

@ -39,8 +39,10 @@ typedef struct handle_tlv_arg {
gp_babel_node_id_t node_id; gp_babel_node_id_t node_id;
} handle_tlv_arg_t; } handle_tlv_arg_t;
static inline gp_babel_neigh_t* get_tlv_neigh(handle_tlv_arg_t *arg) { static inline gp_babel_neigh_t* get_tlv_neigh(gmrf_context_t *ctx, handle_tlv_arg_t *arg) {
return gp_babel_neigh_get(arg->iface, arg->source); gp_babel_neigh_t *neigh = gp_babel_neigh_get(arg->iface, arg->source);
neigh->last_packet = gmrf_now(ctx->gmrf);
return neigh;
} }
static void handle_tlv_ack_req(gmrf_context_t *ctx, const gp_babel_tlv_ack_req_t *tlv, size_t len, handle_tlv_arg_t *arg) { static void handle_tlv_ack_req(gmrf_context_t *ctx, const gp_babel_tlv_ack_req_t *tlv, size_t len, handle_tlv_arg_t *arg) {
@ -49,7 +51,7 @@ static void handle_tlv_ack_req(gmrf_context_t *ctx, const gp_babel_tlv_ack_req_t
return; return;
} }
gp_babel_send_ack(ctx, get_tlv_neigh(arg), ntohs(tlv->nonce)); gp_babel_send_ack(ctx, get_tlv_neigh(ctx, arg), ntohs(tlv->nonce));
} }
static void handle_tlv_ack(gmrf_context_t *ctx, const gp_babel_tlv_ack_t *tlv, size_t len, handle_tlv_arg_t *arg) { static void handle_tlv_ack(gmrf_context_t *ctx, const gp_babel_tlv_ack_t *tlv, size_t len, handle_tlv_arg_t *arg) {
@ -72,7 +74,7 @@ static void handle_tlv_hello(gmrf_context_t *ctx, const gp_babel_tlv_hello_t *tl
arg->source->d[4], arg->source->d[5], arg->source->d[6], arg->source->d[7], arg->source->d[4], arg->source->d[5], arg->source->d[6], arg->source->d[7],
gmrf_iface_get_name(ctx->gmrf, arg->iface->gmrf_iface), ntohs(tlv->seqno)); gmrf_iface_get_name(ctx->gmrf, arg->iface->gmrf_iface), ntohs(tlv->seqno));
gp_babel_neigh_t *neigh = get_tlv_neigh(arg); gp_babel_neigh_t *neigh = get_tlv_neigh(ctx, arg);
uint16_t seqno = ntohs(tlv->seqno); uint16_t seqno = ntohs(tlv->seqno);
@ -131,7 +133,7 @@ static void handle_tlv_ihu(gmrf_context_t *ctx, const gp_babel_tlv_ihu_t *tlv, s
return; return;
} }
gp_babel_neigh_t *neigh = get_tlv_neigh(arg); gp_babel_neigh_t *neigh = get_tlv_neigh(ctx, arg);
neigh->ihu_interval = ntohs(tlv->interval); neigh->ihu_interval = ntohs(tlv->interval);
neigh->last_ihu = gmrf_now(ctx->gmrf); neigh->last_ihu = gmrf_now(ctx->gmrf);
neigh->txcost = ntohs(tlv->rxcost); neigh->txcost = ntohs(tlv->rxcost);
@ -177,7 +179,7 @@ static void handle_tlv_update(gmrf_context_t *ctx, const gp_babel_tlv_update_t *
bool feasible = gp_babel_is_feasible(route, ms); bool feasible = gp_babel_is_feasible(route, ms);
gp_babel_neigh_t *neigh = get_tlv_neigh(arg); gp_babel_neigh_t *neigh = get_tlv_neigh(ctx, arg);
gp_babel_nexthop_t *nexthop = gp_babel_route_nexthop_find(route, neigh); gp_babel_nexthop_t *nexthop = gp_babel_route_nexthop_find(route, neigh);
gmrf_logf(ctx->gmrf, LOG_DEBUG, "update received from %04x%04x, metric %u, seqno %04x.", gmrf_logf(ctx->gmrf, LOG_DEBUG, "update received from %04x%04x, metric %u, seqno %04x.",
@ -218,7 +220,7 @@ static void handle_tlv_route_req(gmrf_context_t *ctx, const gp_babel_tlv_route_r
return; return;
} }
gp_babel_neigh_t *neigh = get_tlv_neigh(arg); gp_babel_neigh_t *neigh = get_tlv_neigh(ctx, arg);
if (gp_babel_node_id_is_unspec(&tlv->node)) { if (gp_babel_node_id_is_unspec(&tlv->node)) {
gmrf_logf(ctx->gmrf, LOG_DEBUG, "received wildcard route request, dumping table."); gmrf_logf(ctx->gmrf, LOG_DEBUG, "received wildcard route request, dumping table.");
@ -253,7 +255,7 @@ static void handle_tlv_seqno_req(gmrf_context_t *ctx, const gp_babel_tlv_seqno_r
ntohl(*(uint32_t*)tlv->node.id), ntohl(*(uint32_t*)(tlv->node.id+4)), ntohl(*(uint32_t*)tlv->node.id), ntohl(*(uint32_t*)(tlv->node.id+4)),
ntohs(tlv->seqno)); ntohs(tlv->seqno));
gp_babel_neigh_t *neigh = get_tlv_neigh(arg); gp_babel_neigh_t *neigh = get_tlv_neigh(ctx, arg);
if (!gp_babel_less(route->metric.seqno, ntohs(tlv->seqno))) { if (!gp_babel_less(route->metric.seqno, ntohs(tlv->seqno))) {
/* local seqno is high enough */ /* local seqno is high enough */