aboutsummaryrefslogtreecommitdiffstats
path: root/libccnx-transport-rta/ccnx/api/control/controlPlaneInterface.h
blob: 01b6e861257574d049753e11ac14683e4c861d16 (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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/*
 * Copyright (c) 2017 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 controlPlaneInterface.h
 *
 * Based loosely on Netlink (RFC 3549)
 *
 * Constructs `CCNxControl` for common control plane operations.
 * These methods do not actually communicate with the transport.
 * The user must send the message down their protocol stack and await a response.
 *
 * CPI messages have a Type: Request, Response, or ACK.
 * A request may ask for an ACK if successful for commands that would otherwise not
 * produce a response.
 * Request that fail always generate a NACK.
 *
 * All messages must carry a "sequence number" which must be unique within
 * the Transport.
 * Although sequence numbers imply an ordering, they do not imply
 * causality or precedence.
 * They only imply a duplicate.
 *
 * An ACK is a reponse that carries no data, it just ACKs (or NACKs) a sequence number.
 * A field in the ACK indicates it is an error (NACK).  An ACK carries the original
 * request and an optional message.
 *
 * All messages carry a mandatory sequence number,
 * which is unique in all messages.
 * An ACK (or NACK) contains the original message that generated the ACK,
 * including its sequence number.
 * These conventions allow one to implement a reliable CPI messaging system, if desired.
 *
 * The Control Plane operations are:
 *
 * * CPI_INTERFACE_LIST
 *    Return: A response with an array of network interfaces ("interfaceIndex", type, and flags), or a NACK.
 *
 * * CPI_REGISTER
 *    Add a FIB entry with the given CCNxName prefix to the specified interfaceIndex.
 *    The value of "-1" means the current interface.
 *    Return: an ACK (or NACK)
 *
 * * CPI_UNREGISTER
 *    Remove a FIB entry with the given CCNxName prefix from the specified interfaceIndex.
 *    The value of "-1" means the current interface.
 *    Return: an ACK (or NACK)
 *
 * * CPI_FORWARDER_VERSION:
 *    Return: Response (a string) or a NACK.
 *
 * * CPI_ADDRESS
 *    Request: by interfaceIndex
 *    Response: the sockaddr_storage list for the interface, or a NACK
 *
 * * CPI_PREFIX_REGISTRATION_LIST
 *    Request: by interfaceIndex, value "-1" means the current interface
 *    Response: the list of CCNxNames (with their flags) registered on the interface or a NACK
 *
 * * CPI_PAUSE_INPUT
 *    Request: by current connection, causes stack to pause the input (top and bottom)
 *    Response: Forwarder sends ACK up the stack.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 */
/*
 * This description needs to be revised based on the recent refactoring.
 *
 * The user will be interested in cpi_Forwarding.h and cpi_ManageLinks.h.
 *
 * Case 1027: need to specify the memory management, especially for variable sized messages.
 */

#ifndef libccnx_controlPlaneInterface_h
#define libccnx_controlPlaneInterface_h

#include <ccnx/transport/common/transport_MetaMessage.h>
#include <sys/socket.h>

#include <ccnx/api/control/cpi_ControlMessage.h>
#include <ccnx/api/control/cpi_Forwarding.h>
#include <ccnx/api/control/cpi_ManageLinks.h>
#include <ccnx/api/control/cpi_CancelFlow.h>
#include <ccnx/api/control/cpi_ManageCaches.h>
#include <ccnx/api/control/cpi_ManageWldr.h>

typedef enum {
    CPI_REQUEST,
    CPI_RESPONSE,       // a resonse with contents
    CPI_ACK             // a response without contents
} CpiMessageType;

typedef enum {
    CPI_ERROR,                      // a NACK response, carries original message
    CPI_REGISTER_PREFIX,
    CPI_UNREGISTER_PREFIX,
    CPI_FORWARDER_VERSION,
    CPI_INTERFACE_LIST,
    CPI_ADDRESS,
    CPI_PREFIX_REGISTRATION_LIST,
    CPI_PAUSE,
    CPI_FLUSH,
    CPI_CANCEL_FLOW,
    CPI_CREATE_TUNNEL,
    CPI_REMOVE_TUNNEL,
    CPI_CONNECTION_LIST,
    CPI_ADD_ETHER_CONNECTION,
    CPI_ADD_CONNECTION_ETHERNET,
    CPI_REMOVE_CONNECTION_ETHERNET,
    CPI_ADD_LISTENER,
    CPI_REMOVE_LISTENER,
    CPI_CACHE_STORE_ON,
    CPI_CACHE_STORE_OFF,
    CPI_CACHE_SERVE_ON,
    CPI_CACHE_SERVE_OFF,
    CPI_CACHE_CLEAR,
    CPI_SET_FORWARDING_STRATEGY,
    CPI_SET_WLDR
} CpiOperation;

typedef enum {
    ACK_ACK,
    ACK_NACK
} CpiAckType;

typedef struct control_plane_information {
    CpiMessageType messageType;
    CpiOperation operation;
    uint64_t serialNumber;
} ControlPlaneInformation;


const char *cpiRequest_GetJsonTag();
const char *cpiResponse_GetJsonTag();

/**
 * Return the name used in the JSON representation for a control message sequence number.
 *
 * @return The name used in the JSON representation for a control message sequence number.
 *
 * Example:
 * @code
 * {
 **cpiSequence_GetJSONTag
 * }
 * @endcode
 */
const char *cpiSequence_GetJSONTag(void);

/**
 * Get the CpiOperation from the given JSON representation of the CPI command.
 *
 * @param [in] json A pointer to a valid PARCJSON instance.
 *
 * @return The CpiOperation specified in the JSON.
 *
 * Example:
 * @code
 * {
 *     const char *sequenceNumberJSONName = cpiSequence_GetJSONTag();
 * }
 * @endcode
 *
 * @see <#references#>
 */
CpiOperation cpi_getCPIOperation2(const PARCJSON *json);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [in] control A pointer to a valid CCNxControl instance.
 *
 * @return <#value#> <#explanation#>
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 *
 * @see <#references#>
 */
CpiOperation cpi_GetMessageOperation(CCNxControl *control);

/**
 * Get the CpiMessageType from the given JSON representation of the CPIMessage
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 *
 * @see <#references#>
 */
CpiMessageType controlPlaneInterface_GetCPIMessageType(PARCJSON *json);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 *
 * @see <#references#>
 */
CpiMessageType cpi_GetMessageType(const CCNxControl *control);

/**
 * Get the sequence number of the given Control Plane Message.
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 *
 * @see <#references#>
 */
uint64_t controlPlaneInterface_GetSequenceNumber(const PARCJSON *controlPlaneMessage);

/**
 * All CPI messages carry a sequence number.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
uint64_t cpi_GetSequenceNumber(CCNxControl *control);

/**
 * Gererate a CPI request
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
#define CPI_CURRENT_INTERFACE 0x7FFFFFFF

/**
 * Generate a control object to request the forewarder version
 *
 *   Will cause a CPI Response to be sent back, if the forwarder supports the command.
 *   Otherwise, the ForwarderConnector should send a NACK back.
 *
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
CCNxControl *cpi_ForwarderVersion(void);

/**
 * Cause the connection to pause input (from the top and bottom).
 * When the ACk arrives back to the top, caller know there are no
 * more data messages in the stack.
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 *
 * @see <#references#>
 */
PARCJSON *cpi_CreatePauseInputRequest(void);

/**
 * Creates a message that the forwarder connector will ACK.  Once the
 * ACK with the corresponding sequence number is received, the sender knows
 * that all prior messages had been handled by the forwarder connector.
 *
 * @return non-null An allocted JSON object
 * @return null An error
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 *
 * @see <#references#>
 */
PARCJSON *cpi_CreateFlushRequest(void);

/**
 * Given the inner operation member, wrap it in a Request with a sequence number
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
PARCJSON *cpi_CreateRequest(const char *key, PARCJSON *operation);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
CCNxControl *cpi_CreateResponse(CCNxControl *request, PARCJSON *response);

/**
 * Create an acknowledgement to the given request (expressed in JSON).
 *
 * @param [in] request A pointer to a PARCJSON representation of the request to acknowledge.
 *
 * @return NULL Memory could not be allocated.
 * @return non-NULL A pointer to a PARCJSON instance representing the acknowledgement.
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 *
 * @see <#references#>
 */
PARCJSON *cpiAcks_CreateAck(const PARCJSON *request);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 *
 * @see <#references#>
 */
PARCJSON *cpiAcks_CreateNack(const PARCJSON *request);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 *
 * @see <#references#>
 */
bool cpiAcks_IsAck(const PARCJSON *json);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 *
 * @see <#references#>
 */
uint64_t cpiAcks_GetAckOriginalSequenceNumber(const PARCJSON *json);
#endif // libccnx_controlPlaneInterface_h