Move source routing state management from RPL Lite and RPL Classic to uip.

This commit is contained in:
Simon Duquennoy 2017-12-13 12:00:33 -08:00
parent 62d128f5c7
commit 123105ab20
22 changed files with 240 additions and 529 deletions

View File

@ -40,17 +40,11 @@
#include "node-id.h"
#include "sys/log.h"
#include "net/ipv6/uip-ds6-route.h"
#include "net/ipv6/uip-sr.h"
#include "net/mac/tsch/tsch.h"
#include "net/mac/tsch/tsch-log.h"
#include "net/routing/routing.h"
#if ROUTING_CONF_RPL_LITE
#include "net/routing/rpl-lite/rpl.h"
#elif ROUTING_CONF_RPL_CLASSIC
#include "net/routing/rpl-classic/rpl.h"
#include "net/routing/rpl-classic/rpl-ns.h"
#endif
#define DEBUG DEBUG_PRINT
#include "net/ipv6/uip-debug.h"
@ -86,8 +80,8 @@ PROCESS_THREAD(node_process, ev, data)
#if (UIP_MAX_ROUTES != 0)
PRINTF("Routing entries: %u\n", uip_ds6_route_num_routes());
#endif
#if UIP_CONF_IPV6_RPL
PRINTF("Routing links: %u\n", rpl_ns_num_nodes());
#if (UIP_SR_LINK_NUM != 0)
PRINTF("Routing links: %u\n", uip_sr_num_nodes());
#endif
PROCESS_YIELD_UNTIL(etimer_expired(&et));
etimer_reset(&et);

View File

