aboutsummaryrefslogtreecommitdiffstats
path: root/metis/ccnx/forwarder/metis/core/metis_Forwarder.h
blob: b3240dc66cbd55f4a3aea15a246b3ecf54e7ed32 (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
/*
 * 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.
 */


/*
 * The methods in this header are for the non-threaded forwarder.  They should only be called
 * within the forwarders thread of execution.
 */

#ifndef Metis_metis_Forwarder_h
#define Metis_metis_Forwarder_h

#include <sys/time.h>
#include <stdlib.h>

#include <ccnx/api/control/cpi_RouteEntry.h>

#include <ccnx/forwarder/metis/messenger/metis_Messenger.h>
#include <ccnx/forwarder/metis/core/metis_Dispatcher.h>
#include <ccnx/forwarder/metis/core/metis_ConnectionTable.h>

#include <ccnx/forwarder/metis/core/metis_Message.h>
#include <ccnx/forwarder/metis/core/metis_Ticks.h>
#include <ccnx/forwarder/metis/core/metis_Logger.h>
#include <ccnx/forwarder/metis/io/metis_ListenerSet.h>

#include <ccnx/forwarder/metis/processor/metis_FibEntryList.h>

#include <parc/algol/parc_Clock.h>


#define PORT_NUMBER 9695
#define PORT_NUMBER_AS_STRING "9695"

// ==============================================

struct metis_forwarder;
typedef struct metis_forwarder MetisForwarder;

// needs to be after the definition of MetisForwarder
#include <ccnx/forwarder/metis/config/metis_Configuration.h>

/**
 * @function metisForwarder_Create
 * @abstract Create the forwarder and use the provided logger for diagnostic output
 * @discussion
 *   If the logger is null, Metis will create a STDOUT logger.
 *
 * @param logger may be NULL
 * @return <#return#>
 */
MetisForwarder *metisForwarder_Create(MetisLogger *logger);

/**
 * @function metisForwarder_Destroy
 * @abstract Destroys the forwarder, stopping all traffic and freeing all memory
 * @discussion
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return <#return#>
 */
void metisForwarder_Destroy(MetisForwarder **metisPtr);

/**
 * @function metisForwarder_SetupAllListeners
 * @abstract Setup all listeners (tcp, udp, local, ether, ip multicast) on all interfaces
 * @discussion
 *   Sets up all listeners on all running interfaces.  This provides a quick and easy
 *   startup, rather than providing a configuration file or programmatic commands.
 *
 * @param port is used by TCP and UDP listeners, in host byte order
 * @param localPath is the AF_UNIX path to use, if NULL no AF_UNIX listener is setup
 */
void metisForwarder_SetupAllListeners(MetisForwarder *forwarder, uint16_t port, const char *localPath);

/**
 * Configure Metis via a configuration file
 *
 * The configuration file is a set of lines, just like used in metis_control.
 * You need to have "add listener" lines in the file to receive connections.  No default
 * listeners are configured.
 *
 * @param [in] forwarder An alloated MetisForwarder
 * @param [in] filename The path to the configuration file
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void metisForwarder_SetupFromConfigFile(MetisForwarder *forwarder, const char *filename);

/**
 * Returns the logger used by this forwarder
 *
 * If you will store the logger, you should acquire a reference to it.
 *
 * @param [in] metis An allocated Metis forwarder
 *
 * @retval non-null The logger used by Metis
 * @retval null An error
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
MetisLogger *metisForwarder_GetLogger(const MetisForwarder *metis);

/**
 * @function metisForwarder_SetLogLevel
 * @abstract Sets the minimum level to log
 * @discussion
 *   <#Discussion#>
 *
 * @param <#param1#>
 */
void metisForwarder_SetLogLevel(MetisForwarder *metis, PARCLogLevel level);

/**
 * @function metisForwarder_GetNextConnectionId
 * @abstract Get the next identifier for a new connection
 * @discussion
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return <#return#>
 */
unsigned metisForwarder_GetNextConnectionId(MetisForwarder *metis);

MetisMessenger *metisForwarder_GetMessenger(MetisForwarder *metis);

MetisDispatcher *metisForwarder_GetDispatcher(MetisForwarder *metis);

/**
 * Returns the set of currently active listeners
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [in] metis An allocated Metis forwarder
 *
 * @retval non-null The set of active listeners
 * @retval null An error
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
MetisListenerSet *metisForwarder_GetListenerSet(MetisForwarder *metis);

/**
 * Returns the forwrder's connection table
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [in] metis An allocated Metis forwarder
 *
 * @retval non-null The connection tabler
 * @retval null An error
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
MetisConnectionTable *metisForwarder_GetConnectionTable(MetisForwarder *metis);

/**
 * Returns a Tick-based clock
 *
 * Runs at approximately 1 msec per tick (see METISHZ in metis_Forwarder.c).
 * Do not Release this clock.  If you save a copy of it, create your own
 * reference to it with parcClock_Acquire().
 *
 * @param [in] metis An allocated Metis forwarder
 *
 * @retval non-null An allocated Metis Clock based on the Tick counter
 * @retval null An error
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
PARCClock *metisForwarder_GetClock(const MetisForwarder *metis);

/**
 * Direct call to get the Tick clock
 *
 * Runs at approximately 1 msec per tick (see METISHZ in metis_Forwarder.c)
 *
 * @param [in] metis An allocated Metis forwarder
 *
 * @retval <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
MetisTicks metisForwarder_GetTicks(const MetisForwarder *metis);

/**
 * Convert nano seconds to Ticks
 *
 * Converts nano seconds to Ticks, based on METISHZ (in metis_Forwarder.c)
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @retval <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
MetisTicks metisForwarder_NanosToTicks(uint64_t nanos);


uint64_t metisForwarder_TicksToNanos(MetisTicks ticks);

void metisForwarder_Receive(MetisForwarder *metis, MetisMessage *mesage);

/**
 * @function metisForwarder_AddOrUpdateRoute
 * @abstract Adds or updates a route on all the message processors
 * @discussion
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return <#return#>
 */
bool metisForwarder_AddOrUpdateRoute(MetisForwarder *metis, CPIRouteEntry *route);

/**
 * @function metisForwarder_RemoveRoute
 * @abstract Removes a route from all the message processors
 * @discussion
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return <#return#>
 */
bool metisForwarder_RemoveRoute(MetisForwarder *metis, CPIRouteEntry *route);

/**
 * Removes a connection id from all routes
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void metisForwarder_RemoveConnectionIdFromRoutes(MetisForwarder *metis, unsigned connectionId);

/**
 * @function metisForwarder_GetConfiguration
 * @abstract The configuration object
 * @discussion
 *   The configuration contains all user-issued commands.  It does not include dynamic state.
 *
 * @param <#param1#>
 * @return <#return#>
 */
MetisConfiguration *metisForwarder_GetConfiguration(MetisForwarder *metis);

MetisFibEntryList *metisForwarder_GetFibEntries(MetisForwarder *metis);

/**
 * Sets the maximum number of content objects in the content store
 *
 * Implementation dependent - may wipe the cache.
 *
 * @param [<#in out in,out#>] <#name#> <#description#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void metisForwarder_SetContentObjectStoreSize(MetisForwarder *metis, size_t maximumContentStoreSize);

// ========================
// Functions to manipulate the event dispatcher

#include <ccnx/forwarder/metis/processor/metis_Tap.h>

/**
 * @function metisForwarder_AddTap
 * @abstract Add a diagnostic tap to see message events.
 * @discussion
 *   There can only be one tap at a time.  The most recent add wins.
 *
 * @param <#param1#>
 */
void metisForwarder_AddTap(MetisForwarder *metis, MetisTap *tap);

/**
 * @function metisForwarder_RemoveTap
 * @abstract Removes a message tap, no effect if it was not in effect
 * @discussion
 *   <#Discussion#>
 *
 * @param <#param1#>
 */
void metisForwarder_RemoveTap(MetisForwarder *metis, MetisTap *tap);

void metisForwarder_SetChacheStoreFlag(MetisForwarder *metis, bool val);

bool metisForwarder_GetChacheStoreFlag(MetisForwarder *metis);

void metisForwarder_SetChacheServeFlag(MetisForwarder *metis, bool val);

bool metisForwarder_GetChacheServeFlag(MetisForwarder *metis);

void metisForwarder_ClearCache(MetisForwarder *metis);

void metisForwarder_SetStrategy(MetisForwarder *metis, CCNxName *prefix, const char *strategy);

#endif // Metis_metis_Forwarder_h