Refactor how packet sent callbacks are handled for TSCH, RPL, 6lowpan and DS6

This commit is contained in:
Simon Duquennoy 2017-06-24 11:46:37 +02:00
parent aeba4c275b
commit c3ec92dc2c
14 changed files with 88 additions and 56 deletions

View File

@ -71,6 +71,13 @@
#include "net/packetbuf.h"
#include "net/queuebuf.h"
#if UIP_CONF_IPV6_RPL_LITE == 1
#include "net/rpl-lite/rpl.h"
#else /* UIP_CONF_IPV6_RPL_LITE == 1 */
#include "net/rpl/rpl.h"
#include "net/rpl/rpl-private.h"
#endif /* UIP_CONF_IPV6_RPL_LITE == 1 */
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "6LoWPAN"
@ -1209,12 +1216,29 @@ compress_hdr_ipv6(linkaddr_t *link_destaddr)
static void
packet_sent(void *ptr, int status, int transmissions)
{
uip_ds6_link_neighbor_callback(status, transmissions);
const linkaddr_t *dest;
if(callback != NULL) {
callback->output_callback(status);
}
last_tx_status = status;
/* What follows only applies to unicast */
dest = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
if(linkaddr_cmp(dest, &linkaddr_null)) {
return;
}
/* Update neighbor link statistics */
link_stats_packet_sent(dest, status, transmissions);
#if UIP_CONF_IPV6_RPL
/* Call RPL link callback */
rpl_link_callback(dest, status, transmissions);
#endif /* UIP_CONF_IPV6_RPL */
/* DS6 callback, used for UIP_DS6_LL_NUD */
uip_ds6_link_callback(status, transmissions);
}
/*--------------------------------------------------------------------*/
/**

View File

@ -64,13 +64,6 @@ void NEIGHBOR_STATE_CHANGED(uip_ds6_nbr_t *n);
#define NEIGHBOR_STATE_CHANGED(n)
#endif /* UIP_DS6_CONF_NEIGHBOR_STATE_CHANGED */
#ifdef UIP_CONF_DS6_LINK_NEIGHBOR_CALLBACK
#define LINK_NEIGHBOR_CALLBACK(addr, status, numtx) UIP_CONF_DS6_LINK_NEIGHBOR_CALLBACK(addr, status, numtx)
void LINK_NEIGHBOR_CALLBACK(const linkaddr_t *addr, int status, int numtx);
#else
#define LINK_NEIGHBOR_CALLBACK(addr, status, numtx)
#endif /* UIP_CONF_DS6_LINK_NEIGHBOR_CALLBACK */
NBR_TABLE_GLOBAL(uip_ds6_nbr_t, ds6_neighbors);
/*---------------------------------------------------------------------------*/
@ -205,19 +198,14 @@ uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr)
}
/*---------------------------------------------------------------------------*/
void
uip_ds6_link_neighbor_callback(int status, int numtx)
uip_ds6_link_callback(int status, int numtx)
{
#if UIP_DS6_LL_NUD
const linkaddr_t *dest = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
if(linkaddr_cmp(dest, &linkaddr_null)) {
return;
}
/* Update neighbor link statistics */
link_stats_packet_sent(dest, status, numtx);
/* Call upper-layer callback (e.g. RPL) */
LINK_NEIGHBOR_CALLBACK(dest, status, numtx);
#if UIP_DS6_LL_NUD
/* From RFC4861, page 72, last paragraph of section 7.3.3:
*
* "In some cases, link-specific information may indicate that a path to
@ -245,7 +233,6 @@ uip_ds6_link_neighbor_callback(int status, int numtx)
}
}
#endif /* UIP_DS6_LL_NUD */
}
#if UIP_ND6_SEND_NS
/*---------------------------------------------------------------------------*/

View File

@ -94,7 +94,7 @@ uip_ds6_nbr_t *uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr);
uip_ds6_nbr_t *uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr);
uip_ipaddr_t *uip_ds6_nbr_ipaddr_from_lladdr(const uip_lladdr_t *lladdr);
const uip_lladdr_t *uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr);
void uip_ds6_link_neighbor_callback(int status, int numtx);
void uip_ds6_link_callback(int status, int numtx);
void uip_ds6_neighbor_periodic(void);
int uip_ds6_nbr_num(void);

View File

