Merge pull request #276 from mkovatsc/er-coap-13

Erbium (Er) fixes and updates
This commit is contained in:
Nicolas Tsiftes 2013-06-24 01:44:23 -07:00
commit f606322ae0
24 changed files with 86 additions and 270 deletions

View File

@ -39,6 +39,7 @@
#ifndef COAP_OBSERVING_H_
#define COAP_OBSERVING_H_
#include "sys/stimer.h"
#include "er-coap-03.h"
#include "er-coap-03-transactions.h"

View File

@ -85,8 +85,8 @@
#define COAP_MAX_ATTEMPTS 4
#endif /* COAP_MAX_ATTEMPTS */
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
#define SET_OPTION(packet, opt) ((packet)->options |= 1<<opt)
#define IS_OPTION(packet, opt) ((packet)->options & 1<<opt)

View File

@ -39,6 +39,7 @@
#ifndef COAP_OBSERVING_H_
#define COAP_OBSERVING_H_
#include "sys/stimer.h"
#include "er-coap-07.h"
#include "er-coap-07-transactions.h"

View File

@ -87,8 +87,8 @@
#define COAP_MAX_ATTEMPTS 4
#endif /* COAP_MAX_ATTEMPTS */
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
#define SET_OPTION(packet, opt) ((packet)->options |= 1L<<opt)
#define IS_OPTION(packet, opt) ((packet)->options & 1L<<opt)

View File

@ -39,6 +39,7 @@
#ifndef COAP_OBSERVING_H_
#define COAP_OBSERVING_H_
#include "sys/stimer.h"
#include "er-coap-12.h"
#include "er-coap-12-transactions.h"

View File

