aboutsummaryrefslogtreecommitdiffstats
path: root/libccnx-transport-rta/ccnx/transport/transport_rta/core/rta_Connection.h
blob: 8619ef96c8353b08a4c26db53203f35b827944a0 (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
457
/*
 * 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 rta_Connection.h
 * @brief <#Brief Description#>
 *
 * A connection embodies an API connection to the forwarder.  Multiple
 * connections are multiplexed over one stack.  A connection, however,
 * is largely independent of a particular stack.  All the RTA connections
 * are stored in RtaConnectionTable, which is managed by the Framework.
 *
 * A problem arises using queues between components, because there may
 * be messages in queue that cannot be free'd without slogging through
 * all the queues.
 *
 * Therefore, a connection tracks the number of messages in queue and
 * will not be freed until all messages in queue are flushed.
 *
 * A connection carries an "isopen" flag.  If it is false, no new
 * messages can go in to the connection.  Any message dequeued that
 * references a closed connection discarded.
 *
 * Once the connection reaches 0 messages in queue, if it is closed,
 * it is elegible for garbage collection.  componentServq will call
 * the _Destroy() method.  Destroy() only works if the refcount for
 * the connection is 0.  If the ProtocolStack still has a reference
 * to the connection, the connection will not be destroyed until
 * the protocol stack calls Destroy.
 *
 * A Connection may live longer than its protocol stack.  In the _Destroy,
 * it should not make reference to the protocol stack.
 *
 */
#ifndef Libccnx_Rta_Connection_h
#define Libccnx_Rta_Connection_h

#include <sys/queue.h>
#include <ccnx/transport/common/transport.h>
#include <ccnx/transport/transport_rta/core/components.h>
#include <ccnx/transport/transport_rta/core/rta_ProtocolStack.h>
#include <ccnx/transport/transport_rta/core/rta_ComponentStats.h>
#include <ccnx/transport/transport_rta/commands/rta_CommandOpenConnection.h>

#include <ccnx/api/notify/notify_Status.h>

struct rta_connection;
/**
 *
 * @see rtaConnection_Create
 */
typedef struct rta_connection RtaConnection;

typedef enum {
    CONN_OPEN,
    CONN_CLOSED,
    CONN_PAUSED
} RtaConnectionStateType;

/**
 * Create a connection and set the refcount to 1.  If the connection
 * pointer is stored by multiple entities, they should call
 * IncrementRefcount.  Calling _Destroy() decrements the refcount.
 *
 * transport_fd is our side of the data socketpair provided by rtaTransport.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
RtaConnection *rtaConnection_Create(RtaProtocolStack *stack, const RtaCommandOpenConnection *cmdOpen);

/**
 * Get a reference counted copy
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
RtaConnection *rtaConnection_Copy(RtaConnection *original);

/**
 * Destroys the object if this call decrements the refcount to 0.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void rtaConnection_Destroy(RtaConnection **connPtr);

/**
 * Same as _Destroy, but for using in a TransportMessage Info.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void rtaConnection_FreeFunc(void **voidPtr);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
RtaProtocolStack *rtaConnection_GetStack(RtaConnection *connection);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
RtaFramework *rtaConnection_GetFramework(const RtaConnection *connection);

/**
 *
 * Used to store per-connection state from Open.
 * Should be freed in Close, but you don't need to set it NULL.
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
void rtaConnection_SetPrivateData(RtaConnection *connection, RtaComponents component, void *private);

/**
 * Used to store per-connection state from Open
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
void *rtaConnection_GetPrivateData(RtaConnection *connection, RtaComponents component);

/**
 * Returns the connection state (open, paused, closed)
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
RtaConnectionStateType rtaConnection_GetState(RtaConnection *connection);

/**
 * Sets the connection state
 *
 *   The API connector manages the connection state.  open means all messages
 *   may flow.  Paused means no new messages flow.  closed means all existing
 *   messages will be destroyed.
 *
 * @param <#param1#>
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void rtaConnection_SetState(RtaConnection *connection, RtaConnectionStateType state);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
RtaComponentStats *rtaConnection_GetStats(RtaConnection *connection, RtaComponents component);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
unsigned rtaConnection_IncrementMessagesInQueue(RtaConnection *connection);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
unsigned rtaConnection_DecrementMessagesInQueue(RtaConnection *connection);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
unsigned rtaConnection_MessagesInQueue(RtaConnection *connection);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
unsigned rtaConnection_GetConnectionId(const RtaConnection *connection);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
int rtaConnection_GetStackId(RtaConnection *connection);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
int  rtaConnection_GetApiFd(RtaConnection *connection);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 *
 * @see <#references#>
 */
int  rtaConnection_GetTransportFd(RtaConnection *connection);

/**
 * Creates a status message (see ccnx/api/notify) and sends it up or down the stack.
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
extern void rtaConnection_SendStatus(RtaConnection *connection,
                                     RtaComponents component,
                                     RtaDirection direction,
                                     NotifyStatusCode code,
                                     CCNxName *optionalName,
                                     const char *optionalMessage);

/**
 * Creates a status message (see ccnx/api/notify) and sends it up or down the stack.
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
RtaConnection *rtaConnection_GetFromTransport(TransportMessage *tm);

/**
 * Creates a status message (see ccnx/api/notify) and sends it up or down the stack.
 *
 *   <#Discussion#>
 *
 * @param connection
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
PARCJSON *rtaConnection_GetParameters(RtaConnection *connection);

/**
 * Is the connection blocked in the down direction?
 *
 * Will return true if the connection is not open (DOWN or PAUSED state) or if the
 * given direction is blocked.
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return true Connection blocked, will not accept any more packets in down direction
 * @return false Connection not blocked in down direction
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
bool rtaConnection_BlockedDown(const RtaConnection *connection);

/**
 * Is the connection blocked in the up direction?
 *
 * Will return true if the connection is not open (DOWN or PAUSED state) or if the
 * given direction is blocked.
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return true Connection blocked, will not accept any more packets in up direction
 * @return false Connection not blocked in up direction
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
bool rtaConnection_BlockedUp(const RtaConnection *connection);

void rtaConnection_SetBlockedDown(RtaConnection *connection);
void rtaConnection_ClearBlockedDown(RtaConnection *connection);

void rtaConnection_SetBlockedUp(RtaConnection *connection);
void rtaConnection_ClearBlockedUp(RtaConnection *connection);
#endif