-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: added a core implementation of a FIB
- Loading branch information
BytesGalore
authored and
BytesGalore
committed
Apr 1, 2015
1 parent
2fe68d5
commit 30c76ad
Showing
16 changed files
with
2,014 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
Oops, something went wrong.