Update to the new ds6_route API

This commit is contained in:
George Oikonomou 2012-12-16 17:50:36 +00:00
parent 64a95dcb59
commit f5bc1c92ba
2 changed files with 126 additions and 134 deletions

View file

@ -41,6 +41,7 @@
#include "contiki.h"
#include "contiki-lib.h"
#include "contiki-net.h"
#include "net/uip-ds6-route.h"
#include <string.h>
@ -68,9 +69,10 @@ static int8_t len;
#define REQUEST_TYPE_TOTALS 0xFF
extern uip_ds6_netif_t uip_ds6_if;
extern uip_ds6_route_t uip_ds6_routing_table[UIP_DS6_ROUTE_NB];
extern uip_ds6_nbr_t uip_ds6_nbr_cache[UIP_DS6_NBR_NB];
extern uip_ds6_defrt_t uip_ds6_defrt_list[UIP_DS6_DEFRT_NB];
static uip_ds6_route_t *rt;
static uip_ds6_defrt_t *defrt;
static uip_ipaddr_t *addr;
/*---------------------------------------------------------------------------*/
static uint8_t
process_request() CC_NON_BANKED
@ -90,7 +92,7 @@ process_request() CC_NON_BANKED
for(i = buf[1]; i < UIP_DS6_NBR_NB; i++) {
if(uip_ds6_nbr_cache[i].isused) {
entry_size = sizeof(i) + sizeof(uip_ipaddr_t) + sizeof(uip_lladdr_t)
+ sizeof(uip_ds6_nbr_cache[i].state);
+ sizeof(uip_ds6_nbr_cache[i].state);
PRINTF("%02u: ", i);
PRINT6ADDR(&uip_ds6_nbr_cache[i].ipaddr);
PRINTF(" - ");
@ -104,7 +106,7 @@ process_request() CC_NON_BANKED
memcpy(buf + len, &uip_ds6_nbr_cache[i].lladdr, sizeof(uip_lladdr_t));
len += sizeof(uip_lladdr_t);
memcpy(buf + len, &uip_ds6_nbr_cache[i].state,
sizeof(uip_ds6_nbr_cache[i].state));
sizeof(uip_ds6_nbr_cache[i].state));
len += sizeof(uip_ds6_nbr_cache[i].state);
count++;
@ -117,52 +119,52 @@ process_request() CC_NON_BANKED
}
} else if(buf[0] == REQUEST_TYPE_RT) {
uint32_t flip = 0;
PRINTF("Routing table\n");
for(i = buf[1]; i < UIP_DS6_ROUTE_NB; i++) {
if(uip_ds6_routing_table[i].isused) {
entry_size = sizeof(i) + sizeof(uip_ds6_routing_table[i].ipaddr)
+ sizeof(uip_ds6_routing_table[i].length)
+ sizeof(uip_ds6_routing_table[i].metric)
+ sizeof(uip_ds6_routing_table[i].nexthop)
+ sizeof(uip_ds6_routing_table[i].state.lifetime)
+ sizeof(uip_ds6_routing_table[i].state.learned_from);
rt = uip_ds6_route_list_head();
for(i = buf[1]; i < uip_ds6_route_num_routes(); i++) {
if(rt != NULL) {
entry_size = sizeof(i) + sizeof(rt->ipaddr)
+ sizeof(rt->length)
+ sizeof(rt->metric)
+ sizeof(rt->nexthop)
+ sizeof(rt->state.lifetime)
+ sizeof(rt->state.learned_from);
memcpy(buf + len, &i, sizeof(i));
len += sizeof(i);
memcpy(buf + len, &uip_ds6_routing_table[i].ipaddr,
sizeof(uip_ds6_routing_table[i].ipaddr));
len += sizeof(uip_ds6_routing_table[i].ipaddr);
memcpy(buf + len, &uip_ds6_routing_table[i].length,
sizeof(uip_ds6_routing_table[i].length));
len += sizeof(uip_ds6_routing_table[i].length);
memcpy(buf + len, &uip_ds6_routing_table[i].metric,
sizeof(uip_ds6_routing_table[i].metric));
len += sizeof(uip_ds6_routing_table[i].metric);
memcpy(buf + len, &uip_ds6_routing_table[i].nexthop,
sizeof(uip_ds6_routing_table[i].nexthop));
len += sizeof(uip_ds6_routing_table[i].nexthop);
memcpy(buf + len, &rt->ipaddr, sizeof(rt->ipaddr));
len += sizeof(rt->ipaddr);
memcpy(buf + len, &rt->length, sizeof(rt->length));
len += sizeof(rt->length);
memcpy(buf + len, &rt->metric, sizeof(rt->metric));
len += sizeof(rt->metric);
memcpy(buf + len, &rt->nexthop, sizeof(rt->nexthop));
len += sizeof(rt->nexthop);
PRINT6ADDR(&uip_ds6_routing_table[i].ipaddr);
PRINTF(" - %02x", uip_ds6_routing_table[i].length);
PRINTF(" - %02x", uip_ds6_routing_table[i].metric);
PRINT6ADDR(&rt->ipaddr);
PRINTF(" - %02x", rt->length);
PRINTF(" - %02x", rt->metric);
PRINTF(" - ");
PRINT6ADDR(&uip_ds6_routing_table[i].nexthop);
PRINT6ADDR(&rt->nexthop);
flip = uip_htonl(uip_ds6_routing_table[i].state.lifetime);
flip = uip_htonl(rt->state.lifetime);
memcpy(buf + len, &flip, sizeof(flip));
len += sizeof(flip);
PRINTF(" - %08lx", uip_ds6_routing_table[i].state.lifetime);
PRINTF(" - %08lx", rt->state.lifetime);
memcpy(buf + len, &uip_ds6_routing_table[i].state.learned_from,
sizeof(uip_ds6_routing_table[i].state.learned_from));
len += sizeof(uip_ds6_routing_table[i].state.learned_from);
memcpy(buf + len, &rt->state.learned_from,
sizeof(rt->state.learned_from));
len += sizeof(rt->state.learned_from);
PRINTF(" - %02x [%u]\n", uip_ds6_routing_table[i].state.learned_from,
entry_size);
PRINTF(" - %02x [%u]\n", rt->state.learned_from, entry_size);
count++;
left -= entry_size;
rt = list_item_next(rt);
if(left < entry_size) {
break;
}
@ -170,30 +172,30 @@ process_request() CC_NON_BANKED
}
} else if(buf[0] == REQUEST_TYPE_DRT) {
uint32_t flip = 0;
PRINTF("Default Routes\n");
for(i = buf[1]; i < UIP_DS6_DEFRT_NB; i++) {
if(uip_ds6_defrt_list[i].isused) {
entry_size = sizeof(i) + sizeof(uip_ds6_defrt_list[i].ipaddr)
+ sizeof(uip_ds6_defrt_list[i].isinfinite);
memcpy(buf + len, &i, sizeof(i));
len += sizeof(i);
memcpy(buf + len, &uip_ds6_defrt_list[i].ipaddr,
sizeof(uip_ds6_defrt_list[i].ipaddr));
len += sizeof(uip_ds6_defrt_list[i].ipaddr);
memcpy(buf + len, &uip_ds6_defrt_list[i].isinfinite,
sizeof(uip_ds6_defrt_list[i].isinfinite));
len += sizeof(uip_ds6_defrt_list[i].isinfinite);
PRINTF("Default Route\n");
addr = uip_ds6_defrt_choose();
if(addr != NULL) {
defrt = uip_ds6_defrt_lookup(addr);
}
PRINT6ADDR(&uip_ds6_defrt_list[i].ipaddr);
PRINTF(" - %u\n", uip_ds6_defrt_list[i].isinfinite);
count++;
left -= entry_size;
i = buf[1];
if(left < entry_size) {
break;
}
}
if(defrt != NULL && i < 1) {
entry_size = sizeof(i) + sizeof(defrt->ipaddr)
+ sizeof(defrt->isinfinite);
memcpy(buf + len, &i, sizeof(i));
len += sizeof(i);
memcpy(buf + len, &defrt->ipaddr, sizeof(defrt->ipaddr));
len += sizeof(defrt->ipaddr);
memcpy(buf + len, &defrt->isinfinite, sizeof(defrt->isinfinite));
len += sizeof(defrt->isinfinite);
PRINT6ADDR(&defrt->ipaddr);
PRINTF(" - %u\n", defrt->isinfinite);
count++;
left -= entry_size;
}
} else if(buf[0] == REQUEST_TYPE_ADDR) {
PRINTF("Unicast Addresses\n");
@ -204,7 +206,7 @@ process_request() CC_NON_BANKED
memcpy(buf + len, &i, sizeof(i));
len += sizeof(i);
memcpy(buf + len, &uip_ds6_if.addr_list[i].ipaddr,
sizeof(uip_ds6_if.addr_list[i].ipaddr));
sizeof(uip_ds6_if.addr_list[i].ipaddr));
len += sizeof(uip_ds6_if.addr_list[i].ipaddr);
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
@ -229,16 +231,10 @@ process_request() CC_NON_BANKED
buf[3]++;
}
}
for(i = 0; i < UIP_DS6_ROUTE_NB; i++) {
if(uip_ds6_routing_table[i].isused) {
buf[4]++;
}
}
for(i = 0; i < UIP_DS6_DEFRT_NB; i++) {
if(uip_ds6_defrt_list[i].isused) {
buf[5]++;
}
}
buf[4] = uip_ds6_route_num_routes();
buf[5] = 1;
len += 4;
count = 4;
} else {

View file

@ -41,6 +41,7 @@
#include "contiki.h"
#include "contiki-lib.h"
#include "contiki-net.h"
#include "net/uip-ds6-route.h"
#include <string.h>
@ -68,9 +69,10 @@ static int8_t len;
#define REQUEST_TYPE_TOTALS 0xFF
extern uip_ds6_netif_t uip_ds6_if;
extern uip_ds6_route_t uip_ds6_routing_table[UIP_DS6_ROUTE_NB];
extern uip_ds6_nbr_t uip_ds6_nbr_cache[UIP_DS6_NBR_NB];
extern uip_ds6_defrt_t uip_ds6_defrt_list[UIP_DS6_DEFRT_NB];
static uip_ds6_route_t *rt;
static uip_ds6_defrt_t *defrt;
static uip_ipaddr_t *addr;
/*---------------------------------------------------------------------------*/
static uint8_t
process_request() CC_NON_BANKED
@ -90,7 +92,7 @@ process_request() CC_NON_BANKED
for(i = buf[1]; i < UIP_DS6_NBR_NB; i++) {
if(uip_ds6_nbr_cache[i].isused) {
entry_size = sizeof(i) + sizeof(uip_ipaddr_t) + sizeof(uip_lladdr_t)
+ sizeof(uip_ds6_nbr_cache[i].state);
+ sizeof(uip_ds6_nbr_cache[i].state);
PRINTF("%02u: ", i);
PRINT6ADDR(&uip_ds6_nbr_cache[i].ipaddr);
PRINTF(" - ");
@ -104,7 +106,7 @@ process_request() CC_NON_BANKED
memcpy(buf + len, &uip_ds6_nbr_cache[i].lladdr, sizeof(uip_lladdr_t));
len += sizeof(uip_lladdr_t);
memcpy(buf + len, &uip_ds6_nbr_cache[i].state,
sizeof(uip_ds6_nbr_cache[i].state));
sizeof(uip_ds6_nbr_cache[i].state));
len += sizeof(uip_ds6_nbr_cache[i].state);
count++;
@ -117,52 +119,52 @@ process_request() CC_NON_BANKED
}
} else if(buf[0] == REQUEST_TYPE_RT) {
uint32_t flip = 0;
PRINTF("Routing table\n");
for(i = buf[1]; i < UIP_DS6_ROUTE_NB; i++) {
if(uip_ds6_routing_table[i].isused) {
entry_size = sizeof(i) + sizeof(uip_ds6_routing_table[i].ipaddr)
+ sizeof(uip_ds6_routing_table[i].length)
+ sizeof(uip_ds6_routing_table[i].metric)
+ sizeof(uip_ds6_routing_table[i].nexthop)
+ sizeof(uip_ds6_routing_table[i].state.lifetime)
+ sizeof(uip_ds6_routing_table[i].state.learned_from);
rt = uip_ds6_route_list_head();
for(i = buf[1]; i < uip_ds6_route_num_routes(); i++) {
if(rt != NULL) {
entry_size = sizeof(i) + sizeof(rt->ipaddr)
+ sizeof(rt->length)
+ sizeof(rt->metric)
+ sizeof(rt->nexthop)
+ sizeof(rt->state.lifetime)
+ sizeof(rt->state.learned_from);
memcpy(buf + len, &i, sizeof(i));
len += sizeof(i);
memcpy(buf + len, &uip_ds6_routing_table[i].ipaddr,
sizeof(uip_ds6_routing_table[i].ipaddr));
len += sizeof(uip_ds6_routing_table[i].ipaddr);
memcpy(buf + len, &uip_ds6_routing_table[i].length,
sizeof(uip_ds6_routing_table[i].length));
len += sizeof(uip_ds6_routing_table[i].length);
memcpy(buf + len, &uip_ds6_routing_table[i].metric,
sizeof(uip_ds6_routing_table[i].metric));
len += sizeof(uip_ds6_routing_table[i].metric);
memcpy(buf + len, &uip_ds6_routing_table[i].nexthop,
sizeof(uip_ds6_routing_table[i].nexthop));
len += sizeof(uip_ds6_routing_table[i].nexthop);
memcpy(buf + len, &rt->ipaddr, sizeof(rt->ipaddr));
len += sizeof(rt->ipaddr);
memcpy(buf + len, &rt->length, sizeof(rt->length));
len += sizeof(rt->length);
memcpy(buf + len, &rt->metric, sizeof(rt->metric));
len += sizeof(rt->metric);
memcpy(buf + len, &rt->nexthop, sizeof(rt->nexthop));
len += sizeof(rt->nexthop);
PRINT6ADDR(&uip_ds6_routing_table[i].ipaddr);
PRINTF(" - %02x", uip_ds6_routing_table[i].length);
PRINTF(" - %02x", uip_ds6_routing_table[i].metric);
PRINT6ADDR(&rt->ipaddr);
PRINTF(" - %02x", rt->length);
PRINTF(" - %02x", rt->metric);
PRINTF(" - ");
PRINT6ADDR(&uip_ds6_routing_table[i].nexthop);
PRINT6ADDR(&rt->nexthop);
flip = uip_htonl(uip_ds6_routing_table[i].state.lifetime);
flip = uip_htonl(rt->state.lifetime);
memcpy(buf + len, &flip, sizeof(flip));
len += sizeof(flip);
PRINTF(" - %08lx", uip_ds6_routing_table[i].state.lifetime);
PRINTF(" - %08lx", rt->state.lifetime);
memcpy(buf + len, &uip_ds6_routing_table[i].state.learned_from,
sizeof(uip_ds6_routing_table[i].state.learned_from));
len += sizeof(uip_ds6_routing_table[i].state.learned_from);
memcpy(buf + len, &rt->state.learned_from,
sizeof(rt->state.learned_from));
len += sizeof(rt->state.learned_from);
PRINTF(" - %02x [%u]\n", uip_ds6_routing_table[i].state.learned_from,
entry_size);
PRINTF(" - %02x [%u]\n", rt->state.learned_from, entry_size);
count++;
left -= entry_size;
rt = list_item_next(rt);
if(left < entry_size) {
break;
}
@ -170,30 +172,30 @@ process_request() CC_NON_BANKED
}
} else if(buf[0] == REQUEST_TYPE_DRT) {
uint32_t flip = 0;
PRINTF("Default Routes\n");
for(i = buf[1]; i < UIP_DS6_DEFRT_NB; i++) {
if(uip_ds6_defrt_list[i].isused) {
entry_size = sizeof(i) + sizeof(uip_ds6_defrt_list[i].ipaddr)
+ sizeof(uip_ds6_defrt_list[i].isinfinite);
memcpy(buf + len, &i, sizeof(i));
len += sizeof(i);
memcpy(buf + len, &uip_ds6_defrt_list[i].ipaddr,
sizeof(uip_ds6_defrt_list[i].ipaddr));
len += sizeof(uip_ds6_defrt_list[i].ipaddr);
memcpy(buf + len, &uip_ds6_defrt_list[i].isinfinite,
sizeof(uip_ds6_defrt_list[i].isinfinite));
len += sizeof(uip_ds6_defrt_list[i].isinfinite);
PRINTF("Default Route\n");
addr = uip_ds6_defrt_choose();
if(addr != NULL) {
defrt = uip_ds6_defrt_lookup(addr);
}
PRINT6ADDR(&uip_ds6_defrt_list[i].ipaddr);
PRINTF(" - %u\n", uip_ds6_defrt_list[i].isinfinite);
count++;
left -= entry_size;
i = buf[1];
if(left < entry_size) {
break;
}
}
if(defrt != NULL && i < 1) {
entry_size = sizeof(i) + sizeof(defrt->ipaddr)
+ sizeof(defrt->isinfinite);
memcpy(buf + len, &i, sizeof(i));
len += sizeof(i);
memcpy(buf + len, &defrt->ipaddr, sizeof(defrt->ipaddr));
len += sizeof(defrt->ipaddr);
memcpy(buf + len, &defrt->isinfinite, sizeof(defrt->isinfinite));
len += sizeof(defrt->isinfinite);
PRINT6ADDR(&defrt->ipaddr);
PRINTF(" - %u\n", defrt->isinfinite);
count++;
left -= entry_size;
}
} else if(buf[0] == REQUEST_TYPE_ADDR) {
PRINTF("Unicast Addresses\n");
@ -204,7 +206,7 @@ process_request() CC_NON_BANKED
memcpy(buf + len, &i, sizeof(i));
len += sizeof(i);
memcpy(buf + len, &uip_ds6_if.addr_list[i].ipaddr,
sizeof(uip_ds6_if.addr_list[i].ipaddr));
sizeof(uip_ds6_if.addr_list[i].ipaddr));
len += sizeof(uip_ds6_if.addr_list[i].ipaddr);
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
@ -229,16 +231,10 @@ process_request() CC_NON_BANKED
buf[3]++;
}
}
for(i = 0; i < UIP_DS6_ROUTE_NB; i++) {
if(uip_ds6_routing_table[i].isused) {
buf[4]++;
}
}
for(i = 0; i < UIP_DS6_DEFRT_NB; i++) {
if(uip_ds6_defrt_list[i].isused) {
buf[5]++;
}
}
buf[4] = uip_ds6_route_num_routes();
buf[5] = 1;
len += 4;
count = 4;
} else {