@ -92,8 +92,8 @@
#define COAP_MAX_ATTEMPTS 4
#endif /* COAP_MAX_ATTEMPTS */
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
/* Bitmap for set options */
enum { OPTION_MAP_SIZE = sizeof(uint8_t) * 8 };

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -220,9 +220,14 @@ coap_receive(void)
else
{
/* Responses */
if (message->type==COAP_TYPE_ACK)
if (message->type==COAP_TYPE_CON && message->code==0)
{
PRINTF("Received Ping\n");
coap_error_code = PING_RESPONSE;
}
else if (message->type==COAP_TYPE_ACK)
{
/* Transactions are closed through lookup below */
PRINTF("Received ACK\n");
}
else if (message->type==COAP_TYPE_RST)
@ -261,6 +266,8 @@ coap_receive(void)
}
else
{
coap_message_type_t reply_type = COAP_TYPE_ACK;
PRINTF("ERROR %u: %s\n", coap_error_code, coap_error_message);
coap_clear_transaction(transaction);
@ -269,8 +276,13 @@ coap_receive(void)
{
coap_error_code = INTERNAL_SERVER_ERROR_5_00;
}
if (coap_error_code == PING_RESPONSE)
{
coap_error_code = 0;
reply_type = COAP_TYPE_RST;
}
/* Reuse input buffer for error message. */
coap_init_message(message, COAP_TYPE_ACK, coap_error_code, message->mid);
coap_init_message(message, reply_type, coap_error_code, message->mid);
coap_set_payload(message, coap_error_message, strlen(coap_error_message));
coap_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, uip_appdata, coap_serialize_message(message, uip_appdata));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -39,6 +39,7 @@
#ifndef COAP_OBSERVING_H_
#define COAP_OBSERVING_H_
#include "sys/stimer.h"
#include "er-coap-13.h"
#include "er-coap-13-transactions.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -90,7 +90,7 @@ coap_parse_int_option(uint8_t *bytes, size_t length)
while (i<length)
{
var <<= 8;
var |= 0xFF & bytes[i++];
var |= bytes[i++];
}
return var;
}
@ -117,7 +117,7 @@ static
size_t
coap_set_option_header(unsigned int delta, size_t length, uint8_t *buffer)
{
size_t written = 1;
size_t written = 0;
buffer[0] = coap_option_nibble(delta)<<4 | coap_option_nibble(length);
@ -127,19 +127,19 @@ coap_set_option_header(unsigned int delta, size_t length, uint8_t *buffer)
{
if (*x>268)
{
buffer[written++] = (*x-269)>>8;
buffer[written++] = (*x-269);
buffer[++written] = (*x-269)>>8;
buffer[++written] = (*x-269);
}
else if (delta>12)
else if (*x>12)
{
buffer[written++] = (*x-13);
buffer[++written] = (*x-13);
}
}
while (x!=&length && (x=&length));
PRINTF("WRITTEN %u B opt header\n", written);
return written;
return ++written;
}
/*-----------------------------------------------------------------------------------*/
static
@ -148,14 +148,19 @@ coap_serialize_int_option(unsigned int number, unsigned int current_number, uint
{
size_t i = 0;
if (0xFF000000 & value) buffer[++i] = (uint8_t) (0xFF & value>>24);
if (0xFFFF0000 & value) buffer[++i] = (uint8_t) (0xFF & value>>16);
if (0xFFFFFF00 & value) buffer[++i] = (uint8_t) (0xFF & value>>8);
if (0xFFFFFFFF & value) buffer[++i] = (uint8_t) (0xFF & value);
if (0xFF000000 & value) ++i;
if (0xFFFF0000 & value) ++i;
if (0xFFFFFF00 & value) ++i;
if (0xFFFFFFFF & value) ++i;
PRINTF("OPTION %u (delta %u, len %u)\n", number, number - current_number, i);
i += coap_set_option_header(number - current_number, i, buffer);
i = coap_set_option_header(number - current_number, i, buffer);
if (0xFF000000 & value) buffer[i++] = (uint8_t) (value>>24);
if (0xFFFF0000 & value) buffer[i++] = (uint8_t) (value>>16);
if (0xFFFFFF00 & value) buffer[i++] = (uint8_t) (value>>8);
if (0xFFFFFFFF & value) buffer[i++] = (uint8_t) (value);
return i;
}
@ -319,8 +324,8 @@ coap_serialize_message(void *packet, uint8_t *buffer)
coap_pkt->buffer[0] |= COAP_HEADER_TYPE_MASK & (coap_pkt->type)<<COAP_HEADER_TYPE_POSITION;
coap_pkt->buffer[0] |= COAP_HEADER_TOKEN_LEN_MASK & (coap_pkt->token_len)<<COAP_HEADER_TOKEN_LEN_POSITION;
coap_pkt->buffer[1] = coap_pkt->code;
coap_pkt->buffer[2] = 0xFF & (coap_pkt->mid)>>8;
coap_pkt->buffer[3] = 0xFF & coap_pkt->mid;
coap_pkt->buffer[2] = (uint8_t) ((coap_pkt->mid)>>8);
coap_pkt->buffer[3] = (uint8_t) (coap_pkt->mid);
/* set Token */
PRINTF("Token (len %u)", coap_pkt->token_len);
@ -1008,7 +1013,7 @@ coap_set_header_observe(void *packet, uint32_t observe)
{
coap_packet_t *const coap_pkt = (coap_packet_t *) packet;
coap_pkt->observe = observe;
coap_pkt->observe = 0x00FFFFFF & observe;
SET_OPTION(coap_pkt, COAP_OPTION_OBSERVE);
return 1;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,8 +36,8 @@
* Matthias Kovatsch <kovatsch@inf.ethz.ch>
*/
#ifndef COAP_12_H_
#define COAP_12_H_
#ifndef COAP_13_H_
#define COAP_13_H_
#include <stddef.h> /* for size_t */
#include "contiki-net.h"
@ -92,8 +92,8 @@
#define COAP_MAX_ATTEMPTS 4
#endif /* COAP_MAX_ATTEMPTS */
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
/* Bitmap for set options */
enum { OPTION_MAP_SIZE = sizeof(uint8_t) * 8 };
@ -153,7 +153,8 @@ typedef enum {
PACKET_SERIALIZATION_ERROR,
/* Erbium hooks */
MANUAL_RESPONSE
MANUAL_RESPONSE,
PING_RESPONSE
} coap_status_t;
@ -379,4 +380,4 @@ int coap_set_header_size(void *packet, uint32_t size);
int coap_get_payload(void *packet, const uint8_t **payload);
int coap_set_payload(void *packet, const void *payload, size_t length);
#endif /* COAP_12_H_ */
#endif /* COAP_13_H_ */

View File

@ -1,35 +1,29 @@
all: er-example-server er-example-client
# Use this target explicitly if requried: er-plugtest-server
# use this target explicitly if requried: er-plugtest-server
CONTIKI=../..
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
# for static routing, if enabled
ifeq ($(TARGET),$(filter $(TARGET),sky cooja))
PROJECT_SOURCEFILES += static-routing.c
endif
# variable for root Makefile.include
WITH_UIP6=1
# for some platforms
UIP_CONF_IPV6=1
# radio configuration
#CFLAGS += -DRF_CHANNEL=20
#CFLAGS += -DIEEE802154_CONF_PANID=0xCAFE
# variable for this Makefile
# configure CoAP implementation (3|7|12|13) (er-coap-07 also supports CoAP draft 08)
WITH_COAP=13
# new variable since slip-radio
# variable for Makefile.include
WITH_UIP6=1
# for some platforms
UIP_CONF_IPV6=1
# IPv6 make config disappeared completely
CFLAGS += -DUIP_CONF_IPV6=1
CONTIKI=../..
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
# variable for Makefile.include
ifneq ($(TARGET), minimal-net)
UIP_CONF_RPL=1
CFLAGS += -DUIP_CONF_IPV6_RPL=1
else
# minimal-net does not support RPL under Linux and is mostly used to test CoAP only
${info INFO: compiling without RPL}
UIP_CONF_RPL=0
CFLAGS += -DUIP_CONF_ND6_DEF_MAXDADNS=0
CFLAGS += -DUIP_CONF_IPV6_RPL=0
CFLAGS += -DHARD_CODED_ADDRESS=\"fdfd::10\"
${info INFO: compiling with large buffers}
CFLAGS += -DUIP_CONF_BUFFER_SIZE=2048

View File

@ -11,7 +11,8 @@ EXAMPLE FILES
every 10 seconds and cycles through 4 resources on button press (target
address is hard-coded).
- er-plugtest-server.c: The server used for draft compliance testing at ETSI
IoT CoAP Plugtest in Paris, France, March 2012 (configured for minimal-net).
IoT CoAP Plugtests. Erbium (Er) participated in Paris, France, March 2012 and
Sophia-Antipolis, France, November 2012 (configured for minimal-net).
PRELIMINARIES
-------------

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Matthias Kovatsch and other contributors.
* Copyright (c) 2013, Matthias Kovatsch
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -43,11 +43,6 @@
#include "contiki.h"
#include "contiki-net.h"
#if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE)
#warning "Compiling with static routing!"
#include "static-routing.h"
#endif
#include "dev/button-sensor.h"
#if WITH_COAP == 3

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Matthias Kovatsch and other contributors.
* Copyright (c) 2013, Matthias Kovatsch
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -45,8 +45,7 @@
/* Define which resources to include to meet memory constraints. */
#define REST_RES_HELLO 0
#define REST_RES_MIRROR 0 /* causes largest code size */
#define REST_RES_CHUNKS 0
#define REST_RES_CHUNKS 1
#define REST_RES_SEPARATE 1
#define REST_RES_PUSHING 1
#define REST_RES_EVENT 1
@ -56,14 +55,10 @@
#define REST_RES_LIGHT 0
#define REST_RES_BATTERY 0
#define REST_RES_RADIO 0
#define REST_RES_MIRROR 0 /* causes largest code size */
#if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE)
#warning "Compiling with static routing!"
#include "static-routing.h"
#endif
#include "erbium.h"
@ -811,12 +806,6 @@ PROCESS_THREAD(rest_server_example, ev, data)
PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN);
PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE);
/* if static routes are used rather than RPL */
#if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE)
set_global_address();
configure_routing();
#endif
/* Initialize the REST engine. */
rest_init_engine();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Matthias Kovatsch and other contributors.
* Copyright (c) 2013, Matthias Kovatsch
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -69,10 +69,6 @@
#endif
#if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE)
#warning "Compiling with static routing!"
#include "static-routing.h"
#endif
#include "erbium.h"
@ -1240,12 +1236,6 @@ PROCESS_THREAD(plugtest_server, ev, data)
PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN);
PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE);
/* if static routes are used rather than RPL */
#if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET)
set_global_address();
configure_routing();
#endif
/* Initialize the REST engine. */
rest_init_engine();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Matthias Kovatsch
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -66,7 +66,7 @@
#define COAP_MAX_OBSERVERS 2
*/
/* Filtering can be disabled to save space. */
/* Filtering .well-known/core per query can be disabled to save space. */
/*
#undef COAP_LINK_FORMAT_FILTERING
#define COAP_LINK_FORMAT_FILTERING 0

View File

@ -1,155 +0,0 @@
/*
* static-routing.c
*
* Created on: Oct 12, 2010
* Author: simonduq
*/
#include <stdio.h>
#include "static-routing.h"
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",(lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3],(lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
#include "contiki-net.h"
#include "node-id.h"
int node_rank;
struct id_to_addrs {
int id;
uint32_t addr;
};
const struct id_to_addrs motes_addrs[] = {
/*
* Static routing requires a map nodeid => address.
* The nodeid can be programmed with the sky-shell.
* The addresses should also be added to /etc/hosts.
*
* aaaa::212:7400:1160:f62d sky1
* aaaa::212:7400:0da0:d748 sky2
* aaaa::212:7400:116e:c325 sky3
* aaaa::212:7400:116e:c444 sky4
* aaaa::212:7400:115e:b717 sky5
*
* Add the nodeid and last 4 bytes of the address to the map.
*/
{1, 0x1160f62d},
{2, 0x0da0d748},
{3, 0x116ec325},
{4, 0x116ec444},
{5, 0x115eb717},
};
/* Define the size of the map. */
#define NODES_IN_MAP 5
uint32_t get_mote_suffix(int rank) {
if(--rank >=0 && rank<(sizeof(motes_addrs)/sizeof(struct id_to_addrs))) {
return motes_addrs[rank].addr;
}
return 0;
}
int get_mote_id(uint32_t suffix) {
#if IN_COOJA
return suffix & 0xff;
#else
int i;
for(i=0; i<(sizeof(motes_addrs)/sizeof(struct id_to_addrs)); i++) {
if(suffix == motes_addrs[i].addr) {
return motes_addrs[i].id;
}
}
return 0;
#endif
}
void set_global_address(void) {
uip_ipaddr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
}
static void add_route_ext(int dest, int next) {
PRINTF("add route ext %d %d\n", dest, next);
uip_ipaddr_t ipaddr_dest, ipaddr_next;
uip_ip6addr(&ipaddr_dest, 0xaaaa, 0, 0, 0, 0, 0, 0, dest);
#if IN_COOJA
uip_ip6addr(&ipaddr_next, 0xfe80, 0, 0, 0, 0x0212, 0x7400 | next, next, next<<8 | next);
#else
uint32_t next_suffix = get_mote_suffix(next);
uip_ip6addr(&ipaddr_next, 0xfe80, 0, 0, 0, 0x0212, 0x7400, (next_suffix >> 16) & 0xffff, next_suffix & 0xffff);
#endif
uip_ds6_route_add(&ipaddr_dest, 128, &ipaddr_next, 0);
}
void add_route(int dest, int next) {
PRINTF("add route %d %d\n", dest, next);
uip_ipaddr_t ipaddr_dest, ipaddr_next;
#if IN_COOJA
uip_ip6addr(&ipaddr_dest, 0xaaaa, 0, 0, 0, 0x0212, 0x7400 | dest, dest, dest<<8 | dest);
uip_ip6addr(&ipaddr_next, 0xfe80, 0, 0, 0, 0x0212, 0x7400 | next, next, next<<8 | next);
#else
uint32_t dest_suffix = get_mote_suffix(dest);
uint32_t next_suffix = get_mote_suffix(next);
uip_ip6addr(&ipaddr_dest, 0xaaaa, 0, 0, 0, 0x0212, 0x7400, (dest_suffix >> 16) & 0xffff, dest_suffix & 0xffff);
uip_ip6addr(&ipaddr_next, 0xfe80, 0, 0, 0, 0x0212, 0x7400, (next_suffix >> 16) & 0xffff, next_suffix & 0xffff);
#endif
uip_ds6_route_add(&ipaddr_dest, 128, &ipaddr_next, 0);
}
void configure_routing(void) {
int i;
#if IN_COOJA
node_rank = node_id;
#else
node_rank = -1;
for(i=0; i<(sizeof(motes_addrs)/sizeof(struct id_to_addrs)); ++i) {
if(node_id == motes_addrs[i].id) {
node_rank = i+1;
break;
}
}
if(node_rank == -1) {
printf("unable to configure routing, node_id=%d\n", node_id);
return;
}
#endif
printf("configure_routing, node_id=%d, node_rank %d\n", node_id, node_rank);
if (node_rank == 1) { /* border router #1 */
add_route_ext(2, 2);
for(i=2; i<=NODES_IN_MAP; ++i) {
add_route(i, 2);
}
} else if (node_rank < NODES_IN_MAP) { /* other node */
add_route_ext(1, node_rank-1);
add_route_ext(2, node_rank+1);
for(i=1; i<=NODES_IN_MAP; ++i) {
if(i<node_rank) {
add_route(i, node_rank-1);
} else if(i>node_rank) {
add_route(i, node_rank+1);
}
}
} else if (node_rank == NODES_IN_MAP) { /* 2nd border router */
add_route_ext(1, NODES_IN_MAP-1);
for(i=1; i<=NODES_IN_MAP-1; ++i) {
add_route(i, NODES_IN_MAP-1);
}
}
}

View File

@ -1,20 +0,0 @@
/*
* static-routing.h
*
* Created on: Oct 12, 2010
* Author: simonduq
*/
#ifndef STATICROUTING_H_
#define STATICROUTING_H_
#include "contiki.h"
extern int node_rank;
extern uint32_t get_mote_suffix(int id);
extern int get_mote_id(uint32_t suffix);
extern void add_route(int dest, int next);
extern void set_global_address(void);
extern void configure_routing(void);
#endif /* STATICROUTING_H_ */