Improved multihop/mesh route discovery.
Packetbuffer is now saved before route discovery and resent when a route is found. This solves the following problems: - First packet sent to a certain node is corrupted. - Packet to be forwarded that triggers route discovery is lost.
This commit is contained in:
parent
7397e86f9c
commit
84105f4e47
|
@ -94,7 +94,15 @@ data_packet_forward(struct multihop_conn *multihop,
|
||||||
|
|
||||||
rt = route_lookup(dest);
|
rt = route_lookup(dest);
|
||||||
if(rt == NULL) {
|
if(rt == NULL) {
|
||||||
|
if(c->queued_data != NULL) {
|
||||||
|
queuebuf_free(c->queued_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
PRINTF("data_packet_forward: queueing data, sending rreq\n");
|
||||||
|
c->queued_data = queuebuf_new_from_packetbuf();
|
||||||
|
rimeaddr_copy(&c->queued_data_dest, dest);
|
||||||
route_discovery_discover(&c->route_discovery_conn, dest, PACKET_TIMEOUT);
|
route_discovery_discover(&c->route_discovery_conn, dest, PACKET_TIMEOUT);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
route_refresh(rt);
|
route_refresh(rt);
|
||||||
|
@ -106,15 +114,21 @@ data_packet_forward(struct multihop_conn *multihop,
|
||||||
static void
|
static void
|
||||||
found_route(struct route_discovery_conn *rdc, const rimeaddr_t *dest)
|
found_route(struct route_discovery_conn *rdc, const rimeaddr_t *dest)
|
||||||
{
|
{
|
||||||
|
struct route_entry *rt;
|
||||||
struct mesh_conn *c = (struct mesh_conn *)
|
struct mesh_conn *c = (struct mesh_conn *)
|
||||||
((char *)rdc - offsetof(struct mesh_conn, route_discovery_conn));
|
((char *)rdc - offsetof(struct mesh_conn, route_discovery_conn));
|
||||||
|
|
||||||
|
PRINTF("found_route\n");
|
||||||
|
|
||||||
if(c->queued_data != NULL &&
|
if(c->queued_data != NULL &&
|
||||||
rimeaddr_cmp(dest, &c->queued_data_dest)) {
|
rimeaddr_cmp(dest, &c->queued_data_dest)) {
|
||||||
queuebuf_to_packetbuf(c->queued_data);
|
queuebuf_to_packetbuf(c->queued_data);
|
||||||
queuebuf_free(c->queued_data);
|
queuebuf_free(c->queued_data);
|
||||||
c->queued_data = NULL;
|
c->queued_data = NULL;
|
||||||
if(multihop_send(&c->multihop, dest)) {
|
|
||||||
|
rt = route_lookup(dest);
|
||||||
|
if (rt != NULL) {
|
||||||
|
multihop_resend(&c->multihop, &rt->nexthop);
|
||||||
c->cb->sent(c);
|
c->cb->sent(c);
|
||||||
} else {
|
} else {
|
||||||
c->cb->timedout(c);
|
c->cb->timedout(c);
|
||||||
|
@ -175,15 +189,7 @@ mesh_send(struct mesh_conn *c, const rimeaddr_t *to)
|
||||||
could_send = multihop_send(&c->multihop, to);
|
could_send = multihop_send(&c->multihop, to);
|
||||||
|
|
||||||
if(!could_send) {
|
if(!could_send) {
|
||||||
if(c->queued_data != NULL) {
|
PRINTF("mesh_send: could not send\n");
|
||||||
queuebuf_free(c->queued_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
PRINTF("mesh_send: queueing data, sending rreq\n");
|
|
||||||
c->queued_data = queuebuf_new_from_packetbuf();
|
|
||||||
rimeaddr_copy(&c->queued_data_dest, to);
|
|
||||||
route_discovery_discover(&c->route_discovery_conn, to,
|
|
||||||
PACKET_TIMEOUT);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
c->cb->sent(c);
|
c->cb->sent(c);
|
||||||
|
|
|
@ -94,11 +94,10 @@ data_packet_received(struct unicast_conn *uc, const rimeaddr_t *from)
|
||||||
} else {
|
} else {
|
||||||
nexthop = NULL;
|
nexthop = NULL;
|
||||||
if(c->cb->forward) {
|
if(c->cb->forward) {
|
||||||
nexthop = c->cb->forward(c, &sender, &receiver,
|
|
||||||
from, packetbuf_attr(PACKETBUF_ATTR_HOPS));
|
|
||||||
|
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_HOPS,
|
packetbuf_set_attr(PACKETBUF_ATTR_HOPS,
|
||||||
packetbuf_attr(PACKETBUF_ATTR_HOPS) + 1);
|
packetbuf_attr(PACKETBUF_ATTR_HOPS) + 1);
|
||||||
|
nexthop = c->cb->forward(c, &sender, &receiver,
|
||||||
|
from, packetbuf_attr(PACKETBUF_ATTR_HOPS) - 1);
|
||||||
}
|
}
|
||||||
if(nexthop) {
|
if(nexthop) {
|
||||||
PRINTF("forwarding to %d.%d\n", nexthop->u8[0], nexthop->u8[1]);
|
PRINTF("forwarding to %d.%d\n", nexthop->u8[0], nexthop->u8[1]);
|
||||||
|
@ -133,6 +132,9 @@ multihop_send(struct multihop_conn *c, const rimeaddr_t *to)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
packetbuf_compact();
|
packetbuf_compact();
|
||||||
|
packetbuf_set_addr(PACKETBUF_ADDR_ERECEIVER, to);
|
||||||
|
packetbuf_set_addr(PACKETBUF_ADDR_ESENDER, &rimeaddr_node_addr);
|
||||||
|
packetbuf_set_attr(PACKETBUF_ATTR_HOPS, 1);
|
||||||
nexthop = c->cb->forward(c, &rimeaddr_node_addr, to, NULL, 0);
|
nexthop = c->cb->forward(c, &rimeaddr_node_addr, to, NULL, 0);
|
||||||
|
|
||||||
if(nexthop == NULL) {
|
if(nexthop == NULL) {
|
||||||
|
@ -141,12 +143,15 @@ multihop_send(struct multihop_conn *c, const rimeaddr_t *to)
|
||||||
} else {
|
} else {
|
||||||
PRINTF("multihop_send: sending data towards %d.%d\n",
|
PRINTF("multihop_send: sending data towards %d.%d\n",
|
||||||
nexthop->u8[0], nexthop->u8[1]);
|
nexthop->u8[0], nexthop->u8[1]);
|
||||||
packetbuf_set_addr(PACKETBUF_ADDR_ERECEIVER, to);
|
|
||||||
packetbuf_set_addr(PACKETBUF_ADDR_ESENDER, &rimeaddr_node_addr);
|
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_HOPS, 1);
|
|
||||||
unicast_send(&c->c, nexthop);
|
unicast_send(&c->c, nexthop);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
multihop_resend(const struct multihop_conn *const c, const rimeaddr_t *const nexthop)
|
||||||
|
{
|
||||||
|
unicast_send(&c->c, nexthop);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -104,6 +104,7 @@ void multihop_open(struct multihop_conn *c, uint16_t channel,
|
||||||
const struct multihop_callbacks *u);
|
const struct multihop_callbacks *u);
|
||||||
void multihop_close(struct multihop_conn *c);
|
void multihop_close(struct multihop_conn *c);
|
||||||
int multihop_send(struct multihop_conn *c, const rimeaddr_t *to);
|
int multihop_send(struct multihop_conn *c, const rimeaddr_t *to);
|
||||||
|
void multihop_resend(const struct multihop_conn *const c, const rimeaddr_t *const nexthop);
|
||||||
|
|
||||||
#endif /* __MULTIHOP_H__ */
|
#endif /* __MULTIHOP_H__ */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
Loading…
Reference in a new issue