Skip to content

Commit

Permalink
ng_ndp/ng_sixlowpan: import 6LoWPAN-ND host behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Jun 7, 2015
1 parent 96238df commit 1da599c
Show file tree
Hide file tree
Showing 25 changed files with 1,702 additions and 78 deletions.
31 changes: 29 additions & 2 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,26 @@ ifneq (,$(filter ng_ieee802154,$(USEMODULE)))
USEMODULE += ng_sixlowpan
endif
ifneq (,$(filter ng_ipv6_router, $(USEMODULE)))
USEMODULE += ng_sixlowpan # TODO: replace with ng_sixlowpan_router
USEMODULE += ng_sixlowpan_router
endif
ifneq (,$(filter ng_ipv6_default, $(USEMODULE)))
USEMODULE += ng_sixlowpan_default
endif
ifneq (,$(filter ng_ipv6_router_default, $(USEMODULE)))
USEMODULE += ng_sixlowpan_default # TODO: replace with ng_sixlowpan_router_default
USEMODULE += ng_sixlowpan_router_default
endif
endif

ifneq (,$(filter ng_sixlowpan_router_default,$(USEMODULE)))
USEMODULE += ng_sixlowpan_default
USEMODULE += ng_sixlowpan_router
endif

ifneq (,$(filter ng_sixlowpan_default,$(USEMODULE)))
USEMODULE += ng_ipv6_default
USEMODULE += ng_sixlowpan
USEMODULE += ng_sixlowpan_frag
USEMODULE += ng_sixlowpan_nd
endif

ifneq (,$(filter ng_sixlowpan_frag,$(USEMODULE)))
Expand All @@ -100,6 +106,27 @@ ifneq (,$(filter ng_sixlowpan_iphc,$(USEMODULE)))
USEMODULE += ng_sixlowpan_ctx
endif

ifneq (,$(filter ng_sixlowpan_router,$(USEMODULE)))
USEMODULE += ng_ipv6_router
USEMODULE += ng_sixlowpan
USEMODULE += ng_sixlowpan_nd_rtr
endif

ifneq (,$(filter ng_sixlowpan_nd_br,$(USEMODULE)))
USEMODULE += ng_sixlowpan_nd_br
endif

ifneq (,$(filter ng_sixlowpan_nd_rtr,$(USEMODULE)))
USEMODULE += ng_ndp_rtr
USEMODULE += ng_sixlowpan_nd
endif

ifneq (,$(filter ng_sixlowpan_nd,$(USEMODULE)))
USEMODULE += ng_ndp_hst
USEMODULE += ng_sixlowpan
USEMODULE += random
endif

ifneq (,$(filter ng_sixlowpan,$(USEMODULE)))
USEMODULE += ng_ipv6
USEMODULE += ng_sixlowpan_netif
Expand Down
5 changes: 5 additions & 0 deletions Makefile.pseudomodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ PSEUDOMODULES += ng_ieee802154
PSEUDOMODULES += ng_ipv6_default
PSEUDOMODULES += ng_ipv6_router
PSEUDOMODULES += ng_ipv6_router_default
PSEUDOMODULES += ng_sixlowpan_nd_br # border router
PSEUDOMODULES += ng_sixlowpan_router
PSEUDOMODULES += ng_sixlowpan_router_default
PSEUDOMODULES += ng_sixlowpan_border_router
PSEUDOMODULES += ng_sixlowpan_border_router_default
PSEUDOMODULES += pktqueue
PSEUDOMODULES += ng_netbase
PSEUDOMODULES += newlib
Expand Down
6 changes: 6 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ endif
ifneq (,$(filter ng_sixlowpan_iphc,$(USEMODULE)))
DIRS += net/network_layer/ng_sixlowpan/iphc
endif
ifneq (,$(filter ng_sixlowpan_nd,$(USEMODULE)))
DIRS += net/network_layer/ng_sixlowpan/nd
endif
ifneq (,$(filter ng_sixlowpan_nd_rtr,$(USEMODULE)))
DIRS += net/network_layer/ng_sixlowpan/nd/rtr
endif
ifneq (,$(filter ng_sixlowpan_netif,$(USEMODULE)))
DIRS += net/network_layer/ng_sixlowpan/netif
endif
Expand Down
17 changes: 17 additions & 0 deletions sys/include/net/ng_ipv6/nc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <stdint.h>

#include "kernel_types.h"
#include "net/eui64.h"
#include "net/ng_ipv6/addr.h"
#include "net/ng_netif.h"
#include "net/ng_pktqueue.h"
Expand Down Expand Up @@ -141,6 +142,22 @@ typedef struct {
/**
* @}
*/
#ifdef MODULE_NG_SIXLOWPAN_ND
vtimer_t rtr_sol_timer; /**< timer for next router solicitation */
#endif
#ifdef MODULE_NG_SIXLOWPAN_ND_RTR
vtimer_t type_timeout; /**< timeout for types */
/**
* @name 6LoWPAN specific variables.
* @see [RFC 6775, section 6.5.3](https://tools.ietf.org/html/rfc6775#section-6.5.3)
* @{
*/
uint16_t reg_ltime; /**< registration lifetime */
eui64_t eui64; /**< the identifying EUI-64 */
/**
* @}
*/
#endif
} ng_ipv6_nc_t;

