From abc0280543e2df7b8047a115fd2816bfa39dfe4c Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 30 Apr 2015 21:27:17 +0200 Subject: [PATCH] ng_rpl: add source routing header parsing for ng_net --- sys/Makefile | 3 + sys/include/net/ng_rpl.h | 33 +++++++++ sys/include/net/ng_rpl/srh.h | 69 +++++++++++++++++++ .../ng_ipv6/ext/rh/ng_ipv6_ext_rh.c | 5 ++ sys/net/routing/ng_rpl/srh/ng_rpl_srh.c | 24 +++++++ 5 files changed, 134 insertions(+) create mode 100644 sys/include/net/ng_rpl.h create mode 100644 sys/include/net/ng_rpl/srh.h create mode 100644 sys/net/routing/ng_rpl/srh/ng_rpl_srh.c diff --git a/sys/Makefile b/sys/Makefile index 489cc115207b..8349157362f7 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -113,6 +113,9 @@ endif ifneq (,$(filter ng_pktbuf,$(USEMODULE))) DIRS += net/crosslayer/ng_pktbuf endif +ifneq (,$(filter ng_rpl_srh,$(USEMODULE))) + DIRS += net/routing/ng_rpl/srh +endif ifneq (,$(filter ng_sixlowpan,$(USEMODULE))) DIRS += net/network_layer/ng_sixlowpan endif diff --git a/sys/include/net/ng_rpl.h b/sys/include/net/ng_rpl.h new file mode 100644 index 000000000000..fc738e282314 --- /dev/null +++ b/sys/include/net/ng_rpl.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 Martine Lenders + * + * 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_rpl New RPL + * @ingroup net + * @{ + * + * @file + * @brief TODO + * + * @author Martine Lenders + */ +#ifndef NG_RPL_H_ +#define NG_RPL_H_ + + + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* NG_RPL_H_ */ +/** @} */ diff --git a/sys/include/net/ng_rpl/srh.h b/sys/include/net/ng_rpl/srh.h new file mode 100644 index 000000000000..653ab7ea4d54 --- /dev/null +++ b/sys/include/net/ng_rpl/srh.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2015 Martine Lenders + * + * 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_rpl_srh RPL source routing header extension + * @ingroup net_rpl + * @brief Implementation of RPL source routing extension headers + * @see + * RFC 6554 + * + * @{ + * + * @file + * @brief Definititions for RPL source routing extension headers + * + * @author Martine Lenders + */ +#ifndef NG_RPL_SRH_H_ +#define NG_RPL_SRH_H_ + +#include "net/ng_ipv6/addr.h" +#include "net/ng_ipv6/ext.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Type for source routing header. + */ +#define NG_RPL_SRH_TYPE (3U) + +/** + * @brief The RPL Source routing header. + * + * @see + * RFC 6554 + * + * + * @extends ng_ipv6_ext_rh_t + */ +typedef struct __attribute__((packed)) { + uint8_t nh; /**< next header */ + uint8_t len; /**< length in 8 octets without first octet */ + uint8_t type; /**< identifier of a particular routing header type */ + uint8_t seg_left; /**< number of route segments remaining */ +} ng_rpl_srh_t; + +/** + * @brief Extract next hop from the RPL source routing header. + * + * @param[in] rh A RPL source routing header. + * + * @return next hop, on success + * @return NULL, if not found. + */ +ng_ipv6_addr_t *ng_rpl_srh_next_hop(ng_rpl_srh_t *rh); + +#ifdef __cplusplus +} +#endif + +#endif /* NG_RPL_SRH_H_ */ +/** @} */ diff --git a/sys/net/network_layer/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c b/sys/net/network_layer/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c index ae09b16fe84b..5373651ac7f9 100644 --- a/sys/net/network_layer/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c +++ b/sys/net/network_layer/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c @@ -46,6 +46,11 @@ ng_ipv6_addr_t *ng_ipv6_ext_rh_next_hop(ng_ipv6_hdr_t *ipv6) if (ipv6->nh == NG_PROTNUM_IPV6_EXT_RH) { switch (ext->type) { +#ifdef MODULE_NG_RPL_SRH + case NG_RPL_SRH_TYPE: + return ng_rpl_srh_next_hop((ng_rpl_srh_t *)ext); +#endif + default: break; } diff --git a/sys/net/routing/ng_rpl/srh/ng_rpl_srh.c b/sys/net/routing/ng_rpl/srh/ng_rpl_srh.c new file mode 100644 index 000000000000..dad470e04677 --- /dev/null +++ b/sys/net/routing/ng_rpl/srh/ng_rpl_srh.c @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2015 Martine Lenders + * + * 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. + */ + +/** + * @{ + * + * @file + */ + +#include "net/ng_rpl/srh.h" + +ng_ipv6_addr_t *ng_rpl_srh_next_hop(ng_rpl_srh_t *rh) +{ + /* TODO */ + + return NULL; +} + +/** @} */