From 15ad172a847fa667c57a4594ef4158405db9a984 Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Tue, 31 Mar 2020 17:50:43 +0200 Subject: [HICN-554] hicn-light refactoring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I36f2d393741d4502ce14d3791158e43e3e9cd4cf Signed-off-by: Jordan Augé --- lib/includes/hicn/base.h | 9 +- lib/includes/hicn/face.h | 213 ++++++++++++++++++++++++++++++++++++ lib/includes/hicn/policy.h | 64 ----------- lib/includes/hicn/protocol/tcp.h | 6 +- lib/includes/hicn/util/ip_address.h | 2 + 5 files changed, 223 insertions(+), 71 deletions(-) create mode 100644 lib/includes/hicn/face.h (limited to 'lib/includes/hicn') diff --git a/lib/includes/hicn/base.h b/lib/includes/hicn/base.h index d8a79a9c2..3112d1140 100644 --- a/lib/includes/hicn/base.h +++ b/lib/includes/hicn/base.h @@ -27,7 +27,7 @@ #define HICN_DEFAULT_TTL 254 typedef u32 hicn_faceid_t; -typedef u8 hicn_pathlabel_t; +typedef u32 hicn_pathlabel_t; typedef u32 hicn_lifetime_t; #define HICN_MAX_LIFETIME_SCALED 0xFFFF @@ -95,12 +95,16 @@ HICN_TYPE(int x, int y, int z, int t) #endif #define HICN_TYPE_IPV4_TCP HICN_TYPE(IPPROTO_IP, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_TYPE_IPV4_UDP HICN_TYPE(IPPROTO_IP, IPPROTO_UDP, IPPROTO_NONE, IPPROTO_NONE) #define HICN_TYPE_IPV4_ICMP HICN_TYPE(IPPROTO_IP, IPPROTO_ICMP, IPPROTO_NONE, IPPROTO_NONE) #define HICN_TYPE_IPV6_TCP HICN_TYPE(IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_TYPE_IPV6_UDP HICN_TYPE(IPPROTO_IPV6, IPPROTO_UDP, IPPROTO_NONE, IPPROTO_NONE) #define HICN_TYPE_IPV6_ICMP HICN_TYPE(IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_NONE, IPPROTO_NONE) #define HICN_TYPE_IPV4_TCP_AH HICN_TYPE(IPPROTO_IP, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_TYPE_IPV4_UDP_AH HICN_TYPE(IPPROTO_IP, IPPROTO_UDP, IPPROTO_NONE, IPPROTO_NONE) #define HICN_TYPE_IPV4_ICMP_AH HICN_TYPE(IPPROTO_IP, IPPROTO_ICMP, IPPROTO_NONE, IPPROTO_NONE) #define HICN_TYPE_IPV6_TCP_AH HICN_TYPE(IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE) +#define HICN_TYPE_IPV6_UDP_AH HICN_TYPE(IPPROTO_IPV6, IPPROTO_UDP, IPPROTO_AH, IPPROTO_NONE) #define HICN_TYPE_IPV6_ICMP_AH HICN_TYPE(IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_AH, IPPROTO_NONE) #define HICN_TYPE_NONE HICN_TYPE(IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE) @@ -127,8 +131,9 @@ typedef enum * NOTE: this computation is not (yet) part of the hICN specification. */ +// XXX TODO deprecate TODO XXX #define HICN_PATH_LABEL_MASK 0xF000 /* 1000 0000 0000 0000 */ -#define HICN_PATH_LABEL_SIZE 8 +#define HICN_PATH_LABEL_SIZE 8 /* XXX in bits ? */ /** * @brief Path label update diff --git a/lib/includes/hicn/face.h b/lib/includes/hicn/face.h new file mode 100644 index 000000000..45a1b97da --- /dev/null +++ b/lib/includes/hicn/face.h @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2017-2019 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: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file face.h + * \brief Face abstraction + */ +#ifndef HICN_FACE_H +#define HICN_FACE_H + +#ifndef SPACES +#define SPACES(x) x +#endif +#ifndef SPACE +#define SPACE 1 +#endif +#ifndef NULLTERM +#define NULLTERM 1 +#endif + +#include + +#include + +/* Netdevice type */ + +#include // IFNAMSIZ + +#define foreach_netdevice_type \ + _(UNDEFINED) \ + _(LOOPBACK) \ + _(WIRED) \ + _(WIFI) \ + _(CELLULAR) \ + _(VPN) \ + _(N) + +#define MAXSZ_NETDEVICE_TYPE_ 9 +#define MAXSZ_NETDEVICE_TYPE MAXSZ_NETDEVICE_TYPE_ + NULLTERM + +typedef enum { +#define _(x) NETDEVICE_TYPE_ ## x, +foreach_netdevice_type +#undef _ +} netdevice_type_t; + +extern const char * _netdevice_type_str[]; +#define netdevice_type_str(x) _netdevice_type_str[x] + + +/* Netdevice */ + +/** + * \brief Netdevice type + * + * NOTE + * - This struct cannot be made opaque as it is currently part of face_t + * - We recommand using the API as to keep redundant attributes consistent + */ +typedef struct { + u32 index; + char name[IFNAMSIZ]; +} netdevice_t; + +#define NETDEVICE_EMPTY (netdevice_t) { \ + .index = 0, \ + .name = {0}, \ +} + +netdevice_t * netdevice_create_from_index(u32 index); +netdevice_t * netdevice_create_from_name(const char * name); +#define netdevice_initialize_from_index netdevice_set_index +#define netdevice_initialize_from_name netdevice_set_name +void netdevice_free(netdevice_t * netdevice); +int netdevice_get_index(const netdevice_t * netdevice, u32 * index); +int netdevice_set_index(netdevice_t * netdevice, u32 index); +int netdevice_get_name(const netdevice_t * netdevice, const char ** name); +int netdevice_set_name(netdevice_t * netdevice, const char * name); +int netdevice_update_index(netdevice_t * netdevice); +int netdevice_update_name(netdevice_t * netdevice); +int netdevice_cmp(const netdevice_t * nd1, const netdevice_t * nd2); + +#define NETDEVICE_UNDEFINED_INDEX 0 + +/* Face state */ + +#define foreach_face_state \ + _(UNDEFINED) \ + _(DOWN) \ + _(UP) \ + _(N) + + +#define MAXSZ_FACE_STATE_ 9 +#define MAXSZ_FACE_STATE MAXSZ_FACE_STATE_ + 1 + +typedef enum { +#define _(x) FACE_STATE_ ## x, +foreach_face_state +#undef _ +} face_state_t; + +extern const char * _face_state_str[]; + +#define face_state_str(x) _face_state_str[x] + + +/* Face type */ + +#define foreach_face_type \ + _(UNDEFINED) \ + _(HICN) \ + _(HICN_LISTENER) \ + _(TCP) \ + _(TCP_LISTENER) \ + _(UDP) \ + _(UDP_LISTENER) \ + _(N) + +#define MAXSZ_FACE_TYPE_ 13 +#define MAXSZ_FACE_TYPE MAXSZ_FACE_TYPE_ + 1 + +typedef enum { +#define _(x) FACE_TYPE_ ## x, +foreach_face_type +#undef _ +} face_type_t; + +#define face_type_is_valid(face_type) \ + (((face_type) >= FACE_TYPE_UNDEFINED) && (face_type < FACE_TYPE_N)) +#define face_type_is_defined(face_type) \ + (((face_type) > FACE_TYPE_UNDEFINED) && (face_type < FACE_TYPE_N)) + +extern const char * _face_type_str[]; +#define face_type_str(x) _face_type_str[x] + + +#ifdef WITH_POLICY +#define MAXSZ_FACE_ MAXSZ_FACE_TYPE_ + 2 * MAXSZ_URL_ + 2 * MAXSZ_FACE_STATE_ + MAXSZ_POLICY_TAGS_ + 7 +#else +#define MAXSZ_FACE_ MAXSZ_FACE_TYPE_ + 2 * MAXSZ_URL_ + 2 * MAXSZ_FACE_STATE_ + 4 +#endif /* WITH_POLICY */ +#define MAXSZ_FACE MAXSZ_FACE_ + 1 + +/* Face */ + +typedef u32 face_id_t; + +typedef struct { + face_type_t type; + face_state_t admin_state; + face_state_t state; +#ifdef WITH_POLICY + uint32_t priority; + policy_tags_t tags; /**< \see policy_tag_t */ +#endif /* WITH_POLICY */ + + /* + * Depending on the face type, some of the following fields will be unused + */ + netdevice_t netdevice; + int family; /* To access family independently of face type */ + ip_address_t local_addr; + ip_address_t remote_addr; + u16 local_port; + u16 remote_port; +} face_t; + +int face_initialize(face_t * face); +int face_initialize_udp(face_t * face, const char * interface_name, + const ip_address_t * local_addr, u16 local_port, + const ip_address_t * remote_addr, u16 remote_port, + int family); +int face_initialize_udp_sa(face_t * face, + const char * interface_name, + const struct sockaddr * local_addr, const struct sockaddr * remote_addr); + +face_t * face_create(); +face_t * face_create_udp(const char * interface_name, + const ip_address_t * local_addr, u16 local_port, + const ip_address_t * remote_addr, u16 remote_port, int family); +face_t * face_create_udp_sa(const char * interface_name, + const struct sockaddr * local_addr, + const struct sockaddr * remote_addr); + +int face_finalize(face_t * face); + +void face_free(face_t * face); + +typedef int (*face_cmp_t)(const face_t * f1, const face_t * f2); + +int face_cmp(const face_t * f1, const face_t * f2); + +size_t +face_snprintf(char * s, size_t size, const face_t * face); + +policy_tags_t face_get_tags(const face_t * face); +int face_set_tags(face_t * face, policy_tags_t tags); + +#endif /* HICN_FACE_H */ + diff --git a/lib/includes/hicn/policy.h b/lib/includes/hicn/policy.h index 51bab4241..1fe0dd766 100644 --- a/lib/includes/hicn/policy.h +++ b/lib/includes/hicn/policy.h @@ -147,68 +147,6 @@ typedef struct { int policy_tag_state_snprintf(char * s, size_t size, const policy_tag_state_t * tag_state); - -/* INTERFACE STATS */ - -typedef struct { - float throughput; - float latency; - float loss_rate; -} interface_stats_t; - -#define INTERFACE_STATS_NONE { \ - .throughput = 0, \ - .latency = 0, \ - .loss_rate = 0, \ -} - - -/* POLICY STATS */ - -typedef struct { - interface_stats_t wired; - interface_stats_t wifi; - interface_stats_t cellular; - interface_stats_t all; -} policy_stats_t; - -#define POLICY_STATS_NONE { \ - .wired = INTERFACE_STATS_NONE, \ - .wifi = INTERFACE_STATS_NONE, \ - .cellular = INTERFACE_STATS_NONE, \ - .all = INTERFACE_STATS_NONE, \ -} - -typedef struct { - uint32_t num_packets; - uint32_t num_bytes; - uint32_t num_losses; - uint32_t latency_idle; -} interface_counters_t; - -#define INTERFACE_COUNTERS_NONE { \ - .num_packets = 0, \ - .num_bytes = 0, \ - .num_losses = 0, \ - .latency_idle = 0, \ -} - -typedef struct { - interface_counters_t wired; - interface_counters_t wifi; - interface_counters_t cellular; - interface_counters_t all; - uint64_t last_update; -} policy_counters_t; - -#define POLICY_COUNTERS_NONE (policy_counters_t) { \ - .wired = INTERFACE_COUNTERS_NONE, \ - .wifi = INTERFACE_COUNTERS_NONE, \ - .cellular = INTERFACE_COUNTERS_NONE, \ - .all = INTERFACE_COUNTERS_NONE, \ - .last_update = 0, \ -} - /* POLICY */ #define APP_NAME_LEN 128 @@ -216,7 +154,6 @@ typedef struct { typedef struct { char app_name[APP_NAME_LEN]; policy_tag_state_t tags[POLICY_TAG_N]; - policy_stats_t stats; } policy_t; static const policy_t POLICY_NONE = { @@ -226,7 +163,6 @@ static const policy_t POLICY_NONE = { foreach_policy_tag #undef _ }, - .stats = POLICY_STATS_NONE, }; diff --git a/lib/includes/hicn/protocol/tcp.h b/lib/includes/hicn/protocol/tcp.h index ded9a06b2..5cf1a3625 100644 --- a/lib/includes/hicn/protocol/tcp.h +++ b/lib/includes/hicn/protocol/tcp.h @@ -42,11 +42,7 @@ typedef struct union { u32 seq_ack; - struct - { - hicn_pathlabel_t pathlabel; - u8 pad[3]; - }; + hicn_pathlabel_t pathlabel; }; union diff --git a/lib/includes/hicn/util/ip_address.h b/lib/includes/hicn/util/ip_address.h index 4facd9ad0..27880047c 100644 --- a/lib/includes/hicn/util/ip_address.h +++ b/lib/includes/hicn/util/ip_address.h @@ -108,6 +108,7 @@ typedef struct { #define MAXSZ_PREFIX_ MAXSZ_IP_ADDRESS_ + 1 + 3 #define MAXSZ_PREFIX MAXSZ_PREFIX_ + 1 +#define MAXSZ_IP_PREFIX MAXSZ_PREFIX extern const ip_address_t IPV4_LOOPBACK; extern const ip_address_t IPV6_LOOPBACK; @@ -146,6 +147,7 @@ int ip_address_empty(const ip_address_t * ip); int ip_prefix_pton (const char *ip_address_str, ip_prefix_t * ip_prefix); int ip_prefix_ntop_short (const ip_prefix_t * ip_prefix, char *dst, size_t size); int ip_prefix_ntop (const ip_prefix_t * ip_prefix, char *dst, size_t size); +int ip_prefix_snprintf(char * s, size_t size, const ip_prefix_t * prefix); int ip_prefix_len (const ip_prefix_t * prefix); bool ip_prefix_empty (const ip_prefix_t * prefix); int ip_prefix_to_sockaddr(const ip_prefix_t * prefix, struct sockaddr *sa); -- cgit 1.2.3-korg