The multihop module used the pre-chameleon style packet headers. Converted it to use packet attributes instead of packet headers

This commit is contained in:
adamdunkels 2009-03-23 16:20:37 +00:00
parent c791d851bb
commit 143bf11548
2 changed files with 29 additions and 34 deletions

View file

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: multihop.c,v 1.2 2009/03/12 21:58:21 adamdunkels Exp $ * $Id: multihop.c,v 1.3 2009/03/23 16:20:37 adamdunkels Exp $
*/ */
/** /**
@ -50,12 +50,11 @@
#include <string.h> #include <string.h>
struct data_hdr { static const struct packetbuf_attrlist attributes[] =
rimeaddr_t dest; {
rimeaddr_t originator; MULTIHOP_ATTRIBUTES
uint8_t hops; PACKETBUF_ATTR_LAST
uint8_t pad; };
};
#define DEBUG 0 #define DEBUG 0
#if DEBUG #if DEBUG
@ -70,31 +69,30 @@ void
data_packet_received(struct unicast_conn *uc, rimeaddr_t *from) data_packet_received(struct unicast_conn *uc, rimeaddr_t *from)
{ {
struct multihop_conn *c = (struct multihop_conn *)uc; struct multihop_conn *c = (struct multihop_conn *)uc;
struct data_hdr msg;
rimeaddr_t *nexthop; rimeaddr_t *nexthop;
memcpy(&msg, packetbuf_dataptr(), sizeof(struct data_hdr));
PRINTF("data_packet_received from %d.%d towards %d.%d len %d\n", PRINTF("data_packet_received from %d.%d towards %d.%d len %d\n",
from->u8[0], from->u8[1], from->u8[0], from->u8[1],
msg.dest.u8[0], msg.dest.u8[1], msg.dest.u8[0], msg.dest.u8[1],
packetbuf_datalen()); packetbuf_datalen());
if(rimeaddr_cmp(&msg.dest, &rimeaddr_node_addr)) { if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_ERECEIVER),
&rimeaddr_node_addr)) {
PRINTF("for us!\n"); PRINTF("for us!\n");
packetbuf_hdrreduce(sizeof(struct data_hdr));
if(c->cb->recv) { if(c->cb->recv) {
c->cb->recv(c, &msg.originator, from, msg.hops); c->cb->recv(c, packetbuf_addr(PACKETBUF_ADDR_ESENDER), from,
packetbuf_attr(PACKETBUF_ATTR_HOPS));
} }
} else { } else {
nexthop = NULL; nexthop = NULL;
if(c->cb->forward) { if(c->cb->forward) {
packetbuf_hdrreduce(sizeof(struct data_hdr)); nexthop = c->cb->forward(c,
nexthop = c->cb->forward(c, &msg.originator, packetbuf_addr(PACKETBUF_ADDR_ESENDER),
&msg.dest, from, msg.hops); packetbuf_addr(PACKETBUF_ADDR_ERECEIVER),
packetbuf_hdralloc(sizeof(struct data_hdr)); from, packetbuf_attr(PACKETBUF_ATTR_HOPS));
msg.hops++;
memcpy(packetbuf_hdrptr(), &msg, sizeof(struct data_hdr)); packetbuf_set_attr(PACKETBUF_ATTR_HOPS,
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]);
@ -110,6 +108,7 @@ multihop_open(struct multihop_conn *c, uint16_t channel,
const struct multihop_callbacks *callbacks) const struct multihop_callbacks *callbacks)
{ {
unicast_open(&c->c, channel, &data_callbacks); unicast_open(&c->c, channel, &data_callbacks);
channel_set_attributes(channel, attributes);
c->cb = callbacks; c->cb = callbacks;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -123,7 +122,6 @@ int
multihop_send(struct multihop_conn *c, rimeaddr_t *to) multihop_send(struct multihop_conn *c, rimeaddr_t *to)
{ {
rimeaddr_t *nexthop; rimeaddr_t *nexthop;
struct data_hdr *hdr;
if(c->cb->forward == NULL) { if(c->cb->forward == NULL) {
return 0; return 0;
@ -137,13 +135,10 @@ multihop_send(struct multihop_conn *c, 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]);
if(packetbuf_hdralloc(sizeof(struct data_hdr))) { packetbuf_set_addr(PACKETBUF_ADDR_ERECEIVER, to);
hdr = packetbuf_hdrptr(); packetbuf_set_addr(PACKETBUF_ADDR_ESENDER, &rimeaddr_node_addr);
rimeaddr_copy(&hdr->dest, to); packetbuf_set_attr(PACKETBUF_ATTR_HOPS, 1);
rimeaddr_copy(&hdr->originator, &rimeaddr_node_addr);
hdr->hops = 1;
unicast_send(&c->c, nexthop); unicast_send(&c->c, nexthop);
}
return 1; return 1;
} }
} }

View file

@ -58,7 +58,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: multihop.h,v 1.4 2009/03/12 21:58:21 adamdunkels Exp $ * $Id: multihop.h,v 1.5 2009/03/23 16:20:37 adamdunkels Exp $
*/ */
/** /**
@ -78,20 +78,20 @@ struct multihop_conn;
#define MULTIHOP_ATTRIBUTES { PACKETBUF_ADDR_ESENDER, PACKETBUF_ADDRSIZE }, \ #define MULTIHOP_ATTRIBUTES { PACKETBUF_ADDR_ESENDER, PACKETBUF_ADDRSIZE }, \
{ PACKETBUF_ADDR_ERECEIVER, PACKETBUF_ADDRSIZE }, \ { PACKETBUF_ADDR_ERECEIVER, PACKETBUF_ADDRSIZE }, \
{ PACKETBUF_ATTR_TTL, PACKETBUF_ATTR_BIT * 5 }, \ { PACKETBUF_ATTR_HOPS, PACKETBUF_ATTR_BIT * 5 }, \
UNICAST_ATTRIBUTES UNICAST_ATTRIBUTES
struct multihop_callbacks { struct multihop_callbacks {
void (* recv)(struct multihop_conn *ptr, void (* recv)(struct multihop_conn *ptr,
rimeaddr_t *sender, const rimeaddr_t *sender,
rimeaddr_t *prevhop, const rimeaddr_t *prevhop,
uint8_t hops); uint8_t hops);
rimeaddr_t *(* forward)(struct multihop_conn *ptr, rimeaddr_t *(* forward)(struct multihop_conn *ptr,
rimeaddr_t *originator, const rimeaddr_t *originator,
rimeaddr_t *dest, const rimeaddr_t *dest,
rimeaddr_t *prevhop, const rimeaddr_t *prevhop,
uint8_t hops); uint8_t hops);
}; };