aboutsummaryrefslogtreecommitdiffstats
path: root/lib/includes/hicn/common.h
diff options
context:
space:
mode:
authorLuca Muscariello <muscariello@ieee.org>2022-08-04 16:06:34 +0200
committerLuca Muscariello <muscariello@ieee.org>2022-08-04 16:31:51 +0200
commit6d22a0db96aa7f8e3102ae44d00c09e36a2e9c57 (patch)
tree79546bbf09f6fbf74db7bc89117843f06ce937ea /lib/includes/hicn/common.h
parent012843b1c0bc0838e69085ed83a79ec8b6f97360 (diff)
feat: Due to the deep modifications related to names and packet format,
this task cover a large part of the codebase and involves several changes: - the library provides a name data structure (hicn_name_t ), which is composed of a name prefix (hicn_name_prefix_t) and a name suffix (hicn_name_suffix_t), and it has been extended to provide all support functions required for name manipulation, including common prefix computation, as required for the Longest Prefix Match (LPM)in the forwarder, in addition to Exact Prefix Match (EPM). - all code has been rewritten to use this data structure instead of having for instance the forwarder define its own name class (used to be Name and NameBitVector) the code has been refactored to minimize name allocations and copies, one remaining aspect is the difference of name storage between PIT and CS entries (respectively in the PIT entry, and in the message buffer), which causes the packet cache index to be updated when a PIT entry is converted into a CS entry. By storing the name in the PIT/CS entry everytime, we might save on this operation). - hicn-light FIB has been rewritten : code has been refactored and should now be shorter and documented; unit tests have been drafted but more would be required to cover all cases and match the algorithms to add/remove nodes, as specified in the doc. all protocol details and hICN header formats are now abstracted by the library for the forwarder (and thus header.h and  protocols/*.h have been removed from public includes, and replaced by packet.h providing protocol agnostic packet level functions, completely replacing the compat.h header that used to provide similar functions. - this works by exposing a opaque buffer to the application (a kind of socket buffer) which is used by the lib to cache the packet format and offsets of the different layers in the buffer and provider efficient operations (the packet format is either defined for packet construction, or guessed at ingress, and this structure is updated accordingly only once). Co-authored-by: Jordan Augé <jordan.auge+fdio@cisco.com> Signed-off-by: Luca Muscariello <muscariello@ieee.org> Change-Id: I31e321897f85f0267fe8ba4720363c180564492f
Diffstat (limited to 'lib/includes/hicn/common.h')
-rw-r--r--lib/includes/hicn/common.h94
1 files changed, 31 insertions, 63 deletions
diff --git a/lib/includes/hicn/common.h b/lib/includes/hicn/common.h
index 1998099db..a84124617 100644
--- a/lib/includes/hicn/common.h
+++ b/lib/includes/hicn/common.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Cisco and/or its affiliates.
+ * Copyright (c) 2021-2022 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -36,25 +36,11 @@
#include <stdint.h>
#include <assert.h>
-/* Concise type definitions */
+#include <hicn/util/types.h>
-typedef uint64_t u64;
-typedef uint32_t u32;
-typedef uint16_t u16;
-typedef uint8_t u8;
-
-/*
- * Code annotations
- *
- * NOTE: these are defined by default in VPP.
- */
-
-#ifndef HICN_VPP_PLUGIN
-
-#define PREDICT_FALSE(x) (x)
-#define PREDICT_TRUE(x) (x)
-#define STRUCT_SIZE_OF(type, member) sizeof (((type *) 0)->member)
-#define ASSERT
+#define HICN_EXPECT_FALSE(x) __builtin_expect ((x), 1)
+#define HICN_EXPECT_TRUE(x) __builtin_expect ((x), 0)
+#define HICN_UNUSED(x) x __attribute__ ((unused))
#ifndef NDEBUG
#define _ASSERT(x) assert (x)
@@ -62,36 +48,6 @@ typedef uint8_t u8;
#define _ASSERT(x) ((void) (x))
#endif
-#define STATIC_ASSERT(x)
-
-/* Architecture-dependent uword size */
-#if INTPTR_MAX == INT64_MAX
-#define log2_uword_bits 6
-#elif INTPTR_MAX == INT32_MAX
-#define log2_uword_bits 5
-#else
-#error "Impossible to detect architecture"
-#endif
-
-#define uword_bits (1 << log2_uword_bits)
-
-/* Word types. */
-#if uword_bits == 64
-/* 64 bit word machines. */
-typedef u64 uword;
-#else
-/* 32 bit word machines. */
-typedef u32 uword;
-#endif
-
-typedef uword ip_csum_t;
-
-#else
-
-#include <vppinfra/clib.h>
-
-#endif /* ! HICN_VPP_PLUGIN */
-
/*
* Windows compilers do not support named initilizers when .h files are
* included inside C++ files. For readability, we either use the following
@@ -178,11 +134,11 @@ int get_addr_family (const char *ip_address);
*/
static inline u16
-ip_csum_fold (ip_csum_t c)
+ip_csum_fold (hicn_ip_csum_t c)
{
/* Reduce to 16 bits. */
#if uword_bits == 64
- c = (c & (ip_csum_t) 0xffffffff) + (c >> (ip_csum_t) 32);
+ c = (c & (hicn_ip_csum_t) 0xffffffff) + (c >> (hicn_ip_csum_t) 32);
c = (c & 0xffff) + (c >> 16);
#endif
@@ -192,18 +148,18 @@ ip_csum_fold (ip_csum_t c)
return (u16) c;
}
-static inline ip_csum_t
-ip_csum_with_carry (ip_csum_t sum, ip_csum_t x)
+static inline hicn_ip_csum_t
+ip_csum_with_carry (hicn_ip_csum_t sum, hicn_ip_csum_t x)
{
- ip_csum_t t = sum + x;
+ hicn_ip_csum_t t = sum + x;
return t + (t < x);
}
/* Update checksum changing field at even byte offset from x -> 0. */
-static inline ip_csum_t
-ip_csum_add_even (ip_csum_t c, ip_csum_t x)
+static inline hicn_ip_csum_t
+ip_csum_add_even (hicn_ip_csum_t c, hicn_ip_csum_t x)
{
- ip_csum_t d;
+ hicn_ip_csum_t d;
d = c - x;
@@ -214,8 +170,8 @@ ip_csum_add_even (ip_csum_t c, ip_csum_t x)
}
/* Update checksum changing field at even byte offset from 0 -> x. */
-static inline ip_csum_t
-ip_csum_sub_even (ip_csum_t c, ip_csum_t x)
+static inline hicn_ip_csum_t
+ip_csum_sub_even (hicn_ip_csum_t c, hicn_ip_csum_t x)
{
return ip_csum_with_carry (c, x);
}
@@ -265,8 +221,19 @@ csum (const void *addr, size_t size, u16 init)
* Query IP version from packet (either 4 or 6)
* (version is located as same offsets in both protocol headers)
*/
-#define HICN_IP_VERSION(packet) \
- ((hicn_header_t *) packet)->protocol.ipv4.version
+typedef struct
+{
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+ u8 dummy : 4;
+ u8 version : 4;
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ u8 version : 4;
+ u8 dummy : 4;
+#else
+#error "Unsupported endianness"
+#endif
+} ip_version_t;
+#define HICN_IP_VERSION(packet) ((ip_version_t *) packet)->version
#ifndef ntohll
static inline uint64_t
@@ -296,9 +263,9 @@ htonll (uint64_t input)
}
#endif
-#define round_pow2(x, pow2) (((x) + (pow2) -1) & ~((pow2) -1))
+#define hicn_round_pow2(x, pow2) (((x) + (pow2) -1) & ~((pow2) -1))
-#define _SIZEOF_ALIGNED(x, size) round_pow2 (sizeof (x), size)
+#define _SIZEOF_ALIGNED(x, size) hicn_round_pow2 (sizeof (x), size)
#define SIZEOF_ALIGNED(x) _SIZEOF_ALIGNED (x, sizeof (void *))
/* Definitions for builtins unavailable on MSVC */
@@ -336,6 +303,7 @@ uint32_t __inline __builtin_clzl2 (uint64_t value)
#endif
#define next_pow2(x) (x <= 1 ? 1 : 1ul << (64 - __builtin_clzl (x - 1)))
+#define _unused(x) ((void) (x))
#endif /* HICN_COMMON_H */