aboutsummaryrefslogtreecommitdiffstats
path: root/libccnx-transport-rta/ccnx/api/control/cpi_Connection.h
blob: dea866e8aca8cfe339b229547bfc75803b66c6d9 (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
/*
 * 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 cpi_Connection.h
 * @brief Represents a point-to-point tunnel over IP.
 *
 * The carries can be UDP, TCP, or GRE
 *
 * We use InterfaceGeneric to back this type.  We always use 2 addresses in the address list.
 * Address 0 is the source and address 1 is the destination.
 *
 */
#ifndef libccnx_cpi_Connection_h
#define libccnx_cpi_Connection_h

#include <ccnx/api/control/cpi_InterfaceType.h>
#include <ccnx/api/control/cpi_Address.h>

struct cpi_connection;
typedef struct cpi_connection CPIConnection;

typedef enum {
    cpiConnection_GRE,
    cpiConnection_TCP,
    cpiConnection_UDP,
    cpiConnection_MULTICAST,
    cpiConnection_L2
} CPIConnectionType;

/**
 * Return a static, nul-terminated C string representing the given `CPIConnectionType`
 *
 * @param type A valid CPIConnectionType value.
 * @return A static, nul-terminated C string
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
const char *cpiConnectionType_ToString(CPIConnectionType type);

/**
 * <#OneLineDescription#>
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
CPIConnectionType cpiConnectionType_FromString(const char *typeAsString);

/**
 * <#OneLineDescription#>
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
PARCBufferComposer *cpiConnectionType_BuildString(CPIConnectionType type, PARCBufferComposer *composer);

/**
 * A representation of a Connection, being two addresses and a type
 *
 *   <#Discussion#>
 *
 * @param ifidx The interface index
 * @param source is the local address
 * @param destination is the remote address
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
CPIConnection *cpiConnection_Create(unsigned ifidx, CPIAddress *source, CPIAddress *destination, CPIConnectionType connType);


CPIConnection *cpiConnection_Acquire(const CPIConnection *conn);

/**
 * Creates a reference counted copy
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return An allocated copy, you must destroy it
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
CPIConnection *cpiConnection_Copy(const CPIConnection *conn);

/**
 * Reference counted release
 *
 *   Only on the last reference will the call free the contents.
 *
 * @param <#param1#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void cpiConnection_Release(CPIConnection **connPtr);

/**
 * A connection may be up, down, or don't know state.
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void cpiConnection_SetState(CPIConnection *conn, CPIInterfaceStateType state);

/**
 * Returns the interface index
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return The interface index
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
unsigned cpiConnection_GetIndex(const CPIConnection *conn);

/**
 * The source address
 *
 *   This is not a copy, it is the pointer to what is in the object.  If you
 *   want to save it, make a copy.
 *
 * @param <#param1#>
 * @return Do not destroy it.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
const CPIAddress *cpiConnection_GetSourceAddress(const CPIConnection *conn);

/**
 * The destination (remote) address
 *
 *   This is not a copy, it is the pointer to what is in the object.  If you
 *   want to save it, make a copy.
 *
 * @param <#param1#>
 * @return Do not destroy it.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
const CPIAddress *cpiConnection_GetDestinationAddress(const CPIConnection *conn);

/**
 * The type of connection
 *
 *   A connection may be a TCP tunnel, UDP tunnel, IP multicast overlay,
 *   PF_LOCAL connection, or a layer 2 connection.
 *
 * @param <#param1#>
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
CPIConnectionType         cpiConnection_GetConnectionType(const CPIConnection *conn);

/**
 * The connection state, Up, Down, or Don't Know
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
CPIInterfaceStateType  cpiConnection_GetState(const CPIConnection *conn);

/**
 * Determine if two CPIConnection instances are equal.
 *
 * Two CPIConnection instances are equal if, and only if,
 * (a) the interface index is the same, (b) the connection types are the same,
 * (c) the connection state is the same, (d) the source address are the same, and
 * (e) the destination addresses are the same.
 *
 * The following equivalence relations on non-null `CPIConnection` instances are maintained:
 *
 *  * It is reflexive: for any non-null reference value x, `CPIConnection_Equals(x, x)`
 *      must return true.
 *
 *  * It is symmetric: for any non-null reference values x and y,
 *    `cpiConnection_Equals(x, y)` must return true if and only if
 *        `cpiConnection_Equals(y, x)` returns true.
 *
 *  * It is transitive: for any non-null reference values x, y, and z, if
 *        `cpiConnection_Equals(x, y)` returns true and
 *        `cpiConnection_Equals(y, z)` returns true,
 *        then  `cpiConnection_Equals(x, z)` must return true.
 *
 *  * It is consistent: for any non-null reference values x and y, multiple
 *      invocations of `cpiConnection_Equals(x, y)` consistently return true or
 *      consistently return false.
 *
 *  * For any non-null reference value x, `cpiConnection_Equals(x, NULL)` must
 *      return false.
 *
 * @param a A pointer to a `CPIConnection` instance.
 * @param b A pointer to a `CPIConnection` instance.
 * @return true if the two `CPIConnection` instances are equal.
 *
 * Example:
 * @code
 * {
 *    CPIConnection *a = cpiConnection_Create();
 *    CPIConnection *b = cpiConnection_Create();
 *
 *    if (cpiConnection_Equals(a, b)) {
 *        // true
 *    } else {
 *        // false
 *    }
 * }
 * @endcode
 */
bool cpiConnection_Equals(const CPIConnection *a, const CPIConnection *b);

/**
 * A JSON representation of the connection
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return An allocated object that you must destroy
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
PARCJSON *cpiConnection_ToJson(const CPIConnection *conn);

/**
 * Creates a Connection object based on a JSON representation.
 *
 *   Will assert if there's a parsing error
 *
 * @param <#param1#>
 * @return An allocated connection that you must destroy
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
CPIConnection *cpiConnection_CreateFromJson(PARCJSON *json);

/**
 * <#OneLineDescription#>
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
char *cpiConnection_ToString(const CPIConnection *connection);
#endif // libccnx_cpi_Connection_h