/**
Expand Down
21 changes: 21 additions & 0 deletions sys/include/net/ng_ipv6/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,23 @@ extern "C" {
*/
#define NG_IPV6_NETIF_FLAGS_ADV_RETRANS_TIMER (0x0040)

/**
* @brief Flag to indicate that the interface sends periodic router
* advertisements.
*
* @details On most nodes this flag is set. However, for mesh-under topologies
* in 6LoWPANs it can be deactivated, also for route-over topologies
* this can be deactivated too in certain cases.
* The difference to @ref NG_IPV6_NETIF_FLAGS_RTR_ADV is that it only
* applies for periodic advertisements and not advertisements in
* response to router solicitations. If @ref NG_IPV6_NETIF_FLAGS_ROUTER
* or @ref NG_IPV6_NETIF_FLAGS_RTR_ADV are unset, this flag will be
* ignored.
*
* @see [RFC 6775](https://tools.ietf.org/html/rfc6775#section-6.4)
*/
#define NG_IPV6_NETIF_FLAGS_ADV_PERIODIC (0x0100)

/**
* @brief Flag to indicate that the interface has other address
* configuration.
Expand Down Expand Up @@ -284,6 +301,10 @@ typedef struct {

vtimer_t rtr_adv_timer; /**< Timer for periodic router advertisements */
#endif
#ifdef MODULE_NG_SIXLOWPAN_ND
uint8_t backoff_exp; /**< exponent for the truncated exponential binary
* backoff */
#endif
} ng_ipv6_netif_t;

/**
Expand Down
4 changes: 3 additions & 1 deletion sys/include/net/ng_ndp.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ void ng_ndp_rtr_adv_handle(kernel_pid_t iface, ng_pktsnip_t *pkt,
* @param[in] nc_entry A neighbor cache entry. Will be ignored if its state
* is not @ref NG_IPV6_NC_STATE_INCOMPLETE or
* @ref NG_IPV6_NC_STATE_PROBE.
* @param[in] src The source for the neigbor solicitation. Is chosen
* from the interface, if `src == NULL`.
*/
void ng_ndp_retrans_nbr_sol(ng_ipv6_nc_t *nc_entry);
void ng_ndp_retrans_nbr_sol(ng_ipv6_nc_t *nc_entry, ng_ipv6_addr_t *src);

/**
* @brief Event handler for a neighbor cache state timeout.
Expand Down
5 changes: 4 additions & 1 deletion sys/include/net/ng_ndp/hst.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ extern "C" {
* @brief Sends a router solicitation for interface @p iface
*
* @param[in] iface An IPv6 interface
* @param[in] rtr The address of the router to solicitate. If `rtr == NULL`
* it will be send to @p NG_IPV6_ADDR_ALL_ROUTERS_LINK_LOCAL.
*/
void ng_ndp_hst_solicitate_router(ng_ipv6_netif_t *iface);
void ng_ndp_hst_solicitate_router(ng_ipv6_netif_t *iface,
ng_ipv6_addr_t *rtr);

/**
* @brief Initiates the interface to send router solicitations.
Expand Down
13 changes: 13 additions & 0 deletions sys/include/net/ng_sixlowpan.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@

#include "net/ng_sixlowpan/frag.h"
#include "net/ng_sixlowpan/iphc.h"
#include "net/ng_sixlowpan/nd.h"

#ifdef __cplusplus
extern "C" {
#endif

#define NG_SIXLOWPAN_MSG_DELETE_CTX (0x0220) /**< Message type for IPHC removal */

/**
* @brief Default stack size to use for the 6LoWPAN thread
*/
Expand All @@ -57,6 +60,16 @@ extern "C" {
*/
#define NG_SIXLOWPAN_UNCOMPRESSED (0x41)

/**
* @brief The PID to the 6LoWPAN thread.
*
* @note Use @ref ng_sixlowpan_init() to initialize. **Do not set by hand**.
*
* @details This variable is preferred for 6LoWPAN internal communication *only*.
* Please use @ref net_ng_netreg for external communication.
*/
kernel_pid_t ng_sixlowpan_pid;

/**
* @brief Checks if dispatch indicats that fram is not a 6LoWPAN (NALP) frame.
*
Expand Down
9 changes: 7 additions & 2 deletions sys/include/net/ng_sixlowpan/ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <inttypes.h>
#include <stdbool.h>

#include "vtimer.h"

#include "net/ng_ipv6/addr.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -75,6 +77,9 @@ typedef struct {
* </a>
*/
uint16_t ltime;
#ifdef MODULE_NG_SIXLOWPAN_ND
vtimer_t delete_timer; /**< timer for context deletion */
#endif
} ng_sixlowpan_ctx_t;

