Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
api_private.h
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 
16 #ifndef HICN_API_PRIVATE_H
17 #define HICN_API_PRIVATE_H
18 
19 #include <hicn/ctrl/api.h>
20 #include <hicn/ctrl/commands.h>
21 #include <hicn/util/token.h>
22 #include <hicn/util/log.h>
23 #include <hicn/util/map.h>
24 
25 #define INT_CMP(x, y) ((x > y) ? 1 : (x < y) ? -1 : 0)
26 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(*array))
27 
28 #if 0
29 #ifdef __APPLE__
30 #define RANDBYTE() (u8)(arc4random() & 0xFF)
31 #else
32 #define RANDBYTE() (u8)(random() & 0xFF)
33 #endif
34 #endif
35 #define RANDBYTE() (u8)(rand() & 0xFF)
36 
37 hc_connection_type_t
38 connection_type_from_str(const char * str);
39 
40 extern const hc_connection_type_t map_from_list_connections_type[];
41 extern const hc_connection_type_t map_from_encap_type[];
42 extern const connection_type map_to_connection_type[];
43 extern const listener_mode map_to_listener_mode[];
44 extern const hc_connection_state_t map_from_list_connections_state[];
45 extern const int map_from_addr_type[];
46 extern const address_type map_to_addr_type[];
47 extern const char * connection_state_str[];
48 extern const char * connection_type_str[];
49 
50 typedef enum {
51  ENCAP_TCP,
52  ENCAP_UDP,
55  ENCAP_HICN
56 } EncapType;
57 
58 #define connection_state_to_face_state(x) ((face_state_t)(x))
59 #define face_state_to_connection_state(x) ((hc_connection_state_t)(x))
60 
61 #define IS_VALID_ADDR_TYPE(x) ((x >= ADDR_INET) && (x <= ADDR_UNIX))
62 
63 #define IS_VALID_CONNECTION_TYPE(x) IS_VALID_ENUM_TYPE(CONNECTION_TYPE, x)
64 
65 typedef struct hc_sock_impl_s hc_sock_impl_t;
66 
67 int hc_data_ensure_available(hc_data_t * data, size_t count);
68 u8 *hc_data_get_next(hc_data_t * data);
69 int hc_data_set_error(hc_data_t * data);
70 
71 int
72 hc_connection_parse_to_face(void * in, hc_face_t * face);
73 
74 int
75 hc_listener_to_face(const hc_listener_t * listener, hc_face_t * face);
76 
77 int
78 hc_connection_to_face(const hc_connection_t * connection, hc_face_t * face);
79 
80 int
81 hc_face_to_listener(const hc_face_t * face, hc_listener_t * listener);
82 
83 int
84 hc_connection_to_local_listener(const hc_connection_t * connection, hc_listener_t * listener);
85 
86 int
87 hc_face_to_connection(const hc_face_t * face, hc_connection_t * connection, bool generate_name);
88 
89 struct hc_sock_s {
90  int (*hc_sock_get_next_seq)(hc_sock_t *s);
91  int (*hc_sock_set_nonblocking)(hc_sock_t *s);
92  int (*hc_sock_get_fd)(hc_sock_t *s);
93  int (*hc_sock_connect)(hc_sock_t *s);
94  int (*hc_sock_get_available)(hc_sock_t *s, u8 **buffer, size_t *size);
95  int (*hc_sock_send)(hc_sock_t *s, hc_msg_t *msg, size_t msglen, int seq);
96  int (*hc_sock_recv)(hc_sock_t *s);
97  int (*hc_sock_process)(hc_sock_t *s, hc_data_t **data);
98  int (*hc_sock_callback)(hc_sock_t *s, hc_data_t **data);
99  int (*hc_sock_reset)(hc_sock_t *s);
100  void (*hc_sock_free)(hc_sock_t *s);
101 
102  int (*hc_listener_create)(hc_sock_t *s, hc_listener_t *listener);
103  int (*hc_listener_create_async)(hc_sock_t *s, hc_listener_t *listener);
104  int (*hc_listener_get)(hc_sock_t *s, hc_listener_t *listener,
105  hc_listener_t **listener_found);
106  int (*hc_listener_delete)(hc_sock_t *s, hc_listener_t *listener);
107  int (*hc_listener_delete_async)(hc_sock_t *s, hc_listener_t *listener);
108  int (*hc_listener_list)(hc_sock_t *s, hc_data_t **pdata);
109  int (*hc_listener_list_async)(hc_sock_t *s, hc_data_t **pdata);
110  int (*hc_listener_validate)(const hc_listener_t *listener);
111  int (*hc_listener_cmp)(const hc_listener_t *l1, const hc_listener_t *l2);
112  int (*hc_listener_parse)(void *in, hc_listener_t *listener);
113 
114  int (*hc_connection_create)(hc_sock_t *s, hc_connection_t *connection);
115  int (*hc_connection_create_async)(hc_sock_t *s, hc_connection_t *connection);
116  int (*hc_connection_get)(hc_sock_t *s, hc_connection_t *connection,
117  hc_connection_t **connection_found);
118  int (*hc_connection_update_by_id)(hc_sock_t *s, int hc_connection_id,
119  hc_connection_t *connection);
120  int (*hc_connection_update)(hc_sock_t *s, hc_connection_t *connection_current,
121  hc_connection_t *connection_updated);
122  int (*hc_connection_delete)(hc_sock_t *s, hc_connection_t *connection);
123  int (*hc_connection_delete_async)(hc_sock_t *s, hc_connection_t *connection);
124  int (*hc_connection_list)(hc_sock_t *s, hc_data_t **pdata);
125  int (*hc_connection_list_async)(hc_sock_t *s, hc_data_t **pdata);
126  int (*hc_connection_validate)(const hc_connection_t *connection);
127  int (*hc_connection_cmp)(const hc_connection_t *c1, const hc_connection_t *c2);
128  int (*hc_connection_parse)(void *in, hc_connection_t *connection);
129  int (*hc_connection_set_admin_state)(hc_sock_t * s, const char * conn_id_or_name, face_state_t state);
130  int (*hc_connection_set_admin_state_async)(hc_sock_t * s, const char * conn_id_or_name, face_state_t state);
131 
132 #ifdef WITH_POLICY
133  int (*hc_connection_set_priority)(hc_sock_t * s, const char * conn_id_or_name, uint32_t priority);
134  int (*hc_connection_set_priority_async)(hc_sock_t * s, const char * conn_id_or_name, uint32_t priority);
135  int (*hc_connection_set_tags)(hc_sock_t * s, const char * conn_id_or_name, policy_tags_t tags);
136  int (*hc_connection_set_tags_async)(hc_sock_t * s, const char * conn_id_or_name, policy_tags_t tags);
137 #endif // WITH_POLICY
138 
139  int (*hc_connection_snprintf)(char *s, size_t size,
140  const hc_connection_t *connection);
141 
142  int (*hc_face_create)(hc_sock_t *s, hc_face_t *face);
143  int (*hc_face_get)(hc_sock_t *s, hc_face_t *face, hc_face_t **face_found);
144  int (*hc_face_delete)(hc_sock_t *s, hc_face_t *face);
145  int (*hc_face_list)(hc_sock_t *s, hc_data_t **pdata);
146  int (*hc_face_list_async)(hc_sock_t *s);
147  int (*hc_face_set_admin_state)(hc_sock_t * s, const char * conn_id_or_name, face_state_t state);
148  int (*hc_face_set_admin_state_async)(hc_sock_t * s, const char * conn_id_or_name, face_state_t state);
149 
150 #ifdef WITH_POLICY
151  int (*hc_face_set_priority)(hc_sock_t * s, const char * conn_id_or_name, uint32_t priority);
152  int (*hc_face_set_priority_async)(hc_sock_t * s, const char * conn_id_or_name, uint32_t priority);
153  int (*hc_face_set_tags)(hc_sock_t * s, const char * conn_id_or_name, policy_tags_t tags);
154  int (*hc_face_set_tags_async)(hc_sock_t * s, const char * conn_id_or_name, policy_tags_t tags);
155 #endif // WITH_POLICY
156 
157  int (*hc_face_snprintf)(char *s, size_t size, hc_face_t *face);
158 
159  int (*hc_route_parse)(void *in, hc_route_t *route);
160  int (*hc_route_create)(hc_sock_t * s, hc_route_t * route);
161  int (*hc_route_create_async)(hc_sock_t * s, hc_route_t * route);
162  int (*hc_route_delete)(hc_sock_t * s, hc_route_t * route);
163  int (*hc_route_delete_async)(hc_sock_t * s, hc_route_t * route);
164  int (*hc_route_list)(hc_sock_t * s, hc_data_t ** pdata);
165  int (*hc_route_list_async)(hc_sock_t * s);
166 
167  int (*hc_punting_create)(hc_sock_t *s, hc_punting_t *punting);
168  int (*hc_punting_create_async)(hc_sock_t *s, hc_punting_t *punting);
169  int (*hc_punting_get)(hc_sock_t *s, hc_punting_t *punting,
170  hc_punting_t **punting_found);
171  int (*hc_punting_delete)(hc_sock_t *s, hc_punting_t *punting);
172  int (*hc_punting_list)(hc_sock_t *s, hc_data_t **pdata);
173  int (*hc_punting_validate)(const hc_punting_t *punting);
174  int (*hc_punting_cmp)(const hc_punting_t *c1, const hc_punting_t *c2);
175  int (*hc_punting_parse)(void *in, hc_punting_t *punting);
176 
177  int (*hc_cache_set_store)(hc_sock_t *s, int enabled);
178  int (*hc_cache_set_serve)(hc_sock_t *s, int enabled);
179  int (*hc_cache_set_store_async)(hc_sock_t *s, int enabled);
180  int (*hc_cache_set_serve_async)(hc_sock_t *s, int enabled);
181 
182  int (*hc_strategy_list)(hc_sock_t *s, hc_data_t **data);
183  int (*hc_strategy_snprintf)(char *s, size_t size, hc_strategy_t *strategy);
184  int (*hc_strategy_set)(hc_sock_t *s /* XXX */);
185 
186  int (*hc_wldr_set)(hc_sock_t *s /* XXX */);
187 
188  int (*hc_mapme_set)(hc_sock_t *s, int enabled);
189  int (*hc_mapme_set_discovery)(hc_sock_t *s, int enabled);
190  int (*hc_mapme_set_timescale)(hc_sock_t *s, double timescale);
191  int (*hc_mapme_set_retx)(hc_sock_t *s, double timescale);
192 
193 #ifdef WITH_POLICY
194  int (*hc_policy_parse)(void *in, hc_policy_t *policy);
195  int (*hc_policy_create)(hc_sock_t *s, hc_policy_t *policy);
196  int (*hc_policy_create_async)(hc_sock_t *s, hc_policy_t *policy);
197  int (*hc_policy_delete)(hc_sock_t *s, hc_policy_t *policy);
198  int (*hc_policy_delete_async)(hc_sock_t *s, hc_policy_t *policy);
199  int (*hc_policy_list)(hc_sock_t *s, hc_data_t **pdata);
200  int (*hc_policy_list_async)(hc_sock_t *s, hc_data_t **pdata);
201  int (*hc_policy_snprintf)(char *s, size_t size, hc_policy_t *policy);
202 #endif // WITH_POLICY
203 
204  // Reference to module containing the implementation
205  void *handle;
206 };
207 
208 #endif // HICN_API_PRIVATE_H
hc_data_s
Holds the results of an hICN control request.
Definition: api.h:132
hc_strategy_t
Definition: api.h:693
ENCAP_ETHER
@ ENCAP_ETHER
Definition: listener.h:39
ENCAP_UDP
@ ENCAP_UDP
Definition: listener.h:38
hc_face_t
Definition: api.h:577
EncapType
EncapType
Definition: listener.h:36
hc_connection_t
Definition: api.h:512
ENCAP_LOCAL
@ ENCAP_LOCAL
Definition: listener.h:40
hc_punting_t
Definition: api.h:654
hc_route_t
Definition: api.h:621
hc_sock_s
Definition: api_private.h:89
hc_msg_t
struct hc_msg_s hc_msg_t
hICN control message header
Definition: api.h:120
api.h
hICN control library API
ENCAP_TCP
@ ENCAP_TCP
Definition: listener.h:37
hc_listener_t
Definition: api.h:472