@ -32,13 +32,8 @@
#include "contiki.h"
#include "net/routing/routing.h"
/* For RPL-specific data inclusion, in particular non-storing routing link */
#if ROUTING_CONF_RPL_LITE
#include "net/routing/rpl-lite/rpl.h"
#elif ROUTING_CONF_RPL_CLASSIC
#include "net/routing/rpl-classic/rpl.h"
#include "net/routing/rpl-classic/rpl-ns.h"
#endif
#include "net/ipv6/uip-ds6-route.h"
#include "net/ipv6/uip-sr.h"
#include <stdio.h>
#include <string.h>
@ -125,18 +120,18 @@ PT_THREAD(generate_routes(struct httpd_state *s))
}
#endif /* UIP_MAX_ROUTES != 0 */
#if UIP_CONF_IPV6_RPL
if(rpl_ns_num_nodes() > 0) {
static rpl_ns_node_t *link;
#if (UIP_SR_LINK_NUM != 0)
if(uip_sr_num_nodes() > 0) {
static uip_sr_node_t *link;
ADD(" Routing links\n <ul>\n");
SEND(&s->sout);
for(link = rpl_ns_node_head(); link != NULL; link = rpl_ns_node_next(link)) {
for(link = uip_sr_node_head(); link != NULL; link = uip_sr_node_next(link)) {
if(link->parent != NULL) {
uip_ipaddr_t child_ipaddr;
uip_ipaddr_t parent_ipaddr;
rpl_ns_get_node_global_addr(&child_ipaddr, link);
rpl_ns_get_node_global_addr(&parent_ipaddr, link->parent);
NETSTACK_ROUTING.get_sr_node_ipaddr(&child_ipaddr, link);
NETSTACK_ROUTING.get_sr_node_ipaddr(&parent_ipaddr, link->parent);
ADD(" <li>");
ipaddr_add(&child_ipaddr);
@ -152,7 +147,7 @@ PT_THREAD(generate_routes(struct httpd_state *s))
ADD(" </ul>");
SEND(&s->sout);
}
#endif /* UIP_CONF_IPV6_RPL */
#endif /* UIP_SR_LINK_NUM != 0 */
SEND_STRING(&s->sout, BOTTOM);

View File

@ -30,55 +30,59 @@
*/
/**
* \addtogroup rpl-lite
* \addtogroup uip
* @{
*
* \file
* RPL non-storing mode specific functions. Includes support for
* source routing.
* Source routing support
*
* \author Simon Duquennoy <simon.duquennoy@inria.fr>
*/
#include "net/routing/rpl-lite/rpl.h"
#include "contiki.h"
#include "net/ipv6/uip-sr.h"
#include "net/routing/routing.h"
#include "lib/list.h"
#include "lib/memb.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "RPL"
#define LOG_LEVEL LOG_LEVEL_RPL
#define LOG_MODULE "IPv6 SR"
#define LOG_LEVEL LOG_LEVEL_IPV6
/* Total number of nodes */
static int num_nodes;
/* Every known node in the network */
LIST(nodelist);
MEMB(nodememb, rpl_ns_node_t, RPL_NS_LINK_NUM);
MEMB(nodememb, uip_sr_node_t, UIP_SR_LINK_NUM);
/*---------------------------------------------------------------------------*/
int
rpl_ns_num_nodes(void)
uip_sr_num_nodes(void)
{
return num_nodes;
}
/*---------------------------------------------------------------------------*/
static int
node_matches_address(const rpl_ns_node_t *node, const uip_ipaddr_t *addr)
node_matches_address(void *graph, const uip_sr_node_t *node, const uip_ipaddr_t *addr)
{
return addr != NULL
&& node != NULL
&& !memcmp(addr, &curr_instance.dag.dag_id, 8)
&& !memcmp(((const unsigned char *)addr) + 8, node->link_identifier, 8);
if(node == NULL || addr == NULL || graph != node->graph) {
return 0;
} else {
uip_ipaddr_t node_ipaddr;
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_ipaddr, node);
return uip_ipaddr_cmp(&node_ipaddr, addr);
}
}
/*---------------------------------------------------------------------------*/
rpl_ns_node_t *
rpl_ns_get_node(const uip_ipaddr_t *addr)
uip_sr_node_t *
uip_sr_get_node(void *graph, const uip_ipaddr_t *addr)
{
rpl_ns_node_t *l;
uip_sr_node_t *l;
for(l = list_head(nodelist); l != NULL; l = list_item_next(l)) {
/* Compare prefix and node identifier */
if(node_matches_address(l, addr)) {
if(node_matches_address(graph, l, addr)) {
return l;
}
}
@ -86,11 +90,17 @@ rpl_ns_get_node(const uip_ipaddr_t *addr)
}
/*---------------------------------------------------------------------------*/
int
rpl_ns_is_addr_reachable(const uip_ipaddr_t *addr)
uip_sr_is_addr_reachable(void *graph, const uip_ipaddr_t *addr)
{
int max_depth = RPL_NS_LINK_NUM;
rpl_ns_node_t *node = rpl_ns_get_node(addr);
rpl_ns_node_t *root_node = rpl_ns_get_node(&curr_instance.dag.dag_id);
int max_depth = UIP_SR_LINK_NUM;
uip_ipaddr_t root_ipaddr;
uip_sr_node_t *node;
uip_sr_node_t *root_node;
NETSTACK_ROUTING.get_root_ipaddr(&root_ipaddr);
node = uip_sr_get_node(graph, addr);
root_node = uip_sr_get_node(graph, &root_ipaddr);
while(node != NULL && node != root_node && max_depth > 0) {
node = node->parent;
max_depth--;
@ -99,26 +109,26 @@ rpl_ns_is_addr_reachable(const uip_ipaddr_t *addr)
}
/*---------------------------------------------------------------------------*/
void
rpl_ns_expire_parent(const uip_ipaddr_t *child, const uip_ipaddr_t *parent)
uip_sr_expire_parent(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent)
{
rpl_ns_node_t *l = rpl_ns_get_node(child);
uip_sr_node_t *l = uip_sr_get_node(graph, child);
/* Check if parent matches */
if(l != NULL && node_matches_address(l->parent, parent)) {
l->lifetime = RPL_NOPATH_REMOVAL_DELAY;
if(l != NULL && node_matches_address(graph, l->parent, parent)) {
l->lifetime = UIP_SR_REMOVAL_DELAY;
}
}
/*---------------------------------------------------------------------------*/
rpl_ns_node_t *
rpl_ns_update_node(const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime)
uip_sr_node_t *
uip_sr_update_node(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime)
{
rpl_ns_node_t *child_node = rpl_ns_get_node(child);
rpl_ns_node_t *parent_node = rpl_ns_get_node(parent);
rpl_ns_node_t *old_parent_node;
uip_sr_node_t *child_node = uip_sr_get_node(graph, child);
uip_sr_node_t *parent_node = uip_sr_get_node(graph, parent);
uip_sr_node_t *old_parent_node;
if(parent != NULL) {
/* No node for the parent, add one with infinite lifetime */
if(parent_node == NULL) {
parent_node = rpl_ns_update_node(parent, NULL, RPL_ROUTE_INFINITE_LIFETIME);
parent_node = uip_sr_update_node(graph, parent, NULL, UIP_SR_INFINITE_LIFETIME);
if(parent_node == NULL) {
LOG_ERR("NS: no space left for root node!\n");
return NULL;
@ -142,16 +152,17 @@ rpl_ns_update_node(const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32
}
/* Initialize node */
child_node->graph = graph;
child_node->lifetime = lifetime;
memcpy(child_node->link_identifier, ((const unsigned char *)child) + 8, 8);
/* Is the node reachable before the update? */
if(rpl_ns_is_addr_reachable(child)) {
if(uip_sr_is_addr_reachable(graph, child)) {
old_parent_node = child_node->parent;
/* Update node */
child_node->parent = parent_node;
/* Has the node become unreachable? May happen if we create a loop. */
if(!rpl_ns_is_addr_reachable(child)) {
if(!uip_sr_is_addr_reachable(graph, child)) {
/* The new parent makes the node unreachable, restore old parent.
* We will take the update next time, with chances we know more of
* the topology and the loop is gone. */
@ -171,48 +182,36 @@ rpl_ns_update_node(const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32
}
/*---------------------------------------------------------------------------*/
void
rpl_ns_init(void)
uip_sr_init(void)
{
num_nodes = 0;
memb_init(&nodememb);
list_init(nodelist);
}
/*---------------------------------------------------------------------------*/
rpl_ns_node_t *
rpl_ns_node_head(void)
uip_sr_node_t *
uip_sr_node_head(void)
{
return list_head(nodelist);
}
/*---------------------------------------------------------------------------*/
rpl_ns_node_t *
rpl_ns_node_next(rpl_ns_node_t *item)
uip_sr_node_t *
uip_sr_node_next(uip_sr_node_t *item)
{
return list_item_next(item);
}
/*---------------------------------------------------------------------------*/
int
rpl_ns_get_node_global_addr(uip_ipaddr_t *addr, rpl_ns_node_t *node)
{
if(addr != NULL && node != NULL) {
memcpy(addr, &curr_instance.dag.dag_id, 8);
memcpy(((unsigned char *)addr) + 8, &node->link_identifier, 8);
return 1;
} else {
return 0;
}
}
/*---------------------------------------------------------------------------*/
void
rpl_ns_periodic(unsigned seconds)
uip_sr_periodic(unsigned seconds)
{
rpl_ns_node_t *l;
rpl_ns_node_t *next;
uip_sr_node_t *l;
uip_sr_node_t *next;
/* First pass, for all expired nodes, deallocate them iff no child points to them */
for(l = list_head(nodelist); l != NULL; l = next) {
next = list_item_next(l);
if(l->lifetime == 0) {
rpl_ns_node_t *l2;
uip_sr_node_t *l2;
for(l2 = list_head(nodelist); l2 != NULL; l2 = list_item_next(l2)) {
if(l2->parent == l) {
break;
@ -220,7 +219,7 @@ rpl_ns_periodic(unsigned seconds)
}
#if LOG_INFO_ENABLED
uip_ipaddr_t node_addr;
rpl_ns_get_node_global_addr(&node_addr, l);
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, l);
LOG_INFO("NS: removing expired node ");
LOG_INFO_6ADDR(&node_addr);
LOG_INFO_("\n");
@ -229,17 +228,17 @@ rpl_ns_periodic(unsigned seconds)
list_remove(nodelist, l);
memb_free(&nodememb, l);
num_nodes--;
} else if(l->lifetime != RPL_ROUTE_INFINITE_LIFETIME) {
} else if(l->lifetime != UIP_SR_INFINITE_LIFETIME) {
l->lifetime = l->lifetime > seconds ? l->lifetime - seconds : 0;
}
}
}
/*---------------------------------------------------------------------------*/
void
rpl_ns_free_all(void)
uip_sr_free_all(void)
{
rpl_ns_node_t *l;
rpl_ns_node_t *next;
uip_sr_node_t *l;
uip_sr_node_t *next;
for(l = list_head(nodelist); l != NULL; l = next) {
next = list_item_next(l);
list_remove(nodelist, l);

View File

@ -30,37 +30,75 @@
*/
/**
* \addtogroup rpl-lite
* \addtogroup uip
* @{
*
* \file
* RPL non-storing mode specific functions. Includes support for
* source routing.
* Source routing support
*
* \author Simon Duquennoy <simon.duquennoy@inria.fr>
*/
#ifndef RPL_NS_H
#define RPL_NS_H
#ifndef UIP_SR_H
#define UIP_SR_H
/********** Includes **********/
#include "contiki.h"
#include "net/ipv6/uip.h"
#include "net/routing/rpl-lite/rpl.h"
/********** Configuration **********/
/* The number of source routing nodes, i.e. the maximum netwrok size at the root */
#ifdef UIP_SR_CONF_LINK_NUM
#define UIP_SR_LINK_NUM UIP_SR_CONF_LINK_NUM
#else /* UIP_SR_CONF_LINK_NUM */
#if ROUTING_CONF_RPL_LITE
#define UIP_SR_LINK_NUM NETSTACK_MAX_ROUTE_ENTRIES
#elif ROUTING_CONF_RPL_CLASSIC
#include "net/routing/rpl-classic/rpl-conf.h"
#if RPL_WITH_NON_STORING
#define UIP_SR_LINK_NUM NETSTACK_MAX_ROUTE_ENTRIES
#else /* RPL_WITH_NON_STORING */
#define UIP_SR_LINK_NUM 0
#endif /* RPL_WITH_NON_STORING */
#else
#define UIP_SR_LINK_NUM 0
#endif
#endif /* UIP_SR_CONF_LINK_NUM */
/* Delay between between expiration order and actual node removal */
#ifdef UIP_SR_CONF_REMOVAL_DELAY
#define UIP_SR_REMOVAL_DELAY UIP_SR_CONF_REMOVAL_DELAY
#else /* UIP_SR_CONF_REMOVAL_DELAY */
#define UIP_SR_REMOVAL_DELAY 60
#endif /* UIP_SR_CONF_REMOVAL_DELAY */
#define UIP_SR_INFINITE_LIFETIME 0xFFFFFFFF
/********** Data Structures **********/
/* A node in a RPL Non-storing graph, stored at the root and representing
/** \brief A node in a source routing graph, stored at the root and representing
* all child-parent relationship. Used to build source routes */
typedef struct rpl_ns_node {
struct rpl_ns_node *next;
typedef struct uip_sr_node {
struct uip_sr_node *next;
uint32_t lifetime;
rpl_dag_t *dag;
/* Store only IPv6 link identifiers as all nodes in the DAG share the same prefix */
/* Protocol-specific graph structure */
void *graph;
/* Store only IPv6 link identifiers, the routing protocol will provide
us with the prefix */
unsigned char link_identifier[8];
struct rpl_ns_node *parent;
} rpl_ns_node_t;
struct uip_sr_node *parent;
} uip_sr_node_t;
/********** Public functions **********/
@ -69,31 +107,33 @@ typedef struct rpl_ns_node {
*
* \return The number of nodes
*/
int rpl_ns_num_nodes(void);
int uip_sr_num_nodes(void);
/**
* Expires a given child-parent link
*
* \param graph The graph the link belongs to
* \param child The IPv6 address of the child
* \param parent The IPv6 address of the parent
*/
void rpl_ns_expire_parent(const uip_ipaddr_t *child, const uip_ipaddr_t *parent);
void uip_sr_expire_parent(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent);
/**
* Updates a child-parent link
*
* \param graph The graph the link belongs to
* \param child The IPv6 address of the child
* \param parent The IPv6 address of the parent
* \param lifetime The link lifetime in seconds
*/
rpl_ns_node_t *rpl_ns_update_node(const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime);
uip_sr_node_t *uip_sr_update_node(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime);
/**
* Returns the head of the non-storing node list
*
* \return The head of the list
*/
rpl_ns_node_t *rpl_ns_node_head(void);
uip_sr_node_t *uip_sr_node_head(void);
/**
* Returns the next element of the non-storing node list
@ -101,33 +141,26 @@ rpl_ns_node_t *rpl_ns_node_head(void);
* \param item The current element in the list
* \return The next element of the list
*/
rpl_ns_node_t *rpl_ns_node_next(rpl_ns_node_t *item);
uip_sr_node_t *uip_sr_node_next(uip_sr_node_t *item);
/**
* Looks up for a RPL NS node from its IPv6 global address
* Looks up for a source routing node from its IPv6 global address
*
* \param graph The graph where to look up for the node
* \param addr The target address
* \return A pointer to the node
*/
rpl_ns_node_t *rpl_ns_get_node(const uip_ipaddr_t *addr);
uip_sr_node_t *uip_sr_get_node(void *graph, const uip_ipaddr_t *addr);
/**
* Telle whether an address is reachable, i.e. if there exists a path from
* the root to the node in the current RPL NS graph
* the root to the node in the current source routing graph
*
* \param graph The graph where to look up for the node
* \param addr The target IPv6 global address
* \return 1 if the node is reachable, 0 otherwise
*/
int rpl_ns_is_addr_reachable(const uip_ipaddr_t *addr);
/**
* Finds the global address of a given node
*
* \param addr A pointer to the address to be written
* \param node The target node
* \return 1 if success, 0 otherwise
*/
int rpl_ns_get_node_global_addr(uip_ipaddr_t *addr, rpl_ns_node_t *node);
int uip_sr_is_addr_reachable(void *graph, const uip_ipaddr_t *addr);
/**
* A function called periodically. Used to age the links (decrease lifetime
@ -135,18 +168,18 @@ int rpl_ns_get_node_global_addr(uip_ipaddr_t *addr, rpl_ns_node_t *node);
*
* \param seconds The number of seconds elapsted since last call
*/
void rpl_ns_periodic(unsigned seconds);
void uip_sr_periodic(unsigned seconds);
/**
* Initialize rpl-ns module
* Initialize this module
*/
void rpl_ns_init(void);
void uip_sr_init(void);
/**
* Deallocate all neighbors
*/
void rpl_ns_free_all(void);
void uip_sr_free_all(void);
/** @} */
#endif /* RPL_NS_H */
#endif /* UIP_SR_H */

View File

@ -70,6 +70,12 @@ get_root_ipaddr(uip_ipaddr_t *ipaddr)
return 0;
}
/*---------------------------------------------------------------------------*/
static int
get_sr_node_ipaddr(uip_ipaddr_t *addr, const uip_sr_node_t *node)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static void
leave_network(void)
{
@ -143,6 +149,7 @@ const struct routing_driver nullrouting_driver = {
root_start,
node_is_root,
get_root_ipaddr,
get_sr_node_ipaddr,
leave_network,
node_is_reachable,
global_repair,

View File

@ -44,6 +44,7 @@
#include "net/ipv6/uip.h"
#include "net/ipv6/uip-ds6-nbr.h"
#include "net/ipv6/uip-ds6-route.h"
#include "net/ipv6/uip-sr.h"
#include "net/linkaddr.h"
/**
@ -79,6 +80,14 @@ struct routing_driver {
* \return 1 if the root address was copied, 0 otherwise
*/
int (* get_root_ipaddr)(uip_ipaddr_t *ipaddr);
/**
* Returns the global IPv6 address of a source routing node
*
* \param ipaddr A pointer where to copy the IP address of the node
* \param node The source routing node
* \return 1 if the global node address was copied, 0 otherwise
*/
int (* get_sr_node_ipaddr)(uip_ipaddr_t *addr, const uip_sr_node_t *node);
/**
* Leave the network the node is part of
*

View File

@ -47,6 +47,7 @@
#include "net/link-stats.h"
#include "net/routing/rpl-classic/rpl.h"
#include "net/routing/rpl-classic/rpl-private.h"
#include "net/routing/rpl-classic/rpl-dag-root.h"
#include "net/ipv6/uip.h"
#include "net/ipv6/uip-nd6.h"
#include "net/ipv6/uip-ds6-nbr.h"
@ -1008,6 +1009,9 @@ int
rpl_has_downward_route(void)
{
int i;
if(rpl_dag_root_is_root()) {
return 1; /* We are the root, and know the route to ourself */
}
for(i = 0; i < RPL_MAX_INSTANCES; ++i) {
if(instance_table[i].used && instance_table[i].has_downward_route) {
return 1;

View File

@ -44,11 +44,12 @@
* @{
*/
#include "net/routing/routing.h"
#include "net/ipv6/uip.h"
#include "net/ipv6/tcpip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/ipv6/uip-sr.h"
#include "net/routing/rpl-classic/rpl-private.h"
#include "net/routing/rpl-classic/rpl-ns.h"
#include "net/packetbuf.h"
#define DEBUG DEBUG_NONE
@ -181,8 +182,8 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr)
uint8_t *uip_next_hdr;
int last_uip_ext_len = uip_ext_len;
rpl_dag_t *dag;
rpl_ns_node_t *dest_node;
rpl_ns_node_t *root_node;
uip_sr_node_t *dest_node;
uip_sr_node_t *root_node;
uip_ext_len = 0;
uip_next_hdr = &UIP_IP_BUF->proto;
@ -208,8 +209,8 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr)
}
dag = rpl_get_dag(&UIP_IP_BUF->destipaddr);
root_node = rpl_ns_get_node(dag, &dag->dag_id);
dest_node = rpl_ns_get_node(dag, &UIP_IP_BUF->destipaddr);
root_node = uip_sr_get_node(dag, &dag->dag_id);
dest_node = uip_sr_get_node(dag, &UIP_IP_BUF->destipaddr);
if((uip_next_hdr != NULL && *uip_next_hdr == UIP_PROTO_ROUTING
&& UIP_RH_BUF->routing_type == RPL_RH_TYPE_SRH) ||
@ -339,9 +340,9 @@ insert_srh_header(void)
uint8_t cmpri, cmpre; /* ComprI and ComprE fields of the RPL Source Routing Header */
uint8_t *hop_ptr;
uint8_t padding;
rpl_ns_node_t *dest_node;
rpl_ns_node_t *root_node;
rpl_ns_node_t *node;
uip_sr_node_t *dest_node;
uip_sr_node_t *root_node;
uip_sr_node_t *node;
rpl_dag_t *dag;
uip_ipaddr_t node_addr;
@ -359,19 +360,19 @@ insert_srh_header(void)
return 0;
}
dest_node = rpl_ns_get_node(dag, &UIP_IP_BUF->destipaddr);
dest_node = uip_sr_get_node(dag, &UIP_IP_BUF->destipaddr);
if(dest_node == NULL) {
/* The destination is not found, skip SRH insertion */
return 1;
}
root_node = rpl_ns_get_node(dag, &dag->dag_id);
root_node = uip_sr_get_node(dag, &dag->dag_id);
if(root_node == NULL) {
PRINTF("RPL: SRH root node not found\n");
return 0;
}
if(!rpl_ns_is_node_reachable(dag, &UIP_IP_BUF->destipaddr)) {
if(!uip_sr_is_addr_reachable(dag, &UIP_IP_BUF->destipaddr)) {
PRINTF("RPL: SRH no path found to destination\n");
return 0;
}
@ -390,7 +391,7 @@ insert_srh_header(void)
while(node != NULL && node != root_node) {
rpl_ns_get_node_global_addr(&node_addr, node);
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node);
/* How many bytes in common between all nodes in the path? */
cmpri = MIN(cmpri, count_matching_bytes(&node_addr, &UIP_IP_BUF->destipaddr, 16));
@ -444,7 +445,7 @@ insert_srh_header(void)
hop_ptr = ((uint8_t *)UIP_RH_BUF) + ext_len - padding; /* Pointer where to write the next hop compressed address */
while(node != NULL && node->parent != root_node) {
rpl_ns_get_node_global_addr(&node_addr, node);
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node);
hop_ptr -= (16 - cmpri);
memcpy(hop_ptr, ((uint8_t*)&node_addr) + cmpri, 16 - cmpri);
@ -453,7 +454,7 @@ insert_srh_header(void)
}
/* The next hop (i.e. node whose parent is the root) is placed as the current IPv6 destination */
rpl_ns_get_node_global_addr(&node_addr, node);
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node);
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &node_addr);
/* In-place update of IPv6 length field */

View File

@ -49,9 +49,9 @@
#include "net/ipv6/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/ipv6/uip-nd6.h"
#include "net/ipv6/uip-sr.h"
#include "net/ipv6/uip-icmp6.h"
#include "net/routing/rpl-classic/rpl-private.h"
#include "net/routing/rpl-classic/rpl-ns.h"
#include "net/packetbuf.h"
#include "net/ipv6/multicast/uip-mcast6.h"
#include "random.h"
@ -993,9 +993,9 @@ dao_input_nonstoring(void)
if(lifetime == RPL_ZERO_LIFETIME) {
PRINTF("RPL: No-Path DAO received\n");
rpl_ns_expire_parent(dag, &prefix, &dao_parent_addr);
uip_sr_expire_parent(dag, &prefix, &dao_parent_addr);
} else {
if(rpl_ns_update_node(dag, &prefix, &dao_parent_addr, RPL_LIFETIME(instance, lifetime)) == NULL) {
if(uip_sr_update_node(dag, &prefix, &dao_parent_addr, RPL_LIFETIME(instance, lifetime)) == NULL) {
PRINTF("RPL: failed to add link\n");
return;
}

View File

@ -1,269 +0,0 @@
/*
* Copyright (c) 2016, Inria.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*/
/**
* \file
* RPL non-storing mode specific functions. Includes support for
* source routing.
*
* \author Simon Duquennoy <simon.duquennoy@inria.fr>
*/
#include "net/routing/rpl-classic/rpl-conf.h"
#include "net/ipv6/uip.h"
#include "net/ipv6/tcpip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/ipv6/uip-icmp6.h"
#include "net/routing/rpl-classic/rpl-private.h"
#include "net/routing/rpl-classic/rpl-ns.h"
#include "lib/list.h"
#include "lib/memb.h"
#if RPL_WITH_NON_STORING
#define DEBUG DEBUG_NONE
#include "net/ipv6/uip-debug.h"
#include <limits.h>
#include <string.h>
/* Total number of nodes */
static int num_nodes;
/* Every known node in the network */
LIST(nodelist);
MEMB(nodememb, rpl_ns_node_t, RPL_NS_LINK_NUM);
/*---------------------------------------------------------------------------*/
int
rpl_ns_num_nodes(void)
{
return num_nodes;
}
/*---------------------------------------------------------------------------*/
static int
node_matches_address(const rpl_dag_t *dag, const rpl_ns_node_t *node, const uip_ipaddr_t *addr)
{
return addr != NULL
&& node != NULL
&& dag != NULL
&& dag == node->dag
&& !memcmp(addr, &node->dag->dag_id, 8)
&& !memcmp(((const unsigned char *)addr) + 8, node->link_identifier, 8);
}
/*---------------------------------------------------------------------------*/
rpl_ns_node_t *
rpl_ns_get_node(const rpl_dag_t *dag, const uip_ipaddr_t *addr)
{
rpl_ns_node_t *l;
for(l = list_head(nodelist); l != NULL; l = list_item_next(l)) {
/* Compare prefix and node identifier */
if(node_matches_address(dag, l, addr)) {
return l;
}
}
return NULL;
}
/*---------------------------------------------------------------------------*/
int
rpl_ns_is_node_reachable(const rpl_dag_t *dag, const uip_ipaddr_t *addr)
{
int max_depth = RPL_NS_LINK_NUM;
rpl_ns_node_t *node = rpl_ns_get_node(dag, addr);
rpl_ns_node_t *root_node = rpl_ns_get_node(dag, dag != NULL ? &dag->dag_id : NULL);
while(node != NULL && node != root_node && max_depth > 0) {
node = node->parent;
max_depth--;
}
return node != NULL && node == root_node;
}
/*---------------------------------------------------------------------------*/
void
rpl_ns_expire_parent(rpl_dag_t *dag, const uip_ipaddr_t *child, const uip_ipaddr_t *parent)
{
rpl_ns_node_t *l = rpl_ns_get_node(dag, child);
/* Check if parent matches */
if(l != NULL && node_matches_address(dag, l->parent, parent)) {
l->lifetime = RPL_NOPATH_REMOVAL_DELAY;
}
}
/*---------------------------------------------------------------------------*/
rpl_ns_node_t *
rpl_ns_update_node(rpl_dag_t *dag, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime)
{
rpl_ns_node_t *child_node = rpl_ns_get_node(dag, child);
rpl_ns_node_t *parent_node = rpl_ns_get_node(dag, parent);
rpl_ns_node_t *old_parent_node;
if(parent != NULL) {
/* No node for the parent, add one with infinite lifetime */
if(parent_node == NULL) {
parent_node = rpl_ns_update_node(dag, parent, NULL, 0xffffffff);
if(parent_node == NULL) {
return NULL;
}
}
}
/* No node for this child, add one */
if(child_node == NULL) {
child_node = memb_alloc(&nodememb);
/* No space left, abort */
if(child_node == NULL) {
return NULL;
}
child_node->parent = NULL;
list_add(nodelist, child_node);
num_nodes++;
}
/* Initialize node */
child_node->dag = dag;
child_node->lifetime = lifetime;
memcpy(child_node->link_identifier, ((const unsigned char *)child) + 8, 8);
/* Is the node reachable before the update? */
if(rpl_ns_is_node_reachable(dag, child)) {
old_parent_node = child_node->parent;
/* Update node */
child_node->parent = parent_node;
/* Has the node become unreachable? May happen if we create a loop. */
if(!rpl_ns_is_node_reachable(dag, child)) {
/* The new parent makes the node unreachable, restore old parent.
* We will take the update next time, with chances we know more of
* the topology and the loop is gone. */
child_node->parent = old_parent_node;
}
} else {
child_node->parent = parent_node;
}
return child_node;
}
/*---------------------------------------------------------------------------*/
void
rpl_ns_init(void)
{
num_nodes = 0;
memb_init(&nodememb);
list_init(nodelist);
}
/*---------------------------------------------------------------------------*/
rpl_ns_node_t *
rpl_ns_node_head(void)
{
return list_head(nodelist);
}
/*---------------------------------------------------------------------------*/
rpl_ns_node_t *
rpl_ns_node_next(rpl_ns_node_t *item)
{
return list_item_next(item);
}
/*---------------------------------------------------------------------------*/
void
rpl_ns_get_node_global_addr(uip_ipaddr_t *addr, rpl_ns_node_t *node)
{
if(addr != NULL && node != NULL && node->dag != NULL) {
memcpy(addr, &node->dag->dag_id, 8);
memcpy(((unsigned char *)addr) + 8, &node->link_identifier, 8);
}
}
/*---------------------------------------------------------------------------*/
void
rpl_ns_periodic(void)
{
rpl_ns_node_t *l;
rpl_ns_node_t *next;
/* First pass, for all expired nodes, deallocate them iff no child points to them */
for(l = list_head(nodelist); l != NULL; l = next) {
next = list_item_next(l);
if(l->lifetime == 0) {
rpl_ns_node_t *l2;
for(l2 = list_head(nodelist); l2 != NULL; l2 = list_item_next(l2)) {
if(l2->parent == l) {
break;
}
}
/* No child found, deallocate node */
list_remove(nodelist, l);
memb_free(&nodememb, l);
num_nodes--;
} else if(l->lifetime != 0xffffffff) {
/* Decrement lifetime for all nodes with non-infinite lifetime */
l->lifetime--;
}
}
}
/*---------------------------------------------------------------------------*/
#else /* RPL_WITH_NON_STORING */
/*---------------------------------------------------------------------------*/
int
rpl_ns_num_nodes(void)
{
return 0;
}
/*---------------------------------------------------------------------------*/
rpl_ns_node_t *
rpl_ns_node_head(void)
{
return NULL;
}
/*---------------------------------------------------------------------------*/
rpl_ns_node_t *
rpl_ns_node_next(rpl_ns_node_t *item)
{
return NULL;
}
/*---------------------------------------------------------------------------*/
void
rpl_ns_get_node_global_addr(uip_ipaddr_t *addr, rpl_ns_node_t *node)
{
}
/*---------------------------------------------------------------------------*/
rpl_ns_node_t *
rpl_ns_get_node(const rpl_dag_t *dag, const uip_ipaddr_t *addr)
{
return NULL;
}
/*---------------------------------------------------------------------------*/
int
rpl_ns_is_node_reachable(const rpl_dag_t *dag, const uip_ipaddr_t *addr)
{
return 0;
}
/*---------------------------------------------------------------------------*/
#endif /* RPL_WITH_NON_STORING */

View File

@ -1,76 +0,0 @@
/*
* Copyright (c) 2016, Inria.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*/
/**
* \file
* RPL non-storing mode specific functions. Includes support for
* source routing.
*
* \author Simon Duquennoy <simon.duquennoy@inria.fr>
*/
#ifndef RPL_NS_H
#define RPL_NS_H
#include "net/routing/rpl-classic/rpl-conf.h"
#ifdef RPL_NS_CONF_LINK_NUM
#define RPL_NS_LINK_NUM RPL_NS_CONF_LINK_NUM
#else /* RPL_NS_CONF_LINK_NUM */
#if RPL_WITH_NON_STORING
#define RPL_NS_LINK_NUM NETSTACK_MAX_ROUTE_ENTRIES
#else
#define RPL_NS_LINK_NUM 0
#endif
#endif /* RPL_NS_CONF_LINK_NUM */
typedef struct rpl_ns_node {
struct rpl_ns_node *next;
uint32_t lifetime;
rpl_dag_t *dag;
/* Store only IPv6 link identifiers as all nodes in the DAG share the same prefix */
unsigned char link_identifier[8];
struct rpl_ns_node *parent;
} rpl_ns_node_t;
int rpl_ns_num_nodes(void);
void rpl_ns_expire_parent(rpl_dag_t *dag, const uip_ipaddr_t *child, const uip_ipaddr_t *parent);
rpl_ns_node_t *rpl_ns_update_node(rpl_dag_t *dag, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime);
void rpl_ns_init(void);
rpl_ns_node_t *rpl_ns_node_head(void);
rpl_ns_node_t *rpl_ns_node_next(rpl_ns_node_t *item);
rpl_ns_node_t *rpl_ns_get_node(const rpl_dag_t *dag, const uip_ipaddr_t *addr);
int rpl_ns_is_node_reachable(const rpl_dag_t *dag, const uip_ipaddr_t *addr);
void rpl_ns_get_node_global_addr(uip_ipaddr_t *addr, rpl_ns_node_t *node);
void rpl_ns_periodic(void);
#endif /* RPL_NS_H */

View File

@ -45,7 +45,6 @@
#include "sys/ctimer.h"
#include "net/ipv6/uip-ds6.h"
#include "net/ipv6/uip-ds6-route.h"
#include "net/routing/rpl-classic/rpl-ns.h"
#include "net/ipv6/multicast/uip-mcast6.h"
/*---------------------------------------------------------------------------*/

View File

@ -43,9 +43,9 @@
#include "contiki.h"
#include "net/routing/rpl-classic/rpl-private.h"
#include "net/routing/rpl-classic/rpl-ns.h"
#include "net/link-stats.h"
#include "net/ipv6/multicast/uip-mcast6.h"
#include "net/ipv6/uip-sr.h"
#include "lib/random.h"
#include "sys/ctimer.h"
@ -89,7 +89,7 @@ handle_periodic_timer(void *ptr)
rpl_purge_routes();
}
if(RPL_IS_NON_STORING(dag->instance)) {
rpl_ns_periodic();
uip_sr_periodic(1);
}
}
rpl_recalculate_ranks();

View File

@ -45,10 +45,10 @@
#include "net/ipv6/uip.h"
#include "net/ipv6/tcpip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/ipv6/uip-sr.h"
#include "net/ipv6/uip-icmp6.h"
#include "net/routing/routing.h"
#include "net/routing/rpl-classic/rpl-private.h"
#include "net/routing/rpl-classic/rpl-ns.h"
#include "net/routing/rpl-classic/rpl-dag-root.h"
#include "net/ipv6/multicast/uip-mcast6.h"
@ -349,10 +349,22 @@ init(void)
#endif
#if RPL_WITH_NON_STORING
rpl_ns_init();
uip_sr_init();
#endif /* RPL_WITH_NON_STORING */
}
/*---------------------------------------------------------------------------*/
static int
get_sr_node_ipaddr(uip_ipaddr_t *addr, const uip_sr_node_t *node)
{
if(addr != NULL && node != NULL) {
memcpy(addr, &((rpl_dag_t *)node->graph)->dag_id, 8);
memcpy(((unsigned char *)addr) + 8, &node->link_identifier, 8);
return 1;
} else {
return 0;
}
}
/*---------------------------------------------------------------------------*/
static void
global_repair(const char *str)
{
@ -409,6 +421,7 @@ const struct routing_driver rpl_classic_driver = {
rpl_dag_root_start,
rpl_dag_root_is_root,
get_root_ipaddr,
get_sr_node_ipaddr,
leave_network,
rpl_has_downward_route,
global_repair,

View File

@ -318,13 +318,6 @@
#define RPL_DAO_DELAY (CLOCK_SECOND * 4)
#endif /* RPL_CONF_DAO_DELAY */
/* Delay between reception of a no-path DAO and actual route removal */
#ifdef RPL_CONF_NOPATH_REMOVAL_DELAY
#define RPL_NOPATH_REMOVAL_DELAY RPL_CONF_NOPATH_REMOVAL_DELAY
#else /* RPL_CONF_NOPATH_REMOVAL_DELAY */
#define RPL_NOPATH_REMOVAL_DELAY 60
#endif /* RPL_CONF_NOPATH_REMOVAL_DELAY */
#ifdef RPL_CONF_DAO_MAX_RETRANSMISSIONS
#define RPL_DAO_MAX_RETRANSMISSIONS RPL_CONF_DAO_MAX_RETRANSMISSIONS
#else

View File

@ -43,6 +43,7 @@
*/
#include "net/routing/rpl-lite/rpl.h"
#include "net/ipv6/uip-sr.h"
#include "net/nbr-table.h"
#include "net/link-stats.h"
@ -106,7 +107,7 @@ rpl_dag_leave(void)
/* Remove all neighbors and lnks */
rpl_neighbor_remove_all();
rpl_ns_free_all();
uip_sr_free_all();
/* Stop all timers */
rpl_timers_stop_dag_timers();
@ -589,9 +590,9 @@ void
rpl_process_dao(uip_ipaddr_t *from, rpl_dao_t *dao)
{
if(dao->lifetime == 0) {
rpl_ns_expire_parent(from, &dao->parent_addr);
uip_sr_expire_parent(NULL, from, &dao->parent_addr);
} else {
if(!rpl_ns_update_node(from, &dao->parent_addr, RPL_LIFETIME(dao->lifetime))) {
if(!uip_sr_update_node(NULL, from, &dao->parent_addr, RPL_LIFETIME(dao->lifetime))) {
LOG_ERR("failed to add link on incoming DAO\n");
return;
}

View File

@ -42,8 +42,10 @@
* Nicolas Tsiftes <nvt@sics.se>,
* Simon Duquennoy <simon.duquennoy@inria.fr>
*/
#include "net/routing/routing.h"
#include "net/routing/rpl-lite/rpl.h"
#include "net/ipv6/uip-sr.h"
#include "net/packetbuf.h"
/* Log configuration */
@ -68,8 +70,8 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr)
{
uint8_t *uip_next_hdr;
int last_uip_ext_len = uip_ext_len;
rpl_ns_node_t *dest_node;
rpl_ns_node_t *root_node;
uip_sr_node_t *dest_node;
uip_sr_node_t *root_node;
uip_ext_len = 0;
uip_next_hdr = &UIP_IP_BUF->proto;
@ -96,8 +98,8 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr)
return 0;
}
root_node = rpl_ns_get_node(&curr_instance.dag.dag_id);
dest_node = rpl_ns_get_node(&UIP_IP_BUF->destipaddr);
root_node = uip_sr_get_node(NULL, &curr_instance.dag.dag_id);
dest_node = uip_sr_get_node(NULL, &UIP_IP_BUF->destipaddr);
if((uip_next_hdr != NULL && *uip_next_hdr == UIP_PROTO_ROUTING
&& UIP_RH_BUF->routing_type == RPL_RH_TYPE_SRH) ||
@ -227,9 +229,9 @@ insert_srh_header(void)
uint8_t cmpri, cmpre; /* ComprI and ComprE fields of the RPL Source Routing Header */
uint8_t *hop_ptr;
uint8_t padding;
rpl_ns_node_t *dest_node;
rpl_ns_node_t *root_node;
rpl_ns_node_t *node;
uip_sr_node_t *dest_node;
uip_sr_node_t *root_node;
uip_sr_node_t *node;
uip_ipaddr_t node_addr;
LOG_INFO("SRH creating source routing header with destination ");
@ -246,20 +248,20 @@ insert_srh_header(void)
return 1;
}
dest_node = rpl_ns_get_node(&UIP_IP_BUF->destipaddr);
dest_node = uip_sr_get_node(NULL, &UIP_IP_BUF->destipaddr);
if(dest_node == NULL) {
/* The destination is not found, skip SRH insertion */
LOG_INFO("SRH node not found, skip SRH insertion\n");
return 1;
}
root_node = rpl_ns_get_node(&curr_instance.dag.dag_id);
root_node = uip_sr_get_node(NULL, &curr_instance.dag.dag_id);
if(root_node == NULL) {
LOG_ERR("SRH root node not found\n");
return 0;
}
if(!rpl_ns_is_addr_reachable(&UIP_IP_BUF->destipaddr)) {
if(!uip_sr_is_addr_reachable(NULL, &UIP_IP_BUF->destipaddr)) {
LOG_ERR("SRH no path found to destination\n");
return 0;
}
@ -277,7 +279,7 @@ insert_srh_header(void)
while(node != NULL && node != root_node) {
rpl_ns_get_node_global_addr(&node_addr, node);
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node);
/* How many bytes in common between all nodes in the path? */
cmpri = MIN(cmpri, count_matching_bytes(&node_addr, &UIP_IP_BUF->destipaddr, 16));
@ -331,7 +333,7 @@ insert_srh_header(void)
hop_ptr = ((uint8_t *)UIP_RH_BUF) + ext_len - padding; /* Pointer where to write the next hop compressed address */
while(node != NULL && node->parent != root_node) {
rpl_ns_get_node_global_addr(&node_addr, node);
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node);
hop_ptr -= (16 - cmpri);
memcpy(hop_ptr, ((uint8_t*)&node_addr) + cmpri, 16 - cmpri);
@ -340,7 +342,7 @@ insert_srh_header(void)
}
/* The next hop (i.e. node whose parent is the root) is placed as the current IPv6 destination */
rpl_ns_get_node_global_addr(&node_addr, node);
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node);
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &node_addr);
/* In-place update of IPv6 length field */

View File

@ -42,6 +42,7 @@
#include "contiki.h"
#include "net/routing/rpl-lite/rpl.h"
#include "net/ipv6/uip-sr.h"
#include "net/link-stats.h"
#include "lib/random.h"
#include "sys/ctimer.h"
@ -500,7 +501,7 @@ handle_periodic_timer(void *ptr)
{
if(curr_instance.used) {
rpl_dag_periodic(PERIODIC_DELAY_SECONDS);
rpl_ns_periodic(PERIODIC_DELAY_SECONDS);
uip_sr_periodic(PERIODIC_DELAY_SECONDS);
}
if(!curr_instance.used ||

View File

@ -190,7 +190,19 @@ init(void)
rpl_timers_init();
rpl_icmp6_init();
rpl_ns_init();
uip_sr_init();
}
/*---------------------------------------------------------------------------*/
static int
get_sr_node_ipaddr(uip_ipaddr_t *addr, const uip_sr_node_t *node)
{
if(addr != NULL && node != NULL) {
memcpy(addr, &curr_instance.dag.dag_id, 8);
memcpy(((unsigned char *)addr) + 8, &node->link_identifier, 8);
return 1;
} else {
return 0;
}
}
/*---------------------------------------------------------------------------*/
static void
@ -212,6 +224,7 @@ const struct routing_driver rpl_lite_driver = {
rpl_dag_root_start,
rpl_dag_root_is_root,
rpl_dag_get_root_ipaddr,
get_sr_node_ipaddr,
rpl_dag_poison_and_leave,
rpl_is_reachable,
rpl_global_repair,

View File

@ -53,7 +53,6 @@
#include "net/routing/rpl-lite/rpl-types.h"
#include "net/routing/rpl-lite/rpl-icmp6.h"
#include "net/routing/rpl-lite/rpl-dag.h"
#include "net/routing/rpl-lite/rpl-ns.h"
#include "net/routing/rpl-lite/rpl-dag-root.h"
#include "net/routing/rpl-lite/rpl-neighbor.h"
#include "net/routing/rpl-lite/rpl-ext-header.h"

View File

@ -570,16 +570,16 @@ PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args))
}
#if UIP_CONF_IPV6_RPL
if(rpl_ns_num_nodes() > 0) {
rpl_ns_node_t *link;
if(uip_sr_num_nodes() > 0) {
uip_sr_node_t *link;
/* Our routing links */
SHELL_OUTPUT(output, "Routing links (%u in total):\n", rpl_ns_num_nodes());
link = rpl_ns_node_head();
SHELL_OUTPUT(output, "Routing links (%u in total):\n", uip_sr_num_nodes());
link = uip_sr_node_head();
while(link != NULL) {
uip_ipaddr_t child_ipaddr;
uip_ipaddr_t parent_ipaddr;
rpl_ns_get_node_global_addr(&child_ipaddr, link);
rpl_ns_get_node_global_addr(&parent_ipaddr, link->parent);
NETSTACK_ROUTING.get_sr_node_ipaddr(&child_ipaddr, link);
NETSTACK_ROUTING.get_sr_node_ipaddr(&parent_ipaddr, link->parent);
SHELL_OUTPUT(output, "-- ");
shell_output_6addr(output, &child_ipaddr);
if(link->parent == NULL) {
@ -589,12 +589,12 @@ PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args))
SHELL_OUTPUT(output, " to ");
shell_output_6addr(output, &parent_ipaddr);
}
if(link->lifetime != 0xFFFFFFFF) {
if(link->lifetime != UIP_SR_INFINITE_LIFETIME) {
SHELL_OUTPUT(output, " (lifetime: %lu seconds)\n", (unsigned long)link->lifetime);
} else {
SHELL_OUTPUT(output, " (lifetime: infinite)\n");
}
link = rpl_ns_node_next(link);
link = uip_sr_node_next(link);
}
} else {
SHELL_OUTPUT(output, "No routing links\n");

View File

@ -37,12 +37,6 @@
#include "net/ipv6/uip.h"
#include <string.h>
#if ROUTING_CONF_RPL_LITE
#include "net/routing/rpl-lite/rpl.h"
#elif ROUTING_CONF_RPL_CLASSIC
#include "net/routing/rpl-classic/rpl.h"
#endif
#define DEBUG DEBUG_FULL
#include "net/ipv6/uip-debug.h"
@ -55,8 +49,7 @@ AUTOSTART_PROCESSES(&wait_for_dag);
static void
timeout_handler(void)
{
rpl_dag_t *dag = rpl_get_any_dag();
if (dag != NULL) {
if(NETSTACK_ROUTING.node_is_reachable()) {
PRINTF("DAG Found\n");
}
}
@ -73,7 +66,7 @@ PROCESS_THREAD(wait_for_dag, ev, data)
if(etimer_expired(&et)) {
timeout_handler();
etimer_restart(&et);
}
}
}
PROCESS_END();
}