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.
|
* 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(...)
|
#define PRINTF(...)
|
||||||
#endif
|
#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
|
void
|
||||||
data_packet_received(struct uc_conn *uc, rimeaddr_t *from)
|
data_packet_received(struct uc_conn *uc, rimeaddr_t *from)
|
||||||
{
|
{
|
||||||
struct mh_conn *c = (struct mh_conn *)uc;
|
struct mh_conn *c = (struct mh_conn *)uc;
|
||||||
struct data_hdr *msg = rimebuf_dataptr();
|
struct data_hdr *msg = rimebuf_dataptr();
|
||||||
struct route_entry *rt;
|
rimeaddr_t *nexthop;
|
||||||
int should_forward;
|
|
||||||
|
|
||||||
PRINTF("data_packet_received from %d towards %d len %d\n", from->u16[0],
|
PRINTF("data_packet_received from %d towards %d len %d\n", from->u16[0],
|
||||||
msg->dest.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);
|
c->cb->recv(c, &msg->originator);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(c->cb->forwarding) {
|
nexthop = NULL;
|
||||||
should_forward = c->cb->forwarding(c);
|
if(c->cb->forward) {
|
||||||
} else {
|
nexthop = c->cb->forward(c, &msg->originator,
|
||||||
should_forward = 1;
|
&msg->dest, from, msg->hops);
|
||||||
}
|
}
|
||||||
if(should_forward) {
|
if(nexthop) {
|
||||||
rt = route_lookup(&msg->dest);
|
|
||||||
if(rt != NULL) {
|
|
||||||
PRINTF("forwarding to %d\n", rt->nexthop.u16[0]);
|
PRINTF("forwarding to %d\n", rt->nexthop.u16[0]);
|
||||||
/* msg->hops++;*/
|
msg->hops++;
|
||||||
uc_send(&c->c, &rt->nexthop);
|
uc_send(&c->c, 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]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,15 +114,23 @@ mh_close(struct mh_conn *c)
|
||||||
int
|
int
|
||||||
mh_send(struct mh_conn *c, rimeaddr_t *to)
|
mh_send(struct mh_conn *c, rimeaddr_t *to)
|
||||||
{
|
{
|
||||||
struct route_entry *rt;
|
rimeaddr_t *nexthop;
|
||||||
|
struct data_hdr *hdr;
|
||||||
|
|
||||||
rt = route_lookup(to);
|
nexthop = c->cb->forward(c, &rimeaddr_node_addr, to, NULL, 0);
|
||||||
if(rt == NULL) {
|
|
||||||
|
if(nexthop == NULL) {
|
||||||
PRINTF("mh_send: no route\n");
|
PRINTF("mh_send: no route\n");
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
PRINTF("mh_send: sending data\n");
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* 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__
|
#ifndef __MH_H__
|
||||||
#define __MH_H__
|
#define __MH_H__
|
||||||
|
|
||||||
#include "net/rime/abc.h"
|
#include "net/rime/uc.h"
|
||||||
#include "net/rime/rimeaddr.h"
|
#include "net/rime/rimeaddr.h"
|
||||||
|
|
||||||
struct mh_conn;
|
struct mh_conn;
|
||||||
|
|
||||||
struct mh_callbacks {
|
struct mh_callbacks {
|
||||||
void (* recv)(struct mh_conn *ptr, rimeaddr_t *sender);
|
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 {
|
struct mh_conn {
|
||||||
|
|
Loading…
Reference in a new issue