Skip to content

Commit

Permalink
net: added a core implementation of a FIB
Browse files Browse the repository at this point in the history
  • Loading branch information
BytesGalore authored and BytesGalore committed Apr 1, 2015
1 parent 2fe68d5 commit af787a2
Show file tree
Hide file tree
Showing 16 changed files with 2,009 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,9 @@ ifneq (,$(filter nhdp,$(USEMODULE)))
USEMODULE += oonf_common
USEMODULE += oonf_rfc5444
endif

ifneq (,$(filter fib,$(USEMODULE)))
USEMODULE += timex
USEMODULE += vtimer
USEMODULE += net_help
endif
3 changes: 3 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ endif
ifneq (,$(filter ng_pktdump,$(USEMODULE)))
DIRS += net/crosslayer/ng_pktdump
endif
ifneq (,$(filter fib,$(USEMODULE)))
DIRS += net/network_layer/fib
endif

DIRS += $(dir $(wildcard $(addsuffix /Makefile, ${USEMODULE})))

Expand Down
4 changes: 4 additions & 0 deletions sys/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ ifneq (,$(filter oneway_malloc,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/sys/oneway-malloc/include
endif

ifneq (,$(filter fib,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/sys/include/net
endif

ifneq (,$(filter embunit,$(USEMODULE)))
ifeq ($(OUTPUT),XML)
CFLAGS += -DOUTPUT=OUTPUT_XML
Expand Down
149 changes: 149 additions & 0 deletions sys/include/net/ng_fib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Copyright (C) 2014 Martin Landsmann <Martin.Landsmann@HAW-Hamburg.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_fib Forwarding Information Base (FIB)
* @ingroup net
* @brief FIB implementation
*
* @{
*
* @file
* @brief Types and functions for FIB
* @author Martin Landsmann
*/

#ifndef FIB_H_
#define FIB_H_

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Reactive Routing Protocol (RRP) message content to request/reply route discovery
*/
typedef struct rrp_address_msg_t {
uint8_t *address; /**< The pointer to the address */
uint8_t address_size; /**< The address size */
uint32_t address_flags; /**< The flags for the given address */
} rrp_address_msg_t;

#define FIB_MSG_RRP_SIGNAL (0x99) /**< message type for RRP notifications */

/**
* @brief indicator of a lifetime that does not expire (2^32 - 1)
*/
#define FIB_LIFETIME_NO_EXPIRE (0xFFFFFFFF)

/**
* @brief initializes all FIB entries with 0
*/
void fib_init(void);

/**
* @brief de-initializes the FIB entries
*/
void fib_deinit(void);

/**
* @brief Registration of reactive routing protocol handler function
*/
void fib_register_rrp(void);

/**
* @brief Adds a new entry in the corresponding FIB table for global destination and next hop
*
* @param[in] iface_id the interface ID
* @param[in] dst the destination address
* @param[in] dst_size the destination address size
* @param[in] dst_flags the destination address flags
* @param[in] next_hop the next hop address to be updated
* @param[in] next_hop_size the next hop address size
* @param[in] next_hop_flags the next-hop address flags
* @param[in] lifetime the lifetime in ms to be updates
*
* @return 0 on success
* -ENOMEM if the entry cannot be created due to unsufficient RAM
*/
int fib_add_entry(kernel_pid_t iface_id, uint8_t *dst, size_t dst_size, uint32_t dst_flags,
uint8_t *next_hop, size_t next_hop_size, uint32_t next_hop_flags,
uint32_t lifetime);

/**
* @brief Updates an entry in the FIB table with next hop and lifetime
*
* @param[in] dst the destination address
* @param[in] dst_size the destination address size
* @param[in] next_hop the next hop address to be updated
* @param[in] next_hop_size the next hop address size
* @param[in] next_hop_flags the next-hop address flags
* @param[in] lifetime the lifetime in ms to be updates
*
* @return 0 on success
* -ENOMEM if the entry cannot be updated due to unsufficient RAM
*/
int fib_update_entry(uint8_t *dst, size_t dst_size,
uint8_t *next_hop, size_t next_hop_size, uint32_t next_hop_flags,
uint32_t lifetime);

/**
* @brief removes an entry from the corresponding FIB table
*
* @param[in] dst the destination address
* @param[in] dst_size the destination address size
*/
void fib_remove_entry(uint8_t *dst, size_t dst_size);

/**
* @brief provides a next hop for a given destination
*
* @param[in, out] iface_id pointer to store the interface ID for the next hop
* @param[out] next_hop pointer where the next hop address should be stored
* @param[in, out] next_hop_size the next hop address size. The value is
* overwritten with the actual next hop size
* @param[out] next_hop_flags the next-hop address flags, e.g. compression type
* @param[in] dst the destination address
* @param[in] dst_size the destination address size
* @param[in] dst_flags the destination address flags
*
* @return 0 on success
* -EHOSTUNREACH if no next hop is available in any FIB table
* all RRPs are notified before the return
* -ENOBUFS if the size for the next hop address is insufficient low
*/
int fib_get_next_hop(kernel_pid_t *iface_id,
uint8_t *next_hop, size_t *next_hop_size, uint32_t* next_hop_flags,
uint8_t *dst, size_t dst_size, uint32_t dst_flags);

/**
* @brief returns the actual number of used FIB entries
*/
int fib_get_num_used_entries(void);

/**
* @brief Prints the kernel_pid_t for all registered RRPs
*/
void fib_print_notify_rrp(void);

/**
* @brief Prints the FIB content (does not print the entries)
*/
void fib_print_fib_table(void);

/**
* @brief Prints the FIB content
*/
void fib_print_routes(void);

#ifdef __cplusplus
}
#endif

#endif /* FIB_H_ */
/** @} */
54 changes: 54 additions & 0 deletions sys/include/net/ng_fib/ng_fib_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2014 Martin Landsmann <Martin.Landsmann@HAW-Hamburg.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.
*/

/**
* @brief forwarding table structs
* @ingroup net_fib
*
* @{
*
* @file
* @brief Types and functions for operating fib tables
* @author Martin Landsmann
*/

#ifndef FIB_TABLE_H_
#define FIB_TABLE_H_

#include <stdint.h>
#include "vtimer.h"
#include "ng_universal_address.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Container descriptor for a FIB entry
*/
typedef struct fib_entry_t {
/** interface ID */
kernel_pid_t iface_id;
/** Lifetime of this entry */
timex_t lifetime;
/** Unique identifier for the type of the global address */
uint32_t global_flags;
/** Pointer to the shared generic address */
struct universal_address_container_t *global;
/** Unique identifier for the type of the next hop address */
uint32_t next_hop_flags;
/** Pointer to the shared generic address */
struct universal_address_container_t *next_hop;
} fib_entry_t;

#ifdef __cplusplus
}
#endif

#endif /* FIB_TABLE_H_ */
/** @} */
121 changes: 121 additions & 0 deletions sys/include/net/ng_fib/ng_universal_address.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright (C) 2014 Martin Landsmann <Martin.Landsmann@HAW-Hamburg.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_universal_address Universal Address Container
* @ingroup net
* @brief universal address container
*
* @{
*
* @file
* @brief Types and functions for operating universal addresses
* @author Martin Landsmann
*/

#ifndef UNIVERSAL_ADDRESS_H_
#define UNIVERSAL_ADDRESS_H_

#ifdef __cplusplus
extern "C" {
#endif

#define UNIVERSAL_ADDRESS_SIZE (16) /**< size of the used addresses in bytes */

/**
* @brief The container descriptor used to identify a universal address entry
*/
typedef struct universal_address_container_t {
uint8_t use_count; /**< The number of entries link here */
uint8_t address_size; /**< Size in bytes of the used genereic address */
uint8_t address[UNIVERSAL_ADDRESS_SIZE]; /**< the genereic address data */
} universal_address_container_t;

/**
* @brief initializes the datastructure for the entries
*/
void universal_address_init(void);

/**
* @brief resets the usecoumt for all entries
*/
void universal_address_reset(void);

/**
* @brief Adds a given address to the universal address entries
* if the entry already exists, the use_count will be increased.
*
* @param[in] addr pointer to the address
* @param[in] addr_size the number of bytes required for the address entry
*
* @return pointer to the universal_address_container_t containing the address on success
* NULL if the address could not be inserted
*/
universal_address_container_t *universal_address_add(uint8_t *addr, size_t addr_size);

/**
* @brief Adds a given container from the universal address entries
* if the entry exists, the use_count will be decreased.
*
* @param[in] entry pointer to the universal_address_container_t to be removed
*/
void universal_address_rem(universal_address_container_t *entry);

/**
* @brief copies the address from the given container to the provided pointer
*
* @param[in] entry pointer to the universal_address_container_t
* @param[out] addr pointer to store the address entry
* @param[in, out] addr_size pointer providing the size of available memory on addr
* this value is overwritten with the actual size required
*
* @return addr if the address is copied to the addr destination
* NULL if the size is unsufficient for copy
*/
uint8_t* universal_address_get_address(universal_address_container_t *entry,
uint8_t *addr, size_t *addr_size);

/**
* @brief determines if the entry equals the provided address
*
* @param[in] entry pointer to the universal_address_container_t for compare
* @param[in] addr pointer to the address for compare
* @param[in, out] addr_size the number of bytes used for the address entry
* on sucessfull return this value is overwritten
* with the number of matching bytes till the
* first of trailing `0`s indicating a prefix
*
* @return 0 if the entries are equal or comperable
* -ENOENT if the given adresses do not match
*/
int universal_address_compare(universal_address_container_t *entry,
uint8_t *addr, size_t *addr_size);

/**
* @brief Prints the content of the given entry
*
* @param[in] entry pointer to the universal_address_container_t to be printed
*/
void universal_address_print_entry(universal_address_container_t *entry);

/**
* @brief returns the number of used entries
*/
int universal_address_get_num_used_entries(void);

/**
* @brief Prints the content of the genereic address table up to the used element
*/
void universal_address_print_table(void);

#ifdef __cplusplus
}
#endif

#endif /* UNIVERSAL_ADDRESS_H_ */
/** @} */
1 change: 1 addition & 0 deletions sys/net/network_layer/fib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
Loading

0 comments on commit af787a2

Please sign in to comment.