/**
Expand Down Expand Up @@ -104,8 +109,8 @@ ng_sixlowpan_ctx_t *ng_sixlowpan_ctx_lookup_id(uint8_t id);
* Must be < @ref NG_SIXLOWPAN_CTX_SIZE.
* @param[in] prefix The prefix for the context.
* @param[in] prefix_len Length of @p prefix in bits. Must be > 0.
* @param[in] ltime New lifetime of the context. @p comp will be
* implicitly set to `false` if @p ltime == 0.
* @param[in] ltime New lifetime of the context. Entry will be implicitly
* deleted if @p ltime == 0.
* @param[in] comp Use for compression if true, do not use for
* compression, but still for decompression if false.
*
Expand Down
137 changes: 137 additions & 0 deletions sys/include/net/ng_sixlowpan/nd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @defgroup net_ng_sixlowpan_nd Neighbor Discovery Optimization for 6LoWPAN
* @ingroup net_ng_sixlowpan
* @brief Implements Neighbor Discovery Optimization for 6LoWPAN.
* @see <a href="https://tools.ietf.org/html/rfc6775">
* RFC 6775
* </a>
* @{
*
* @file
* @brief 6LoWPAN Neighbor Discovery definitions.
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef NG_SIXLOWPAN_ND_H_
#define NG_SIXLOWPAN_ND_H_

#include <stdint.h>

#include "net/eui64.h"
#include "net/ng_ipv6/addr.h"
#include "net/ng_netapi.h"
#include "net/ng_netconf.h"

#include "net/ng_sixlowpan/nd/rtr.h"
#include "net/ng_sixlowpan/nd/types.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Message type for next unicast router solicitation.
*/
#define NG_SIXLOWPAN_ND_MSG_UC_RTR_SOL (0x0221)

/**
* @brief Registration Lifetime of an address in minutes.
* This lifetime is highly depenent on the sleep cycles of the node and should
* be set to a value bigger than these sleep cycles.
*
* @see <a href="https://tools.ietf.org/html/rfc6775#section-5.8.1">
* RFC 6775, section 5.8.1
* </a>
*/
#ifndef NG_SIXLOWPAN_ND_REG_LTIME
#define NG_SIXLOWPAN_ND_REG_LTIME (5U)
#endif

/**
* @brief Interval in seconds between initial router solicitation
* transmissions
*
* @see @ref NG_NDP_MAX_RTR_SOL_INT
*/
#define NG_SIXLOWPAN_ND_MAX_RTR_SOL_INT (10U)

/**
* @brief Truncation for truncated binary exponential backoff after initial
* resends.
*
* @note The RFC is a little ambiguous since the truncation should be a
* binary exponent, while the
*
* @see <a href="https://tools.ietf.org/html/rfc6775#section-5.3">
* RFC 6775, section 5.3
* </a>
*/
#define NG_SIXLOWPAN_ND_MAX_RTR_SOL_INT_TRUNC (6U)

/**
* @brief Binary exponential backoff for router solicitation
* re-sends.
*
* @param[in] base_sec Base time in seconds for the backoff.
* @param[in] exp Exponent for the factor of the backoff.
*
* @return The resulting backoff time in seconds.
*/
uint32_t ng_sixlowpan_nd_beb(uint32_t base_sec, uint8_t exp);

void ng_sixlowpan_nd_l2addr_resolution(uint8_t *l2addr, uint8_t *l2addr_len,
ng_ipv6_addr_t *next_hop_ip);

/**
* @brief Handles 6LoWPAN context option.
*
* @param[in] icmpv6_type Message type of the ICMPv6 message that contained.
* this message.
* @param[in] 6ctx_opt The 6LoWPAN context option.
*
* @return true, when 6LoWPAN context option was correct.
* @return false, when it was incorrect.
*/
bool ng_sixlowpan_nd_opt_6ctx_handle(uint8_t icmpv6_type,
ng_sixlowpan_nd_opt_6ctx_t *ctx_opt,
uint16_t rtr_ltime);

uint8_t ng_sixlowpan_nd_opt_ar_handle(kernel_pid_t iface, ng_ipv6_hdr_t *ipv6,
uint8_t icmpv6_type,
ng_sixlowpan_nd_opt_ar_t *ar_opt,
ng_ndp_opt_t *sl2a_opt);

ng_pktsnip_t *ng_sixlowpan_nd_opt_ar_build(uint8_t status, uint16_t ltime,
eui64_t *eui64,
ng_pktsnip_t *next);

static inline ng_pktsnip_t *ng_sixlowpan_nd_opt_ar_iface_build(kernel_pid_t iface,
uint8_t status, ng_pktsnip_t *next)
{
eui64_t eui64;

if (ng_netapi_get(iface, NETCONF_OPT_ADDRESS_LONG, 0, &eui64,
sizeof(eui64)) < 0) {
return NULL;
}

return ng_sixlowpan_nd_opt_ar_build(0, NG_SIXLOWPAN_ND_REG_LTIME, &eui64,
next);
}

/* TODO: wake-up behavior */

#ifdef __cplusplus
}
#endif

#endif /* NG_SIXLOWPAN_ND_H_ */
/** @} */
Loading

0 comments on commit 1da599c

Please sign in to comment.