Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnrc_sixlowpan_nd_router: initial import of router behavior of 6LoWPAN-ND #3749

Merged
merged 2 commits into from
Sep 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ ifneq (,$(filter ieee802154,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan
endif
ifneq (,$(filter gnrc_ipv6_router, $(USEMODULE)))
USEMODULE += gnrc_sixlowpan # TODO: replace with gnrc_sixlowpan_router
USEMODULE += gnrc_sixlowpan_router
endif
ifneq (,$(filter gnrc_ipv6_default, $(USEMODULE)))
USEMODULE += gnrc_sixlowpan_default
endif
ifneq (,$(filter gnrc_ipv6_router_default, $(USEMODULE)))
USEMODULE += gnrc_sixlowpan_default # TODO: replace with gnrc_sixlowpan_router_default
USEMODULE += gnrc_sixlowpan_router_default
endif
endif

Expand All @@ -57,6 +57,17 @@ ifneq (,$(filter gnrc_sixlowpan_default,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan_iphc
endif

ifneq (,$(filter gnrc_sixlowpan_router_default,$(USEMODULE)))
USEMODULE += gnrc_ipv6_router_default
USEMODULE += gnrc_sixlowpan_router
USEMODULE += gnrc_sixlowpan_frag
USEMODULE += gnrc_sixlowpan_iphc
endif

ifneq (,$(filter gnrc_sixlowpan_router,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan
endif

ifneq (,$(filter gnrc_sixlowpan_frag,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan
USEMODULE += vtimer
Expand All @@ -78,6 +89,10 @@ ifneq (,$(filter gnrc_sixlowpan_ctx,$(USEMODULE)))
USEMODULE += vtimer
endif

ifneq (,$(filter gnrc_sixlowpan_nd_router,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan_nd
endif

ifneq (,$(filter gnrc_sixlowpan_nd,$(USEMODULE)))
USEMODULE += gnrc_ndp
USEMODULE += gnrc_ndp_internal
Expand All @@ -101,7 +116,13 @@ endif
ifneq (,$(filter gnrc_ipv6_router_default,$(USEMODULE)))
USEMODULE += gnrc_ipv6_router
USEMODULE += gnrc_icmpv6
USEMODULE += gnrc_ndp_router
ifeq (1,$(GNRC_NETIF_NUMOF))
ifeq (,$(filter gnrc_sixlowpan_nd_router,$(USEMODULE)))
USEMODULE += gnrc_ndp_router
endif
else
USEMODULE += gnrc_ndp_router
endif
endif

ifneq (,$(filter gnrc_ndp_host,$(USEMODULE)))
Expand Down
2 changes: 2 additions & 0 deletions Makefile.pseudomodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ PSEUDOMODULES += gnrc_ipv6_default
PSEUDOMODULES += gnrc_ipv6_router
PSEUDOMODULES += gnrc_ipv6_router_default
PSEUDOMODULES += gnrc_sixlowpan_default
PSEUDOMODULES += gnrc_sixlowpan_router
PSEUDOMODULES += gnrc_sixlowpan_router_default
PSEUDOMODULES += gnrc_pktbuf
PSEUDOMODULES += ieee802154
PSEUDOMODULES += log
Expand Down
3 changes: 2 additions & 1 deletion doc/doxygen/riot.doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,8 @@ PREDEFINED = DOXYGEN \
DEVELHELP \
ENABLE_DEBUG \
TEST_SUITES \
MODULE_GNRC_NDP_ROUTER
MODULE_GNRC_NDP_ROUTER \
MODULE_GNRC_SIXLOWPAN_ND_ROUTER


# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
Expand Down
83 changes: 83 additions & 0 deletions sys/include/net/gnrc/sixlowpan/nd.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "net/sixlowpan/nd.h"
#include "timex.h"

#include "net/gnrc/sixlowpan/nd/router.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -52,6 +54,16 @@ extern "C" {
*/
#define GNRC_SIXLOWPAN_ND_MSG_DELETE_CTX (0x0222)

/**
* @brief Message type for authoritative border router timeout
*/
#define GNRC_SIXLOWPAN_ND_MSG_ABR_TIMEOUT (0x0223)

/**
* @brief Message type for address registration timeout
*/
#define GNRC_SIXLOWPAN_ND_MSG_AR_TIMEOUT (0x0224)

#ifndef GNRC_SIXLOWPAN_ND_AR_LTIME
/**
* @brief Registration lifetime in minutes for the address registration option
Expand All @@ -78,6 +90,28 @@ extern "C" {
#define GNRC_SIXLOWPAN_ND_MAX_RTR_SOL_INT (60U) /**< retransmission increment for exponential
* backoff of subsequent RS */
/** @} */
/**
* @name Router constants
* @{
* @see <a href="https://tools.ietf.org/html/rfc6775#section-9">
* RFC 6775, section 9
* </a>
*/
#define GNRC_SIXLOWPAN_ND_MIN_RTR_ADV_DELAY (10U) /**< replacement value (in seconds) for
* @ref GNRC_NDP_MIN_RTR_ADV_DELAY */
/**
* @brief replacement value (in microseconds) for @ref GNRC_NDP_MAX_RTR_ADV_DELAY
*/
#define GNRC_SIXLOWPAN_ND_MAX_RTR_ADV_DELAY (2U * SEC_IN_USEC)
/**
* @brief Lifetime of a tentative address entry in seconds
*/
#define GNRC_SIXLOWPAN_ND_TENTATIVE_NCE_LIFETIME (20U)
/**
* @brief 6LoWPAN Multihop Hoplimit
*/
#define GNRC_SIXLOWPAN_ND_MULTIHOP_HOPLIMIT (64U)
/** @} */

/**
* @brief Initializes 6LoWPAN neighbor discovery for the interface.
Expand Down Expand Up @@ -182,6 +216,55 @@ bool gnrc_sixlowpan_nd_opt_6ctx_handle(uint8_t icmpv6_type, sixlowpan_nd_opt_6ct
*/
void gnrc_sixlowpan_nd_wakeup(void);

#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER
/**
* @brief Handles authoritative border router option.
*
* @param[in] iface Interface the source link-layer option was received
* on.
* @param[in] rtr_adv The router advertisement containing the ABRO.
* @param[in] icmpv6_size The size of the @p rtr_adv.
* @param[in] abr_opt The ABRO.
*
* @note Erroneous ABROs are always ignored silently.
*/
void gnrc_sixlowpan_nd_opt_abr_handle(kernel_pid_t iface, ndp_rtr_adv_t *rtr_adv, int icmpv6_size,
sixlowpan_nd_opt_abr_t *abr_opt);

/**
* @brief Builds the 6LoWPAN context option.
*
* @param[in] prefix_len The length of the context's prefix.
* @param[in] flags Flags + CID for the context.
* @param[in] ltime Lifetime of the context.
* @param[in] prefix The context's prefix
* @param[in] next More options in the packet. NULL, if there are none.
*
* @return The pkt snip list of options, on success
* @return NULL, if packet buffer is full or on error
*/
gnrc_pktsnip_t *gnrc_sixlowpan_nd_opt_6ctx_build(uint8_t prefix_len, uint8_t flags, uint16_t ltime,
ipv6_addr_t *prefix, gnrc_pktsnip_t *next);

/**
* @brief Builds the authoritative border router option.
*
* @param[in] version Version of the border router information.
* @param[in] ltime Registration lifetime for the border router.
* @param[in] braddr The IPv6 address of the border router.
* @param[in] next More options in the packet. NULL, if there are none.
*
* @return The pkt snip list of options, on success
* @return NULL, if packet buffer is full or on error
*/
gnrc_pktsnip_t *gnrc_sixlowpan_nd_opt_abr_build(uint32_t version, uint16_t ltime,
ipv6_addr_t *braddr, gnrc_pktsnip_t *next);
#else
#define gnrc_sixlowpan_nd_opt_abr_handle(iface, rtr_adv, icmpv6_size, abr_opt)
#define gnrc_sixlowpan_nd_opt_6ctx_build(prefix_len, flags, ltime, prefix, next) (NULL)
#define gnrc_sixlowpan_nd_opt_abr_build(version, ltime, braddr, next) (NULL)
#endif

#ifdef __cplusplus
}
#endif
Expand Down
164 changes: 164 additions & 0 deletions sys/include/net/gnrc/sixlowpan/nd/router.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* 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 gnrc_sixlowpan_nd_router Router-part of 6LoWPAN-ND
* @ingroup gnrc_sixlowpan_nd
* @brief Router-part of 6LoWPAN-ND
* @{
*
* @file
* @brief Router-definitions for 6LoWPAN-ND.
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef GNRC_SIXLOWPAN_ND_ROUTER_H_
#define GNRC_SIXLOWPAN_ND_ROUTER_H_

#include <stdbool.h>

#include "bitfield.h"
#include "net/gnrc/sixlowpan/ctx.h"
#include "net/gnrc/ipv6/netif.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Number of registerable border routers
*
* @note More than one border routers require some way of synchronization
* of the context information (see
* [RFC 6775, section 8.1](https://tools.ietf.org/html/rfc6775#section-8.1))
*/
#ifndef GNRC_SIXLOWPAN_ND_ROUTER_ABR_NUMOF
#define GNRC_SIXLOWPAN_ND_ROUTER_ABR_NUMOF (1)
#endif

/**
* @brief The number of non-link-local prefixes associated with border routers
* at maximum.
*/
#ifndef GNRC_SIXLOWPAN_ND_ROUTER_ABR_PRF_NUMOF
#define GNRC_SIXLOWPAN_ND_ROUTER_ABR_PRF_NUMOF (GNRC_SIXLOWPAN_ND_ROUTER_ABR_NUMOF)
#endif

/**
* @brief Representation for prefixes coming from a router
*/
typedef struct gnrc_sixlowpan_nd_router_prf {
struct gnrc_sixlowpan_nd_router_prf *next; /**< next prefix */
gnrc_ipv6_netif_t *iface; /**< interface the prefix is registered too */
gnrc_ipv6_netif_addr_t *prefix; /**< prefix on the interface/in the prefix list */
} gnrc_sixlowpan_nd_router_prf_t;

/**
* @brief Abstract representation of a border router on all (border) routers.
*/
typedef struct {
ipv6_addr_t addr; /**< the IPv6 address of the border router (BR) */
uint32_t version; /**< version of the information dissiminated by the
* BR */
uint16_t ltime; /**< the time in minutes until deletion */
BITFIELD(ctxs, GNRC_SIXLOWPAN_CTX_SIZE);/**< contexts associated with BR */
gnrc_sixlowpan_nd_router_prf_t *prfs; /**< prefixes associated with BR */
vtimer_t ltimer; /**< timer for deletion */
} gnrc_sixlowpan_nd_router_abr_t;

/**
* @brief Removes tentetative neighbor cache entries or sets registered ones to
* garbage-collectible.
*
* @param[in] nc_entry A neighbor cache entry.
*/
static inline void gnrc_sixlowpan_nd_router_gc_nc(gnrc_ipv6_nc_t *nc_entry)
{
switch (gnrc_ipv6_nc_get_type(nc_entry)) {
case GNRC_IPV6_NC_TYPE_TENTATIVE:
case GNRC_IPV6_NC_TYPE_REGISTERED:
gnrc_ipv6_nc_remove(nc_entry->iface, &nc_entry->ipv6_addr);
break;
default:
break;
}

}

/**
* @brief Set @p netif to router mode.
*
* @details This sets/unsets the GNRC_IPV6_NETIF_FLAGS_ROUTER and initializes or ceases router
* behavior for 6LoWPAN neighbor discovery.
*
* @param[in] netif An IPv6 interface. Must not be NULL.
* @param[in] enable Status for the GNRC_IPV6_NETIF_FLAGS_ROUTER flag.
*/
static inline void gnrc_sixlowpan_nd_router_set_router(gnrc_ipv6_netif_t *netif, bool enable)
{
if (enable) {
netif->flags |= GNRC_IPV6_NETIF_FLAGS_ROUTER;
}
else {
netif->flags &= ~GNRC_IPV6_NETIF_FLAGS_ROUTER;
}
}

/**
* @brief Set/Unset GNRC_IPV6_NETIF_FLAGS_RTR_ADV flag for @p netif.
*
* @details GNRC_IPV6_NETIF_FLAGS_RTR_ADV and initializes or ceases
* periodic router advertising behavior for neighbor discovery.
*
* @param[in] netif An IPv6 interface. Must not be NULL.
* @param[in] enable Status for the GNRC_IPV6_NETIF_FLAGS_RTR_ADV flag.
*/
static inline void gnrc_sixlowpan_nd_router_set_rtr_adv(gnrc_ipv6_netif_t *netif, bool enable)
{
if (enable) {
netif->flags |= GNRC_IPV6_NETIF_FLAGS_RTR_ADV;
}
else {
netif->flags &= ~GNRC_IPV6_NETIF_FLAGS_RTR_ADV;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These setter functions look much like Java code to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit-operations are not typical java operations. Moreover, it makes https://github.com/RIOT-OS/RIOT/pull/3749/files#diff-f9bf85cb337616822921e4230ede1572R239 more readable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that anything gets more readable by replacing an assignment by a function and IMO it adds just 18 lines of additional code plus documentation, but this is not a blocker for this PR.


/**
* @brief Get's the border router for this router.
*
* @return The border router, if one is specified.
* @return NULL, otherwise.
*/
gnrc_sixlowpan_nd_router_abr_t *gnrc_sixlowpan_nd_router_abr_get(void);

/**
* @brief Checks if the version data @p abr_opt is older than the version of the currently
* registered border router.
*
* @param[in] abr_opt An authoritative border router option containing potentially new
* information on the currently registered border router.
*
* @return true, if the information in @p abr_opt is newer.
* @return false, if the information in @p abr_opt is older.
*/
bool gnrc_sixlowpan_nd_router_abr_older(sixlowpan_nd_opt_abr_t *abr_opt);

/**
* @brief Removes the border router and all the prefixes and contexts it disseminated through
* the network for this node.
*
* @param[in] abr The border router.
*/
void gnrc_sixlowpan_nd_router_abr_remove(gnrc_sixlowpan_nd_router_abr_t *abr);

#ifdef __cplusplus
}
#endif

#endif /* GNRC_SIXLOWPAN_ND_ROUTER_H_ */
/** @} */
3 changes: 3 additions & 0 deletions sys/net/gnrc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ endif
ifneq (,$(filter gnrc_sixlowpan_nd,$(USEMODULE)))
DIRS += network_layer/sixlowpan/nd
endif
ifneq (,$(filter gnrc_sixlowpan_nd_router,$(USEMODULE)))
DIRS += network_layer/sixlowpan/nd/router
endif
ifneq (,$(filter gnrc_sixlowpan_netif,$(USEMODULE)))
DIRS += network_layer/sixlowpan/netif
endif
Expand Down
11 changes: 11 additions & 0 deletions sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ static void *_event_loop(void *args)
gnrc_sixlowpan_ctx_remove(((((gnrc_sixlowpan_ctx_t *)msg.content.ptr)->flags_id) &
GNRC_SIXLOWPAN_CTX_FLAGS_CID_MASK));
break;
#endif
#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER
case GNRC_SIXLOWPAN_ND_MSG_ABR_TIMEOUT:
DEBUG("ipv6: border router timeout event received\n");
gnrc_sixlowpan_nd_router_abr_remove(
(gnrc_sixlowpan_nd_router_abr_t *)msg.content.ptr);
break;
case GNRC_SIXLOWPAN_ND_MSG_AR_TIMEOUT:
DEBUG("ipv6: address registration timeout received\n");
gnrc_sixlowpan_nd_router_gc_nc((gnrc_ipv6_nc_t *)msg.content.ptr);
break;
#endif
default:
break;
Expand Down
Loading