Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
face.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 
20 #ifndef HICN_FACE_H
21 #define HICN_FACE_H
22 
23 #ifndef SPACES
24 #define SPACES(x) x
25 #endif
26 #ifndef SPACE
27 #define SPACE 1
28 #endif
29 #ifndef NULLTERM
30 #define NULLTERM 1
31 #endif
32 
33 #include <hicn/policy.h>
34 
35 #include <hicn/util/ip_address.h>
36 
37 //typedef unsigned int hash_t; //incompatible with vpp
38 
39 /* Netdevice type */
40 
41 #include <net/if.h> // IFNAMSIZ
42 
43 #define foreach_netdevice_type \
44  _(UNDEFINED) \
45  _(LOOPBACK) \
46  _(WIRED) \
47  _(WIFI) \
48  _(CELLULAR) \
49  _(VPN) \
50  _(N)
51 
52 #define MAXSZ_NETDEVICE_TYPE_ 9
53 #define MAXSZ_NETDEVICE_TYPE MAXSZ_NETDEVICE_TYPE_ + NULLTERM
54 
55 typedef enum {
56 #define _(x) NETDEVICE_TYPE_ ## x,
57 foreach_netdevice_type
58 #undef _
59 } netdevice_type_t;
60 
61 extern const char * netdevice_type_str[];
62 
63 
64 /* Netdevice */
65 
73 typedef struct {
74  u32 index;
75  char name[IFNAMSIZ];
76 } netdevice_t;
77 
78 #define NETDEVICE_EMPTY (netdevice_t) { \
79  .index = 0, \
80  .name = {0}, \
81 }
82 
83 netdevice_t * netdevice_create_from_index(u32 index);
84 netdevice_t * netdevice_create_from_name(const char * name);
85 #define netdevice_initialize_from_index netdevice_set_index
86 #define netdevice_initialize_from_name netdevice_set_name
87 void netdevice_free(netdevice_t * netdevice);
88 int netdevice_get_index(const netdevice_t * netdevice, u32 * index);
89 int netdevice_set_index(netdevice_t * netdevice, u32 index);
90 int netdevice_get_name(const netdevice_t * netdevice, const char ** name);
91 int netdevice_set_name(netdevice_t * netdevice, const char * name);
92 int netdevice_update_index(netdevice_t * netdevice);
93 int netdevice_update_name(netdevice_t * netdevice);
94 int netdevice_cmp(const netdevice_t * nd1, const netdevice_t * nd2);
95 
96 #define NETDEVICE_UNDEFINED_INDEX 0
97 
98 /* Face state */
99 
100 #define foreach_face_state \
101  _(UNDEFINED) \
102  _(DOWN) \
103  _(UP) \
104  _(N)
105 
106 
107 #define MAXSZ_FACE_STATE_ 9
108 #define MAXSZ_FACE_STATE MAXSZ_FACE_STATE_ + 1
109 
110 typedef enum {
111 #define _(x) FACE_STATE_ ## x,
112 foreach_face_state
113 #undef _
114 } face_state_t;
115 
116 extern const char * face_state_str[];
117 
118 
119 /* Face type */
120 
121 #define foreach_face_type \
122  _(UNDEFINED) \
123  _(HICN) \
124  _(HICN_LISTENER) \
125  _(TCP) \
126  _(TCP_LISTENER) \
127  _(UDP) \
128  _(UDP_LISTENER) \
129  _(N)
130 
131 #define MAXSZ_FACE_TYPE_ 13
132 #define MAXSZ_FACE_TYPE MAXSZ_FACE_TYPE_ + 1
133 
134 typedef enum {
135 #define _(x) FACE_TYPE_ ## x,
136 foreach_face_type
137 #undef _
138 } face_type_t;
139 
140 extern const char * face_type_str[];
141 
142 #ifdef WITH_POLICY
143 #define MAXSZ_FACE_ MAXSZ_FACE_TYPE_ + 2 * MAXSZ_URL_ + 2 * MAXSZ_FACE_STATE_ + MAXSZ_POLICY_TAGS_ + 7
144 #else
145 #define MAXSZ_FACE_ MAXSZ_FACE_TYPE_ + 2 * MAXSZ_URL_ + 2 * MAXSZ_FACE_STATE_ + 4
146 #endif /* WITH_POLICY */
147 #define MAXSZ_FACE MAXSZ_FACE_ + 1
148 
149 /* Face */
150 
151 typedef u32 face_id_t;
152 
153 typedef struct {
154  face_type_t type;
155  face_state_t admin_state;
156  face_state_t state;
157 #ifdef WITH_POLICY
158  uint32_t priority;
159  policy_tags_t tags;
160 #endif /* WITH_POLICY */
161 
162  /*
163  * Depending on the face type, some of the following fields will be unused
164  */
165  netdevice_t netdevice;
166  int family; /* To access family independently of face type */
167  ip_address_t local_addr;
168  ip_address_t remote_addr;
169  u16 local_port;
170  u16 remote_port;
171 } face_t;
172 
173 int face_initialize(face_t * face);
174 int face_initialize_udp(face_t * face, const char * interface_name,
175  const ip_address_t * local_addr, u16 local_port,
176  const ip_address_t * remote_addr, u16 remote_port,
177  int family);
178 int face_initialize_udp_sa(face_t * face,
179  const char * interface_name,
180  const struct sockaddr * local_addr, const struct sockaddr * remote_addr);
181 
182 face_t * face_create();
183 face_t * face_create_udp(const char * interface_name,
184  const ip_address_t * local_addr, u16 local_port,
185  const ip_address_t * remote_addr, u16 remote_port, int family);
186 face_t * face_create_udp_sa(const char * interface_name,
187  const struct sockaddr * local_addr,
188  const struct sockaddr * remote_addr);
189 
190 int face_finalize(face_t * face);
191 
192 void face_free(face_t * face);
193 
194 typedef int (*face_cmp_t)(const face_t * f1, const face_t * f2);
195 
196 int face_cmp(const face_t * f1, const face_t * f2);
197 unsigned int face_hash(const face_t * face);
198 
199 size_t
200 face_snprintf(char * s, size_t size, const face_t * face);
201 
202 policy_tags_t face_get_tags(const face_t * face);
203 int face_set_tags(face_t * face, policy_tags_t tags);
204 
205 #endif /* HICN_FACE_H */
206 
policy.h
Policy description.
face_t
Definition: face.h:153
ip_address_t
Definition: ip_address.h:68
netdevice_t
Netdevice type.
Definition: face.h:73