mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
fib: add data struct for meta information
In order to properly make use of different FIB tables, handling of different sizes is required. The fib_table_t provides a pointer to the array of entries and its size.
This commit is contained in:
parent
882080460a
commit
86cabbd102
@ -17,6 +17,7 @@
|
|||||||
* @brief Types and functions for FIB
|
* @brief Types and functions for FIB
|
||||||
*
|
*
|
||||||
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de>
|
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de>
|
||||||
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef FIB_H_
|
#ifndef FIB_H_
|
||||||
@ -30,15 +31,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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
|
* @brief Routing Protocol (RP) message content to request/reply notification
|
||||||
*/
|
*/
|
||||||
@ -72,16 +64,18 @@ typedef struct fib_destination_set_entry_t {
|
|||||||
/**
|
/**
|
||||||
* @brief initializes all FIB entries with 0
|
* @brief initializes all FIB entries with 0
|
||||||
*
|
*
|
||||||
* @param[in] table the fib instance to initialize
|
* @param[in] table the fib instance to initialize
|
||||||
|
*
|
||||||
|
* @pre @p table is not NULL and points to a pre-filled struct
|
||||||
*/
|
*/
|
||||||
void fib_init(fib_entry_t table[]);
|
void fib_init(fib_table_t *table);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief de-initializes the FIB entries
|
* @brief de-initializes the FIB entries
|
||||||
*
|
*
|
||||||
* @param[in] table the fib instance to de-initialize
|
* @param[in] table the fib instance to de-initialize
|
||||||
*/
|
*/
|
||||||
void fib_deinit(fib_entry_t table[]);
|
void fib_deinit(fib_table_t *table);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Registration of a routing protocol handler function
|
* @brief Registration of a routing protocol handler function
|
||||||
@ -113,7 +107,7 @@ int fib_register_rp(uint8_t *prefix, size_t prefix_addr_type_size);
|
|||||||
* -ENOMEM if the entry cannot be created due to insufficient RAM
|
* -ENOMEM if the entry cannot be created due to insufficient RAM
|
||||||
* -EFAULT if dst and/or next_hop is not a valid pointer
|
* -EFAULT if dst and/or next_hop is not a valid pointer
|
||||||
*/
|
*/
|
||||||
int fib_add_entry(fib_entry_t table[], kernel_pid_t iface_id, uint8_t *dst,
|
int fib_add_entry(fib_table_t *table, kernel_pid_t iface_id, uint8_t *dst,
|
||||||
size_t dst_size, uint32_t dst_flags, uint8_t *next_hop,
|
size_t dst_size, uint32_t dst_flags, uint8_t *next_hop,
|
||||||
size_t next_hop_size, uint32_t next_hop_flags,
|
size_t next_hop_size, uint32_t next_hop_flags,
|
||||||
uint32_t lifetime);
|
uint32_t lifetime);
|
||||||
@ -133,18 +127,18 @@ int fib_add_entry(fib_entry_t table[], kernel_pid_t iface_id, uint8_t *dst,
|
|||||||
* -ENOMEM if the entry cannot be updated due to insufficient RAM
|
* -ENOMEM if the entry cannot be updated due to insufficient RAM
|
||||||
* -EFAULT if dst and/or next_hop is not a valid pointer
|
* -EFAULT if dst and/or next_hop is not a valid pointer
|
||||||
*/
|
*/
|
||||||
int fib_update_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size,
|
int fib_update_entry(fib_table_t *table, uint8_t *dst, size_t dst_size,
|
||||||
uint8_t *next_hop, size_t next_hop_size, uint32_t next_hop_flags,
|
uint8_t *next_hop, size_t next_hop_size,
|
||||||
uint32_t lifetime);
|
uint32_t next_hop_flags, uint32_t lifetime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief removes an entry from the corresponding FIB table
|
* @brief removes an entry from the corresponding FIB table
|
||||||
*
|
*
|
||||||
* @param[in] table the fib table containing the entry to remove
|
* @param[in] table the fib table containing the entry to remove
|
||||||
* @param[in] dst the destination address
|
* @param[in] dst the destination address
|
||||||
* @param[in] dst_size the destination address size
|
* @param[in] dst_size the destination address size
|
||||||
*/
|
*/
|
||||||
void fib_remove_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size);
|
void fib_remove_entry(fib_table_t *table, uint8_t *dst, size_t dst_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief provides a next hop for a given destination
|
* @brief provides a next hop for a given destination
|
||||||
@ -166,9 +160,10 @@ void fib_remove_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size);
|
|||||||
* -EFAULT if dst and/or next_hop is not a valid pointer
|
* -EFAULT if dst and/or next_hop is not a valid pointer
|
||||||
* -EINVAL if one of the other passed out pointers is NULL
|
* -EINVAL if one of the other passed out pointers is NULL
|
||||||
*/
|
*/
|
||||||
int fib_get_next_hop(fib_entry_t table[], kernel_pid_t *iface_id,
|
int fib_get_next_hop(fib_table_t *table, kernel_pid_t *iface_id,
|
||||||
uint8_t *next_hop, size_t *next_hop_size, uint32_t* next_hop_flags,
|
uint8_t *next_hop, size_t *next_hop_size,
|
||||||
uint8_t *dst, size_t dst_size, uint32_t dst_flags);
|
uint32_t* next_hop_flags, uint8_t *dst, size_t dst_size,
|
||||||
|
uint32_t dst_flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief provides a set of destination addresses matching the given prefix
|
* @brief provides a set of destination addresses matching the given prefix
|
||||||
@ -189,16 +184,17 @@ int fib_get_next_hop(fib_entry_t table[], kernel_pid_t *iface_id,
|
|||||||
* The actual needed size is stored then in dst_set_size,
|
* The actual needed size is stored then in dst_set_size,
|
||||||
* however the required size may change in between calls.
|
* however the required size may change in between calls.
|
||||||
*/
|
*/
|
||||||
int fib_get_destination_set(fib_entry_t table[], uint8_t *prefix, size_t prefix_size,
|
int fib_get_destination_set(fib_table_t *table, uint8_t *prefix,
|
||||||
fib_destination_set_entry_t *dst_set, size_t* dst_set_size);
|
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
|
* @brief returns the actual number of used FIB entries
|
||||||
*
|
*
|
||||||
* @param[in] table the fib instance to check
|
* @param[in] table the fib instance to check
|
||||||
*/
|
*/
|
||||||
int fib_get_num_used_entries(fib_entry_t table[]);
|
int fib_get_num_used_entries(fib_table_t *table);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints the kernel_pid_t for all registered RRPs
|
* @brief Prints the kernel_pid_t for all registered RRPs
|
||||||
@ -208,22 +204,22 @@ void fib_print_notify_rrp(void);
|
|||||||
/**
|
/**
|
||||||
* @brief Prints the FIB content (does not print the entries)
|
* @brief Prints the FIB content (does not print the entries)
|
||||||
*
|
*
|
||||||
* @param[in] table the fib instance to print
|
* @param[in] table the fib instance to print
|
||||||
*/
|
*/
|
||||||
void fib_print_fib_table(fib_entry_t table[]);
|
void fib_print_fib_table(fib_table_t *table);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints the FIB content
|
* @brief Prints the FIB content
|
||||||
*
|
*
|
||||||
* @param[in] table the fib instance to print
|
* @param[in] table the fib instance to print
|
||||||
*/
|
*/
|
||||||
void fib_print_routes(fib_entry_t table[]);
|
void fib_print_routes(fib_table_t *table);
|
||||||
|
|
||||||
#if FIB_DEVEL_HELPER
|
#if FIB_DEVEL_HELPER
|
||||||
/**
|
/**
|
||||||
* @brief get the point in time at which the entry for destination dst expires.
|
* @brief get the point in time at which the entry for destination dst expires.
|
||||||
*
|
*
|
||||||
* @param[in] table the fib instance to check
|
* @param[in] table the fib instance to check
|
||||||
* @param[out] lifetime pointer where the expiration time is written on success
|
* @param[out] lifetime pointer where the expiration time is written on success
|
||||||
* @param[in] dst the destination address
|
* @param[in] dst the destination address
|
||||||
* @param[in] dst_size the destination address size
|
* @param[in] dst_size the destination address size
|
||||||
@ -231,7 +227,9 @@ void fib_print_routes(fib_entry_t table[]);
|
|||||||
* @return 0 on success: entry for dst found and lifetime copied
|
* @return 0 on success: entry for dst found and lifetime copied
|
||||||
* -EHOSTUNREACH if no fitting entry is available
|
* -EHOSTUNREACH if no fitting entry is available
|
||||||
*/
|
*/
|
||||||
int fib_devel_get_lifetime(fib_entry_t table[], timex_t *lifetime, uint8_t *dst, size_t dst_size);
|
int fib_devel_get_lifetime(fib_table_t *table, timex_t *lifetime, uint8_t *dst,
|
||||||
|
size_t dst_size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -28,8 +28,8 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Container descriptor for a FIB entry
|
* @brief Container descriptor for a FIB entry
|
||||||
*/
|
*/
|
||||||
typedef struct fib_entry_t {
|
typedef struct fib_entry_t {
|
||||||
/** interface ID */
|
/** interface ID */
|
||||||
kernel_pid_t iface_id;
|
kernel_pid_t iface_id;
|
||||||
@ -45,6 +45,14 @@ typedef struct fib_entry_t {
|
|||||||
struct universal_address_container_t *next_hop;
|
struct universal_address_container_t *next_hop;
|
||||||
} fib_entry_t;
|
} fib_entry_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Meta information about the FIB table
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
fib_entry_t *entries; /**< array holding the FIB entries */
|
||||||
|
size_t size; /**< number of entries in this table */
|
||||||
|
} fib_table_t;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
* @brief Definitions for IPv6
|
* @brief Definitions for IPv6
|
||||||
*
|
*
|
||||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||||
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -78,12 +79,18 @@ extern "C" {
|
|||||||
extern kernel_pid_t gnrc_ipv6_pid;
|
extern kernel_pid_t gnrc_ipv6_pid;
|
||||||
|
|
||||||
#ifdef MODULE_FIB
|
#ifdef MODULE_FIB
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Maximum number of entries in the IPv6 FIB table.
|
||||||
|
*/
|
||||||
|
#define GNRC_IPV6_FIB_TABLE_SIZE (20)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The forwarding information base (FIB) for the IPv6 stack.
|
* @brief The forwarding information base (FIB) for the IPv6 stack.
|
||||||
*
|
*
|
||||||
* @see @ref net_fib
|
* @see @ref net_fib
|
||||||
*/
|
*/
|
||||||
extern fib_entry_t gnrc_ipv6_fib_table[FIB_MAX_FIB_TABLE_ENTRIES];
|
extern fib_table_t gnrc_ipv6_fib_table;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,10 +45,15 @@ static char _stack[GNRC_IPV6_STACK_SIZE];
|
|||||||
#ifdef MODULE_FIB
|
#ifdef MODULE_FIB
|
||||||
#include "net/fib.h"
|
#include "net/fib.h"
|
||||||
#include "net/fib/table.h"
|
#include "net/fib/table.h"
|
||||||
|
/**
|
||||||
|
* @brief buffer to store the entries in the IPv6 forwarding table
|
||||||
|
*/
|
||||||
|
static fib_entry_t _fib_entries[GNRC_IPV6_FIB_TABLE_SIZE];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief the IPv6 forwarding table
|
* @brief the IPv6 forwarding table
|
||||||
*/
|
*/
|
||||||
fib_entry_t gnrc_ipv6_fib_table[FIB_MAX_FIB_TABLE_ENTRIES];
|
fib_table_t gnrc_ipv6_fib_table;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_DEBUG
|
#if ENABLE_DEBUG
|
||||||
@ -80,7 +85,9 @@ kernel_pid_t gnrc_ipv6_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MODULE_FIB
|
#ifdef MODULE_FIB
|
||||||
fib_init(gnrc_ipv6_fib_table);
|
gnrc_ipv6_fib_table.entries = _fib_entries;
|
||||||
|
gnrc_ipv6_fib_table.size = GNRC_IPV6_FIB_TABLE_SIZE;
|
||||||
|
fib_init(&gnrc_ipv6_fib_table);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return gnrc_ipv6_pid;
|
return gnrc_ipv6_pid;
|
||||||
|
@ -78,8 +78,8 @@ 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 */
|
ipv6_addr_t next_hop_actual; /* FIB copies address into this variable */
|
||||||
|
|
||||||
if ((next_hop_ip == NULL) &&
|
if ((next_hop_ip == NULL) &&
|
||||||
(fib_get_next_hop(gnrc_ipv6_fib_table, &iface, next_hop_actual.u8, &next_hop_size,
|
(fib_get_next_hop(&gnrc_ipv6_fib_table, &iface, next_hop_actual.u8,
|
||||||
&next_hop_flags, (uint8_t *)dst,
|
&next_hop_size, &next_hop_flags, (uint8_t *)dst,
|
||||||
sizeof(ipv6_addr_t), 0) >= 0) &&
|
sizeof(ipv6_addr_t), 0) >= 0) &&
|
||||||
(next_hop_size == sizeof(ipv6_addr_t))) {
|
(next_hop_size == sizeof(ipv6_addr_t))) {
|
||||||
next_hop_ip = &next_hop_actual;
|
next_hop_ip = &next_hop_actual;
|
||||||
|
@ -307,7 +307,7 @@ bool _parse_options(int msg_type, gnrc_rpl_dodag_t *dodag, gnrc_rpl_opt_t *opt,
|
|||||||
first_target = target;
|
first_target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
fib_add_entry(gnrc_ipv6_fib_table, if_id, target->target.u8,
|
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, src->u8,
|
||||||
sizeof(ipv6_addr_t), AF_INET6,
|
sizeof(ipv6_addr_t), AF_INET6,
|
||||||
(dodag->default_lifetime * dodag->lifetime_unit) *
|
(dodag->default_lifetime * dodag->lifetime_unit) *
|
||||||
@ -328,10 +328,12 @@ a preceding RPL TARGET DAO option\n");
|
|||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
fib_update_entry(gnrc_ipv6_fib_table, first_target->target.u8,
|
fib_update_entry(&gnrc_ipv6_fib_table,
|
||||||
|
first_target->target.u8,
|
||||||
sizeof(ipv6_addr_t), src->u8,
|
sizeof(ipv6_addr_t), src->u8,
|
||||||
sizeof(ipv6_addr_t), AF_INET6,
|
sizeof(ipv6_addr_t), AF_INET6,
|
||||||
(transit->path_lifetime * dodag->lifetime_unit * SEC_IN_MS));
|
(transit->path_lifetime *
|
||||||
|
dodag->lifetime_unit * SEC_IN_MS));
|
||||||
first_target = (gnrc_rpl_opt_target_t *) (((uint8_t *) (first_target)) +
|
first_target = (gnrc_rpl_opt_target_t *) (((uint8_t *) (first_target)) +
|
||||||
sizeof(gnrc_rpl_opt_t) + first_target->length);
|
sizeof(gnrc_rpl_opt_t) + first_target->length);
|
||||||
}
|
}
|
||||||
@ -530,7 +532,8 @@ void gnrc_rpl_send_DAO(gnrc_rpl_dodag_t *dodag, ipv6_addr_t *destination, uint8_
|
|||||||
/* find prefix for my address */
|
/* find prefix for my address */
|
||||||
ipv6_addr_t prefix;
|
ipv6_addr_t prefix;
|
||||||
ipv6_addr_init_prefix(&prefix, me, me_netif->prefix_len);
|
ipv6_addr_init_prefix(&prefix, me, me_netif->prefix_len);
|
||||||
fib_get_destination_set(gnrc_ipv6_fib_table, 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) +
|
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);
|
(sizeof(gnrc_rpl_opt_target_t) * (dst_size + 1)) + sizeof(gnrc_rpl_opt_transit_t);
|
||||||
|
@ -264,12 +264,11 @@ 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");
|
DEBUG("RPL: no interface found for the parent addres\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (fib_add_entry(gnrc_ipv6_fib_table, if_id, def.u8,
|
if (fib_add_entry(&gnrc_ipv6_fib_table, if_id, def.u8,
|
||||||
sizeof(ipv6_addr_t), AF_INET6,
|
sizeof(ipv6_addr_t), AF_INET6,
|
||||||
dodag->parents->addr.u8, sizeof(ipv6_addr_t),
|
dodag->parents->addr.u8, sizeof(ipv6_addr_t),
|
||||||
AF_INET6,
|
AF_INET6, (dodag->default_lifetime *
|
||||||
(dodag->default_lifetime * dodag->lifetime_unit) *
|
dodag->lifetime_unit) * SEC_IN_MS) != 0) {
|
||||||
SEC_IN_MS) != 0) {
|
|
||||||
DEBUG("RPL: error adding parent to FIB\n");
|
DEBUG("RPL: error adding parent to FIB\n");
|
||||||
gnrc_rpl_parent_remove(*parent);
|
gnrc_rpl_parent_remove(*parent);
|
||||||
return false;
|
return false;
|
||||||
@ -304,7 +303,7 @@ bool gnrc_rpl_parent_remove(gnrc_rpl_parent_t *parent)
|
|||||||
{
|
{
|
||||||
if (parent == parent->dodag->parents) {
|
if (parent == parent->dodag->parents) {
|
||||||
ipv6_addr_t def = { .u64 = {{0}, {0}} };
|
ipv6_addr_t def = { .u64 = {{0}, {0}} };
|
||||||
fib_remove_entry(gnrc_ipv6_fib_table, 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;
|
gnrc_rpl_dodag_t *dodag = parent->dodag;
|
||||||
LL_DELETE(dodag->parents, parent);
|
LL_DELETE(dodag->parents, parent);
|
||||||
@ -321,7 +320,7 @@ void gnrc_rpl_local_repair(gnrc_rpl_dodag_t *dodag)
|
|||||||
if (dodag->parents) {
|
if (dodag->parents) {
|
||||||
gnrc_rpl_dodag_remove_all_parents(dodag);
|
gnrc_rpl_dodag_remove_all_parents(dodag);
|
||||||
ipv6_addr_t def = IPV6_ADDR_UNSPECIFIED;
|
ipv6_addr_t def = IPV6_ADDR_UNSPECIFIED;
|
||||||
fib_remove_entry(gnrc_ipv6_fib_table, 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) {
|
if (dodag->my_rank != GNRC_RPL_INFINITE_RANK) {
|
||||||
@ -349,9 +348,11 @@ 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;
|
ipv6_addr_t all_RPL_nodes = GNRC_RPL_ALL_NODES_ADDR;
|
||||||
kernel_pid_t if_id;
|
kernel_pid_t if_id;
|
||||||
if ((if_id = gnrc_ipv6_netif_find_by_addr(NULL, &all_RPL_nodes)) != KERNEL_PID_UNDEF) {
|
if ((if_id = gnrc_ipv6_netif_find_by_addr(NULL, &all_RPL_nodes)) != KERNEL_PID_UNDEF) {
|
||||||
fib_add_entry(gnrc_ipv6_fib_table, if_id, def.u8, sizeof(ipv6_addr_t), AF_INET6,
|
fib_add_entry(&gnrc_ipv6_fib_table, if_id, def.u8,
|
||||||
dodag->parents->addr.u8, sizeof(ipv6_addr_t), AF_INET6,
|
sizeof(ipv6_addr_t), AF_INET6,
|
||||||
(dodag->default_lifetime * dodag->lifetime_unit) * SEC_IN_MS);
|
dodag->parents->addr.u8, sizeof(ipv6_addr_t),
|
||||||
|
AF_INET6, (dodag->default_lifetime *
|
||||||
|
dodag->lifetime_unit) * SEC_IN_MS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -404,7 +405,7 @@ static gnrc_rpl_parent_t *_gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *doda
|
|||||||
}
|
}
|
||||||
trickle_reset_timer(&dodag->trickle);
|
trickle_reset_timer(&dodag->trickle);
|
||||||
|
|
||||||
fib_remove_entry(gnrc_ipv6_fib_table, 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;
|
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);
|
kernel_pid_t if_id = gnrc_ipv6_netif_find_by_addr(NULL, &all_RPL_nodes);
|
||||||
@ -414,10 +415,10 @@ static gnrc_rpl_parent_t *_gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *doda
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fib_add_entry(gnrc_ipv6_fib_table, if_id, def.u8, sizeof(ipv6_addr_t),
|
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->parents->addr.u8, sizeof(ipv6_addr_t),
|
||||||
AF_INET6,
|
AF_INET6, (dodag->default_lifetime *
|
||||||
(dodag->default_lifetime * dodag->lifetime_unit) * SEC_IN_MS);
|
dodag->lifetime_unit) * SEC_IN_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dodag->parents;
|
return dodag->parents;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
* @brief Functions to manage FIB entries
|
* @brief Functions to manage FIB entries
|
||||||
*
|
*
|
||||||
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de>
|
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de>
|
||||||
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
||||||
*
|
*
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@ -92,6 +93,7 @@ static void fib_ms_to_timex(uint32_t ms, timex_t *timex)
|
|||||||
/**
|
/**
|
||||||
* @brief returns pointer to the entry for the given destination address
|
* @brief returns pointer to the entry for the given destination address
|
||||||
*
|
*
|
||||||
|
* @param[in] table the FIB table to search in
|
||||||
* @param[in] dst the destination address
|
* @param[in] dst the destination address
|
||||||
* @param[in] dst_size the destination address size
|
* @param[in] dst_size the destination address size
|
||||||
* @param[out] entry_arr the array to scribe the found match
|
* @param[out] entry_arr the array to scribe the found match
|
||||||
@ -102,9 +104,8 @@ static void fib_ms_to_timex(uint32_t ms, timex_t *timex)
|
|||||||
* 1 if we found the exact address next-hop
|
* 1 if we found the exact address next-hop
|
||||||
* -EHOSTUNREACH if no fitting next-hop is available
|
* -EHOSTUNREACH if no fitting next-hop is available
|
||||||
*/
|
*/
|
||||||
static int fib_find_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size,
|
static int fib_find_entry(fib_table_t *table, uint8_t *dst, size_t dst_size,
|
||||||
fib_entry_t **entry_arr, size_t *entry_arr_size)
|
fib_entry_t **entry_arr, size_t *entry_arr_size) {
|
||||||
{
|
|
||||||
timex_t now;
|
timex_t now;
|
||||||
vtimer_now(&now);
|
vtimer_now(&now);
|
||||||
|
|
||||||
@ -121,39 +122,39 @@ static int fib_find_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
|
for (size_t i = 0; i < table->size; ++i) {
|
||||||
|
|
||||||
/* autoinvalidate if the entry lifetime is not set to not expire */
|
/* autoinvalidate if the entry lifetime is not set to not expire */
|
||||||
if ((table[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE)
|
if ((table->entries[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE)
|
||||||
|| (table[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) {
|
|| (table->entries[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) {
|
||||||
|
|
||||||
/* check if the lifetime expired */
|
/* check if the lifetime expired */
|
||||||
if (timex_cmp(now, table[i].lifetime) > -1) {
|
if (timex_cmp(now, table->entries[i].lifetime) > -1) {
|
||||||
/* remove this entry if its lifetime expired */
|
/* remove this entry if its lifetime expired */
|
||||||
table[i].lifetime.seconds = 0;
|
table->entries[i].lifetime.seconds = 0;
|
||||||
table[i].lifetime.microseconds = 0;
|
table->entries[i].lifetime.microseconds = 0;
|
||||||
table[i].global_flags = 0;
|
table->entries[i].global_flags = 0;
|
||||||
table[i].next_hop_flags = 0;
|
table->entries[i].next_hop_flags = 0;
|
||||||
table[i].iface_id = KERNEL_PID_UNDEF;
|
table->entries[i].iface_id = KERNEL_PID_UNDEF;
|
||||||
|
|
||||||
if (table[i].global != NULL) {
|
if (table->entries[i].global != NULL) {
|
||||||
universal_address_rem(table[i].global);
|
universal_address_rem(table->entries[i].global);
|
||||||
table[i].global = NULL;
|
table->entries[i].global = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (table[i].next_hop != NULL) {
|
if (table->entries[i].next_hop != NULL) {
|
||||||
universal_address_rem(table[i].next_hop);
|
universal_address_rem(table->entries[i].next_hop);
|
||||||
table[i].next_hop = NULL;
|
table->entries[i].next_hop = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((prefix_size < (dst_size<<3)) && (table[i].global != NULL)) {
|
if ((prefix_size < (dst_size<<3)) && (table->entries[i].global != NULL)) {
|
||||||
|
|
||||||
int ret_comp = universal_address_compare(table[i].global, dst, &match_size);
|
int ret_comp = universal_address_compare(table->entries[i].global, dst, &match_size);
|
||||||
/* If we found an exact match */
|
/* If we found an exact match */
|
||||||
if (ret_comp == 0 || (is_all_zeros_addr && match_size == 0)) {
|
if (ret_comp == 0 || (is_all_zeros_addr && match_size == 0)) {
|
||||||
entry_arr[0] = &(table[i]);
|
entry_arr[0] = &(table->entries[i]);
|
||||||
*entry_arr_size = 1;
|
*entry_arr_size = 1;
|
||||||
/* we will not find a better one so we return */
|
/* we will not find a better one so we return */
|
||||||
return 1;
|
return 1;
|
||||||
@ -161,7 +162,7 @@ static int fib_find_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size,
|
|||||||
else {
|
else {
|
||||||
/* we try to find the most fitting prefix */
|
/* we try to find the most fitting prefix */
|
||||||
if (ret_comp == 1) {
|
if (ret_comp == 1) {
|
||||||
entry_arr[0] = &(table[i]);
|
entry_arr[0] = &(table->entries[i]);
|
||||||
/* we could find a better one so we move on */
|
/* we could find a better one so we move on */
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
@ -189,8 +190,8 @@ static int fib_find_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size,
|
|||||||
* @return 0 if the entry has been updated
|
* @return 0 if the entry has been updated
|
||||||
* -ENOMEM if the entry cannot be updated due to insufficient RAM
|
* -ENOMEM if the entry cannot be updated due to insufficient RAM
|
||||||
*/
|
*/
|
||||||
static int fib_upd_entry(fib_entry_t *entry,
|
static int fib_upd_entry(fib_entry_t *entry, uint8_t *next_hop,
|
||||||
uint8_t *next_hop, size_t next_hop_size, uint32_t next_hop_flags,
|
size_t next_hop_size, uint32_t next_hop_flags,
|
||||||
uint32_t lifetime)
|
uint32_t lifetime)
|
||||||
{
|
{
|
||||||
universal_address_container_t *container = universal_address_add(next_hop, next_hop_size);
|
universal_address_container_t *container = universal_address_add(next_hop, next_hop_size);
|
||||||
@ -217,6 +218,7 @@ static int fib_upd_entry(fib_entry_t *entry,
|
|||||||
/**
|
/**
|
||||||
* @brief creates a new FIB entry with the provided parameters
|
* @brief creates a new FIB entry with the provided parameters
|
||||||
*
|
*
|
||||||
|
* @param[in] table the FIB table to create the entry in
|
||||||
* @param[in] iface_id the interface ID
|
* @param[in] iface_id the interface ID
|
||||||
* @param[in] dst the destination address
|
* @param[in] dst the destination address
|
||||||
* @param[in] dst_size the destination address size
|
* @param[in] dst_size the destination address size
|
||||||
@ -229,32 +231,33 @@ static int fib_upd_entry(fib_entry_t *entry,
|
|||||||
* @return 0 on success
|
* @return 0 on success
|
||||||
* -ENOMEM if no new entry can be created
|
* -ENOMEM if no new entry can be created
|
||||||
*/
|
*/
|
||||||
static int fib_create_entry(fib_entry_t table[], kernel_pid_t iface_id,
|
static int fib_create_entry(fib_table_t *table, kernel_pid_t iface_id,
|
||||||
uint8_t *dst, size_t dst_size, uint32_t dst_flags,
|
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,
|
uint8_t *next_hop, size_t next_hop_size, uint32_t
|
||||||
uint32_t lifetime)
|
next_hop_flags, uint32_t lifetime)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
|
for (size_t i = 0; i < table->size; ++i) {
|
||||||
if (table[i].lifetime.seconds == 0 && table[i].lifetime.microseconds == 0) {
|
if ((table->entries[i].lifetime.seconds == 0) &&
|
||||||
|
(table->entries[i].lifetime.microseconds == 0)) {
|
||||||
|
|
||||||
table[i].global = universal_address_add(dst, dst_size);
|
table->entries[i].global = universal_address_add(dst, dst_size);
|
||||||
|
|
||||||
if (table[i].global != NULL) {
|
if (table->entries[i].global != NULL) {
|
||||||
table[i].global_flags = dst_flags;
|
table->entries[i].global_flags = dst_flags;
|
||||||
table[i].next_hop = universal_address_add(next_hop, next_hop_size);
|
table->entries[i].next_hop = universal_address_add(next_hop, next_hop_size);
|
||||||
table[i].next_hop_flags = next_hop_flags;
|
table->entries[i].next_hop_flags = next_hop_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (table[i].next_hop != NULL) {
|
if (table->entries[i].next_hop != NULL) {
|
||||||
/* everything worked fine */
|
/* everything worked fine */
|
||||||
table[i].iface_id = iface_id;
|
table->entries[i].iface_id = iface_id;
|
||||||
|
|
||||||
if (lifetime < FIB_LIFETIME_NO_EXPIRE) {
|
if (lifetime < FIB_LIFETIME_NO_EXPIRE) {
|
||||||
fib_ms_to_timex(lifetime, &table[i].lifetime);
|
fib_ms_to_timex(lifetime, &table->entries[i].lifetime);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
table[i].lifetime.seconds = FIB_LIFETIME_NO_EXPIRE;
|
table->entries[i].lifetime.seconds = FIB_LIFETIME_NO_EXPIRE;
|
||||||
table[i].lifetime.microseconds = FIB_LIFETIME_NO_EXPIRE;
|
table->entries[i].lifetime.microseconds = FIB_LIFETIME_NO_EXPIRE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -340,10 +343,10 @@ static int fib_signal_rp(uint8_t *dst, size_t dst_size, uint32_t dst_flags)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fib_add_entry(fib_entry_t table[], kernel_pid_t iface_id, uint8_t *dst,
|
int fib_add_entry(fib_table_t *table,
|
||||||
size_t dst_size, uint32_t dst_flags, uint8_t *next_hop,
|
kernel_pid_t iface_id, uint8_t *dst, size_t dst_size,
|
||||||
size_t next_hop_size, uint32_t next_hop_flags,
|
uint32_t dst_flags, uint8_t *next_hop, size_t next_hop_size,
|
||||||
uint32_t lifetime)
|
uint32_t next_hop_flags, uint32_t lifetime)
|
||||||
{
|
{
|
||||||
mutex_lock(&mtx_access);
|
mutex_lock(&mtx_access);
|
||||||
DEBUG("[fib_add_entry]\n");
|
DEBUG("[fib_add_entry]\n");
|
||||||
@ -371,9 +374,9 @@ int fib_add_entry(fib_entry_t table[], kernel_pid_t iface_id, uint8_t *dst,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fib_update_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size,
|
int fib_update_entry(fib_table_t *table, uint8_t *dst, size_t dst_size,
|
||||||
uint8_t *next_hop, size_t next_hop_size, uint32_t next_hop_flags,
|
uint8_t *next_hop, size_t next_hop_size,
|
||||||
uint32_t lifetime)
|
uint32_t next_hop_flags, uint32_t lifetime)
|
||||||
{
|
{
|
||||||
mutex_lock(&mtx_access);
|
mutex_lock(&mtx_access);
|
||||||
DEBUG("[fib_update_entry]\n");
|
DEBUG("[fib_update_entry]\n");
|
||||||
@ -403,7 +406,7 @@ int fib_update_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fib_remove_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size)
|
void fib_remove_entry(fib_table_t *table, uint8_t *dst, size_t dst_size)
|
||||||
{
|
{
|
||||||
mutex_lock(&mtx_access);
|
mutex_lock(&mtx_access);
|
||||||
DEBUG("[fib_remove_entry]\n");
|
DEBUG("[fib_remove_entry]\n");
|
||||||
@ -426,9 +429,10 @@ void fib_remove_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size)
|
|||||||
mutex_unlock(&mtx_access);
|
mutex_unlock(&mtx_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fib_get_next_hop(fib_entry_t table[], kernel_pid_t *iface_id,
|
int fib_get_next_hop(fib_table_t *table, kernel_pid_t *iface_id,
|
||||||
uint8_t *next_hop, size_t *next_hop_size, uint32_t *next_hop_flags,
|
uint8_t *next_hop, size_t *next_hop_size,
|
||||||
uint8_t *dst, size_t dst_size, uint32_t dst_flags)
|
uint32_t *next_hop_flags, uint8_t *dst, size_t dst_size,
|
||||||
|
uint32_t dst_flags)
|
||||||
{
|
{
|
||||||
mutex_lock(&mtx_access);
|
mutex_lock(&mtx_access);
|
||||||
DEBUG("[fib_get_next_hop]\n");
|
DEBUG("[fib_get_next_hop]\n");
|
||||||
@ -478,20 +482,22 @@ int fib_get_next_hop(fib_entry_t table[], kernel_pid_t *iface_id,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fib_get_destination_set(fib_entry_t table[], uint8_t *prefix, size_t prefix_size,
|
int fib_get_destination_set(fib_table_t *table, uint8_t *prefix,
|
||||||
fib_destination_set_entry_t *dst_set, size_t* dst_set_size)
|
size_t prefix_size,
|
||||||
|
fib_destination_set_entry_t *dst_set,
|
||||||
|
size_t* dst_set_size)
|
||||||
{
|
{
|
||||||
mutex_lock(&mtx_access);
|
mutex_lock(&mtx_access);
|
||||||
int ret = -EHOSTUNREACH;
|
int ret = -EHOSTUNREACH;
|
||||||
size_t found_entries = 0;
|
size_t found_entries = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
|
for (size_t i = 0; i < table->size; ++i) {
|
||||||
if ((table[i].global != NULL) &&
|
if ((table->entries[i].global != NULL) &&
|
||||||
(universal_address_compare_prefix(table[i].global, prefix, prefix_size<<3) >= 0)) {
|
(universal_address_compare_prefix(table->entries[i].global, prefix, prefix_size<<3) >= 0)) {
|
||||||
if( (dst_set != NULL) && (found_entries < *dst_set_size) ) {
|
if( (dst_set != NULL) && (found_entries < *dst_set_size) ) {
|
||||||
/* set the size to full byte usage */
|
/* set the size to full byte usage */
|
||||||
dst_set[found_entries].dest_size = sizeof(dst_set[found_entries].dest);
|
dst_set[found_entries].dest_size = sizeof(dst_set[found_entries].dest);
|
||||||
universal_address_get_address(table[i].global,
|
universal_address_get_address(table->entries[i].global,
|
||||||
dst_set[found_entries].dest,
|
dst_set[found_entries].dest,
|
||||||
&dst_set[found_entries].dest_size);
|
&dst_set[found_entries].dest_size);
|
||||||
}
|
}
|
||||||
@ -512,7 +518,7 @@ int fib_get_destination_set(fib_entry_t table[], uint8_t *prefix, size_t prefix_
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fib_init(fib_entry_t table[])
|
void fib_init(fib_table_t *table)
|
||||||
{
|
{
|
||||||
DEBUG("[fib_init] hello. Initializing some stuff.\n");
|
DEBUG("[fib_init] hello. Initializing some stuff.\n");
|
||||||
mutex_lock(&mtx_access);
|
mutex_lock(&mtx_access);
|
||||||
@ -522,21 +528,21 @@ void fib_init(fib_entry_t table[])
|
|||||||
prefix_rp[i] = NULL;
|
prefix_rp[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
|
for (size_t i = 0; i < table->size; ++i) {
|
||||||
table[i].iface_id = 0;
|
table->entries[i].iface_id = 0;
|
||||||
table[i].lifetime.seconds = 0;
|
table->entries[i].lifetime.seconds = 0;
|
||||||
table[i].lifetime.microseconds = 0;
|
table->entries[i].lifetime.microseconds = 0;
|
||||||
table[i].global_flags = 0;
|
table->entries[i].global_flags = 0;
|
||||||
table[i].global = NULL;
|
table->entries[i].global = NULL;
|
||||||
table[i].next_hop_flags = 0;
|
table->entries[i].next_hop_flags = 0;
|
||||||
table[i].next_hop = NULL;
|
table->entries[i].next_hop = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
universal_address_init();
|
universal_address_init();
|
||||||
mutex_unlock(&mtx_access);
|
mutex_unlock(&mtx_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fib_deinit(fib_entry_t table[])
|
void fib_deinit(fib_table_t *table)
|
||||||
{
|
{
|
||||||
DEBUG("[fib_deinit] hello. De-Initializing stuff.\n");
|
DEBUG("[fib_deinit] hello. De-Initializing stuff.\n");
|
||||||
mutex_lock(&mtx_access);
|
mutex_lock(&mtx_access);
|
||||||
@ -548,14 +554,14 @@ void fib_deinit(fib_entry_t table[])
|
|||||||
|
|
||||||
notify_rp_pos = 0;
|
notify_rp_pos = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
|
for (size_t i = 0; i < table->size; ++i) {
|
||||||
table[i].iface_id = 0;
|
table->entries[i].iface_id = 0;
|
||||||
table[i].lifetime.seconds = 0;
|
table->entries[i].lifetime.seconds = 0;
|
||||||
table[i].lifetime.microseconds = 0;
|
table->entries[i].lifetime.microseconds = 0;
|
||||||
table[i].global_flags = 0;
|
table->entries[i].global_flags = 0;
|
||||||
table[i].global = NULL;
|
table->entries[i].global = NULL;
|
||||||
table[i].next_hop_flags = 0;
|
table->entries[i].next_hop_flags = 0;
|
||||||
table[i].next_hop = NULL;
|
table->entries[i].next_hop = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
universal_address_reset();
|
universal_address_reset();
|
||||||
@ -587,13 +593,13 @@ int fib_register_rp(uint8_t *prefix, size_t prefix_addr_type_size)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fib_get_num_used_entries(fib_entry_t table[])
|
int fib_get_num_used_entries(fib_table_t *table)
|
||||||
{
|
{
|
||||||
mutex_lock(&mtx_access);
|
mutex_lock(&mtx_access);
|
||||||
size_t used_entries = 0;
|
size_t used_entries = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
|
for (size_t i = 0; i < table->size; ++i) {
|
||||||
used_entries += (size_t)(table[i].global != NULL);
|
used_entries += (size_t)(table->entries[i].global != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&mtx_access);
|
mutex_unlock(&mtx_access);
|
||||||
@ -613,18 +619,17 @@ void fib_print_notify_rp(void)
|
|||||||
mutex_unlock(&mtx_access);
|
mutex_unlock(&mtx_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fib_print_fib_table(fib_entry_t table[])
|
void fib_print_fib_table(fib_table_t *table)
|
||||||
{
|
{
|
||||||
mutex_lock(&mtx_access);
|
mutex_lock(&mtx_access);
|
||||||
|
|
||||||
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
|
for (size_t i = 0; i < table->size; ++i) {
|
||||||
printf("[fib_print_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)i, (int)table->entries[i].iface_id,
|
||||||
(int)table[i].iface_id, \
|
(void *)table->entries[i].global,
|
||||||
(void *)table[i].global, \
|
(void *)table->entries[i].next_hop,
|
||||||
(void *)table[i].next_hop, \
|
(int)table->entries[i].lifetime.seconds,
|
||||||
(int)table[i].lifetime.seconds, \
|
(int)table->entries[i].lifetime.microseconds);
|
||||||
(int)table[i].lifetime.microseconds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&mtx_access);
|
mutex_unlock(&mtx_access);
|
||||||
@ -661,7 +666,7 @@ static void fib_print_address(universal_address_container_t *entry)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fib_print_routes(fib_entry_t table[])
|
void fib_print_routes(fib_table_t *table)
|
||||||
{
|
{
|
||||||
mutex_lock(&mtx_access);
|
mutex_lock(&mtx_access);
|
||||||
printf("%-" FIB_ADDR_PRINT_LENS "s %-6s %-" FIB_ADDR_PRINT_LENS "s %-6s %-16s Interface\n"
|
printf("%-" FIB_ADDR_PRINT_LENS "s %-6s %-" FIB_ADDR_PRINT_LENS "s %-6s %-16s Interface\n"
|
||||||
@ -670,17 +675,17 @@ void fib_print_routes(fib_entry_t table[])
|
|||||||
timex_t now;
|
timex_t now;
|
||||||
vtimer_now(&now);
|
vtimer_now(&now);
|
||||||
|
|
||||||
for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
|
for (size_t i = 0; i < table->size; ++i) {
|
||||||
if (table[i].lifetime.seconds != 0 || table[i].lifetime.microseconds != 0) {
|
if (table->entries[i].lifetime.seconds != 0 || table->entries[i].lifetime.microseconds != 0) {
|
||||||
fib_print_address(table[i].global);
|
fib_print_address(table->entries[i].global);
|
||||||
printf(" 0x%04"PRIx32" ", table[i].global_flags);
|
printf(" 0x%04"PRIx32" ", table->entries[i].global_flags);
|
||||||
fib_print_address(table[i].next_hop);
|
fib_print_address(table->entries[i].next_hop);
|
||||||
printf(" 0x%04"PRIx32" ", table[i].next_hop_flags);
|
printf(" 0x%04"PRIx32" ", table->entries[i].next_hop_flags);
|
||||||
|
|
||||||
if ((table[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE)
|
if ((table->entries[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE)
|
||||||
|| (table[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) {
|
|| (table->entries[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) {
|
||||||
|
|
||||||
timex_t tm = timex_sub(table[i].lifetime, now);
|
timex_t tm = timex_sub(table->entries[i].lifetime, now);
|
||||||
|
|
||||||
/* we must interpret the values as signed */
|
/* we must interpret the values as signed */
|
||||||
if ((int32_t)tm.seconds < 0
|
if ((int32_t)tm.seconds < 0
|
||||||
@ -695,7 +700,7 @@ void fib_print_routes(fib_entry_t table[])
|
|||||||
printf("%-16s ", "NEVER");
|
printf("%-16s ", "NEVER");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%d\n", (int)table[i].iface_id);
|
printf("%d\n", (int)table->entries[i].iface_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -703,7 +708,8 @@ void fib_print_routes(fib_entry_t table[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if FIB_DEVEL_HELPER
|
#if FIB_DEVEL_HELPER
|
||||||
int fib_devel_get_lifetime(fib_entry_t table[], timex_t *lifetime, uint8_t *dst, size_t dst_size)
|
int fib_devel_get_lifetime(fib_table_t *table, timex_t *lifetime, uint8_t *dst,
|
||||||
|
size_t dst_size)
|
||||||
{
|
{
|
||||||
size_t count = 1;
|
size_t count = 1;
|
||||||
fib_entry_t *entry[count];
|
fib_entry_t *entry[count];
|
||||||
|
@ -105,14 +105,15 @@ static void _fib_add(const char *dest, const char *next, kernel_pid_t pid, uint3
|
|||||||
nxt_flags = AF_INET;
|
nxt_flags = AF_INET;
|
||||||
}
|
}
|
||||||
|
|
||||||
fib_add_entry(gnrc_ipv6_fib_table, 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)
|
int _fib_route_handler(int argc, char **argv)
|
||||||
{
|
{
|
||||||
/* e.g. fibroute right now dont care about the adress/protocol family */
|
/* e.g. fibroute right now dont care about the adress/protocol family */
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
fib_print_routes(gnrc_ipv6_fib_table);
|
fib_print_routes(&gnrc_ipv6_fib_table);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,13 +140,14 @@ int _fib_route_handler(int argc, char **argv)
|
|||||||
/* e.g. fibroute del <destination> */
|
/* e.g. fibroute del <destination> */
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
if (inet_pton(AF_INET6, argv[2], tmp_ipv6_dst)) {
|
if (inet_pton(AF_INET6, argv[2], tmp_ipv6_dst)) {
|
||||||
fib_remove_entry(gnrc_ipv6_fib_table, 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)) {
|
else if (inet_pton(AF_INET, argv[2], tmp_ipv4_dst)) {
|
||||||
fib_remove_entry(gnrc_ipv6_fib_table, tmp_ipv4_dst, INADDRSZ);
|
fib_remove_entry(&gnrc_ipv6_fib_table, tmp_ipv4_dst, INADDRSZ);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fib_remove_entry(gnrc_ipv6_fib_table, (uint8_t *)argv[2], (strlen(argv[2])));
|
fib_remove_entry(&gnrc_ipv6_fib_table, (uint8_t *)argv[2],
|
||||||
|
(strlen(argv[2])));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
#include "net/fib.h"
|
#include "net/fib.h"
|
||||||
#include "universal_address.h"
|
#include "universal_address.h"
|
||||||
|
|
||||||
static fib_entry_t test_fib_table[20];
|
#define TEST_FIB_TABLE_SIZE (20)
|
||||||
|
static fib_entry_t _entries[TEST_FIB_TABLE_SIZE];
|
||||||
|
static fib_table_t test_fib_table = { _entries, TEST_FIB_TABLE_SIZE };
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief helper to fill FIB with unique entries
|
* @brief helper to fill FIB with unique entries
|
||||||
@ -37,8 +39,10 @@ static void _fill_FIB_unique(size_t entries)
|
|||||||
snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i);
|
snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i);
|
||||||
snprintf(addr_nxt, add_buf_size, "Test address %02d", entries + i);
|
snprintf(addr_nxt, add_buf_size, "Test address %02d", entries + i);
|
||||||
/* the terminating \0 is unnecessary here */
|
/* the terminating \0 is unnecessary here */
|
||||||
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, addr_dst_flags,
|
fib_add_entry(&test_fib_table, 42,
|
||||||
(uint8_t *)addr_nxt, add_buf_size - 1, addr_nxt_flags, 10000);
|
(uint8_t *)addr_dst, add_buf_size - 1, addr_dst_flags,
|
||||||
|
(uint8_t *)addr_nxt, add_buf_size - 1, addr_nxt_flags,
|
||||||
|
10000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,8 +62,10 @@ static void _fill_FIB_multiple(size_t entries, size_t modulus)
|
|||||||
/* construct "addresses" for the FIB */
|
/* construct "addresses" for the FIB */
|
||||||
snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i);
|
snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i);
|
||||||
snprintf(addr_nxt, add_buf_size, "Test address %02d", i % modulus);
|
snprintf(addr_nxt, add_buf_size, "Test address %02d", i % modulus);
|
||||||
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, addr_dst_flags,
|
fib_add_entry(&test_fib_table, 42,
|
||||||
(uint8_t *)addr_nxt, add_buf_size - 1, addr_nxt_flags, 10000);
|
(uint8_t *)addr_dst, add_buf_size - 1, addr_dst_flags,
|
||||||
|
(uint8_t *)addr_nxt, add_buf_size - 1, addr_nxt_flags,
|
||||||
|
10000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,14 +77,14 @@ static void test_fib_01_fill_unique_entries(void)
|
|||||||
{
|
{
|
||||||
_fill_FIB_unique(20);
|
_fill_FIB_unique(20);
|
||||||
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries());
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -91,14 +97,14 @@ static void test_fib_02_fill_multiple_entries(void)
|
|||||||
_fill_FIB_multiple(entries, 11);
|
_fill_FIB_multiple(entries, 11);
|
||||||
|
|
||||||
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -113,26 +119,26 @@ static void test_fib_03_removing_all_entries(void)
|
|||||||
size_t entries = 20;
|
size_t entries = 20;
|
||||||
_fill_FIB_unique(entries);
|
_fill_FIB_unique(entries);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries());
|
||||||
|
|
||||||
for (size_t i = 0; i < entries; ++i) {
|
for (size_t i = 0; i < entries; ++i) {
|
||||||
/* construct "addresses" to remove */
|
/* construct "addresses" to remove */
|
||||||
snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i);
|
snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(0, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(0, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(0, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(0, universal_address_get_num_used_entries());
|
||||||
|
|
||||||
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -147,24 +153,24 @@ static void test_fib_04_remove_lower_half(void)
|
|||||||
size_t entries = 20;
|
size_t entries = 20;
|
||||||
_fill_FIB_multiple(entries, 11);
|
_fill_FIB_multiple(entries, 11);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
|
|
||||||
for (size_t i = 0; i < entries / 2; ++i) {
|
for (size_t i = 0; i < entries / 2; ++i) {
|
||||||
/* construct "addresses" to remove */
|
/* construct "addresses" to remove */
|
||||||
snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i);
|
snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i);
|
||||||
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)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
TEST_ASSERT_EQUAL_INT(10, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(10, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(19, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(19, universal_address_get_num_used_entries());
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -179,24 +185,25 @@ static void test_fib_05_remove_upper_half(void)
|
|||||||
size_t entries = 20;
|
size_t entries = 20;
|
||||||
_fill_FIB_multiple(entries, 11);
|
_fill_FIB_multiple(entries, 11);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
|
|
||||||
for (size_t i = 0; i < entries / 2; ++i) {
|
for (size_t i = 0; i < entries / 2; ++i) {
|
||||||
/* construct "addresses" to remove */
|
/* construct "addresses" to remove */
|
||||||
snprintf(addr_dst, add_buf_size, "Test address %02d", ((entries / 2) + i));
|
snprintf(addr_dst, add_buf_size, "Test address %02d", ((entries / 2) + i));
|
||||||
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)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
TEST_ASSERT_EQUAL_INT(10, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(10, fib_get_num_used_entries(&test_fib_table));
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(10, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(10, universal_address_get_num_used_entries());
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -213,20 +220,20 @@ static void test_fib_06_remove_one_entry(void)
|
|||||||
size_t entries = 20;
|
size_t entries = 20;
|
||||||
_fill_FIB_multiple(entries, 11);
|
_fill_FIB_multiple(entries, 11);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
|
|
||||||
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)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
TEST_ASSERT_EQUAL_INT(19, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(19, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -242,23 +249,23 @@ static void test_fib_07_remove_one_entry_multiple_times(void)
|
|||||||
size_t entries = 20;
|
size_t entries = 20;
|
||||||
_fill_FIB_multiple(entries, 11);
|
_fill_FIB_multiple(entries, 11);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
|
|
||||||
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);
|
||||||
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)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
TEST_ASSERT_EQUAL_INT(19, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(19, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(19, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(19, universal_address_get_num_used_entries());
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -273,22 +280,22 @@ static void test_fib_08_remove_unknown(void)
|
|||||||
size_t entries = 20;
|
size_t entries = 20;
|
||||||
_fill_FIB_multiple(entries, 11);
|
_fill_FIB_multiple(entries, 11);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
|
|
||||||
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);
|
||||||
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)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -307,26 +314,29 @@ static void test_fib_09_update_entry(void)
|
|||||||
size_t entries = 20;
|
size_t entries = 20;
|
||||||
_fill_FIB_multiple(entries, 11);
|
_fill_FIB_multiple(entries, 11);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
|
|
||||||
fib_update_entry(test_fib_table, (uint8_t *)addr_dst13, add_buf_size - 1,
|
fib_update_entry(&test_fib_table, (uint8_t *)addr_dst13,
|
||||||
(uint8_t *)addr_nxt2, add_buf_size - 1, 0x99, 9999);
|
add_buf_size - 1, (uint8_t *)addr_nxt2, add_buf_size - 1,
|
||||||
fib_update_entry(test_fib_table, (uint8_t *)addr_dst07, add_buf_size - 1,
|
0x99, 9999);
|
||||||
(uint8_t *)addr_nxt77, add_buf_size - 1, 0x77, 7777);
|
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)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief filling the FIB with entries and adding an additional one (not fitting)
|
* @brief filling the FIB with entries and adding an additional one (not fitting)
|
||||||
* It is expected to have 20 FIB entries and to receive FPC_ERROR on adding an additional one
|
* It is expected to have 20 FIB entries and to receive FPC_ERROR on adding an
|
||||||
|
* additional one
|
||||||
*/
|
*/
|
||||||
static void test_fib_10_add_exceed(void)
|
static void test_fib_10_add_exceed(void)
|
||||||
{
|
{
|
||||||
@ -337,23 +347,24 @@ static void test_fib_10_add_exceed(void)
|
|||||||
size_t entries = 20;
|
size_t entries = 20;
|
||||||
_fill_FIB_unique(entries);
|
_fill_FIB_unique(entries);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries());
|
||||||
|
|
||||||
int ret = fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x98,
|
int ret = fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst,
|
||||||
(uint8_t *)addr_nxt, add_buf_size - 1, 0x99, 9999);
|
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(-ENOMEM, ret);
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries());
|
||||||
|
|
||||||
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -372,26 +383,26 @@ static void test_fib_11_get_next_hop_success(void)
|
|||||||
size_t entries = 20;
|
size_t entries = 20;
|
||||||
_fill_FIB_multiple(entries, 11);
|
_fill_FIB_multiple(entries, 11);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
int ret = fib_get_next_hop(test_fib_table, &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_nxt, &add_buf_size, &next_hop_flags,
|
||||||
(uint8_t *)addr_dst, add_buf_size - 1, 0x13);
|
(uint8_t *)addr_dst, add_buf_size - 1, 0x13);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(0, ret);
|
TEST_ASSERT_EQUAL_INT(0, ret);
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
|
|
||||||
ret = strncmp(addr_expect, addr_nxt, add_buf_size);
|
ret = strncmp(addr_expect, addr_nxt, add_buf_size);
|
||||||
TEST_ASSERT_EQUAL_INT(0, ret);
|
TEST_ASSERT_EQUAL_INT(0, ret);
|
||||||
|
|
||||||
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -408,21 +419,21 @@ static void test_fib_12_get_next_hop_fail(void)
|
|||||||
|
|
||||||
size_t entries = 20;
|
size_t entries = 20;
|
||||||
_fill_FIB_multiple(entries, 11);
|
_fill_FIB_multiple(entries, 11);
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
int ret = fib_get_next_hop(test_fib_table, &iface_id,
|
int ret = fib_get_next_hop(&test_fib_table, &iface_id, (uint8_t *)addr_nxt,
|
||||||
(uint8_t *)addr_nxt, &add_buf_size, &next_hop_flags,
|
&add_buf_size, &next_hop_flags,
|
||||||
(uint8_t *)addr_dst, add_buf_size - 1, 0x99);
|
(uint8_t *)addr_dst, add_buf_size - 1, 0x99);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(-EHOSTUNREACH, ret);
|
TEST_ASSERT_EQUAL_INT(-EHOSTUNREACH, ret);
|
||||||
|
|
||||||
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -440,23 +451,23 @@ static void test_fib_13_get_next_hop_fail_on_buffer_size(void)
|
|||||||
|
|
||||||
size_t entries = 20;
|
size_t entries = 20;
|
||||||
_fill_FIB_multiple(entries, 11);
|
_fill_FIB_multiple(entries, 11);
|
||||||
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(test_fib_table));
|
TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table));
|
||||||
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries());
|
||||||
|
|
||||||
int ret = fib_get_next_hop(test_fib_table, &iface_id,
|
int ret = fib_get_next_hop(&test_fib_table, &iface_id, (uint8_t *)addr_nxt,
|
||||||
(uint8_t *)addr_nxt, &add_buf_size_nxt, &next_hop_flags,
|
&add_buf_size_nxt, &next_hop_flags,
|
||||||
(uint8_t *)addr_dst, add_buf_size - 1, 0x13);
|
(uint8_t *)addr_dst, add_buf_size - 1, 0x13);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(-ENOBUFS, ret);
|
TEST_ASSERT_EQUAL_INT(-ENOBUFS, ret);
|
||||||
TEST_ASSERT_EQUAL_INT(add_buf_size_nxt, add_buf_size - 1);
|
TEST_ASSERT_EQUAL_INT(add_buf_size_nxt, add_buf_size - 1);
|
||||||
|
|
||||||
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -477,23 +488,26 @@ static void test_fib_14_exact_and_prefix_match(void)
|
|||||||
|
|
||||||
snprintf(addr_dst, add_buf_size, "Test addr12");
|
snprintf(addr_dst, add_buf_size, "Test addr12");
|
||||||
snprintf(addr_nxt, add_buf_size, "Test address %02d", 12);
|
snprintf(addr_nxt, add_buf_size, "Test address %02d", 12);
|
||||||
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x12,
|
fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst,
|
||||||
(uint8_t *)addr_nxt, add_buf_size - 1, 0x12, 100000);
|
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_dst, add_buf_size, "Test addr123");
|
||||||
snprintf(addr_nxt, add_buf_size, "Test address %02d", 23);
|
snprintf(addr_nxt, add_buf_size, "Test address %02d", 23);
|
||||||
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x123,
|
fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst,
|
||||||
(uint8_t *)addr_nxt, add_buf_size - 1, 0x23, 100000);
|
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_dst, add_buf_size, "Test addr1234");
|
||||||
snprintf(addr_nxt, add_buf_size, "Test address %02d", 34);
|
snprintf(addr_nxt, add_buf_size, "Test address %02d", 34);
|
||||||
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x1234,
|
fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst,
|
||||||
(uint8_t *)addr_nxt, add_buf_size - 1, 0x34, 100000);
|
add_buf_size - 1, 0x1234, (uint8_t *)addr_nxt, add_buf_size - 1,
|
||||||
|
0x34, 100000);
|
||||||
|
|
||||||
memset(addr_lookup, 0, add_buf_size);
|
memset(addr_lookup, 0, add_buf_size);
|
||||||
/* exact match */
|
/* exact match */
|
||||||
snprintf(addr_lookup, add_buf_size, "Test addr123");
|
snprintf(addr_lookup, add_buf_size, "Test addr123");
|
||||||
int ret = fib_get_next_hop(test_fib_table, &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_nxt, &add_buf_size, &next_hop_flags,
|
||||||
(uint8_t *)addr_lookup, add_buf_size - 1, 0x123);
|
(uint8_t *)addr_lookup, add_buf_size - 1, 0x123);
|
||||||
|
|
||||||
@ -514,7 +528,7 @@ static void test_fib_14_exact_and_prefix_match(void)
|
|||||||
*/
|
*/
|
||||||
/* cppcheck-suppress redundantCopy */
|
/* cppcheck-suppress redundantCopy */
|
||||||
snprintf(addr_lookup, add_buf_size, "Test addr124");
|
snprintf(addr_lookup, add_buf_size, "Test addr124");
|
||||||
ret = fib_get_next_hop(test_fib_table, &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_nxt, &add_buf_size, &next_hop_flags,
|
||||||
(uint8_t *)addr_lookup, add_buf_size - 1, 0x124);
|
(uint8_t *)addr_lookup, add_buf_size - 1, 0x124);
|
||||||
|
|
||||||
@ -526,12 +540,12 @@ static void test_fib_14_exact_and_prefix_match(void)
|
|||||||
TEST_ASSERT_EQUAL_INT(0, ret);
|
TEST_ASSERT_EQUAL_INT(0, ret);
|
||||||
|
|
||||||
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_fib_15_get_lifetime(void)
|
static void test_fib_15_get_lifetime(void)
|
||||||
@ -544,11 +558,14 @@ static void test_fib_15_get_lifetime(void)
|
|||||||
uint32_t addr_dst_flags = 0x77777777;
|
uint32_t addr_dst_flags = 0x77777777;
|
||||||
uint32_t addr_nxt_flags = 0x77777777;
|
uint32_t addr_nxt_flags = 0x77777777;
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(0, fib_add_entry(test_fib_table, 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_dst_flags, (uint8_t *)addr_nxt, add_buf_size - 1,
|
||||||
addr_nxt_flags, 1000));
|
addr_nxt_flags, 1000));
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(0, fib_devel_get_lifetime(test_fib_table, &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... */
|
/* assuming some ms passed during these operations... */
|
||||||
vtimer_now(&now);
|
vtimer_now(&now);
|
||||||
@ -558,7 +575,7 @@ static void test_fib_15_get_lifetime(void)
|
|||||||
/* make sure lifetime hasn't grown magically either */
|
/* make sure lifetime hasn't grown magically either */
|
||||||
TEST_ASSERT_EQUAL_INT(-1, timex_cmp(lifetime, cmp_max_lifetime));
|
TEST_ASSERT_EQUAL_INT(-1, timex_cmp(lifetime, cmp_max_lifetime));
|
||||||
|
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -586,16 +603,18 @@ static void test_fib_16_prefix_match(void)
|
|||||||
addr_dst[14] = (char)0x80; /* 1000 0000 */
|
addr_dst[14] = (char)0x80; /* 1000 0000 */
|
||||||
addr_lookup[14] = (char)0x87; /* 1000 0111 */
|
addr_lookup[14] = (char)0x87; /* 1000 0111 */
|
||||||
|
|
||||||
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x123,
|
fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst,
|
||||||
(uint8_t *)addr_nxt, add_buf_size - 1, 0x23, 100000);
|
add_buf_size - 1, 0x123, (uint8_t *)addr_nxt, add_buf_size - 1,
|
||||||
|
0x23, 100000);
|
||||||
|
|
||||||
addr_dst[14] = (char)0x3c; /* 0011 1100 */
|
addr_dst[14] = (char)0x3c; /* 0011 1100 */
|
||||||
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x123,
|
fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst,
|
||||||
(uint8_t *)addr_nxt, add_buf_size - 1, 0x23, 100000);
|
add_buf_size - 1, 0x123, (uint8_t *)addr_nxt, add_buf_size - 1,
|
||||||
|
0x23, 100000);
|
||||||
|
|
||||||
memset(addr_nxt, 0, add_buf_size);
|
memset(addr_nxt, 0, add_buf_size);
|
||||||
|
|
||||||
int ret = fib_get_next_hop(test_fib_table, &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_nxt, &add_buf_size, &next_hop_flags,
|
||||||
(uint8_t *)addr_lookup, add_buf_size - 1, 0x123);
|
(uint8_t *)addr_lookup, add_buf_size - 1, 0x123);
|
||||||
|
|
||||||
@ -606,12 +625,13 @@ static void test_fib_16_prefix_match(void)
|
|||||||
addr_lookup[14] = (char)0x34; /* 0011 0100 */
|
addr_lookup[14] = (char)0x34; /* 0011 0100 */
|
||||||
add_buf_size = 16;
|
add_buf_size = 16;
|
||||||
|
|
||||||
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size - 1, 0x123,
|
fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst,
|
||||||
(uint8_t *)addr_nxt, add_buf_size - 1, 0x23, 100000);
|
add_buf_size - 1, 0x123, (uint8_t *)addr_nxt, add_buf_size -
|
||||||
|
1, 0x23, 100000);
|
||||||
|
|
||||||
memset(addr_nxt, 0, add_buf_size);
|
memset(addr_nxt, 0, add_buf_size);
|
||||||
|
|
||||||
ret = fib_get_next_hop(test_fib_table, &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_nxt, &add_buf_size, &next_hop_flags,
|
||||||
(uint8_t *)addr_lookup, add_buf_size - 1, 0x123);
|
(uint8_t *)addr_lookup, add_buf_size - 1, 0x123);
|
||||||
|
|
||||||
@ -623,19 +643,19 @@ static void test_fib_16_prefix_match(void)
|
|||||||
|
|
||||||
memset(addr_nxt, 0, add_buf_size);
|
memset(addr_nxt, 0, add_buf_size);
|
||||||
|
|
||||||
ret = fib_get_next_hop(test_fib_table, &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_nxt, &add_buf_size, &next_hop_flags,
|
||||||
(uint8_t *)addr_lookup, add_buf_size - 1, 0x123);
|
(uint8_t *)addr_lookup, add_buf_size - 1, 0x123);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(0, ret);
|
TEST_ASSERT_EQUAL_INT(0, ret);
|
||||||
|
|
||||||
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -653,7 +673,8 @@ static void test_fib_17_get_entry_set(void)
|
|||||||
/* construct "addresses" for the FIB */
|
/* construct "addresses" for the FIB */
|
||||||
snprintf(addr_dst, addr_buf_size, "Test address %02d", (int)i);
|
snprintf(addr_dst, addr_buf_size, "Test address %02d", (int)i);
|
||||||
snprintf(addr_nxt, addr_buf_size, "Test address %02d", i % 11);
|
snprintf(addr_nxt, addr_buf_size, "Test address %02d", i % 11);
|
||||||
fib_add_entry(test_fib_table, 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);
|
(uint8_t *)addr_nxt, addr_buf_size - 1, 0x0, 100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,7 +684,9 @@ static void test_fib_17_get_entry_set(void)
|
|||||||
memset(prefix,0, addr_buf_size);
|
memset(prefix,0, addr_buf_size);
|
||||||
snprintf(prefix, addr_buf_size, "Test address 1");
|
snprintf(prefix, addr_buf_size, "Test address 1");
|
||||||
|
|
||||||
int ret = fib_get_destination_set(test_fib_table, (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);
|
TEST_ASSERT_EQUAL_INT(0, ret);
|
||||||
|
|
||||||
/* we should receive 10 entries 10 to 19 */
|
/* we should receive 10 entries 10 to 19 */
|
||||||
@ -673,7 +696,9 @@ static void test_fib_17_get_entry_set(void)
|
|||||||
memset(prefix,0, addr_buf_size);
|
memset(prefix,0, addr_buf_size);
|
||||||
snprintf(prefix, addr_buf_size, "Test address 0");
|
snprintf(prefix, addr_buf_size, "Test address 0");
|
||||||
|
|
||||||
ret = fib_get_destination_set(test_fib_table, (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);
|
TEST_ASSERT_EQUAL_INT(0, ret);
|
||||||
|
|
||||||
/* we should receive 20 entries 0-19 */
|
/* we should receive 20 entries 0-19 */
|
||||||
@ -683,7 +708,9 @@ static void test_fib_17_get_entry_set(void)
|
|||||||
memset(prefix,0, addr_buf_size);
|
memset(prefix,0, addr_buf_size);
|
||||||
snprintf(prefix, addr_buf_size, "Test address");
|
snprintf(prefix, addr_buf_size, "Test address");
|
||||||
|
|
||||||
ret = fib_get_destination_set(test_fib_table, (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);
|
TEST_ASSERT_EQUAL_INT(0, ret);
|
||||||
|
|
||||||
/* we should receive 20 entries 0-19 */
|
/* we should receive 20 entries 0-19 */
|
||||||
@ -699,7 +726,7 @@ static void test_fib_17_get_entry_set(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -718,12 +745,12 @@ static void test_fib_18_get_next_hop_invalid_parameters(void)
|
|||||||
size_t entries = 20;
|
size_t entries = 20;
|
||||||
_fill_FIB_multiple(entries, 11);
|
_fill_FIB_multiple(entries, 11);
|
||||||
|
|
||||||
int ret = fib_get_next_hop(test_fib_table, NULL, NULL, NULL, NULL,NULL,
|
int ret = fib_get_next_hop(&test_fib_table, NULL, NULL,
|
||||||
add_buf_size - 1, 0x13);
|
NULL, NULL,NULL, add_buf_size - 1, 0x13);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(-EINVAL, ret);
|
TEST_ASSERT_EQUAL_INT(-EINVAL, ret);
|
||||||
|
|
||||||
ret = fib_get_next_hop(test_fib_table, &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_nxt, &add_buf_size, &next_hop_flags,
|
||||||
(uint8_t *)addr_dst, add_buf_size - 1, 0x13);
|
(uint8_t *)addr_dst, add_buf_size - 1, 0x13);
|
||||||
|
|
||||||
@ -733,12 +760,12 @@ static void test_fib_18_get_next_hop_invalid_parameters(void)
|
|||||||
TEST_ASSERT_EQUAL_INT(0, ret);
|
TEST_ASSERT_EQUAL_INT(0, ret);
|
||||||
|
|
||||||
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -767,13 +794,15 @@ static void test_fib_19_default_gateway(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* add a default gateway entry */
|
/* add a default gateway entry */
|
||||||
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size, 0x123,
|
fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst,
|
||||||
(uint8_t *)addr_nxt, add_buf_size, 0x23, 100000);
|
add_buf_size, 0x123, (uint8_t *)addr_nxt, add_buf_size, 0x23,
|
||||||
|
100000);
|
||||||
|
|
||||||
/* check if it matches all */
|
/* check if it matches all */
|
||||||
int ret = fib_get_next_hop(test_fib_table, &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_nxt_hop, &add_buf_size,
|
||||||
(uint8_t *)addr_lookup, add_buf_size, 0x123);
|
&next_hop_flags, (uint8_t *)addr_lookup,
|
||||||
|
add_buf_size, 0x123);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(0, ret);
|
TEST_ASSERT_EQUAL_INT(0, ret);
|
||||||
TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size));
|
TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size));
|
||||||
@ -786,11 +815,12 @@ static void test_fib_19_default_gateway(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* change the default gateway entry */
|
/* change the default gateway entry */
|
||||||
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size, 0x123,
|
fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst,
|
||||||
(uint8_t *)addr_nxt, add_buf_size, 0x24, 100000);
|
add_buf_size, 0x123, (uint8_t *)addr_nxt, add_buf_size, 0x24,
|
||||||
|
100000);
|
||||||
|
|
||||||
/* and check again if it matches all */
|
/* and check again if it matches all */
|
||||||
ret = fib_get_next_hop(test_fib_table, &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_nxt_hop, &add_buf_size, &next_hop_flags,
|
||||||
(uint8_t *)addr_lookup, add_buf_size, 0x123);
|
(uint8_t *)addr_lookup, add_buf_size, 0x123);
|
||||||
|
|
||||||
@ -798,12 +828,12 @@ static void test_fib_19_default_gateway(void)
|
|||||||
TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size));
|
TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size));
|
||||||
|
|
||||||
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -840,18 +870,21 @@ static void test_fib_20_replace_prefix(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* add a prefix entry */
|
/* add a prefix entry */
|
||||||
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size, 0x123,
|
fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst,
|
||||||
(uint8_t *)addr_nxt, add_buf_size, 0x23, 100000);
|
add_buf_size, 0x123, (uint8_t *)addr_nxt, add_buf_size, 0x23,
|
||||||
|
100000);
|
||||||
|
|
||||||
/* check if it matches */
|
/* check if it matches */
|
||||||
int ret = fib_get_next_hop(test_fib_table, &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_nxt_hop, &add_buf_size,
|
||||||
(uint8_t *)addr_lookup, add_buf_size, 0x123);
|
&next_hop_flags, (uint8_t *)addr_lookup,
|
||||||
|
add_buf_size, 0x123);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(0, ret);
|
TEST_ASSERT_EQUAL_INT(0, ret);
|
||||||
TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size));
|
TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size));
|
||||||
|
|
||||||
fib_remove_entry(test_fib_table, (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);
|
memset(addr_nxt_hop, 0, add_buf_size);
|
||||||
|
|
||||||
@ -866,11 +899,12 @@ static void test_fib_20_replace_prefix(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* change the prefix entry */
|
/* change the prefix entry */
|
||||||
fib_add_entry(test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size, 0x123,
|
fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst,
|
||||||
(uint8_t *)addr_nxt, add_buf_size, 0x24, 100000);
|
add_buf_size, 0x123, (uint8_t *)addr_nxt, add_buf_size, 0x24,
|
||||||
|
100000);
|
||||||
|
|
||||||
/* and check again if it matches */
|
/* and check again if it matches */
|
||||||
ret = fib_get_next_hop(test_fib_table, &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_nxt_hop, &add_buf_size, &next_hop_flags,
|
||||||
(uint8_t *)addr_lookup, add_buf_size, 0x123);
|
(uint8_t *)addr_lookup, add_buf_size, 0x123);
|
||||||
|
|
||||||
@ -878,17 +912,17 @@ static void test_fib_20_replace_prefix(void)
|
|||||||
TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size));
|
TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size));
|
||||||
|
|
||||||
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
#if (TEST_FIB_SHOW_OUTPUT == 1)
|
||||||
fib_print_fib_table(test_fib_table);
|
fib_print_fib_table(&test_fib_table);
|
||||||
puts("");
|
puts("");
|
||||||
universal_address_print_table();
|
universal_address_print_table();
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
fib_deinit(test_fib_table);
|
fib_deinit(&test_fib_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
Test *tests_fib_tests(void)
|
Test *tests_fib_tests(void)
|
||||||
{
|
{
|
||||||
fib_init(test_fib_table);
|
fib_init(&test_fib_table);
|
||||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||||
new_TestFixture(test_fib_01_fill_unique_entries),
|
new_TestFixture(test_fib_01_fill_unique_entries),
|
||||||
new_TestFixture(test_fib_02_fill_multiple_entries),
|
new_TestFixture(test_fib_02_fill_multiple_entries),
|
||||||
|
Loading…
Reference in New Issue
Block a user