aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h
blob: 3758f0f418b1a6c5259f46515f8a517779fb3e98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
/*
 * 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 commands.h
 * @brief All hicn-light commands: 14 in total.
 *
 * Header and payload in binary format.
 */

#ifndef commands_h
#define commands_h

#ifndef _WIN32
#include <netinet/in.h>
#include <sys/socket.h>
#endif

#include <stdint.h>
#include <stdlib.h>

#include <hicn/util/ip_address.h>
#ifdef WITH_POLICY
#include <hicn/policy.h>
#endif /* WITH_POLICY */

#define SYMBOLIC_NAME_LEN 16
#define MAX_FWD_STRATEGY_RELATED_PREFIXES 10

typedef struct in6_addr ipv6_addr_t;
typedef uint32_t ipv4_addr_t;

typedef enum {
  REQUEST_LIGHT = 0xc0, // this is a command
  RESPONSE_LIGHT,
  ACK_LIGHT,
  NACK_LIGHT,
  LAST_MSG_TYPE_VALUE
} message_type;

typedef enum {
  ADD_LISTENER = 0,
  ADD_CONNECTION,
  LIST_CONNECTIONS,
  ADD_ROUTE,
  LIST_ROUTES,
  REMOVE_CONNECTION,
  REMOVE_LISTENER,
  REMOVE_ROUTE,
  CACHE_STORE,
  CACHE_SERVE,
  CACHE_CLEAR,
  SET_STRATEGY,
  SET_WLDR,
  ADD_PUNTING,
  LIST_LISTENERS,
  MAPME_ENABLE,
  MAPME_DISCOVERY,
  MAPME_TIMESCALE,
  MAPME_RETX,
  MAPME_SEND_UPDATE,
  CONNECTION_SET_ADMIN_STATE,
#ifdef WITH_POLICY
  ADD_POLICY,
  LIST_POLICIES,
  REMOVE_POLICY,
  UPDATE_CONNECTION,
  CONNECTION_SET_PRIORITY,
  CONNECTION_SET_TAGS,
#endif /* WITH_POLICY */
  LAST_COMMAND_VALUE
} command_id;

typedef enum {
  ADDR_INET = 1,
  ADDR_INET6,
  ADDR_LINK,
  ADDR_IFACE,
  ADDR_UNIX /* PF_UNIX */
} address_type;

typedef enum {
  UDP_CONN,
  TCP_CONN,
  GRE_CONN,  // not implemented
  HICN_CONN
} connection_type;

typedef enum { ACTIVATE_ON, ACTIVATE_OFF } activate_type;

//==========    HEADER    ==========

typedef struct {
  uint8_t messageType;
  uint8_t commandID;
  uint16_t length;  // tells the number of structures in the payload
  uint32_t seqNum;
} header_control_message;
// for the moment has to be at least 8 bytes

// SIZE=8

//==========  [00]  ADD LISTENER    ==========

typedef enum { ETHER_MODE, IP_MODE, HICN_MODE } listener_mode;

typedef struct {
  char symbolic[SYMBOLIC_NAME_LEN];
  char interfaceName[SYMBOLIC_NAME_LEN];
  ip_address_t address;
  uint16_t port;
  // uint16_t etherType;
  uint8_t addressType;
  uint8_t listenerMode;
  uint8_t connectionType;
} add_listener_command;

// SIZE=56

//==========  [01]  ADD CONNECTION    ==========

typedef struct {
  char symbolic[SYMBOLIC_NAME_LEN];
  //char interfaceName[SYMBOLIC_NAME_LEN];
  ip_address_t remoteIp;
  ip_address_t localIp;
  uint16_t remotePort;
  uint16_t localPort;
  uint8_t ipType;
  uint8_t connectionType;
  uint8_t admin_state;
#ifdef WITH_POLICY
  uint32_t priority;
  policy_tags_t tags;
#endif /* WITH_POLICY */
} add_connection_command;

// SIZE=56

//==========  [02]  LIST CONNECTIONS    ==========

typedef enum {
  CONN_GRE,
  CONN_TCP,
  CONN_UDP,
  CONN_MULTICAST,
  CONN_L2,
  CONN_HICN
} list_connections_type;

typedef enum {
  IFACE_UP = 0,
  IFACE_DOWN = 1,
  IFACE_UNKNOWN = 2  // not used actually
} connection_state;

typedef struct {
  add_connection_command connectionData;
  uint32_t connid;
  uint8_t state;
  char interfaceName[SYMBOLIC_NAME_LEN];
  char connectionName[SYMBOLIC_NAME_LEN];
} list_connections_command;

// SIZE=80

//==========  [03]  ADD ROUTE    ==========

typedef struct {
  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
  ip_address_t address;
  uint16_t cost;
  uint8_t addressType;
  uint8_t len;
} add_route_command;

// SIZE=36

//==========  [04]  LIST ROUTE    ==========

typedef struct {
  ip_address_t address;
  uint32_t connid;
  uint16_t cost;
  uint8_t addressType;
  uint8_t len;
} list_routes_command;

// SIZE=24

//==========  [05]  REMOVE CONNECTION    ==========
typedef struct {
  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
} remove_connection_command;

//==========  [06]  REMOVE LISTENER    ==========
typedef struct {
  char symbolicOrListenerid[SYMBOLIC_NAME_LEN];
} remove_listener_command;

// SIZE=16

//==========  [07]  REMOVE ROUTE    ==========

typedef struct {
  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
  ip_address_t address;
  uint8_t addressType;
  uint8_t len;
} remove_route_command;

