diff --git a/Makefile.dep b/Makefile.dep index 340493d03d14cbf6713caf6e21b643476abadeef..7df41384273c5555b81eb04c7c7e06e414b08fb7 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -283,8 +283,7 @@ endif ifneq (,$(filter fib,$(USEMODULE))) USEMODULE += universal_address - USEMODULE += timex - USEMODULE += vtimer + USEMODULE += xtimer USEMODULE += net_help endif diff --git a/sys/include/net/fib.h b/sys/include/net/fib.h index 91230c3030b7e283475d800422ceb596f07969f1..59a3cc59913f076f3223f85c8b637d14cec78440 100644 --- a/sys/include/net/fib.h +++ b/sys/include/net/fib.h @@ -23,9 +23,10 @@ #ifndef FIB_H_ #define FIB_H_ +#include <stdint.h> + #include "net/fib/table.h" #include "kernel_types.h" -#include "timex.h" #ifdef __cplusplus extern "C" { @@ -59,7 +60,7 @@ typedef struct fib_destination_set_entry_t { /** * @brief indicator of a lifetime that does not expire (2^32 - 1) */ -#define FIB_LIFETIME_NO_EXPIRE (0xFFFFFFFF) +#define FIB_LIFETIME_NO_EXPIRE (0xFFFFFFFFffffffff) /** * @brief initializes all FIB entries with 0 @@ -227,7 +228,7 @@ void fib_print_routes(fib_table_t *table); * @return 0 on success: entry for dst found and lifetime copied * -EHOSTUNREACH if no fitting entry is available */ -int fib_devel_get_lifetime(fib_table_t *table, timex_t *lifetime, uint8_t *dst, +int fib_devel_get_lifetime(fib_table_t *table, uint64_t *lifetime, uint8_t *dst, size_t dst_size); #endif diff --git a/sys/include/net/fib/table.h b/sys/include/net/fib/table.h index 262e0790256bc8b8a9e63ac157704f4ebc8f1088..d60ff944e8a9ad487cd428f4faa3220984728f25 100644 --- a/sys/include/net/fib/table.h +++ b/sys/include/net/fib/table.h @@ -20,7 +20,8 @@ #define FIB_TABLE_H_ #include <stdint.h> -#include "vtimer.h" + +#include "kernel_types.h" #include "universal_address.h" #ifdef __cplusplus @@ -34,7 +35,7 @@ typedef struct fib_entry_t { /** interface ID */ kernel_pid_t iface_id; /** Lifetime of this entry (an absolute time-point is stored by the FIB) */ - timex_t lifetime; + uint64_t lifetime; /** Unique identifier for the type of the global address */ uint32_t global_flags; /** Pointer to the shared generic address */ diff --git a/sys/net/network_layer/fib/fib.c b/sys/net/network_layer/fib/fib.c index 1abe16659c05901d0583cf8f8f286a4fdbabbd42..0076d73cf114d336499381ef611f9e5804146acf 100644 --- a/sys/net/network_layer/fib/fib.c +++ b/sys/net/network_layer/fib/fib.c @@ -27,6 +27,7 @@ #include "thread.h" #include "mutex.h" #include "msg.h" +#include "xtimer.h" #define ENABLE_DEBUG (0) #include "debug.h" @@ -79,15 +80,13 @@ static kernel_pid_t notify_rp[FIB_MAX_REGISTERED_RP]; static universal_address_container_t* prefix_rp[FIB_MAX_REGISTERED_RP]; /** - * @brief convert given ms to a point in time from now on in the future - * @param[in] ms the milliseconds to be converted - * @param[out] timex the converted point in time + * @brief convert an offset given in ms to abolute time in time in us + * @param[in] ms the milliseconds to be converted + * @param[out] target the converted point in time */ -static void fib_ms_to_timex(uint32_t ms, timex_t *timex) +static void fib_lifetime_to_absolute(uint32_t ms, uint64_t *target) { - vtimer_now(timex); - timex->seconds += ms / 1000; - timex->microseconds += (ms - timex->seconds * 1000) * 1000; + *target = xtimer_now64() + (ms * 1000); } /** @@ -106,8 +105,7 @@ static void fib_ms_to_timex(uint32_t ms, timex_t *timex) */ 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) { - timex_t now; - vtimer_now(&now); + uint64_t now = xtimer_now64(); size_t count = 0; size_t prefix_size = 0; @@ -125,14 +123,12 @@ static int fib_find_entry(fib_table_t *table, uint8_t *dst, size_t dst_size, for (size_t i = 0; i < table->size; ++i) { /* autoinvalidate if the entry lifetime is not set to not expire */ - if ((table->entries[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE) - || (table->entries[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) { + if (table->entries[i].lifetime != FIB_LIFETIME_NO_EXPIRE) { /* check if the lifetime expired */ - if (timex_cmp(now, table->entries[i].lifetime) > -1) { + if (table->entries[i].lifetime < now) { /* remove this entry if its lifetime expired */ - table->entries[i].lifetime.seconds = 0; - table->entries[i].lifetime.microseconds = 0; + table->entries[i].lifetime = 0; table->entries[i].global_flags = 0; table->entries[i].next_hop_flags = 0; table->entries[i].iface_id = KERNEL_PID_UNDEF; @@ -204,12 +200,11 @@ static int fib_upd_entry(fib_entry_t *entry, uint8_t *next_hop, entry->next_hop = container; entry->next_hop_flags = next_hop_flags; - if (lifetime < FIB_LIFETIME_NO_EXPIRE) { - fib_ms_to_timex(lifetime, &entry->lifetime); + if (lifetime != (uint32_t)FIB_LIFETIME_NO_EXPIRE) { + fib_lifetime_to_absolute(lifetime, &entry->lifetime); } else { - entry->lifetime.seconds = FIB_LIFETIME_NO_EXPIRE; - entry->lifetime.microseconds = FIB_LIFETIME_NO_EXPIRE; + entry->lifetime = FIB_LIFETIME_NO_EXPIRE; } return 0; @@ -237,8 +232,7 @@ static int fib_create_entry(fib_table_t *table, kernel_pid_t iface_id, next_hop_flags, uint32_t lifetime) { for (size_t i = 0; i < table->size; ++i) { - if ((table->entries[i].lifetime.seconds == 0) && - (table->entries[i].lifetime.microseconds == 0)) { + if (table->entries[i].lifetime == 0) { table->entries[i].global = universal_address_add(dst, dst_size); @@ -252,12 +246,11 @@ static int fib_create_entry(fib_table_t *table, kernel_pid_t iface_id, /* everything worked fine */ table->entries[i].iface_id = iface_id; - if (lifetime < FIB_LIFETIME_NO_EXPIRE) { - fib_ms_to_timex(lifetime, &table->entries[i].lifetime); + if (lifetime != (uint32_t) FIB_LIFETIME_NO_EXPIRE) { + fib_lifetime_to_absolute(lifetime, &table->entries[i].lifetime); } else { - table->entries[i].lifetime.seconds = FIB_LIFETIME_NO_EXPIRE; - table->entries[i].lifetime.microseconds = FIB_LIFETIME_NO_EXPIRE; + table->entries[i].lifetime = FIB_LIFETIME_NO_EXPIRE; } return 0; @@ -291,8 +284,7 @@ static int fib_remove(fib_entry_t *entry) entry->next_hop_flags = 0; entry->iface_id = KERNEL_PID_UNDEF; - entry->lifetime.seconds = 0; - entry->lifetime.microseconds = 0; + entry->lifetime = 0; return 0; } @@ -608,12 +600,11 @@ void fib_print_fib_table(fib_table_t *table) mutex_lock(&mtx_access); 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: %"PRIu32"\n", (int)i, (int)table->entries[i].iface_id, (void *)table->entries[i].global, (void *)table->entries[i].next_hop, - (int)table->entries[i].lifetime.seconds, - (int)table->entries[i].lifetime.microseconds); + (uint32_t)(table->entries[i].lifetime / 1000)); } mutex_unlock(&mtx_access); @@ -656,28 +647,25 @@ void fib_print_routes(fib_table_t *table) printf("%-" FIB_ADDR_PRINT_LENS "s %-6s %-" FIB_ADDR_PRINT_LENS "s %-6s %-16s Interface\n" , "Destination", "Flags", "Next Hop", "Flags", "Expires"); - timex_t now; - vtimer_now(&now); + uint64_t now = xtimer_now64(); for (size_t i = 0; i < table->size; ++i) { - if (table->entries[i].lifetime.seconds != 0 || table->entries[i].lifetime.microseconds != 0) { + if (table->entries[i].lifetime != 0) { fib_print_address(table->entries[i].global); printf(" 0x%04"PRIx32" ", table->entries[i].global_flags); fib_print_address(table->entries[i].next_hop); printf(" 0x%04"PRIx32" ", table->entries[i].next_hop_flags); - if ((table->entries[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE) - || (table->entries[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) { + if (table->entries[i].lifetime != FIB_LIFETIME_NO_EXPIRE) { - timex_t tm = timex_sub(table->entries[i].lifetime, now); + uint64_t tm = table->entries[i].lifetime - now; /* we must interpret the values as signed */ - if ((int32_t)tm.seconds < 0 - || (tm.seconds == 0 && (int32_t)tm.microseconds < 0)) { + if ((int64_t)tm < 0 ) { printf("%-16s ", "EXPIRED"); } else { - printf("%"PRIu32".%05"PRIu32, tm.seconds, tm.microseconds); + printf("%"PRIu32".%05"PRIu32, (uint32_t)(tm / 1000000), (uint32_t)(tm % 1000000)); } } else { @@ -692,7 +680,7 @@ void fib_print_routes(fib_table_t *table) } #if FIB_DEVEL_HELPER -int fib_devel_get_lifetime(fib_table_t *table, timex_t *lifetime, uint8_t *dst, +int fib_devel_get_lifetime(fib_table_t *table, uint64_t *lifetime, uint8_t *dst, size_t dst_size) { size_t count = 1; diff --git a/sys/shell/commands/sc_fib.c b/sys/shell/commands/sc_fib.c index 5debb6fdbc52c892f394724dda5cfc7ef48dd020..500abb974bb8410b17c0af55511b632887c7d0d2 100644 --- a/sys/shell/commands/sc_fib.c +++ b/sys/shell/commands/sc_fib.c @@ -159,7 +159,7 @@ int _fib_route_handler(int argc, char **argv) kernel_pid_t ifs[GNRC_NETIF_NUMOF]; size_t ifnum = gnrc_netif_get(ifs); if (ifnum == 1) { - _fib_add(argv[2], argv[4], ifs[0], FIB_LIFETIME_NO_EXPIRE); + _fib_add(argv[2], argv[4], ifs[0], (uint32_t)FIB_LIFETIME_NO_EXPIRE); } else { _fib_usage(1); @@ -190,7 +190,7 @@ int _fib_route_handler(int argc, char **argv) if (argc == 7) { if ((strcmp("add", argv[1]) == 0) && (strcmp("via", argv[3]) == 0) && (strcmp("dev", argv[5]) == 0)) { - _fib_add(argv[2], argv[4], (kernel_pid_t)atoi(argv[6]), FIB_LIFETIME_NO_EXPIRE); + _fib_add(argv[2], argv[4], (kernel_pid_t)atoi(argv[6]), (uint32_t)FIB_LIFETIME_NO_EXPIRE); } else { _fib_usage(1); diff --git a/tests/unittests/tests-fib/tests-fib.c b/tests/unittests/tests-fib/tests-fib.c index 52edd5384ac7b0a29251a58245776e32f61ee555..0b3a25a02d13b17ee464c09dd3c361cfe5471ea7 100644 --- a/tests/unittests/tests-fib/tests-fib.c +++ b/tests/unittests/tests-fib/tests-fib.c @@ -13,7 +13,7 @@ #include <errno.h> #include "embUnit.h" #include "tests-fib.h" -#include "vtimer.h" +#include "xtimer.h" #include "thread.h" #include "net/fib.h" @@ -550,7 +550,7 @@ static void test_fib_14_exact_and_prefix_match(void) static void test_fib_15_get_lifetime(void) { - timex_t lifetime, now; + uint64_t lifetime, now; kernel_pid_t iface_id = 1; char addr_dst[] = "Test address151"; char addr_nxt[] = "Test address152"; @@ -568,12 +568,13 @@ static void test_fib_15_get_lifetime(void) add_buf_size - 1)); /* assuming some ms passed during these operations... */ - vtimer_now(&now); - timex_t cmp_lifetime = timex_add(now, timex_set(0, 900000)); - timex_t cmp_max_lifetime = timex_add(now, timex_set(1,1)); - TEST_ASSERT_EQUAL_INT(1, timex_cmp(lifetime, cmp_lifetime)); + now = xtimer_now64(); + uint64_t cmp_lifetime = now + 900000lU; + uint64_t cmp_max_lifetime = now + 1100000lU; + + TEST_ASSERT_EQUAL_INT(1, (lifetime > cmp_lifetime)); /* make sure lifetime hasn't grown magically either */ - TEST_ASSERT_EQUAL_INT(-1, timex_cmp(lifetime, cmp_max_lifetime)); + TEST_ASSERT_EQUAL_INT(1, (lifetime < cmp_max_lifetime)); fib_deinit(&test_fib_table); }