Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
name.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
24 #ifndef HICN_NAME_H
25 #define HICN_NAME_H
26 
27 #include <stdbool.h>
28 #ifndef _WIN32
29 #include <netinet/in.h> // struct sockadd
30 #endif
31 #include <hicn/util/ip_address.h>
32 #include "common.h"
33 
34 /******************************************************************************
35  * hICN names
36  ******************************************************************************/
37 
38 #define TCP_SEQNO_LEN 4 /* bytes */
39 #define HICN_V4_PREFIX_LEN IPV4_ADDR_LEN
40 #define HICN_V6_PREFIX_LEN IPV6_ADDR_LEN
41 #define HICN_SEGMENT_LEN TCP_SEQNO_LEN
42 #define HICN_V6_NAME_LEN (HICN_V6_PREFIX_LEN + HICN_SEGMENT_LEN) /* 20 bytes */
43 #define HICN_V4_NAME_LEN (HICN_V4_PREFIX_LEN + HICN_SEGMENT_LEN) /* 8 bytes */
44 
45 /* Prefix */
46 
47 typedef u32 hicn_name_suffix_t;
48 
49 typedef struct
50 {
51  ip46_address_t name;
52  u8 len;
54 
55 /*
56  * Name
57  *
58  * A name is a prefix + a segment name (suffix)
59  */
60 
61 typedef union
62 {
63  struct
64  {
65  union
66  {
67  u32 prefix;
68  u8 prefix_as_u8[4];
69  ip4_address_t prefix_as_ip4;
70  };
71  hicn_name_suffix_t suffix;
72  };
73  u8 buffer[HICN_V4_NAME_LEN];
75 
76 typedef union
77 {
78  struct
79  {
80  union
81  {
82  u64 prefix[2];
83  u8 prefix_as_u8[16];
84  ip6_address_t prefix_as_ip6;
85  };
86  hicn_name_suffix_t suffix;
87  };
88  u8 buffer[HICN_V6_NAME_LEN];
90 
91 #ifndef HICN_VPP_PLUGIN
92 #define HICN_NAME_COMPONENT_SIZE 2
93 
94 typedef struct
95 {
96  struct iovec buffers[HICN_NAME_COMPONENT_SIZE];
98 
99 #define UNSPEC 1 << 0
100 #define HNT_CONTIGUOUS 1 << 1
101 #define HNT_IOV 1 << 2
102 #define HNT_INET 1 << 3
103 #define HNT_INET6 1 << 4
104 
105 typedef enum
106 {
107  HNT_UNSPEC = UNSPEC,
108  HNT_CONTIGUOUS_V4 = HNT_CONTIGUOUS | HNT_INET,
109  HNT_CONTIGUOUS_V6 = HNT_CONTIGUOUS | HNT_INET6,
110  HNT_IOV_V4 = HNT_IOV | HNT_INET,
111  HNT_IOV_V6 = HNT_IOV | HNT_INET6,
112 } hicn_name_type_t;
113 #endif /* HICN_VPP_PLUGIN */
114 
115 typedef struct
116 {
117 #ifndef HICN_VPP_PLUGIN
118  hicn_name_type_t type;
119  u8 len;
120 #endif /* HICN_VPP_PLUGIN */
121  union
122  {
123  hicn_v4_name_t ip4;
124  hicn_v6_name_t ip6;
125  ip46_address_t ip46;
126 #ifndef HICN_VPP_PLUGIN
127  hicn_iov_name_t iov;
128  u8 buffer[HICN_V6_NAME_LEN];
129 #endif /* HICN_VPP_PLUGIN */
130  };
131 } hicn_name_t;
132 
133 #ifndef HICN_VPP_PLUGIN
134 #define _is_unspec(name) ((name->type & UNSPEC))
135 #define _is_contiguous(name) ((name->type & HNT_CONTIGUOUS) >> 1)
136 #define _is_iov(name) ((name->type & HNT_IOV) >> 2)
137 #define _is_inet4(name) ((name->type & HNT_INET) >> 3)
138 #define _is_inet6(name) ((name->type & HNT_INET6) >> 4)
139 #endif /* HICN_VPP_PLUGIN */
140 
148 int hicn_name_create (const char *ip_address, u32 id, hicn_name_t * name);
149 
157 int hicn_name_create_from_ip_prefix (const ip_prefix_t * prefix, u32 id,
158  hicn_name_t * name);
159 
165 u8 hicn_name_get_length (const hicn_name_t * name);
166 
177 int hicn_name_compare (const hicn_name_t * name_1, const hicn_name_t * name_2,
178  bool consider_segment);
179 
187 int hicn_name_hash (const hicn_name_t * name, u32 * hash, bool consider_suffix);
188 
195 int hicn_name_empty (hicn_name_t * name);
196 
203 int hicn_name_copy (hicn_name_t * dst, const hicn_name_t * src);
204 
212 int hicn_name_copy_to_destination (u8 * dst, const hicn_name_t * src,
213  bool copy_suffix);
214 
221 int hicn_name_set_seq_number (hicn_name_t * name, u32 seq_number);
222 
229 int hicn_name_get_seq_number (const hicn_name_t * name, u32 * seq_number);
230 
238  struct sockaddr *ip_address);
239 
246 int hicn_name_to_ip_prefix (const hicn_name_t * name,
247  ip_prefix_t * ip_prefix);
248 
256 int hicn_name_ntop (const hicn_name_t * src, char *dst, size_t len);
257 
264 int hicn_name_pton (const char *src, hicn_name_t * dst);
265 
272 int hicn_name_get_family (const hicn_name_t * name, int *family);
273 
280 int hicn_prefix_create_from_ip_prefix (const ip_prefix_t * ip_prefix,
281  hicn_prefix_t * prefix);
282 
283 #endif /* HICN_NAME_H */
284 
285 /*
286  * fd.io coding-style-patch-verification: ON
287  *
288  * Local Variables:
289  * eval: (c-set-style "gnu")
290  * End:
291  */
hicn_name_to_ip_prefix
int hicn_name_to_ip_prefix(const hicn_name_t *name, ip_prefix_t *ip_prefix)
Convert an hICN name to an IP address.
hicn_name_create
int hicn_name_create(const char *ip_address, u32 id, hicn_name_t *name)
Create an hICN name from IP address in presentation format.
hicn_name_compare
int hicn_name_compare(const hicn_name_t *name_1, const hicn_name_t *name_2, bool consider_segment)
Compare two hICN names.
ip6_address_t
Definition: common.h:173
hicn_v6_name_t
Definition: name.h:76
hicn_name_create_from_ip_prefix
int hicn_name_create_from_ip_prefix(const ip_prefix_t *prefix, u32 id, hicn_name_t *name)
Create an hICN name from IP address.
hicn_prefix_create_from_ip_prefix
int hicn_prefix_create_from_ip_prefix(const ip_prefix_t *ip_prefix, hicn_prefix_t *prefix)
Creates an hICN prefix from an IP address.
hicn_name_get_family
int hicn_name_get_family(const hicn_name_t *name, int *family)
Returns the IP address family of an hICN name.
hicn_name_copy_to_destination
int hicn_name_copy_to_destination(u8 *dst, const hicn_name_t *src, bool copy_suffix)
Copy an hICN name to a buffer.
hicn_name_get_length
u8 hicn_name_get_length(const hicn_name_t *name)
Returns the length of an hICN name.
ip_prefix_t
Definition: ip_address.h:103
hicn_name_to_sockaddr_address
int hicn_name_to_sockaddr_address(const hicn_name_t *name, struct sockaddr *ip_address)
Convert an hICN name to a socket address.
hicn_name_copy
int hicn_name_copy(hicn_name_t *dst, const hicn_name_t *src)
Copy an hICN name.
hicn_name_empty
int hicn_name_empty(hicn_name_t *name)
Test whether an hICN name is empty.
ip4_address_t
Definition: common.h:167
hicn_iov_name_t
Definition: name.h:94
hicn_name_ntop
int hicn_name_ntop(const hicn_name_t *src, char *dst, size_t len)
Convert an hICN name to presentation format.
iovec
Definition: windows_utils.h:33
hicn_name_hash
int hicn_name_hash(const hicn_name_t *name, u32 *hash, bool consider_suffix)
Provides a 32-bit hash of an hICN name.
hicn_prefix_t
Definition: name.h:49
hicn_name_t
Definition: name.h:115
hicn_name_set_seq_number
int hicn_name_set_seq_number(hicn_name_t *name, u32 seq_number)
Sets the segment part of an hICN name.
hicn_v4_name_t
Definition: name.h:61
hicn_name_get_seq_number
int hicn_name_get_seq_number(const hicn_name_t *name, u32 *seq_number)
Retrieves the segment part of an hICN name.
ip46_address_t
Definition: common.h:181
hicn_name_pton
int hicn_name_pton(const char *src, hicn_name_t *dst)
Convert an hICN name from presentation format.