forked from mit-ll/LL-DLEP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProtocolConfig.h
More file actions
452 lines (371 loc) · 18.1 KB
/
ProtocolConfig.h
File metadata and controls
452 lines (371 loc) · 18.1 KB
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
/*
* Dynamic Link Exchange Protocol (DLEP)
*
* Copyright (C) 2015, 2016, 2018 Massachusetts Institute of Technology
*/
/// @file
/// This is the abstract interface to protocol configuration information
/// that the DLEP service library presents to the DLEP client (library user).
/// Clients should include this file indirectly by including DlepInit.h.
#ifndef PROTOCOL_CONFIG_H
#define PROTOCOL_CONFIG_H
#include <cstdint>
#include <string>
#include <array>
#include <vector>
#include "DataItem.h"
// extensions - for ProtocolStrings
#include "LatencyRange.h"
#include "MultiHop.h"
namespace LLDLEP
{
/// This is the abstract interface to protocol configuration
/// information that the DLEP service library presents to the DLEP
/// client (library user). Clients use DlepService::get_protocol_config()
/// to obtain a pointer to a ProtocolConfig object, which can be used
/// until the DlepService terminates. After the ProtocolConfig object
/// is populated from the protocol configuration file(s) at startup by
/// DlepService, it is effectively a read-only object. This means
/// we do not need locking for multithreaded access.
class ProtocolConfig
{
public:
/// @return the configured version number, or (0, 0) if not configured
virtual std::array<std::uint16_t, 2> get_version() const = 0;
//--------------------------------------------------------------------------
//
// Get information about data items
/// @return the number of message bytes used for a data item id
virtual std::size_t get_data_item_id_size() const = 0;
/// @return the number of message bytes used for a data item length
virtual std::size_t get_data_item_length_size() const = 0;
/// Return the data item id for a data item name.
///
/// @param[in] name
/// the data item name for which to find the id
/// @param[in] parent_di_info
/// if \p name belongs to a sub data item, this is a pointer
/// to the parent data item's DataItemInfo. Otherwise,
/// it must be a nullptr.
/// @return the data item id for \p name
/// @throw BadDataItemName if \p name is not a valid data item name
virtual DataItemIdType
get_data_item_id(const std::string & name,
const LLDLEP::DataItemInfo * parent_di_info = nullptr) const = 0;
/// Return the data item name for a data item id.
///
/// @param[in] id
/// the data item id for which to find the name
/// @param[in] parent_di_info
/// if \p id belongs to a sub data item, this is a pointer
/// to the parent data item's DataItemInfo. Otherwise,
/// it must be a nullptr.
/// @return the data item name for \p id
/// @throw BadDataItemId if \p id is not a valid data item id
virtual std::string get_data_item_name(DataItemIdType id,
const LLDLEP::DataItemInfo * parent_di_info = nullptr) const = 0;
/// @return the type for a data item name
/// @throw BadDataItemName if \p name is not a valid data item name
virtual DataItemValueType
get_data_item_value_type(const std::string & name) const = 0;
/// Determine whether a data item id is a metric.
///
/// @param[in] id
/// the data item id to examine
/// @param[in] parent_di_info
/// if \p id belongs to a sub data item, this is a pointer
/// to the parent data item's DataItemInfo. Otherwise,
/// it must be a nullptr.
/// @return true if the data item id is a metric, else false
/// @throw BadDataItemId if \p id is not a valid data item id
virtual bool is_metric(DataItemIdType id,
const LLDLEP::DataItemInfo * parent_di_info = nullptr) const = 0;
/// Determine whether a data item id contains an IP address.
///
/// @param[in] id
/// the data item id to examine
/// @param[in] parent_di_info
/// if \p id belongs to a sub data item, this is a pointer
/// to the parent data item's DataItemInfo. Otherwise,
/// it must be a nullptr.
/// @return true if the data item id contains an IP address, else false
/// @throw BadDataItemId if \p id is not a valid data item id
virtual bool is_ipaddr(DataItemIdType id,
const LLDLEP::DataItemInfo * parent_di_info = nullptr) const = 0;
/// @return information about all configured data items
virtual std::vector<LLDLEP::DataItemInfo> get_data_item_info() const = 0;
/// @return information about the data item \p di_name
/// @throw BadDataItemName if \p di_name is not a valid data item name
virtual LLDLEP::DataItemInfo
get_data_item_info(const std::string & di_name) const = 0;
virtual LLDLEP::DataItemInfo
get_data_item_info(DataItemIdType id,
const LLDLEP::DataItemInfo * parent_di_info = nullptr) const = 0;
/// @return information about all of the data items in \p di_names
/// @throw BadDataItemName if any of \p di_names is not a valid data item
/// name
virtual std::vector<LLDLEP::DataItemInfo>
get_data_item_info(const std::vector<std::string> & di_names) const = 0;
//--------------------------------------------------------------------------
//
// Get information about signals
/// @return the number of message bytes used for a signal/message id
virtual std::size_t get_signal_id_size() const = 0;
/// @return the number of message bytes used for a signal/message length
virtual std::size_t get_signal_length_size() const = 0;
/// We assume there will never be a signal and a message with exactly the
/// same name.
/// @param[in] name the signal or message name
/// @param[out] is_signal_return if non-null, then upon return the value
/// pointed to is set to true if \p name was
/// a signal and false if it was a message
/// @return the signal/message id for a signal/message name
/// @throw BadSignalName if \p name is not a valid signal/message name
virtual SignalIdType get_signal_id(const std::string & name,
bool * is_signal_return = nullptr) const = 0;
/// @return the signal name for a signal id
/// @throw BadSignalId if \p id is not a valid signal id
virtual std::string get_signal_name(SignalIdType id) const = 0;
/// @return the message name for a message id
/// @throw BadSignalId if \p id is not a valid message id
virtual std::string get_message_name(SignalIdType id) const = 0;
/// @return the message response name for a message name, or
/// "" if there is no response
/// @throw BadSignalId if \p id is not a valid message id
virtual std::string get_message_response_name(const std::string & name) const = 0;
/// @return the configured signal prefix, or "" if not configured
virtual std::string get_signal_prefix() const = 0;
/// Information about one data item allowed on a signal
typedef struct SubDataItem DataItemForSignal;
/// Information about one signal/message
struct SignalInfo
{
std::string name; ///< name of this signal
SignalIdType id; ///< id of this signal
/// boolean flag definitions
enum Flags : std::uint32_t
{
message = (1 << 0), ///< this is a message, not a signal
modem_sends = (1 << 1), ///< modem can send this signal/message
router_sends = (1 << 2) ///< router can send this signal/message
// next flag = (1 << 3)
};
std::uint32_t flags; ///< OR-combination of enum Flags
/// all data items allowed for this signal
std::vector<DataItemForSignal> data_items;
/// If this signal/message has a matching response, this is its id.
/// This field is 0 if the signal has no response.
SignalIdType response_id;
std::string module; ///< module that provides this signal
SignalInfo() :
name(""), id(0), flags(0), response_id(0), module("") {}
};
/// @return information about all configured signals/messages
virtual std::vector<SignalInfo> get_signal_info() const = 0;
/// @return information about the signal/message \p sig_name
/// @throw BadSignalName if \p sig_name is not a valid signal/message name
virtual SignalInfo get_signal_info(const std::string & sig_name) const = 0;
/// @return information about all of the signals/messages in \p sig_names
/// @throw BadSignalName if any of \p sig_names is not a valid
/// signal/message name
virtual std::vector<SignalInfo>
get_signal_info(const std::vector<std::string> & sig_names) const = 0;
//--------------------------------------------------------------------------
//
// Get information about status codes
/// @return the number of message bytes used for a status id
/// XXX not currently used
virtual std::size_t get_status_code_size() const = 0;
/// @return the status code id for a status code name
/// @throw BadStatusCodeName if \p name is not a valid status code name
virtual StatusCodeIdType
get_status_code_id(const std::string & name) const = 0;
/// @return the status code name for a status code id
/// @throw BadStatusCodeId if \p id is not a valid status code id
virtual std::string get_status_code_name(StatusCodeIdType id) const = 0;
/// Information about one status code
struct StatusCodeInfo
{
std::string name; ///< name of this status code
StatusCodeIdType id; ///< id of this status code
// There are no flags defined for status codes, but we include the
// field here for future expandability.
std::uint32_t flags; ///< OR-combination of enum Flags
std::string module; ///< module that provides this status code
std::string failure_mode; ///< module that provides this status code
StatusCodeInfo() :
name(""), id(0), flags(0), module(""), failure_mode("") {} ;
};
/// @return information about all configured status codes
virtual std::vector<StatusCodeInfo> get_status_code_info() const = 0;
/// @return information about the status code \p sc_name
/// @throw BadStatusCodeName if \p sc_name is not a valid status code name
virtual StatusCodeInfo
get_status_code_info(const std::string & sc_name) const = 0;
/// @return information about all of the status codes in \p sc_names
/// @throw BadStatusCodeName if any of \p sc_names is not a valid status code
/// name
virtual std::vector<StatusCodeInfo>
get_status_code_info(const std::vector<std::string> & sc_names) const = 0;
//--------------------------------------------------------------------------
//
// Get information about modules
/// Information about one module
struct ModuleInfo
{
std::string name; ///< name of this module
std::string draft; ///< draft of this module, or "" if not configured
/// experiment_name of this module, or "" if not configured
std::string experiment_name;
/// extension id of this module, or 0 if not configured
ExtensionIdType extension_id;
/// data items provided by this module. string is the data item name.
std::vector<std::string> data_items;
/// signals provided by this module
std::vector<SignalIdType> signals;
/// messages provided by this module
std::vector<SignalIdType> messages;
/// status codes provided by this module
std::vector<StatusCodeIdType> status_codes;
ModuleInfo() :
name(""), draft(""), experiment_name(""), extension_id(0) {}
};
/// @return information about all configured modules
virtual std::vector<ModuleInfo> get_module_info() const = 0;
/// @return information about the module \p module_name
/// @throw BadDataItemName if \p module_name is not a valid module name
virtual ModuleInfo
get_module_info(const std::string & module_name) const = 0;
/// @return information about all of the modules in \p module_names
/// @throw BadModuleName if any of \p module_names is not a valid module
/// name
virtual std::vector<ModuleInfo>
get_module_info(const std::vector<std::string> & module_names) const = 0;
/// @return the number of message bytes used for an extension id
virtual std::size_t get_extension_id_size() const = 0;
/// @return all extension ids defined across all modules
virtual std::vector<ExtensionIdType> get_extension_ids() const = 0;
/// @return all experiment names defined across all modules
virtual std::vector<std::string> get_experiment_names() const = 0;
virtual ~ProtocolConfig() {};
//--------------------------------------------------------------------------
//
// exception classes used by the above methods
/// exception class used when an invalid module name is encountered
struct BadModuleName : public std::invalid_argument
{
explicit BadModuleName(const std::string & m) : std::invalid_argument(m) { }
};
/// exception class used when an invalid signal/message id is encountered
struct BadSignalId : public std::invalid_argument
{
explicit BadSignalId(const std::string & m) : std::invalid_argument(m) { }
};
/// exception class used when an invalid signal/message name is encountered
struct BadSignalName : public std::invalid_argument
{
explicit BadSignalName(const std::string & m) : std::invalid_argument(m) { }
};
/// exception class used when an invalid data item id is encountered
struct BadDataItemId : public std::invalid_argument
{
explicit BadDataItemId(const std::string & m) : std::invalid_argument(m) { }
};
/// exception class used when an invalid data item name is encountered
struct BadDataItemName : public std::invalid_argument
{
explicit BadDataItemName(const std::string & m) : std::invalid_argument(m) { }
};
/// exception class used when an invalid status code id is encountered
struct BadStatusCodeId : public std::invalid_argument
{
explicit BadStatusCodeId(const std::string & m) : std::invalid_argument(m) { }
};
/// exception class used when an invalid status code name is encountered
struct BadStatusCodeName : public std::invalid_argument
{
explicit BadStatusCodeName(const std::string & m) : std::invalid_argument(m) { }
};
/// exception class used when a problem with the protocol
/// configuration is encountered
struct BadProtocolConfig : public std::invalid_argument
{
explicit BadProtocolConfig(const std::string & m) : std::invalid_argument(m) { }
};
};
/// Signals/messages, data items, and status codes ("protocol
/// elements" below) are assigned string names. These names are the
/// mechanism by which the code and the configuration are tied
/// together. The protocol configuration file specifies string names
/// of protocol elements. When the code needs information about a
/// protocol element, it usually supplies the string name of the
/// protocol element to a ProtocolConfig method. It is critical that
/// the protocol element names used by the code match those in the
/// protocol configuration file. Rather than have many hardcoded
/// strings scattered throughout the code, we define symbolic
/// constants below for the strings and use those everywhere instead.
/// This way, accidental misspellings are caught at compile time
/// rather than run time.
namespace ProtocolStrings
{
// signal/message strings
extern const std::string Peer_Discovery;
extern const std::string Peer_Offer;
extern const std::string Session_Initialization;
extern const std::string Session_Initialization_Response;
extern const std::string Session_Termination;
extern const std::string Session_Termination_Response;
extern const std::string Session_Update;
extern const std::string Session_Update_Response;
extern const std::string Destination_Up;
extern const std::string Destination_Up_Response;
extern const std::string Destination_Down;
extern const std::string Destination_Down_Response;
extern const std::string Destination_Update;
extern const std::string Link_Characteristics_Request;
extern const std::string Link_Characteristics_Response;
extern const std::string Heartbeat;
extern const std::string Destination_Announce;
extern const std::string Destination_Announce_Response;
// data item strings
extern const std::string Version;
extern const std::string Port;
extern const std::string Peer_Type;
extern const std::string MAC_Address;
extern const std::string IPv4_Address;
extern const std::string IPv6_Address;
extern const std::string Status;
extern const std::string Heartbeat_Interval;
extern const std::string Link_Characteristics_Response_Timer;
extern const std::string IPv4_Attached_Subnet;
extern const std::string IPv6_Attached_Subnet;
extern const std::string Extensions_Supported;
extern const std::string Experimental_Definition;
extern const std::string IPv4_Connection_Point;
extern const std::string IPv6_Connection_Point;
// required metrics strings
extern const std::string Maximum_Data_Rate_Receive;
extern const std::string Maximum_Data_Rate_Transmit;
extern const std::string Current_Data_Rate_Receive;
extern const std::string Current_Data_Rate_Transmit;
extern const std::string Latency;
extern const std::string Resources;
extern const std::string Resources_Receive;
extern const std::string Resources_Transmit;
extern const std::string Relative_Link_Quality_Receive;
extern const std::string Relative_Link_Quality_Transmit;
extern const std::string Maximum_Transmission_Unit;
// status code strings
extern const std::string Success;
extern const std::string Unknown_Message;
extern const std::string Invalid_Message;
extern const std::string Unexpected_Message;
extern const std::string Request_Denied;
extern const std::string Timed_Out;
extern const std::string Invalid_Data;
extern const std::string Invalid_Destination;
extern const std::string Not_Interested;
extern const std::string Inconsistent_Data;
} // namespace ProtocolStrings
} // namespace LLDLEP
#endif // PROTOCOL_CONFIG_H