Updated the multihop forwarding interface to match the intended operation of the module: to let the user produce the route, and the mh module only does the forwarding
This commit is contained in:
parent
d9bda3bc80
commit
6e739853f7
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: mh.c,v 1.3 2007/03/31 18:31:28 adamdunkels Exp $
|
||||
* $Id: mh.c,v 1.4 2007/11/28 19:55:27 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -63,27 +63,13 @@ struct data_hdr {
|
|||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
send_data(struct mh_conn *c, rimeaddr_t *to, struct route_entry *next)
|
||||
{
|
||||
struct data_hdr *hdr;
|
||||
|
||||
if(rimebuf_hdralloc(sizeof(struct data_hdr))) {
|
||||
hdr = rimebuf_hdrptr();
|
||||
rimeaddr_copy(&hdr->dest, to);
|
||||
rimeaddr_copy(&hdr->originator, &rimeaddr_node_addr);
|
||||
uc_send(&c->c, &next->nexthop);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
data_packet_received(struct uc_conn *uc, rimeaddr_t *from)
|
||||
{
|
||||
struct mh_conn *c = (struct mh_conn *)uc;
|
||||
struct data_hdr *msg = rimebuf_dataptr();
|
||||
struct route_entry *rt;
|
||||
int should_forward;
|
||||
rimeaddr_t *nexthop;
|
||||
|
||||
PRINTF("data_packet_received from %d towards %d len %d\n", from->u16[0],
|
||||
msg->dest.u16[0],
|
||||
|
@ -96,24 +82,15 @@ data_packet_received(struct uc_conn *uc, rimeaddr_t *from)
|
|||
c->cb->recv(c, &msg->originator);
|
||||
}
|
||||
} else {
|
||||
if(c->cb->forwarding) {
|
||||
should_forward = c->cb->forwarding(c);
|
||||
} else {
|
||||
should_forward = 1;
|
||||
nexthop = NULL;
|
||||
if(c->cb->forward) {
|
||||
nexthop = c->cb->forward(c, &msg->originator,
|
||||
&msg->dest, from, msg->hops);
|
||||
}
|
||||
if(should_forward) {
|
||||
rt = route_lookup(&msg->dest);
|
||||
if(rt != NULL) {
|
||||
PRINTF("forwarding to %d\n", rt->nexthop.u16[0]);
|
||||
/* msg->hops++;*/
|
||||
uc_send(&c->c, &rt->nexthop);
|
||||
} else {
|
||||
PRINTF("%d.%d: no route to %d.%d\n",
|
||||
rimeaddr_node_addr.u8[0],
|
||||
rimeaddr_node_addr.u8[1],
|
||||
msg->dest.u8[0],
|
||||
msg->dest.u8[1]);
|
||||
}
|
||||
if(nexthop) {
|
||||
PRINTF("forwarding to %d\n", rt->nexthop.u16[0]);
|
||||
msg->hops++;
|
||||
uc_send(&c->c, nexthop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,15 +114,23 @@ mh_close(struct mh_conn *c)
|
|||
int
|
||||
mh_send(struct mh_conn *c, rimeaddr_t *to)
|
||||
{
|
||||
struct route_entry *rt;
|
||||
|
||||
rt = route_lookup(to);
|
||||
if(rt == NULL) {
|
||||
rimeaddr_t *nexthop;
|
||||
struct data_hdr *hdr;
|
||||
|
||||
nexthop = c->cb->forward(c, &rimeaddr_node_addr, to, NULL, 0);
|
||||
|
||||
if(nexthop == NULL) {
|
||||
PRINTF("mh_send: no route\n");
|
||||
return 0;
|
||||
} else {
|
||||
PRINTF("mh_send: sending data\n");
|
||||
send_data(c, to, rt);
|
||||
if(rimebuf_hdralloc(sizeof(struct data_hdr))) {
|
||||
hdr = rimebuf_hdrptr();
|
||||
rimeaddr_copy(&hdr->dest, to);
|
||||
rimeaddr_copy(&hdr->originator, &rimeaddr_node_addr);
|
||||
hdr->hops = 0;
|
||||
uc_send(&c->c, nexthop);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: mh.h,v 1.2 2007/03/31 18:31:28 adamdunkels Exp $
|
||||
* $Id: mh.h,v 1.3 2007/11/28 19:55:27 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -61,14 +61,18 @@
|
|||
#ifndef __MH_H__
|
||||
#define __MH_H__
|
||||
|
||||
#include "net/rime/abc.h"
|
||||
#include "net/rime/uc.h"
|
||||
#include "net/rime/rimeaddr.h"
|
||||
|
||||
struct mh_conn;
|
||||
|
||||
struct mh_callbacks {
|
||||
void (* recv)(struct mh_conn *ptr, rimeaddr_t *sender);
|
||||
int (* forwarding)(struct mh_conn *ptr);
|
||||
rimeaddr_t *(* forward)(struct mh_conn *ptr,
|
||||
rimeaddr_t *originator,
|
||||
rimeaddr_t *dest,
|
||||
rimeaddr_t *prevhop,
|
||||
u8_t hops);
|
||||
};
|
||||
|
||||
struct mh_conn {
|
||||
|
|
Loading…
Reference in a new issue