@ -233,13 +233,6 @@ typedef struct uip_ds6_maddr {
#endif /* UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED */
#endif /* UIP_CONF_IPV6_RPL */
#if UIP_CONF_IPV6_RPL
#ifndef UIP_CONF_DS6_LINK_NEIGHBOR_CALLBACK
#define UIP_CONF_DS6_LINK_NEIGHBOR_CALLBACK rpl_link_neighbor_callback
#endif /* UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED */
#endif /* UIP_CONF_IPV6_RPL */
/** \brief Interface structure (contains all the interface variables) */
typedef struct uip_ds6_netif {
uint32_t link_mtu;

View File

@ -48,6 +48,7 @@
#include "net/mac/tsch/tsch-private.h"
#include "net/mac/tsch/tsch-schedule.h"
#include "net/mac/tsch/tsch-log.h"
#include "net/mac/tsch/tsch-rpl.h"
#include "tsch-rpl.h"
/* Log configuration */
@ -55,6 +56,13 @@
#define LOG_MODULE "TSCH RPL"
#define LOG_LEVEL MAC_LOG_LEVEL
/*---------------------------------------------------------------------------*/
/* To use, set #define TSCH_CALLBACK_KA_SENT tsch_rpl_callback_ka_sent */
void
tsch_rpl_callback_ka_sent(int status, int transmissions)
{
rpl_link_callback(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), status, transmissions);
}
/*---------------------------------------------------------------------------*/
/* To use, set #define TSCH_CALLBACK_JOINING_NETWORK tsch_rpl_callback_joining_network */
void

View File

@ -43,6 +43,9 @@
/********** Functions *********/
/* Keep-alives packet sent callback.
* To use, set #define TSCH_CALLBACK_KA_SENT tsch_rpl_callback_ka_sent */
void tsch_rpl_callback_ka_sent(int status, int transmissions);
/* To use, set #define TSCH_CALLBACK_JOINING_NETWORK tsch_rpl_callback_joining_network */
void tsch_rpl_callback_joining_network(void);
/* Upon leaving a TSCH network, perform a local repair

View File

@ -46,6 +46,7 @@
#include "net/packetbuf.h"
#include "net/queuebuf.h"
#include "net/nbr-table.h"
#include "net/link-stats.h"
#include "net/mac/framer/framer-802154.h"
#include "net/mac/tsch/tsch.h"
#include "net/mac/tsch/tsch-slot-operation.h"
@ -57,6 +58,10 @@
#include "net/mac/mac-sequence.h"
#include "lib/random.h"
#if UIP_CONF_IPV6_RPL
#include "net/mac/tsch/tsch-rpl.h"
#endif /* UIP_CONF_IPV6_RPL */
#if FRAME802154_VERSION < FRAME802154_IEEE802154E_2012
#error TSCH: FRAME802154_VERSION must be at least FRAME802154_IEEE802154E_2012
#endif
@ -248,37 +253,38 @@ tsch_reset(void)
static void
keepalive_packet_sent(void *ptr, int status, int transmissions)
{
if(tsch_is_associated) {
#ifdef TSCH_LINK_NEIGHBOR_CALLBACK
TSCH_LINK_NEIGHBOR_CALLBACK(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), status, transmissions);
#endif
LOG_INFO("KA sent to ");
LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
LOG_INFO_(", st %d-%d\n", status, transmissions);
/* Update neighbor link statistics */
link_stats_packet_sent(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), status, transmissions);
/* Call RPL callback if RPL is enabled */
#ifdef TSCH_CALLBACK_KA_SENT
TSCH_CALLBACK_KA_SENT(status, transmissions);
#endif /* TSCH_CALLBACK_KA_SENT */
LOG_INFO("KA sent to ");
LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
LOG_INFO_(", st %d-%d\n", status, transmissions);
/* We got no ack, try to recover by switching to the last neighbor we received an EB from */
if(status != MAC_TX_OK) {
if(linkaddr_cmp(&last_eb_nbr_addr, &linkaddr_null)) {
LOG_WARN("not able to re-synchronize, received no EB from other neighbors\n");
if(sync_count == 0) {
/* We got no synchronization at all in this session, leave the network */
tsch_disassociate();
}
} else {
LOG_WARN("re-synchronizing on ");
LOG_WARN_LLADDR(&last_eb_nbr_addr);
LOG_WARN_("\n");
/* We simply pick the last neighbor we receiver sync information from */
tsch_queue_update_time_source(&last_eb_nbr_addr);
tsch_join_priority = last_eb_nbr_jp + 1;
/* Try to get in sync ASAP */
tsch_schedule_keepalive_immediately();
return;
/* We got no ack, try to recover by switching to the last neighbor we received an EB from */
if(status != MAC_TX_OK) {
if(linkaddr_cmp(&last_eb_nbr_addr, &linkaddr_null)) {
LOG_WARN("not able to re-synchronize, received no EB from other neighbors\n");
if(sync_count == 0) {
/* We got no synchronization at all in this session, leave the network */
tsch_disassociate();
}
} else {
LOG_WARN("re-synchronizing on ");
LOG_WARN_LLADDR(&last_eb_nbr_addr);
LOG_WARN_("\n");
/* We simply pick the last neighbor we receiver sync information from */
tsch_queue_update_time_source(&last_eb_nbr_addr);
tsch_join_priority = last_eb_nbr_jp + 1;
/* Try to get in sync ASAP */
tsch_schedule_keepalive_immediately();
return;
}
tsch_schedule_keepalive();
}
tsch_schedule_keepalive();
}
/*---------------------------------------------------------------------------*/
/* Prepare and send a keepalive message */

View File

@ -86,7 +86,7 @@ rpl_get_global_address(void)
}
/*---------------------------------------------------------------------------*/
void
rpl_link_neighbor_callback(const linkaddr_t *addr, int status, int numtx)
rpl_link_callback(const linkaddr_t *addr, int status, int numtx)
{
if(curr_instance.used == 1 ) {
rpl_nbr_t *nbr = rpl_neighbor_get_from_lladdr((uip_lladdr_t *)addr);

View File

@ -67,6 +67,15 @@ extern uip_ipaddr_t rpl_multicast_addr;
/********** Public functions **********/
/**
* Called by lower layers after every packet transmission
*
* \param addr The link-layer addrress of the packet destination
* \param status The transmission status (see core/net/mac/mac.h)
* \param numtx The total number of transmission attempts
*/
void rpl_link_callback(const linkaddr_t *addr, int status, int numtx);
/**
* Set prefix from an prefix data structure (from DIO)
*

View File

@ -250,7 +250,7 @@ rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len,
}
/*---------------------------------------------------------------------------*/
void
rpl_link_neighbor_callback(const linkaddr_t *addr, int status, int numtx)
rpl_link_callback(const linkaddr_t *addr, int status, int numtx)
{
uip_ipaddr_t ipaddr;
rpl_parent_t *parent;
@ -265,7 +265,7 @@ rpl_link_neighbor_callback(const linkaddr_t *addr, int status, int numtx)
parent = rpl_find_parent_any_dag(instance, &ipaddr);
if(parent != NULL) {
/* Trigger DAG rank recalculation. */
PRINTF("RPL: rpl_link_neighbor_callback triggering update\n");
PRINTF("RPL: rpl_link_callback triggering update\n");
parent->flags |= RPL_PARENT_FLAG_UPDATED;
}
}

View File

@ -292,7 +292,7 @@ uip_ds6_nbr_t *rpl_get_nbr(rpl_parent_t *parent);
void rpl_print_neighbor_list(void);
int rpl_ext_header_srh_update(void);
int rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr);
void rpl_link_callback(const linkaddr_t *addr, int status, int numtx);
/* Per-parent RPL information */
NBR_TABLE_DECLARE(rpl_parents);

View File

@ -69,6 +69,7 @@
/* TSCH and RPL callbacks */
#define RPL_CALLBACK_PARENT_SWITCH tsch_rpl_callback_parent_switch
#define RPL_CALLBACK_NEW_DIO_INTERVAL tsch_rpl_callback_new_dio_interval
#define TSCH_CALLBACK_KA_SENT tsch_rpl_callback_ka_sent
#define TSCH_CALLBACK_JOINING_NETWORK tsch_rpl_callback_joining_network
#define TSCH_CALLBACK_LEAVING_NETWORK tsch_rpl_callback_leaving_network

View File

@ -65,6 +65,7 @@
/* TSCH and RPL callbacks */
#define RPL_CALLBACK_PARENT_SWITCH tsch_rpl_callback_parent_switch
#define RPL_CALLBACK_NEW_DIO_INTERVAL tsch_rpl_callback_new_dio_interval
#define TSCH_CALLBACK_KA_SENT tsch_rpl_callback_ka_sent
#define TSCH_CALLBACK_JOINING_NETWORK tsch_rpl_callback_joining_network
#define TSCH_CALLBACK_LEAVING_NETWORK tsch_rpl_callback_leaving_network

View File

@ -130,7 +130,7 @@ uip_icmp6chksum(void)
/*---------------------------------------------------------------------------*/
void
uip_ds6_link_neighbor_callback(int status, int numtx)
uip_ds6_link_callback(int status, int numtx)
{
}