diff options
author | Luca Muscariello <lumuscar@cisco.com> | 2022-03-30 22:29:28 +0200 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2022-03-31 19:51:47 +0200 |
commit | c46e5df56b67bb8ea7a068d39324c640084ead2b (patch) | |
tree | eddeb17785938e09bc42eec98ee09b8a28846de6 /lib/includes/hicn/common.h | |
parent | 18fa668f25d3cc5463417ce7df6637e31578e898 (diff) |
feat: boostrap hicn 22.02
The current patch provides several new features, improvements,
bug fixes and also complete rewrite of entire components.
- lib
The hicn packet parser has been improved with a new packet
format fully based on UDP. The TCP header is still temporarily
supported but the UDP header will replace completely the new hicn
packet format. Improvements have been made to make sure every
packet parsing operation is made via this library. The current
new header can be used as header between the payload and the
UDP header or as trailer in the UDP surplus area to be tested
when UDP options will start to be used.
- hicn-light
The portable packet forwarder has been completely rewritten from
scratch with the twofold objective to improve performance and
code size but also to drop dependencies such as libparc which is
now removed by the current implementation.
- hicn control
the control library is the agent that is used to program the
packet forwarders via their binary API. This component has
benefited from significant improvements in terms of interaction
model which is now event driven and more robust to failures.
- VPP plugin has been updated to support VPP 22.02
- transport
Major improvement have been made to the RTC protocol, to the
support of IO modules and to the security sub system. Signed
manifests are the default data authenticity and integrity framework.
Confidentiality can be enabled by sharing the encryption key to the
prod/cons layer. The library has been tested with group key based
applications such as broadcast/multicast and real-time on-line
meetings with trusted server keys or MLS.
- testing
Unit testing has been introduced using GoogleTest. One third of
the code base is covered by unit testing with priority on
critical features. Functional testing has also been introduce
using Docker, linux bridging and Robot Framework to define
test with Less Code techniques to facilitate the extension
of the coverage.
Co-authored-by: Mauro Sardara <msardara@cisco.com>
Co-authored-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Co-authored-by: Michele Papalini <micpapal@cisco.com>
Co-authored-by: Angelo Mantellini <manangel@cisco.com>
Co-authored-by: Jacques Samain <jsamain@cisco.com>
Co-authored-by: Olivier Roques <oroques+fdio@cisco.com>
Co-authored-by: Enrico Loparco <eloparco@cisco.com>
Co-authored-by: Giulio Grassi <gigrassi@cisco.com>
Change-Id: I75d0ef70f86d921e3ef503c99271216ff583c215
Signed-off-by: Luca Muscariello <muscariello@ieee.org>
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'lib/includes/hicn/common.h')
-rw-r--r-- | lib/includes/hicn/common.h | 125 |
1 files changed, 47 insertions, 78 deletions
diff --git a/lib/includes/hicn/common.h b/lib/includes/hicn/common.h index 05f8ad95f..b0898ce1f 100644 --- a/lib/includes/hicn/common.h +++ b/lib/includes/hicn/common.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2021 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: @@ -51,13 +51,17 @@ typedef uint8_t u8; #ifndef HICN_VPP_PLUGIN -#define PREDICT_FALSE(x) (x) -#define PREDICT_TRUE(x) (x) -#define always_inline static inline -#define static_always_inline static inline -#define STRUCT_SIZE_OF(type, member) sizeof(((type *)0)->member) +#define PREDICT_FALSE(x) (x) +#define PREDICT_TRUE(x) (x) +#define STRUCT_SIZE_OF(type, member) sizeof (((type *) 0)->member) #define ASSERT +#ifndef NDEBUG +#define _ASSERT(x) assert (x) +#else +#define _ASSERT(x) ((void) (x)) +#endif + #define STATIC_ASSERT(x) /* Architecture-dependent uword size */ @@ -82,13 +86,17 @@ typedef u32 uword; 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 macro, or - * duplicate some code, with the intent of preserving those safeguards for - * non-Windows platforms. + * Windows compilers do not support named initilizers when .h files are + * included inside C++ files. For readability, we either use the following + * macro, or duplicate some code, with the intent of preserving those + * safeguards for non-Windows platforms. */ #ifndef _WIN32 #define ATTR_INIT(key, value) .key = value @@ -97,12 +105,12 @@ typedef uword ip_csum_t; #endif #ifdef _WIN32 - /* Endianness detection for Windows platforms */ +/* Endianness detection for Windows platforms */ #define __ORDER_LITTLE_ENDIAN__ 0x41424344UL -#define __ORDER_BIG_ENDIAN__ 0x44434241UL -#define __BYTE_ORDER__ ('ABCD') +#define __ORDER_BIG_ENDIAN__ 0x44434241UL +#define __BYTE_ORDER__ ('ABCD') - /* Windows compatibility headers */ +/* Windows compatibility headers */ #define WIN32_LEAN_AND_MEAN #ifndef NOMINMAX #define NOMINMAX @@ -116,10 +124,10 @@ typedef uword ip_csum_t; #define strdup _strdup #define __attribute__(A) -#ifndef IOVEC +#ifndef IOVEC #define IOVEC #define UIO_MAXIOV 16 -#define IOV_MAX UIO_MAXIOV +#define IOV_MAX UIO_MAXIOV struct iovec { void *iov_base; @@ -132,66 +140,20 @@ struct iovec * Portable attribute packed. */ #ifndef _WIN32 -#define PACKED( __Declaration__ ) __Declaration__ __attribute__((__packed__)) +#define PACKED(__Declaration__) __Declaration__ __attribute__ ((__packed__)) #else -#define PACKED( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) ) +#define PACKED(__Declaration__) \ + __pragma (pack (push, 1)) __Declaration__ __pragma (pack (pop)) #endif - /* * IP address types */ -#ifdef HICN_VPP_PLUGIN - -#include <vnet/ip/ip4_packet.h> // ip4_address_t -#include <vnet/ip/ip6_packet.h> // ip6_address_t - -#if __GNUC__ >= 9 -#pragma GCC diagnostic ignored "-Waddress-of-packed-member" -#endif - -#include <vnet/ip/ip46_address.h> - -#if __GNUC__ >= 9 -#pragma GCC diagnostic pop -#endif - -#else - - #ifndef _WIN32 #include <netinet/in.h> #endif -typedef union -{ - u32 as_u32; - struct in_addr as_inaddr; -} ip4_address_t; - -typedef union -{ - u64 as_u64[2]; - u32 as_u32[4]; - u8 as_u8[16]; - struct in6_addr as_in6addr; -} ip6_address_t; - -typedef union -{ - struct - { - u32 pad[3]; - ip4_address_t ip4; - }; - ip6_address_t ip6; -} ip46_address_t; - -#define ip46_address_is_ip4(ip46) (((ip46)->pad[0] | (ip46)->pad[1] | (ip46)->pad[2]) == 0) - -#endif /* ! HICN_VPP_PLUGIN */ - /** * @brief Returns the family of an IP address * @param [in] ip_address - IP address in presentation format @@ -215,7 +177,7 @@ int get_addr_family (const char *ip_address); * borrow this code here. */ -static_always_inline u16 +static inline u16 ip_csum_fold (ip_csum_t c) { /* Reduce to 16 bits. */ @@ -227,10 +189,10 @@ ip_csum_fold (ip_csum_t c) c = (c & 0xffff) + (c >> 16); c = (c & 0xffff) + (c >> 16); - return (u16)c; + return (u16) c; } -static_always_inline ip_csum_t +static inline ip_csum_t ip_csum_with_carry (ip_csum_t sum, ip_csum_t x) { ip_csum_t t = sum + x; @@ -238,7 +200,7 @@ ip_csum_with_carry (ip_csum_t sum, ip_csum_t x) } /* Update checksum changing field at even byte offset from x -> 0. */ -static_always_inline ip_csum_t +static inline ip_csum_t ip_csum_add_even (ip_csum_t c, ip_csum_t x) { ip_csum_t d; @@ -252,19 +214,19 @@ ip_csum_add_even (ip_csum_t c, ip_csum_t x) } /* Update checksum changing field at even byte offset from 0 -> x. */ -static_always_inline ip_csum_t +static inline ip_csum_t ip_csum_sub_even (ip_csum_t c, ip_csum_t x) { return ip_csum_with_carry (c, x); } +#endif /* ! HICN_VPP_PLUGIN */ + u32 cumulative_hash32 (const void *data, size_t len, u32 lastValue); u32 hash32 (const void *data, size_t len); u64 cumulative_hash64 (const void *data, size_t len, u64 lastValue); u64 hash64 (const void *data, size_t len); -void hicn_packet_dump (const uint8_t * buffer, size_t len); - -#endif /* ! HICN_VPP_PLUGIN */ +void hicn_packet_dump (const uint8_t *buffer, size_t len); /** * @brief Computes buffer checksum @@ -273,7 +235,7 @@ void hicn_packet_dump (const uint8_t * buffer, size_t len); * @param [in] init - Checksum initial value * @return Checksum of specified buffer */ -always_inline u16 +static inline u16 csum (const void *addr, size_t size, u16 init) { u32 sum = init; @@ -291,7 +253,7 @@ csum (const void *addr, size_t size, u16 init) sum = (sum >> 16) + (sum & 0xffff); sum += (sum >> 16); - return (u16) ~ sum; + return (u16) ~sum; } /* @@ -305,17 +267,24 @@ 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)->v4.ip.version +#define HICN_IP_VERSION(packet) \ + ((hicn_header_t *) packet)->protocol.ipv4.version /* * ntohll / htonll allows byte swapping for 64 bits integers */ #ifndef htonll -#define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32)) +#define htonll(x) \ + ((1 == htonl (1)) ? \ + (x) : \ + ((uint64_t) htonl ((x) &0xFFFFFFFF) << 32) | htonl ((x) >> 32)) #endif #ifndef ntohll -#define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32)) +#define ntohll(x) \ + ((1 == ntohl (1)) ? \ + (x) : \ + ((uint64_t) ntohl ((x) &0xFFFFFFFF) << 32) | ntohl ((x) >> 32)) #endif #endif /* HICN_COMMON_H */ |