-
Notifications
You must be signed in to change notification settings - Fork 0
/
olsr.h
342 lines (296 loc) · 9.8 KB
/
olsr.h
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
#ifndef OLSR_H_
#define OLSR_H_
/**
* @file
* @brief OLSR structs, constants, etc.
*
* We're going to try really hard to mimic ns3 as much as possible in this
* implementation. We will assume the following:
* - strictly symmetric links
* - single interface
*/
// From http://c-faq.com/misc/bitsets.html
#include <limits.h> /* for CHAR_BIT */
#define BITMASK(b) (1 << ((b) % CHAR_BIT))
#define BITSLOT(b) ((b) / CHAR_BIT)
#define BITSET(a, b) ((a)[BITSLOT(b)] |= BITMASK(b))
#define BITCLEAR(a, b) ((a)[BITSLOT(b)] &= ~BITMASK(b))
#define BITTEST(a, b) ((a)[BITSLOT(b)] & BITMASK(b))
#define BITNSLOTS(nb) ((nb + CHAR_BIT - 1) / CHAR_BIT)
#include "ross.h"
#define ENABLE_OPTIMISTIC 0
/** HELLO message interval */
#define HELLO_INTERVAL 2
/** TC message interval */
#define TC_INTERVAL 5
#define TOP_HOLD_TIME (3*TC_INTERVAL)
#define SA_INTERVAL 10
#define MASTER_SA_INTERVAL 60
#define OLSR_DUP_HOLD_TIME 30
#define OLSR_MPR_POWER 16 // dbm
/** max neighbors (for array implementation) */
#define OLSR_MAX_NEIGHBORS 16
#define OLSR_MAX_2_HOP (OLSR_MAX_NEIGHBORS * OLSR_MAX_NEIGHBORS)
#define OLSR_MAX_TOP_TUPLES (OLSR_MAX_NEIGHBORS * OLSR_MAX_NEIGHBORS)
#define OLSR_MAX_ROUTES (OLSR_MAX_NEIGHBORS * OLSR_MAX_NEIGHBORS)
#define OLSR_MAX_DUPES 64
/** For Situational Awareness (SA) */
#define MASTER_NODE ((s->local_address / OLSR_MAX_NEIGHBORS) * OLSR_MAX_NEIGHBORS)
//#define MASTER_NODE ((s->local_address == 0) ? 0 : (OLSR_MAX_NEIGHBORS / s->local_address))
typedef tw_lpid o_addr; /**< We'll use this as a place holder for addresses */
typedef double Time; /**< Use a double for time, check w/ Chris */
typedef enum {
HELLO_RX,
HELLO_TX,
TC_RX,
TC_TX,
SA_RX,
SA_TX,
SA_MASTER_TX,
SA_MASTER_RX,
RWALK_CHANGE,
OLSR_END_EVENT, // KEEP THIS LAST ELSE STATS ARRAY NOT BIG ENOUGH!!
} olsr_ev_type;
extern char *event_names[];
//= {
// "HELLO_RX",
// "HELLO_TX",
// "TC_RX",
// "TC_TX",
// "SA_RX",
// "SA_TX",
// "SA_MASTER_TX",
// "SA_MASTER_RX",
// "RWALK_CHANGE"
//};
/**
struct hello - a basic hello message used by OLSR for link sensing / topology
detection.
Here is the ns3 hello class:
@code
struct Hello
{
struct LinkMessage {
uint8_t linkCode;
std::vector<Ipv4Address> neighborInterfaceAddresses;
};
uint8_t hTime;
void SetHTime (Time time)
{
this->hTime = SecondsToEmf (time.GetSeconds ());
}
Time GetHTime () const
{
return Seconds (EmfToSeconds (this->hTime));
}
uint8_t willingness;
std::vector<LinkMessage> linkMessages;
void Print (std::ostream &os) const;
uint32_t GetSerializedSize (void) const;
void Serialize (Buffer::Iterator start) const;
uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
};
@endcode
*/
typedef struct /* Hello */
{
/* No support for link codes yet! */
char is_mpr[OLSR_MAX_NEIGHBORS];
/** Addresses of our neighbors */
o_addr neighbor_addrs[OLSR_MAX_NEIGHBORS];
/** Number of neighbors, 0..n-1 */
unsigned num_neighbors;
/** HELLO emission interval */
uint8_t hTime;
/** Willingness to carry and foward traffic for other nodes */
uint8_t Willingness;
/* Link message size is an unnecessary field */
} hello;
/**
struct TC - Topology Control information.
The ns3 code is as follows:
@code
struct Tc
{
std::vector<Ipv4Address> neighborAddresses;
uint16_t ansn;
void Print (std::ostream &os) const;
uint32_t GetSerializedSize (void) const;
void Serialize (Buffer::Iterator start) const;
uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
};
@endcode
*/
typedef struct /* Tc */
{
uint16_t ansn;
o_addr neighborAddresses[OLSR_MAX_TOP_TUPLES];
unsigned num_neighbors;
} TC;
typedef struct
{
double lng;
double lat;
} latlng;
typedef struct
{
latlng ll[OLSR_MAX_NEIGHBORS];
} latlng_cluster;
typedef struct /* LinkTuple */
{
/// Interface address of the local node.
o_addr localIfaceAddr;
/// Interface address of the neighbor node.
o_addr neighborIfaceAddr;
/// The link is considered bidirectional until this time.
Time symTime;
/// The link is considered unidirectional until this time.
Time asymTime;
/// Time at which this tuple expires and must be removed.
Time time;
} link_tuple;
typedef struct /* NeighborTuple */
{
/// Main address of a neighbor node.
o_addr neighborMainAddr;
/// Neighbor Type and Link Type at the four less significative digits.
enum Status {
STATUS_NOT_SYM = 0, // "not symmetric"
STATUS_SYM = 1, // "symmetric"
} status;
/// A value between 0 and 7 specifying the node's willingness to carry traffic on behalf of other nodes.
uint8_t willingness;
} neigh_tuple;
typedef struct /* TwoHopNeighborTuple */
{
/// Main address of a neighbor.
o_addr neighborMainAddr;
/// Main address of a 2-hop neighbor with a symmetric link to nb_main_addr.
o_addr twoHopNeighborAddr;
/// Time at which this tuple expires and must be removed.
Time expirationTime; // previously called 'time_'
} two_hop_neigh_tuple;
typedef struct /* MprSelectorTuple */
{
/// Main address of a node which have selected this node as a MPR.
o_addr mainAddr;
/// Time at which this tuple expires and must be removed.
// Time expirationTime; // previously called 'time_'
} mpr_sel_tuple;
typedef struct /* TopologyTuple */
{
/// Main address of the destination.
o_addr destAddr;
/// Main address of a node which is a neighbor of the destination.
o_addr lastAddr;
/// Sequence number.
uint16_t sequenceNumber;
/// Time at which this tuple expires and must be removed.
Time expirationTime;
} top_tuple;
/// An OLSR's routing table entry.
typedef struct /* RoutingTableEntry */
{
o_addr destAddr; ///< Address of the destination node.
o_addr nextAddr; ///< Address of the next hop.
// Only one interface in our model
//uint32_t interface; ///< Interface index
uint32_t distance; ///< Distance in hops to the destination.
} RT_entry;
/// A Duplicate Tuple
typedef struct /* DuplicateTuple */
{
/// Originator address of the message.
o_addr address;
/// Message sequence number.
uint16_t sequenceNumber;
/// Indicates whether the message has been retransmitted or not.
int retransmitted;
/// List of interfaces which the message has been received on.
// std::vector<Ipv4Address> ifaceList;
/// Time at which this tuple expires and must be removed.
Time expirationTime;
} dup_tuple;
/**
This struct contains all of the OLSR per-node state. Not everything in the
ns3 class is necessary or implemented, but here is the ns3 OlsrState class:
@code
class OlsrState
{
// friend class Olsr;
protected:
LinkSet m_linkSet; ///< Link Set (RFC 3626, section 4.2.1).
NeighborSet m_neighborSet; ///< Neighbor Set (RFC 3626, section 4.3.1).
TwoHopNeighborSet m_twoHopNeighborSet; ///< 2-hop Neighbor Set (RFC 3626, section 4.3.2).
TopologySet m_topologySet; ///< Topology Set (RFC 3626, section 4.4).
MprSet m_mprSet; ///< MPR Set (RFC 3626, section 4.3.3).
MprSelectorSet m_mprSelectorSet; ///< MPR Selector Set (RFC 3626, section 4.3.4).
DuplicateSet m_duplicateSet; ///< Duplicate Set (RFC 3626, section 3.4).
IfaceAssocSet m_ifaceAssocSet; ///< Interface Association Set (RFC 3626, section 4.1).
AssociationSet m_associationSet; ///< Association Set (RFC 3626, section12.2). Associations obtained from HNA messages generated by other nodes.
Associations m_associations; ///< The node's local Host Network Associations that will be advertised using HNA messages.
};
@endcode
*/
typedef struct /*OlsrState */
{
/// Longitude for this node only
double lng;
/// Latitude for this node only
double lat;
/// this node's address
o_addr local_address;
// vector<LinkTuple>
//link_tuple linkSet[OLSR_MAX_NEIGHBORS];
//unsigned num_tuples;
// vector<NeighborTuple>
neigh_tuple neighSet[OLSR_MAX_NEIGHBORS];
unsigned num_neigh;
// vector<TwoHopNeighborTuple>
two_hop_neigh_tuple twoHopSet[OLSR_MAX_2_HOP];
unsigned num_two_hop;
// set<Ipv4Address>
o_addr mprSet[OLSR_MAX_NEIGHBORS];
unsigned num_mpr;
// vector<MprSelectorTuple>
mpr_sel_tuple mprSelSet[OLSR_MAX_NEIGHBORS];
unsigned num_mpr_sel;
// vector<TopologyTuple>
top_tuple topSet[OLSR_MAX_TOP_TUPLES];
unsigned num_top_set;
// vector<RoutingTableEntry>
RT_entry route_table[OLSR_MAX_ROUTES];
unsigned num_routes;
// vector<DuplicateTuple>
dup_tuple dupSet[OLSR_MAX_DUPES];
unsigned num_dupes;
// Not part of the state in ns3 but fits here mostly
uint16_t ansn;
int SA_per_node[OLSR_MAX_NEIGHBORS];
} node_state;
union message_type {
hello h;
TC t;
latlng l;
latlng_cluster llc;
};
typedef struct
{
olsr_ev_type type; ///< What type of message is this?
uint8_t ttl; ///< The Time To Live field for this packet
o_addr originator; ///< Node responsible for this event
o_addr sender; ///< Node to last touch this message (TC) or MITM (SA)
o_addr destination; ///< Destination node
double lng; ///< Longitude for 'sender' (above)
double lat; ///< Latitude for 'sender' (above)
union message_type mt; ///< Union for message type
unsigned long target; ///< Target index into g_tw_lp
uint16_t seq_num; ///< Sequence number for this message
int level; ///< Level for SA_MASTER messages
#if ENABLE_OPTIMISTIC
node_state state_copy; ///< copy state for the lp that processes the event
#endif
} olsr_msg_data;
void olsr_custom_mapping(void);
tw_lp * olsr_mapping_to_lp(tw_lpid lpid);
#endif /* OLSR_H_ */