1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

fib: allow for multiple instances of FIB

This commit is contained in:
Oleg Hahm 2015-08-12 19:04:43 +02:00
parent f7d77428d7
commit 4267212502
10 changed files with 288 additions and 241 deletions

View File

@ -85,10 +85,6 @@
#include "dev_eth_autoinit.h"
#endif
#ifdef MODULE_FIB
#include "net/fib.h"
#endif
#define ENABLE_DEBUG (0)
#include "debug.h"
@ -153,10 +149,6 @@ void auto_init(void)
DEBUG("Auto init UDP module.\n");
gnrc_udp_init();
#endif
#ifdef MODULE_FIB
DEBUG("Auto init FIB module.\n");
fib_init();
#endif
/* initialize network devices */

View File

@ -22,6 +22,7 @@
#ifndef FIB_H_
#define FIB_H_
#include "net/fib/table.h"
#include "kernel_types.h"
#include "timex.h"
@ -29,6 +30,15 @@
extern "C" {
#endif
#ifndef FIB_MAX_FIB_TABLE_ENTRIES
/**
* @brief maximum number of FIB tables entries handled
*
* Might be overwritten by other modules or the application.
*/
#define FIB_MAX_FIB_TABLE_ENTRIES (20)
#endif
/**
* @brief Routing Protocol (RP) message content to request/reply notification
*/
@ -61,13 +71,17 @@ typedef struct fib_destination_set_entry_t {
/**
* @brief initializes all FIB entries with 0
*
* @param[in] table the fib instance to initialize
*/
void fib_init(void);
void fib_init(fib_entry_t table[]);
/**
* @brief de-initializes the FIB entries
*
* @param[in] table the fib instance to de-initialize
*/
void fib_deinit(void);
void fib_deinit(fib_entry_t table[]);
/**
* @brief Registration of a routing protocol handler function
@ -85,6 +99,7 @@ int fib_register_rp(uint8_t *prefix, size_t prefix_addr_type_size);
/**
* @brief Adds a new entry in the corresponding FIB table for global destination and next hop
*
* @param[in] table the fib table the entry should be added to
* @param[in] iface_id the interface ID
* @param[in] dst the destination address
* @param[in] dst_size the destination address size
@ -98,13 +113,15 @@ int fib_register_rp(uint8_t *prefix, size_t prefix_addr_type_size);
* -ENOMEM if the entry cannot be created due to insufficient RAM
* -EFAULT if dst and/or next_hop is not a valid pointer
*/
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,
int fib_add_entry(fib_entry_t table[], 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] table the fib table containing the entry to update
* @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
@ -116,21 +133,23 @@ int fib_add_entry(kernel_pid_t iface_id, uint8_t *dst, size_t dst_size, uint32_t
* -ENOMEM if the entry cannot be updated due to insufficient RAM
* -EFAULT if dst and/or next_hop is not a valid pointer
*/
int fib_update_entry(uint8_t *dst, size_t dst_size,
int fib_update_entry(fib_entry_t table[], 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] table the fib table containing the entry to remove
* @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);
void fib_remove_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size);
/**
* @brief provides a next hop for a given destination
*
* @param[in] table the fib table that should be searched
* @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
@ -147,7 +166,7 @@ void fib_remove_entry(uint8_t *dst, size_t dst_size);
* -EFAULT if dst and/or next_hop is not a valid pointer
* -EINVAL if one of the other passed out pointers is NULL
*/
int fib_get_next_hop(kernel_pid_t *iface_id,
int fib_get_next_hop(fib_entry_t table[], 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);
@ -157,6 +176,7 @@ int fib_get_next_hop(kernel_pid_t *iface_id,
* the function will continue to count the number of matching entries
* and provide the number to the caller.
*
* @param[in] table the fib table that should be searched
* @param[in] prefix the destination address
* @param[in] prefix_size the destination address size
* @param[out] dst_set the destination addresses matching the prefix
@ -169,14 +189,16 @@ int fib_get_next_hop(kernel_pid_t *iface_id,
* The actual needed size is stored then in dst_set_size,
* however the required size may change in between calls.
*/
int fib_get_destination_set(uint8_t *prefix, size_t prefix_size,
int fib_get_destination_set(fib_entry_t table[], uint8_t *prefix, size_t prefix_size,
fib_destination_set_entry_t *dst_set, size_t* dst_set_size);
/**
* @brief returns the actual number of used FIB entries
*
* @param[in] table the fib instance to check
*/
int fib_get_num_used_entries(void);
int fib_get_num_used_entries(fib_entry_t table[]);
/**
* @brief Prints the kernel_pid_t for all registered RRPs
@ -185,18 +207,23 @@ void fib_print_notify_rrp(void);
/**
* @brief Prints the FIB content (does not print the entries)
*
* @param[in] table the fib instance to print
*/
void fib_print_fib_table(void);
void fib_print_fib_table(fib_entry_t table[]);
/**
* @brief Prints the FIB content
*
* @param[in] table the fib instance to print
*/
void fib_print_routes(void);
void fib_print_routes(fib_entry_t table[]);
#if FIB_DEVEL_HELPER
/**
* @brief get the point in time at which the entry for destination dst expires.
*
* @param[in] table the fib instance to check
* @param[out] lifetime pointer where the expiration time is written on success
* @param[in] dst the destination address
* @param[in] dst_size the destination address size
@ -204,7 +231,7 @@ void fib_print_routes(void);
* @return 0 on success: entry for dst found and lifetime copied
* -EHOSTUNREACH if no fitting entry is available
*/
int fib_devel_get_lifetime(timex_t *lifetime, uint8_t *dst, size_t dst_size);
int fib_devel_get_lifetime(fib_entry_t table[], timex_t *lifetime, uint8_t *dst, size_t dst_size);
#endif
#ifdef __cplusplus

View File

@ -38,6 +38,10 @@
#include "net/gnrc/ipv6/nc.h"
#include "net/gnrc/ipv6/netif.h"
#ifdef MODULE_FIB
#include "net/fib.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -73,6 +77,15 @@ extern "C" {
*/
extern kernel_pid_t gnrc_ipv6_pid;
#ifdef MODULE_FIB
/**
* @brief The forwarding information base (FIB) for the IPv6 stack.
*
* @see @ref net_fib
*/
extern fib_entry_t gnrc_ipv6_fib_table[FIB_MAX_FIB_TABLE_ENTRIES];
#endif
/**
* @brief Initialization of the IPv6 thread.
*

View File

@ -41,6 +41,15 @@ static char _stack[GNRC_IPV6_STACK_SIZE + THREAD_EXTRA_STACKSIZE_PRINTF];
static char _stack[GNRC_IPV6_STACK_SIZE];
#endif
#ifdef MODULE_FIB
#include "net/fib.h"
#include "net/fib/table.h"
/**
* @brief the IPv6 forwarding table
*/
fib_entry_t gnrc_ipv6_fib_table[FIB_MAX_FIB_TABLE_ENTRIES];
#endif
#if ENABLE_DEBUG
static char addr_str[IPV6_ADDR_MAX_STR_LEN];
#endif
@ -69,6 +78,10 @@ kernel_pid_t gnrc_ipv6_init(void)
CREATE_STACKTEST, _event_loop, NULL, "ipv6");
}
#ifdef MODULE_FIB
fib_init(gnrc_ipv6_fib_table);
#endif
return gnrc_ipv6_pid;
}

View File

@ -78,7 +78,7 @@ kernel_pid_t gnrc_ndp_node_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len,
ipv6_addr_t next_hop_actual; /* FIB copies address into this variable */
if ((next_hop_ip == NULL) &&
(fib_get_next_hop(&iface, next_hop_actual.u8, &next_hop_size,
(fib_get_next_hop(gnrc_ipv6_fib_table, &iface, next_hop_actual.u8, &next_hop_size,
&next_hop_flags, (uint8_t *)dst,
sizeof(ipv6_addr_t), 0) >= 0) &&
(next_hop_size == sizeof(ipv6_addr_t))) {

View File

@ -303,9 +303,11 @@ bool _parse_options(int msg_type, gnrc_rpl_dodag_t *dodag, gnrc_rpl_opt_t *opt,
first_target = target;
}
fib_add_entry(if_id, target->target.u8, sizeof(ipv6_addr_t), AF_INET6, src->u8,
sizeof(ipv6_addr_t), AF_INET6,
(dodag->default_lifetime * dodag->lifetime_unit) * SEC_IN_MS);
fib_add_entry(gnrc_ipv6_fib_table, if_id, target->target.u8,
sizeof(ipv6_addr_t), AF_INET6, src->u8,
sizeof(ipv6_addr_t), AF_INET6,
(dodag->default_lifetime * dodag->lifetime_unit) *
SEC_IN_MS);
break;
}
case (GNRC_RPL_OPT_TRANSIT): {
@ -322,8 +324,9 @@ a preceding RPL TARGET DAO option\n");
}
do {
fib_update_entry(first_target->target.u8, sizeof(ipv6_addr_t),
src->u8, sizeof(ipv6_addr_t), AF_INET6,
fib_update_entry(gnrc_ipv6_fib_table, first_target->target.u8,
sizeof(ipv6_addr_t), src->u8,
sizeof(ipv6_addr_t), AF_INET6,
(transit->path_lifetime * dodag->lifetime_unit * SEC_IN_MS));
first_target = (gnrc_rpl_opt_target_t *) (((uint8_t *) (first_target)) +
sizeof(gnrc_rpl_opt_t) + first_target->length);
@ -521,7 +524,7 @@ void gnrc_rpl_send_DAO(gnrc_rpl_dodag_t *dodag, ipv6_addr_t *destination, uint8_
/* find prefix for my address */
ipv6_addr_t prefix;
ipv6_addr_init_prefix(&prefix, me, me_netif->prefix_len);
fib_get_destination_set(prefix.u8, sizeof(ipv6_addr_t), fib_dest_set, &dst_size);
fib_get_destination_set(gnrc_ipv6_fib_table, prefix.u8, sizeof(ipv6_addr_t), fib_dest_set, &dst_size);
int size = sizeof(icmpv6_hdr_t) + sizeof(gnrc_rpl_dao_t) +
(sizeof(gnrc_rpl_opt_target_t) * (dst_size + 1)) + sizeof(gnrc_rpl_opt_transit_t);

View File

@ -17,6 +17,7 @@
#include <stdbool.h>
#include "inet_pton.h"
#include "net/gnrc/ipv6.h"
#include "net/gnrc/ipv6/netif.h"
#include "net/gnrc/rpl/dodag.h"
#include "net/gnrc/rpl/structs.h"
@ -249,9 +250,12 @@ bool gnrc_rpl_parent_add_by_addr(gnrc_rpl_dodag_t *dodag, ipv6_addr_t *addr, gnr
DEBUG("RPL: no interface found for the parent addres\n");
return false;
}
if (fib_add_entry(if_id, def.u8, sizeof(ipv6_addr_t), AF_INET6, dodag->parents->addr.u8,
sizeof(ipv6_addr_t), AF_INET6,
(dodag->default_lifetime * dodag->lifetime_unit) * SEC_IN_MS) != 0) {
if (fib_add_entry(gnrc_ipv6_fib_table, if_id, def.u8,
sizeof(ipv6_addr_t), AF_INET6,
dodag->parents->addr.u8, sizeof(ipv6_addr_t),
AF_INET6,
(dodag->default_lifetime * dodag->lifetime_unit) *
SEC_IN_MS) != 0) {
DEBUG("RPL: error adding parent to FIB\n");
gnrc_rpl_parent_remove(*parent);
return false;
@ -286,7 +290,7 @@ bool gnrc_rpl_parent_remove(gnrc_rpl_parent_t *parent)
{
if (parent == parent->dodag->parents) {
ipv6_addr_t def = { .u64 = {{0}, {0}} };
fib_remove_entry(def.u8, sizeof(ipv6_addr_t));
fib_remove_entry(gnrc_ipv6_fib_table, def.u8, sizeof(ipv6_addr_t));
}
gnrc_rpl_dodag_t *dodag = parent->dodag;
LL_DELETE(dodag->parents, parent);
@ -303,7 +307,7 @@ void gnrc_rpl_local_repair(gnrc_rpl_dodag_t *dodag)
if (dodag->parents) {
gnrc_rpl_dodag_remove_all_parents(dodag);
ipv6_addr_t def = IPV6_ADDR_UNSPECIFIED;
fib_remove_entry(def.u8, sizeof(ipv6_addr_t));
fib_remove_entry(gnrc_ipv6_fib_table, def.u8, sizeof(ipv6_addr_t));
}
if (dodag->my_rank != GNRC_RPL_INFINITE_RANK) {
@ -331,7 +335,7 @@ void gnrc_rpl_parent_update(gnrc_rpl_dodag_t *dodag, gnrc_rpl_parent_t *parent)
ipv6_addr_t all_RPL_nodes = GNRC_RPL_ALL_NODES_ADDR;
kernel_pid_t if_id;
if ((if_id = gnrc_ipv6_netif_find_by_addr(NULL, &all_RPL_nodes)) != KERNEL_PID_UNDEF) {
fib_add_entry(if_id, def.u8, sizeof(ipv6_addr_t), AF_INET6,
fib_add_entry(gnrc_ipv6_fib_table, if_id, def.u8, sizeof(ipv6_addr_t), AF_INET6,
dodag->parents->addr.u8, sizeof(ipv6_addr_t), AF_INET6,
(dodag->default_lifetime * dodag->lifetime_unit) * SEC_IN_MS);
}
@ -382,7 +386,7 @@ gnrc_rpl_parent_t *gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *dodag)
}
trickle_reset_timer(&dodag->trickle);
fib_remove_entry(def.u8, sizeof(ipv6_addr_t));
fib_remove_entry(gnrc_ipv6_fib_table, def.u8, sizeof(ipv6_addr_t));
ipv6_addr_t all_RPL_nodes = GNRC_RPL_ALL_NODES_ADDR;
kernel_pid_t if_id = gnrc_ipv6_netif_find_by_addr(NULL, &all_RPL_nodes);
@ -392,8 +396,9 @@ gnrc_rpl_parent_t *gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *dodag)
return NULL;
}
fib_add_entry(if_id, def.u8, sizeof(ipv6_addr_t), AF_INET6, dodag->parents->addr.u8,
sizeof(ipv6_addr_t), AF_INET6,
fib_add_entry(gnrc_ipv6_fib_table, if_id, def.u8, sizeof(ipv6_addr_t),
AF_INET6, dodag->parents->addr.u8, sizeof(ipv6_addr_t),
AF_INET6,
(dodag->default_lifetime * dodag->lifetime_unit) * SEC_IN_MS);
}

View File

@ -77,16 +77,6 @@ static kernel_pid_t notify_rp[FIB_MAX_REGISTERED_RP];
*/
static universal_address_container_t* prefix_rp[FIB_MAX_REGISTERED_RP];
/**
* @brief maximum number of FIB tables entries handled
*/
#define FIB_MAX_FIB_TABLE_ENTRIES (20)
/**
* @brief array of the FIB tables
*/
static fib_entry_t fib_table[FIB_MAX_FIB_TABLE_ENTRIES];
/**
* @brief convert given ms to a point in time from now on in the future
* @param[in] ms the milliseconds to be converted
@ -112,7 +102,7 @@ static void fib_ms_to_timex(uint32_t ms, timex_t *timex)
* 1 if we found the exact address next-hop
* -EHOSTUNREACH if no fitting next-hop is available
*/
static int fib_find_entry(uint8_t *dst, size_t dst_size,
static int fib_find_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size,
fib_entry_t **entry_arr, size_t *entry_arr_size)
{
timex_t now;
@ -134,36 +124,36 @@ static int fib_find_entry(uint8_t *dst, size_t dst_size,
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
/* autoinvalidate if the entry lifetime is not set to not expire */
if ((fib_table[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE)
|| (fib_table[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) {
if ((table[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE)
|| (table[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) {
/* check if the lifetime expired */
if (timex_cmp(now, fib_table[i].lifetime) > -1) {
if (timex_cmp(now, table[i].lifetime) > -1) {
/* remove this entry if its lifetime expired */
fib_table[i].lifetime.seconds = 0;
fib_table[i].lifetime.microseconds = 0;
fib_table[i].global_flags = 0;
fib_table[i].next_hop_flags = 0;
fib_table[i].iface_id = KERNEL_PID_UNDEF;
table[i].lifetime.seconds = 0;
table[i].lifetime.microseconds = 0;
table[i].global_flags = 0;
table[i].next_hop_flags = 0;
table[i].iface_id = KERNEL_PID_UNDEF;
if (fib_table[i].global != NULL) {
universal_address_rem(fib_table[i].global);
fib_table[i].global = NULL;
if (table[i].global != NULL) {
universal_address_rem(table[i].global);
table[i].global = NULL;
}
if (fib_table[i].next_hop != NULL) {
universal_address_rem(fib_table[i].next_hop);
fib_table[i].next_hop = NULL;
if (table[i].next_hop != NULL) {
universal_address_rem(table[i].next_hop);
table[i].next_hop = NULL;
}
}
}
if ((prefix_size < (dst_size<<3)) && (fib_table[i].global != NULL)) {
if ((prefix_size < (dst_size<<3)) && (table[i].global != NULL)) {
int ret_comp = universal_address_compare(fib_table[i].global, dst, &match_size);
int ret_comp = universal_address_compare(table[i].global, dst, &match_size);
/* If we found an exact match */
if (ret_comp == 0 || (is_all_zeros_addr && match_size == 0)) {
entry_arr[0] = &(fib_table[i]);
entry_arr[0] = &(table[i]);
*entry_arr_size = 1;
/* we will not find a better one so we return */
return 1;
@ -171,7 +161,7 @@ static int fib_find_entry(uint8_t *dst, size_t dst_size,
else {
/* we try to find the most fitting prefix */
if (ret_comp == 1) {
entry_arr[0] = &(fib_table[i]);
entry_arr[0] = &(table[i]);
/* we could find a better one so we move on */
ret = 0;
@ -239,32 +229,32 @@ static int fib_upd_entry(fib_entry_t *entry,
* @return 0 on success
* -ENOMEM if no new entry can be created
*/
static int fib_create_entry(kernel_pid_t iface_id,
static int fib_create_entry(fib_entry_t table[], 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)
{
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
if (fib_table[i].lifetime.seconds == 0 && fib_table[i].lifetime.microseconds == 0) {
if (table[i].lifetime.seconds == 0 && table[i].lifetime.microseconds == 0) {
fib_table[i].global = universal_address_add(dst, dst_size);
table[i].global = universal_address_add(dst, dst_size);
if (fib_table[i].global != NULL) {
fib_table[i].global_flags = dst_flags;
fib_table[i].next_hop = universal_address_add(next_hop, next_hop_size);
fib_table[i].next_hop_flags = next_hop_flags;
if (table[i].global != NULL) {
table[i].global_flags = dst_flags;
table[i].next_hop = universal_address_add(next_hop, next_hop_size);
table[i].next_hop_flags = next_hop_flags;
}
if (fib_table[i].next_hop != NULL) {
if (table[i].next_hop != NULL) {
/* everything worked fine */
fib_table[i].iface_id = iface_id;
table[i].iface_id = iface_id;
if (lifetime < FIB_LIFETIME_NO_EXPIRE) {
fib_ms_to_timex(lifetime, &fib_table[i].lifetime);
fib_ms_to_timex(lifetime, &table[i].lifetime);
}
else {
fib_table[i].lifetime.seconds = FIB_LIFETIME_NO_EXPIRE;
fib_table[i].lifetime.microseconds = FIB_LIFETIME_NO_EXPIRE;
table[i].lifetime.seconds = FIB_LIFETIME_NO_EXPIRE;
table[i].lifetime.microseconds = FIB_LIFETIME_NO_EXPIRE;
}
return 0;
@ -350,8 +340,9 @@ static int fib_signal_rp(uint8_t *dst, size_t dst_size, uint32_t dst_flags)
return ret;
}
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,
int fib_add_entry(fib_entry_t table[], 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)
{
mutex_lock(&mtx_access);
@ -365,14 +356,14 @@ int fib_add_entry(kernel_pid_t iface_id, uint8_t *dst, size_t dst_size, uint32_t
return -EFAULT;
}
int ret = fib_find_entry(dst, dst_size, &(entry[0]), &count);
int ret = fib_find_entry(table, dst, dst_size, &(entry[0]), &count);
if (ret == 1) {
/* we must take the according entry and update the values */
ret = fib_upd_entry(entry[0], next_hop, next_hop_size, next_hop_flags, lifetime);
}
else {
ret = fib_create_entry(iface_id, dst, dst_size, dst_flags,
ret = fib_create_entry(table, iface_id, dst, dst_size, dst_flags,
next_hop, next_hop_size, next_hop_flags, lifetime);
}
@ -380,7 +371,7 @@ int fib_add_entry(kernel_pid_t iface_id, uint8_t *dst, size_t dst_size, uint32_t
return ret;
}
int fib_update_entry(uint8_t *dst, size_t dst_size,
int fib_update_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size,
uint8_t *next_hop, size_t next_hop_size, uint32_t next_hop_flags,
uint32_t lifetime)
{
@ -396,7 +387,7 @@ int fib_update_entry(uint8_t *dst, size_t dst_size,
return -EFAULT;
}
if (fib_find_entry(dst, dst_size, &(entry[0]), &count) == 1) {
if (fib_find_entry(table, dst, dst_size, &(entry[0]), &count) == 1) {
DEBUG("[fib_update_entry] found entry: %p\n", (void *)(entry[0]));
/* we must take the according entry and update the values */
ret = fib_upd_entry(entry[0], next_hop, next_hop_size, next_hop_flags, lifetime);
@ -412,14 +403,14 @@ int fib_update_entry(uint8_t *dst, size_t dst_size,
return ret;
}
void fib_remove_entry(uint8_t *dst, size_t dst_size)
void fib_remove_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size)
{
mutex_lock(&mtx_access);
DEBUG("[fib_remove_entry]\n");
size_t count = 1;
fib_entry_t *entry[count];
int ret = fib_find_entry(dst, dst_size, &(entry[0]), &count);
int ret = fib_find_entry(table, dst, dst_size, &(entry[0]), &count);
if (ret == 1) {
/* we must take the according entry and update the values */
@ -435,7 +426,7 @@ void fib_remove_entry(uint8_t *dst, size_t dst_size)
mutex_unlock(&mtx_access);
}
int fib_get_next_hop(kernel_pid_t *iface_id,
int fib_get_next_hop(fib_entry_t table[], 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)
{
@ -456,13 +447,13 @@ int fib_get_next_hop(kernel_pid_t *iface_id,
return -EFAULT;
}
int ret = fib_find_entry(dst, dst_size, &(entry[0]), &count);
int ret = fib_find_entry(table, dst, dst_size, &(entry[0]), &count);
if (!(ret == 0 || ret == 1)) {
/* notify all responsible RPs for unknown next-hop for the destination address */
if (fib_signal_rp(dst, dst_size, dst_flags) == 0) {
count = 1;
/* now lets see if the RRPs have found a valid next-hop */
ret = fib_find_entry(dst, dst_size, &(entry[0]), &count);
ret = fib_find_entry(table, dst, dst_size, &(entry[0]), &count);
}
}
@ -487,7 +478,7 @@ int fib_get_next_hop(kernel_pid_t *iface_id,
return 0;
}
int fib_get_destination_set(uint8_t *prefix, size_t prefix_size,
int fib_get_destination_set(fib_entry_t table[], uint8_t *prefix, size_t prefix_size,
fib_destination_set_entry_t *dst_set, size_t* dst_set_size)
{
mutex_lock(&mtx_access);
@ -495,12 +486,12 @@ int fib_get_destination_set(uint8_t *prefix, size_t prefix_size,
size_t found_entries = 0;
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
if ((fib_table[i].global != NULL) &&
(universal_address_compare_prefix(fib_table[i].global, prefix, prefix_size<<3) >= 0)) {
if ((table[i].global != NULL) &&
(universal_address_compare_prefix(table[i].global, prefix, prefix_size<<3) >= 0)) {
if( (dst_set != NULL) && (found_entries < *dst_set_size) ) {
/* set the size to full byte usage */
dst_set[found_entries].dest_size = sizeof(dst_set[found_entries].dest);
universal_address_get_address(fib_table[i].global,
universal_address_get_address(table[i].global,
dst_set[found_entries].dest,
&dst_set[found_entries].dest_size);
}
@ -521,7 +512,7 @@ int fib_get_destination_set(uint8_t *prefix, size_t prefix_size,
return ret;
}
void fib_init(void)
void fib_init(fib_entry_t table[])
{
DEBUG("[fib_init] hello. Initializing some stuff.\n");
mutex_lock(&mtx_access);
@ -532,20 +523,20 @@ void fib_init(void)
}
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
fib_table[i].iface_id = 0;
fib_table[i].lifetime.seconds = 0;
fib_table[i].lifetime.microseconds = 0;
fib_table[i].global_flags = 0;
fib_table[i].global = NULL;
fib_table[i].next_hop_flags = 0;
fib_table[i].next_hop = NULL;
table[i].iface_id = 0;
table[i].lifetime.seconds = 0;
table[i].lifetime.microseconds = 0;
table[i].global_flags = 0;
table[i].global = NULL;
table[i].next_hop_flags = 0;
table[i].next_hop = NULL;
}
universal_address_init();
mutex_unlock(&mtx_access);
}
void fib_deinit(void)
void fib_deinit(fib_entry_t table[])
{
DEBUG("[fib_deinit] hello. De-Initializing stuff.\n");
mutex_lock(&mtx_access);
@ -558,13 +549,13 @@ void fib_deinit(void)
notify_rp_pos = 0;
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
fib_table[i].iface_id = 0;
fib_table[i].lifetime.seconds = 0;
fib_table[i].lifetime.microseconds = 0;
fib_table[i].global_flags = 0;
fib_table[i].global = NULL;
fib_table[i].next_hop_flags = 0;
fib_table[i].next_hop = NULL;
table[i].iface_id = 0;
table[i].lifetime.seconds = 0;
table[i].lifetime.microseconds = 0;
table[i].global_flags = 0;
table[i].global = NULL;
table[i].next_hop_flags = 0;
table[i].next_hop = NULL;
}
universal_address_reset();
@ -596,13 +587,13 @@ int fib_register_rp(uint8_t *prefix, size_t prefix_addr_type_size)
return 0;
}
int fib_get_num_used_entries(void)
int fib_get_num_used_entries(fib_entry_t table[])
{
mutex_lock(&mtx_access);
size_t used_entries = 0;
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
used_entries += (size_t)(fib_table[i].global != NULL);
used_entries += (size_t)(table[i].global != NULL);
}
mutex_unlock(&mtx_access);
@ -622,18 +613,18 @@ void fib_print_notify_rp(void)
mutex_unlock(&mtx_access);
}
void fib_print_fib_table(void)
void fib_print_fib_table(fib_entry_t table[])
{
mutex_lock(&mtx_access);
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
printf("[fib_print_fib_table] %d) iface_id: %d, global: %p, next hop: %p, lifetime: %d.%d\n", \
printf("[fib_print_table] %d) iface_id: %d, global: %p, next hop: %p, lifetime: %d.%d\n", \
(int)i, \
(int)fib_table[i].iface_id, \
(void *)fib_table[i].global, \
(void *)fib_table[i].next_hop, \
(int)fib_table[i].lifetime.seconds, \
(int)fib_table[i].lifetime.microseconds);
(int)table[i].iface_id, \
(void *)table[i].global, \
(void *)table[i].next_hop, \
(int)table[i].lifetime.seconds, \
(int)table[i].lifetime.microseconds);
}
mutex_unlock(&mtx_access);
@ -670,7 +661,7 @@ static void fib_print_address(universal_address_container_t *entry)
}
}
void fib_print_routes(void)
void fib_print_routes(fib_entry_t table[])
{
mutex_lock(&mtx_access);
printf("%-" FIB_ADDR_PRINT_LENS "s %-6s %-" FIB_ADDR_PRINT_LENS "s %-6s %-16s Interface\n"
@ -680,16 +671,16 @@ void fib_print_routes(void)
vtimer_now(&now);
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
if (fib_table[i].lifetime.seconds != 0 || fib_table[i].lifetime.microseconds != 0) {
fib_print_address(fib_table[i].global);
printf(" 0x%04"PRIx32" ", fib_table[i].global_flags);
fib_print_address(fib_table[i].next_hop);
printf(" 0x%04"PRIx32" ", fib_table[i].next_hop_flags);
if (table[i].lifetime.seconds != 0 || table[i].lifetime.microseconds != 0) {
fib_print_address(table[i].global);
printf(" 0x%04"PRIx32" ", table[i].global_flags);
fib_print_address(table[i].next_hop);
printf(" 0x%04"PRIx32" ", table[i].next_hop_flags);
if ((fib_table[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE)
|| (fib_table[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) {
if ((table[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE)
|| (table[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) {
timex_t tm = timex_sub(fib_table[i].lifetime, now);
timex_t tm = timex_sub(table[i].lifetime, now);
/* we must interpret the values as signed */
if ((int32_t)tm.seconds < 0
@ -704,7 +695,7 @@ void fib_print_routes(void)
printf("%-16s ", "NEVER");
}
printf("%d\n", (int)fib_table[i].iface_id);
printf("%d\n", (int)table[i].iface_id);
}
}
@ -712,12 +703,12 @@ void fib_print_routes(void)
}
#if FIB_DEVEL_HELPER
int fib_devel_get_lifetime(timex_t *lifetime, uint8_t *dst, size_t dst_size)
int fib_devel_get_lifetime(fib_entry_t table[], timex_t *lifetime, uint8_t *dst, size_t dst_size)
{
size_t count = 1;
fib_entry_t *entry[count];
int ret = fib_find_entry(dst, dst_size, &(entry[0]), &count);
int ret = fib_find_entry(table, dst, dst_size, &(entry[0]), &count);
if (ret == 1 ) {
/* only return lifetime of exact matches */
*lifetime = entry[0]->lifetime;

View File

@ -28,6 +28,7 @@
#include "net/gnrc/netif.h"
#endif
#include "net/fib.h"
#include "net/gnrc/ipv6.h"
#define INFO1_TXT "fibroute add <destination> via <next hop> [dev <device>]"
#define INFO2_TXT " [lifetime <lifetime>]"
@ -103,14 +104,14 @@ static void _fib_add(const char *dest, const char *next, kernel_pid_t pid, uint3
nxt_flags = AF_INET;
}
fib_add_entry(pid, dst, dst_size, dst_flags, nxt, nxt_size, nxt_flags, lifetime);
fib_add_entry(gnrc_ipv6_fib_table, pid, dst, dst_size, dst_flags, nxt, nxt_size, nxt_flags, lifetime);
}
int _fib_route_handler(int argc, char **argv)
{
/* e.g. fibroute right now dont care about the adress/protocol family */
if (argc == 1) {
fib_print_routes();
fib_print_routes(gnrc_ipv6_fib_table);
return 0;
}
@ -137,13 +138,13 @@ int _fib_route_handler(int argc, char **argv)
/* e.g. fibroute del <destination> */
if (argc == 3) {
if (inet_pton(AF_INET6, argv[2], tmp_ipv6_dst)) {
fib_remove_entry(tmp_ipv6_dst, IN6ADDRSZ);
fib_remove_entry(gnrc_ipv6_fib_table, tmp_ipv6_dst, IN6ADDRSZ);
}
else if (inet_pton(AF_INET, argv[2], tmp_ipv4_dst)) {
fib_remove_entry(tmp_ipv4_dst, INADDRSZ);
fib_remove_entry(gnrc_ipv6_fib_table, tmp_ipv4_dst, INADDRSZ);
}
else {
fib_remove_entry((uint8_t *)argv[2], (strlen(argv[2])));
fib_remove_entry(gnrc_ipv6_fib_table, (uint8_t *)argv[2], (strlen(argv[2])));
}
return 0;

View File

@ -19,6 +19,8 @@
#include "net/fib.h"
#include "universal_address.h"
static fib_entry_t test_fib_table[20];
/*
* @brief helper to fill FIB with unique entries
*/
@ -35,7 +37,7 @@ static void _fill_FIB_unique(size_t entries)
snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i);
snprintf(addr_nxt, add_buf_size, "Test address %02d", entries + i);
/* the terminating \0 is unnecessary here */
fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size - 1, addr_dst_flags,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, addr_dst_flags,
(uint8_t *)addr_nxt, add_buf_size - 1, addr_nxt_flags, 10000);
}
}
@ -56,7 +58,7 @@ static void _fill_FIB_multiple(size_t entries, size_t modulus)
/* construct "addresses" for the FIB */
snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i);
snprintf(addr_nxt, add_buf_size, "Test address %02d", i % modulus);
fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size - 1, addr_dst_flags,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, addr_dst_flags,
(uint8_t *)addr_nxt, add_buf_size - 1, addr_nxt_flags, 10000);
}
}
@ -69,14 +71,14 @@ static void test_fib_01_fill_unique_entries(void)
{
_fill_FIB_unique(20);
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries());
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -89,14 +91,14 @@ static void test_fib_02_fill_multiple_entries(void)
_fill_FIB_multiple(entries, 11);
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -111,26 +113,26 @@ static void test_fib_03_removing_all_entries(void)
size_t entries = 20;
_fill_FIB_unique(entries);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries());
for (size_t i = 0; i < entries; ++i) {
/* construct "addresses" to remove */
snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i);
fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry(test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1);
}
TEST_ASSERT_EQUAL_INT(0, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(0, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(0, universal_address_get_num_used_entries());
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -145,24 +147,24 @@ static void test_fib_04_remove_lower_half(void)
size_t entries = 20;
_fill_FIB_multiple(entries, 11);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
for (size_t i = 0; i < entries / 2; ++i) {
/* construct "addresses" to remove */
snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i);
fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry(test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1);
}
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
TEST_ASSERT_EQUAL_INT(10, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(10, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(19, universal_address_get_num_used_entries());
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -177,24 +179,24 @@ static void test_fib_05_remove_upper_half(void)
size_t entries = 20;
_fill_FIB_multiple(entries, 11);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
for (size_t i = 0; i < entries / 2; ++i) {
/* construct "addresses" to remove */
snprintf(addr_dst, add_buf_size, "Test address %02d", ((entries / 2) + i));
fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry(test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1);
}
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
TEST_ASSERT_EQUAL_INT(10, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(10, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(10, universal_address_get_num_used_entries());
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -211,20 +213,20 @@ static void test_fib_06_remove_one_entry(void)
size_t entries = 20;
_fill_FIB_multiple(entries, 11);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry(test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1);
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
TEST_ASSERT_EQUAL_INT(19, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(19, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -240,23 +242,23 @@ static void test_fib_07_remove_one_entry_multiple_times(void)
size_t entries = 20;
_fill_FIB_multiple(entries, 11);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry(test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry(test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry(test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry(test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1);
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
TEST_ASSERT_EQUAL_INT(19, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(19, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(19, universal_address_get_num_used_entries());
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -271,22 +273,22 @@ static void test_fib_08_remove_unknown(void)
size_t entries = 20;
_fill_FIB_multiple(entries, 11);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry(test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry(test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1);
fib_remove_entry(test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1);
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -305,21 +307,21 @@ static void test_fib_09_update_entry(void)
size_t entries = 20;
_fill_FIB_multiple(entries, 11);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
fib_update_entry((uint8_t *)addr_dst13, add_buf_size - 1,
fib_update_entry(test_fib_table, (uint8_t *)addr_dst13, add_buf_size - 1,
(uint8_t *)addr_nxt2, add_buf_size - 1, 0x99, 9999);
fib_update_entry((uint8_t *)addr_dst07, add_buf_size - 1,
fib_update_entry(test_fib_table, (uint8_t *)addr_dst07, add_buf_size - 1,
(uint8_t *)addr_nxt77, add_buf_size - 1, 0x77, 7777);
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -335,23 +337,23 @@ static void test_fib_10_add_exceed(void)
size_t entries = 20;
_fill_FIB_unique(entries);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries());
int ret = fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size - 1, 0x98,
int ret = fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x98,
(uint8_t *)addr_nxt, add_buf_size - 1, 0x99, 9999);
TEST_ASSERT_EQUAL_INT(-ENOMEM, ret);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries());
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -370,26 +372,26 @@ static void test_fib_11_get_next_hop_success(void)
size_t entries = 20;
_fill_FIB_multiple(entries, 11);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
int ret = fib_get_next_hop(&iface_id,
int ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt, &add_buf_size, &next_hop_flags,
(uint8_t *)addr_dst, add_buf_size - 1, 0x13);
TEST_ASSERT_EQUAL_INT(0, ret);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
ret = strncmp(addr_expect, addr_nxt, add_buf_size);
TEST_ASSERT_EQUAL_INT(0, ret);
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -406,21 +408,21 @@ static void test_fib_12_get_next_hop_fail(void)
size_t entries = 20;
_fill_FIB_multiple(entries, 11);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
int ret = fib_get_next_hop(&iface_id,
int ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt, &add_buf_size, &next_hop_flags,
(uint8_t *)addr_dst, add_buf_size - 1, 0x99);
TEST_ASSERT_EQUAL_INT(-EHOSTUNREACH, ret);
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -438,10 +440,10 @@ static void test_fib_13_get_next_hop_fail_on_buffer_size(void)
size_t entries = 20;
_fill_FIB_multiple(entries, 11);
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries());
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
int ret = fib_get_next_hop(&iface_id,
int ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt, &add_buf_size_nxt, &next_hop_flags,
(uint8_t *)addr_dst, add_buf_size - 1, 0x13);
@ -449,12 +451,12 @@ static void test_fib_13_get_next_hop_fail_on_buffer_size(void)
TEST_ASSERT_EQUAL_INT(add_buf_size_nxt, add_buf_size - 1);
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -475,23 +477,23 @@ static void test_fib_14_exact_and_prefix_match(void)
snprintf(addr_dst, add_buf_size, "Test addr12");
snprintf(addr_nxt, add_buf_size, "Test address %02d", 12);
fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size - 1, 0x12,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x12,
(uint8_t *)addr_nxt, add_buf_size - 1, 0x12, 100000);
snprintf(addr_dst, add_buf_size, "Test addr123");
snprintf(addr_nxt, add_buf_size, "Test address %02d", 23);
fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size - 1, 0x123,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x123,
(uint8_t *)addr_nxt, add_buf_size - 1, 0x23, 100000);
snprintf(addr_dst, add_buf_size, "Test addr1234");
snprintf(addr_nxt, add_buf_size, "Test address %02d", 34);
fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size - 1, 0x1234,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x1234,
(uint8_t *)addr_nxt, add_buf_size - 1, 0x34, 100000);
memset(addr_lookup, 0, add_buf_size);
/* exact match */
snprintf(addr_lookup, add_buf_size, "Test addr123");
int ret = fib_get_next_hop(&iface_id,
int ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt, &add_buf_size, &next_hop_flags,
(uint8_t *)addr_lookup, add_buf_size - 1, 0x123);
@ -512,7 +514,7 @@ static void test_fib_14_exact_and_prefix_match(void)
*/
/* cppcheck-suppress redundantCopy */
snprintf(addr_lookup, add_buf_size, "Test addr124");
ret = fib_get_next_hop(&iface_id,
ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt, &add_buf_size, &next_hop_flags,
(uint8_t *)addr_lookup, add_buf_size - 1, 0x124);
@ -524,12 +526,12 @@ static void test_fib_14_exact_and_prefix_match(void)
TEST_ASSERT_EQUAL_INT(0, ret);
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
fib_deinit();
fib_deinit(test_fib_table);
}
static void test_fib_15_get_lifetime(void)
@ -542,11 +544,11 @@ static void test_fib_15_get_lifetime(void)
uint32_t addr_dst_flags = 0x77777777;
uint32_t addr_nxt_flags = 0x77777777;
TEST_ASSERT_EQUAL_INT(0, fib_add_entry(iface_id, (uint8_t *)addr_dst, add_buf_size - 1,
TEST_ASSERT_EQUAL_INT(0, fib_add_entry(test_fib_table, iface_id, (uint8_t *)addr_dst, add_buf_size - 1,
addr_dst_flags, (uint8_t *)addr_nxt, add_buf_size - 1,
addr_nxt_flags, 1000));
TEST_ASSERT_EQUAL_INT(0, fib_devel_get_lifetime(&lifetime, (uint8_t *)addr_dst, add_buf_size - 1));
TEST_ASSERT_EQUAL_INT(0, fib_devel_get_lifetime(test_fib_table, &lifetime, (uint8_t *)addr_dst, add_buf_size - 1));
/* assuming some ms passed during these operations... */
vtimer_now(&now);
@ -556,7 +558,7 @@ static void test_fib_15_get_lifetime(void)
/* make sure lifetime hasn't grown magically either */
TEST_ASSERT_EQUAL_INT(-1, timex_cmp(lifetime, cmp_max_lifetime));
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -584,16 +586,16 @@ static void test_fib_16_prefix_match(void)
addr_dst[14] = (char)0x80; /* 1000 0000 */
addr_lookup[14] = (char)0x87; /* 1000 0111 */
fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size - 1, 0x123,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x123,
(uint8_t *)addr_nxt, add_buf_size - 1, 0x23, 100000);
addr_dst[14] = (char)0x3c; /* 0011 1100 */
fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size - 1, 0x123,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x123,
(uint8_t *)addr_nxt, add_buf_size - 1, 0x23, 100000);
memset(addr_nxt, 0, add_buf_size);
int ret = fib_get_next_hop(&iface_id,
int ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt, &add_buf_size, &next_hop_flags,
(uint8_t *)addr_lookup, add_buf_size - 1, 0x123);
@ -604,12 +606,12 @@ static void test_fib_16_prefix_match(void)
addr_lookup[14] = (char)0x34; /* 0011 0100 */
add_buf_size = 16;
fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size - 1, 0x123,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x123,
(uint8_t *)addr_nxt, add_buf_size - 1, 0x23, 100000);
memset(addr_nxt, 0, add_buf_size);
ret = fib_get_next_hop(&iface_id,
ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt, &add_buf_size, &next_hop_flags,
(uint8_t *)addr_lookup, add_buf_size - 1, 0x123);
@ -621,19 +623,19 @@ static void test_fib_16_prefix_match(void)
memset(addr_nxt, 0, add_buf_size);
ret = fib_get_next_hop(&iface_id,
ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt, &add_buf_size, &next_hop_flags,
(uint8_t *)addr_lookup, add_buf_size - 1, 0x123);
TEST_ASSERT_EQUAL_INT(0, ret);
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
fib_deinit();
fib_deinit(test_fib_table);
}
@ -651,7 +653,7 @@ static void test_fib_17_get_entry_set(void)
/* construct "addresses" for the FIB */
snprintf(addr_dst, addr_buf_size, "Test address %02d", (int)i);
snprintf(addr_nxt, addr_buf_size, "Test address %02d", i % 11);
fib_add_entry(42, (uint8_t *)addr_dst, addr_buf_size - 1, 0x0,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, addr_buf_size - 1, 0x0,
(uint8_t *)addr_nxt, addr_buf_size - 1, 0x0, 100000);
}
@ -661,7 +663,7 @@ static void test_fib_17_get_entry_set(void)
memset(prefix,0, addr_buf_size);
snprintf(prefix, addr_buf_size, "Test address 1");
int ret = fib_get_destination_set((uint8_t *)prefix, addr_buf_size-1, &arr_dst[0], &arr_size);
int ret = fib_get_destination_set(test_fib_table, (uint8_t *)prefix, addr_buf_size-1, &arr_dst[0], &arr_size);
TEST_ASSERT_EQUAL_INT(0, ret);
/* we should receive 10 entries 10 to 19 */
@ -671,7 +673,7 @@ static void test_fib_17_get_entry_set(void)
memset(prefix,0, addr_buf_size);
snprintf(prefix, addr_buf_size, "Test address 0");
ret = fib_get_destination_set((uint8_t *)prefix, addr_buf_size-1, &arr_dst[0], &arr_size);
ret = fib_get_destination_set(test_fib_table, (uint8_t *)prefix, addr_buf_size-1, &arr_dst[0], &arr_size);
TEST_ASSERT_EQUAL_INT(0, ret);
/* we should receive 20 entries 0-19 */
@ -681,7 +683,7 @@ static void test_fib_17_get_entry_set(void)
memset(prefix,0, addr_buf_size);
snprintf(prefix, addr_buf_size, "Test address");
ret = fib_get_destination_set((uint8_t *)prefix, addr_buf_size-1, &arr_dst[0], &arr_size);
ret = fib_get_destination_set(test_fib_table, (uint8_t *)prefix, addr_buf_size-1, &arr_dst[0], &arr_size);
TEST_ASSERT_EQUAL_INT(0, ret);
/* we should receive 20 entries 0-19 */
@ -697,7 +699,7 @@ static void test_fib_17_get_entry_set(void)
}
#endif
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -716,12 +718,12 @@ static void test_fib_18_get_next_hop_invalid_parameters(void)
size_t entries = 20;
_fill_FIB_multiple(entries, 11);
int ret = fib_get_next_hop(NULL, NULL, NULL, NULL,NULL,
int ret = fib_get_next_hop(test_fib_table, NULL, NULL, NULL, NULL,NULL,
add_buf_size - 1, 0x13);
TEST_ASSERT_EQUAL_INT(-EINVAL, ret);
ret = fib_get_next_hop(&iface_id,
ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt, &add_buf_size, &next_hop_flags,
(uint8_t *)addr_dst, add_buf_size - 1, 0x13);
@ -731,12 +733,12 @@ static void test_fib_18_get_next_hop_invalid_parameters(void)
TEST_ASSERT_EQUAL_INT(0, ret);
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -765,11 +767,11 @@ static void test_fib_19_default_gateway(void)
}
/* add a default gateway entry */
fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size, 0x123,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size, 0x123,
(uint8_t *)addr_nxt, add_buf_size, 0x23, 100000);
/* check if it matches all */
int ret = fib_get_next_hop(&iface_id,
int ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt_hop, &add_buf_size, &next_hop_flags,
(uint8_t *)addr_lookup, add_buf_size, 0x123);
@ -784,11 +786,11 @@ static void test_fib_19_default_gateway(void)
}
/* change the default gateway entry */
fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size, 0x123,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size, 0x123,
(uint8_t *)addr_nxt, add_buf_size, 0x24, 100000);
/* and check again if it matches all */
ret = fib_get_next_hop(&iface_id,
ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt_hop, &add_buf_size, &next_hop_flags,
(uint8_t *)addr_lookup, add_buf_size, 0x123);
@ -796,12 +798,12 @@ static void test_fib_19_default_gateway(void)
TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size));
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
fib_deinit();
fib_deinit(test_fib_table);
}
/*
@ -838,18 +840,18 @@ static void test_fib_20_replace_prefix(void)
}
/* add a prefix entry */
fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size, 0x123,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size, 0x123,
(uint8_t *)addr_nxt, add_buf_size, 0x23, 100000);
/* check if it matches */
int ret = fib_get_next_hop(&iface_id,
int ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt_hop, &add_buf_size, &next_hop_flags,
(uint8_t *)addr_lookup, add_buf_size, 0x123);
TEST_ASSERT_EQUAL_INT(0, ret);
TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size));
fib_remove_entry((uint8_t *)addr_dst, add_buf_size);
fib_remove_entry(test_fib_table, (uint8_t *)addr_dst, add_buf_size);
memset(addr_nxt_hop, 0, add_buf_size);
@ -864,11 +866,11 @@ static void test_fib_20_replace_prefix(void)
}
/* change the prefix entry */
fib_add_entry(42, (uint8_t *)addr_dst, add_buf_size, 0x123,
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size, 0x123,
(uint8_t *)addr_nxt, add_buf_size, 0x24, 100000);
/* and check again if it matches */
ret = fib_get_next_hop(&iface_id,
ret = fib_get_next_hop(test_fib_table, &iface_id,
(uint8_t *)addr_nxt_hop, &add_buf_size, &next_hop_flags,
(uint8_t *)addr_lookup, add_buf_size, 0x123);
@ -876,17 +878,17 @@ static void test_fib_20_replace_prefix(void)
TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size));
#if (TEST_FIB_SHOW_OUTPUT == 1)
fib_print_fib_table();
fib_print_fib_table(test_fib_table);
puts("");
universal_address_print_table();
puts("");
#endif
fib_deinit();
fib_deinit(test_fib_table);
}
Test *tests_fib_tests(void)
{
fib_init();
fib_init(test_fib_table);
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_fib_01_fill_unique_entries),
new_TestFixture(test_fib_02_fill_multiple_entries),