Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
commands.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 /*
17  * @file commands.h
18  * @brief All hicn-light commands: 14 in total.
19  *
20  * Header and payload in binary format.
21  */
22 
23 #ifndef commands_h
24 #define commands_h
25 
26 #ifndef _WIN32
27 #include <netinet/in.h>
28 #include <sys/socket.h>
29 #endif
30 
31 #include <stdint.h>
32 #include <stdlib.h>
33 
34 #include <hicn/util/ip_address.h>
35 #ifdef WITH_POLICY
36 #include <hicn/policy.h>
37 #endif /* WITH_POLICY */
38 
39 #define SYMBOLIC_NAME_LEN 16
40 #define MAX_FWD_STRATEGY_RELATED_PREFIXES 10
41 
42 typedef struct in6_addr ipv6_addr_t;
43 typedef uint32_t ipv4_addr_t;
44 
45 typedef enum {
46  REQUEST_LIGHT = 0xc0, // this is a command
47  RESPONSE_LIGHT,
48  ACK_LIGHT,
49  NACK_LIGHT,
50  LAST_MSG_TYPE_VALUE
51 } message_type;
52 
53 typedef enum {
54  ADD_LISTENER = 0,
55  ADD_CONNECTION,
56  LIST_CONNECTIONS,
57  ADD_ROUTE,
58  LIST_ROUTES,
59  REMOVE_CONNECTION,
60  REMOVE_LISTENER,
61  REMOVE_ROUTE,
62  CACHE_STORE,
63  CACHE_SERVE,
64  CACHE_CLEAR,
65  SET_STRATEGY,
66  SET_WLDR,
67  ADD_PUNTING,
68  LIST_LISTENERS,
69  MAPME_ENABLE,
70  MAPME_DISCOVERY,
71  MAPME_TIMESCALE,
72  MAPME_RETX,
73  MAPME_SEND_UPDATE,
74  CONNECTION_SET_ADMIN_STATE,
75 #ifdef WITH_POLICY
76  ADD_POLICY,
77  LIST_POLICIES,
78  REMOVE_POLICY,
79  UPDATE_CONNECTION,
80  CONNECTION_SET_PRIORITY,
81  CONNECTION_SET_TAGS,
82 #endif /* WITH_POLICY */
83  LAST_COMMAND_VALUE
84 } command_id;
85 
86 typedef enum {
87  ADDR_INET = 1,
88  ADDR_INET6,
89  ADDR_LINK,
90  ADDR_IFACE,
91  ADDR_UNIX /* PF_UNIX */
92 } address_type;
93 
94 typedef enum {
95  UDP_CONN,
96  TCP_CONN,
97  GRE_CONN, // not implemented
98  HICN_CONN
99 } connection_type;
100 
101 typedef enum { ACTIVATE_ON, ACTIVATE_OFF } activate_type;
102 
103 //========== HEADER ==========
104 
105 typedef struct {
106  uint8_t messageType;
107  uint8_t commandID;
108  uint16_t length; // tells the number of structures in the payload
109  uint32_t seqNum;
111 // for the moment has to be at least 8 bytes
112 
113 // SIZE=8
114 
115 //========== [00] ADD LISTENER ==========
116 
117 typedef enum { ETHER_MODE, IP_MODE, HICN_MODE } listener_mode;
118 
119 typedef struct {
120  char symbolic[SYMBOLIC_NAME_LEN];
121  char interfaceName[SYMBOLIC_NAME_LEN];
122  ip_address_t address;
123  uint16_t port;
124  // uint16_t etherType;
125  uint8_t addressType;
126  uint8_t listenerMode;
127  uint8_t connectionType;
129 
130 // SIZE=56
131 
132 //========== [01] ADD CONNECTION ==========
133 
134 typedef struct {
135  char symbolic[SYMBOLIC_NAME_LEN];
136  //char interfaceName[SYMBOLIC_NAME_LEN];
137  ip_address_t remoteIp;
138  ip_address_t localIp;
139  uint16_t remotePort;
140  uint16_t localPort;
141  uint8_t ipType;
142  uint8_t connectionType;
143  uint8_t admin_state;
144 #ifdef WITH_POLICY
145  uint32_t priority;
146  policy_tags_t tags;
147 #endif /* WITH_POLICY */
149 
150 // SIZE=56
151 
152 //========== [02] LIST CONNECTIONS ==========
153 
154 typedef enum {
155  CONN_GRE,
156  CONN_TCP,
157  CONN_UDP,
158  CONN_MULTICAST,
159  CONN_L2,
160  CONN_HICN
161 } list_connections_type;
162 
163 typedef enum {
164  IFACE_UP = 0,
165  IFACE_DOWN = 1,
166  IFACE_UNKNOWN = 2 // not used actually
167 } connection_state;
168 
169 typedef struct {
170  add_connection_command connectionData;
171  uint32_t connid;
172  uint8_t state;
173  char interfaceName[SYMBOLIC_NAME_LEN];
174  char connectionName[SYMBOLIC_NAME_LEN];
176 
177 // SIZE=80
178 
179 //========== [03] ADD ROUTE ==========
180 
181 typedef struct {
182  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
183  ip_address_t address;
184  uint16_t cost;
185  uint8_t addressType;
186  uint8_t len;
188 
189 // SIZE=36
190 
191 //========== [04] LIST ROUTE ==========
192 
193 typedef struct {
194  ip_address_t address;
195  uint32_t connid;
196  uint16_t cost;
197  uint8_t addressType;
198  uint8_t len;
200 
201 // SIZE=24
202 
203 //========== [05] REMOVE CONNECTION ==========
204 typedef struct {
205  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
207 
208 //========== [06] REMOVE LISTENER ==========
209 typedef struct {
210  char symbolicOrListenerid[SYMBOLIC_NAME_LEN];
212 
213 // SIZE=16
214 
215 //========== [07] REMOVE ROUTE ==========
216 
217 typedef struct {
218  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
219  ip_address_t address;
220  uint8_t addressType;
221  uint8_t len;
223 
224 // SIZE=36
225 
226 //========== [08] CACHE STORE ==========
227 
228 typedef struct {
229  uint8_t activate;
231 
232 // SIZE=1
233 
234 //========== [09] CACHE SERVE ==========
235 
236 typedef struct {
237  uint8_t activate;
239 
240 // SIZE=1
241 
242 //========== [10] SET STRATEGY ==========
243 
244 typedef enum {
245  SET_STRATEGY_LOADBALANCER,
246  SET_STRATEGY_RANDOM,
247  SET_STRATEGY_LOW_LATENCY,
248  LAST_STRATEGY_VALUE
249 } strategy_type;
250 
251 typedef struct {
252  ip_address_t address;
253  uint8_t strategyType;
254  uint8_t addressType;
255  uint8_t len;
256  uint8_t related_prefixes;
257  ip_address_t addresses[MAX_FWD_STRATEGY_RELATED_PREFIXES];
258  uint8_t lens[MAX_FWD_STRATEGY_RELATED_PREFIXES];
259  uint8_t addresses_type[MAX_FWD_STRATEGY_RELATED_PREFIXES];
261 
262 // SIZE=208
263 
264 //========== [11] SET WLDR ==========
265 
266 typedef struct {
267  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
268  uint8_t activate;
270 
271 // SIZE=17
272 
273 //========== [12] ADD PUNTING ==========
274 
275 typedef struct {
276  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
277  ip_address_t address;
278  uint8_t addressType;
279  uint8_t len;
281 
282 // SIZE=36
283 
284 //========== [13] LIST LISTENER ==========
285 
286 typedef struct {
287  ip_address_t address;
288  char listenerName[SYMBOLIC_NAME_LEN];
289  char interfaceName[SYMBOLIC_NAME_LEN];
290  uint32_t connid;
291  uint16_t port;
292  uint8_t addressType;
293  uint8_t encapType;
295 
296 // SIZE=56
297 
298 //========== [14] MAPME ==========
299 
300 // (enable/discovery/timescale/retx)
301 
302 typedef struct {
303  uint8_t activate;
305 
306 // SIZE=1
307 
308 typedef struct {
309  uint32_t timePeriod;
311 
312 typedef struct {
313  ip_address_t address;
314  uint8_t addressType;
315  uint8_t len;
317 
318 // SIZE=1
319 
320 typedef struct {
321  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
322  uint8_t admin_state;
323  uint8_t pad8[3];
325 
326 #ifdef WITH_POLICY
327 
328 typedef struct {
329  ip_address_t address;
330  uint8_t addressType;
331  uint8_t len;
332  hicn_policy_t policy;
333 } add_policy_command;
334 
335 typedef struct {
336  ip_address_t address;
337  uint8_t addressType;
338  uint8_t len;
339  hicn_policy_t policy;
340 } list_policies_command;
341 
342 typedef struct {
343  ip_address_t address;
344  uint8_t addressType;
345  uint8_t len;
346 } remove_policy_command;
347 
348 typedef struct {
349  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
350  uint8_t admin_state;
351  uint32_t priority;
352  policy_tags_t tags;
353 } update_connection_command;
354 
355 typedef struct {
356  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
357  uint32_t priority;
358 } connection_set_priority_command;
359 
360 typedef struct {
361  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
362  policy_tags_t tags;
363 } connection_set_tags_command;
364 
365 #endif /* WITH_POLICY */
366 
367 //===== size of commands ======
368 // REMINDER: when a new_command is added, the following switch has to be
369 // updated.
370 static inline int payloadLengthDaemon(command_id id) {
371  switch (id) {
372  case ADD_LISTENER:
373  return sizeof(add_listener_command);
374  case ADD_CONNECTION:
375  return sizeof(add_connection_command);
376  case LIST_CONNECTIONS:
377  return 0; // list connections: payload always 0
378  case ADD_ROUTE:
379  return sizeof(add_route_command);
380  case LIST_ROUTES:
381  return 0; // list routes: payload always 0
382  case REMOVE_CONNECTION:
383  return sizeof(remove_connection_command);
384  case REMOVE_LISTENER:
385  return sizeof(remove_listener_command);
386  case REMOVE_ROUTE:
387  return sizeof(remove_route_command);
388  case CACHE_STORE:
389  return sizeof(cache_store_command);
390  case CACHE_SERVE:
391  return sizeof(cache_serve_command);
392  case CACHE_CLEAR:
393  return 0; // cache clear
394  case SET_STRATEGY:
395  return sizeof(set_strategy_command);
396  case SET_WLDR:
397  return sizeof(set_wldr_command);
398  case ADD_PUNTING:
399  return sizeof(add_punting_command);
400  case LIST_LISTENERS:
401  return 0; // list listeners: payload always 0
402  case MAPME_ENABLE:
403  return sizeof(mapme_activator_command);
404  case MAPME_DISCOVERY:
405  return sizeof(mapme_activator_command);
406  case MAPME_TIMESCALE:
407  return sizeof(mapme_timing_command);
408  case MAPME_RETX:
409  return sizeof(mapme_timing_command);
410  case MAPME_SEND_UPDATE:
411  return sizeof(mapme_send_update_command);
412  case CONNECTION_SET_ADMIN_STATE:
413  return sizeof(connection_set_admin_state_command);
414 #ifdef WITH_POLICY
415  case ADD_POLICY:
416  return sizeof(add_policy_command);
417  case LIST_POLICIES:
418  return 0; // list policies: payload always 0
419  case REMOVE_POLICY:
420  return sizeof(remove_policy_command);
421  case UPDATE_CONNECTION:
422  return sizeof(update_connection_command);
423  case CONNECTION_SET_PRIORITY:
424  return sizeof(connection_set_priority_command);
425  case CONNECTION_SET_TAGS:
426  return sizeof(connection_set_tags_command);
427 #endif /* WITH_POLICY */
428  case LAST_COMMAND_VALUE:
429  return 0;
430  default:
431  return 0;
432  }
433 }
434 #endif
add_route_command
Definition: commands.h:181
policy.h
Policy description.
add_connection_command
Definition: commands.h:134
header_control_message
Definition: commands.h:105
list_routes_command
Definition: commands.h:193
ip_address_t
Definition: ip_address.h:68
remove_route_command
Definition: commands.h:217
hicn_policy_t
Definition: policy.h:216
set_strategy_command
Definition: commands.h:251
remove_listener_command
Definition: commands.h:209
cache_store_command
Definition: commands.h:228
add_listener_command
Definition: commands.h:119
list_connections_command
Definition: commands.h:169
cache_serve_command
Definition: commands.h:236
remove_connection_command
Definition: commands.h:204
mapme_timing_command
Definition: commands.h:308
list_listeners_command
Definition: commands.h:286
mapme_send_update_command
Definition: commands.h:312
connection_set_admin_state_command
Definition: commands.h:320
mapme_activator_command
Definition: commands.h:302
add_punting_command
Definition: commands.h:275
set_wldr_command
Definition: commands.h:266