// SIZE=36

//==========  [08]  CACHE STORE    ==========

typedef struct {
  uint8_t activate;
} cache_store_command;

// SIZE=1

//==========  [09]  CACHE SERVE    ==========

typedef struct {
  uint8_t activate;
} cache_serve_command;

// SIZE=1

//==========  [10]  SET STRATEGY    ==========

typedef enum {
  SET_STRATEGY_LOADBALANCER,
  SET_STRATEGY_RANDOM,
  SET_STRATEGY_LOW_LATENCY,
  LAST_STRATEGY_VALUE
} strategy_type;

typedef struct {
  ip_address_t address;
  uint8_t strategyType;
  uint8_t addressType;
  uint8_t len;
  uint8_t related_prefixes;
  ip_address_t addresses[MAX_FWD_STRATEGY_RELATED_PREFIXES];
  uint8_t lens[MAX_FWD_STRATEGY_RELATED_PREFIXES];
  uint8_t addresses_type[MAX_FWD_STRATEGY_RELATED_PREFIXES];
} set_strategy_command;

// SIZE=208

//==========  [11]  SET WLDR    ==========

typedef struct {
  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
  uint8_t activate;
} set_wldr_command;

// SIZE=17

//==========  [12]  ADD PUNTING    ==========

typedef struct {
  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
  ip_address_t address;
  uint8_t addressType;
  uint8_t len;
} add_punting_command;

// SIZE=36

//==========  [13]  LIST LISTENER    ==========

typedef struct {
  ip_address_t address;
  char listenerName[SYMBOLIC_NAME_LEN];
  char interfaceName[SYMBOLIC_NAME_LEN];
  uint32_t connid;
  uint16_t port;
  uint8_t addressType;
  uint8_t encapType;
} list_listeners_command;

// SIZE=56

//==========  [14]  MAPME    ==========

//  (enable/discovery/timescale/retx)

typedef struct {
  uint8_t activate;
} mapme_activator_command;

// SIZE=1

typedef struct {
  uint32_t timePeriod;
} mapme_timing_command;

typedef struct {
  ip_address_t address;
  uint8_t addressType;
  uint8_t len;
} mapme_send_update_command;

// SIZE=1

typedef struct {
  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
  uint8_t admin_state;
  uint8_t pad8[3];
} connection_set_admin_state_command;

#ifdef WITH_POLICY

typedef struct {
  ip_address_t address;
  uint8_t addressType;
  uint8_t len;
  hicn_policy_t policy;
} add_policy_command;

typedef struct {
  ip_address_t address;
  uint8_t addressType;
  uint8_t len;
  hicn_policy_t policy;
} list_policies_command;

typedef struct {
  ip_address_t address;
  uint8_t addressType;
  uint8_t len;
} remove_policy_command;

typedef struct {
  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
  uint8_t admin_state;
  uint32_t priority;
  policy_tags_t tags;
} update_connection_command;

typedef struct {
  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
  uint32_t priority;
} connection_set_priority_command;

typedef struct {
  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
  policy_tags_t tags;
} connection_set_tags_command;

#endif /* WITH_POLICY */

//===== size of commands ======
// REMINDER: when a new_command is added, the following switch has to be
// updated.
static inline int payloadLengthDaemon(command_id id) {
  switch (id) {
    case ADD_LISTENER:
      return sizeof(add_listener_command);
    case ADD_CONNECTION:
      return sizeof(add_connection_command);
    case LIST_CONNECTIONS:
      return 0;  // list connections: payload always 0
    case ADD_ROUTE:
      return sizeof(add_route_command);
    case LIST_ROUTES:
      return 0;  // list routes: payload always 0
    case REMOVE_CONNECTION:
      return sizeof(remove_connection_command);
    case REMOVE_LISTENER:
      return sizeof(remove_listener_command);
    case REMOVE_ROUTE:
      return sizeof(remove_route_command);
    case CACHE_STORE:
      return sizeof(cache_store_command);
    case CACHE_SERVE:
      return sizeof(cache_serve_command);
    case CACHE_CLEAR:
      return 0;  // cache clear
    case SET_STRATEGY:
      return sizeof(set_strategy_command);
    case SET_WLDR:
      return sizeof(set_wldr_command);
    case ADD_PUNTING:
      return sizeof(add_punting_command);
    case LIST_LISTENERS:
      return 0;  // list listeners: payload always 0
    case MAPME_ENABLE:
      return sizeof(mapme_activator_command);
    case MAPME_DISCOVERY:
      return sizeof(mapme_activator_command);
    case MAPME_TIMESCALE:
      return sizeof(mapme_timing_command);
    case MAPME_RETX:
      return sizeof(mapme_timing_command);
    case MAPME_SEND_UPDATE:
      return sizeof(mapme_send_update_command);
    case CONNECTION_SET_ADMIN_STATE:
      return sizeof(connection_set_admin_state_command);
#ifdef WITH_POLICY
    case ADD_POLICY:
      return sizeof(add_policy_command);
    case LIST_POLICIES:
      return 0; // list policies: payload always 0
    case REMOVE_POLICY:
      return sizeof(remove_policy_command);
    case UPDATE_CONNECTION:
      return sizeof(update_connection_command);
    case CONNECTION_SET_PRIORITY:
      return sizeof(connection_set_priority_command);
    case CONNECTION_SET_TAGS:
      return sizeof(connection_set_tags_command);
#endif /* WITH_POLICY */
    case LAST_COMMAND_VALUE:
      return 0;
    default:
      return 0;
  }
}
#endif