aboutsummaryrefslogtreecommitdiffstats
path: root/metis/ccnx/forwarder/metis/core/metis_Connection.h
blob: 8dfa119aa082bc2015bd4c0074c5fdeef018baf1 (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
/*
 * 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 metis_Connection.h
 * @brief Wrapper for different types of connections
 *
 * A connection wraps a specific set of {@link MetisIoOperations}.  Those operations
 * allow for input and output.  Connections get stored in the Connection Table.
 *
 */

#ifndef Metis_metis_Connection_h
#define Metis_metis_Connection_h
#include <config.h>
#include <ccnx/api/control/cpi_Address.h>
#include <ccnx/forwarder/metis/core/metis_Message.h>
#include <ccnx/forwarder/metis/io/metis_IoOperations.h>

//packet types for probing
#define METIS_PACKET_TYPE_PROBE_REQUEST 5
#define METIS_PACKET_TYPE_PROBE_REPLY 6

struct metis_connection;
typedef struct metis_connection MetisConnection;


/**
 * Creates a connection object.
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
MetisConnection *metisConnection_Create(MetisIoOperations *ops);

/**
 * @function metisConnection_Release
 * @abstract Releases a reference count, destroying on last release
 * @discussion
 *   Only frees the memory on the final reference count.  The pointer will
 *   always be NULL'd.
 *
 * @param <#param1#>
 * @return <#return#>
 */
void metisConnection_Release(MetisConnection **connectionPtr);

/**
 * @function metisConnection_Acquire
 * @abstract A reference counted copy.
 * @discussion
 *   A shallow copy, they share the same memory.
 *
 * @param <#param1#>
 * @return <#return#>
 */
MetisConnection *metisConnection_Acquire(MetisConnection *connection);

/**
 * @function metisConnection_Send
 * @abstract Sends the ccnx message on the connection
 * @discussion
 *
 * @param <#param1#>
 * @return true if message sent, false if connection not up
 */
bool metisConnection_Send(const MetisConnection *conn, MetisMessage *message);

/**
 * Return the `MetisIoOperations` instance associated with the specified `MetisConnection` instance.
 *
 * @param [in] connection The allocated connection
 *
 * @return a pointer to the MetisIoOperations instance associated by th specified connection.
 *
 * Example:
 * @code
 * {
 *     MetisIoOperations *ioOps = metisConnection_GetIoOperations(conn);
 * }
 * @endcode
 */
MetisIoOperations *metisConnection_GetIoOperations(const MetisConnection *conn);

/**
 * Returns the unique identifier of the connection
 *
 * Calls the underlying MetisIoOperations to fetch the connection id
 *
 * @param [in] connection The allocated connection
 *
 * @return unsigned The unique connection id
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
unsigned metisConnection_GetConnectionId(const MetisConnection *conn);

/**
 * Returns the (remote, local) address pair that describes the connection
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [in] connection The allocated connection
 *
 * @return non-null The connection's remote and local address
 * @return null Should never return NULL
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
const MetisAddressPair *metisConnection_GetAddressPair(const MetisConnection *conn);

/**
 * Tests if the connection is in the "up" state
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [in] connection The allocated connection
 *
 * @return true The connection is in the "up" state
 * @return false The connection is not in the "up" state
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
bool metisConnection_IsUp(const MetisConnection *conn);

/**
 * Tests if the connection is to a Local/Loopback address
 *
 * A local connection is PF_LOCAL (PF_UNIX) and a loopback connection is
 * 127.0.0.0/8 or ::1 for IPv6.
 *
 * @param [in] connection The allocated connection
 *
 * @retval true The connection is local or loopback
 * @retval false The connection is not local or loopback
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
bool metisConnection_IsLocal(const MetisConnection *conn);

/**
 * Returns an opaque pointer representing the class of the Io Operations
 *
 * Returns an opaque pointer that an implementation can use to detect if
 * the connection is based on that class.
 *
 * @param [in] conn The MetisConnection to test
 *
 * @return non-null An opaque pointer for each concrete implementation
 *
 * Example:
 * @code
 * {
 *    bool
 *    metisEtherConnection_IsClass(const MetisConnection *conn)
 *    {
 *        bool result = false;
 *        const void *class = metisConnection_Class(conn);
 *        if (class == _metisIoOperationsGuid) {
 *            result = true;
 *        }
 *        return result;
 *    }
 *
 *    MetisHopByHopFragmenter *
 *    metisEtherConnection_GetFragmenter(const MetisConnection *conn)
 *    {
 *        MetisHopByHopFragmenter *fragmenter = NULL;
 *
 *        if (metisEtherConnection_IsClass(conn)) {
 *            MetisIoOperations *ops = metisConnection_GetIoOperations(conn);
 *            _MetisEtherState *state = (_MetisEtherState *) ops->context;
 *            fragmenter = state->fragmenter;
 *        }
 *        return fragmenter;
 *    }
 * }
 * @endcode
 */
const void *metisConnection_Class(const MetisConnection *conn);

bool metisConnection_ReSend(const MetisConnection *conn, MetisMessage *message);

void metisConnection_Probe(MetisConnection *conn);
void metisConnection_HandleProbe(MetisConnection *conn, uint8_t *message, MetisTicks actualTime);
uint64_t metisConnection_GetDelay(MetisConnection *conn);
void metisConnection_EnableWldr(MetisConnection *conn);
void metisConnection_DisableWldr(MetisConnection *conn);
bool metisConnection_HasWldr(const MetisConnection *conn);
void metisConnection_DetectLosses(MetisConnection *conn, MetisMessage *message);

#endif // Metis_metis_Connection_h