NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
DSR.h
1/************************************************************************************
2* Copyright (C) 2023 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* Author: Shashi Kant Suman *
12* *
13* ---------------------------------------------------------------------------------*/
14
15/****************************************************
16RFC 4728 The Dynamic Source Routing Protocol February 2007
17*****************************************************/
18
19#ifndef _NETSIM_DSR_H_
20#define _NETSIM_DSR_H_
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#pragma comment(lib,"NetworkStack.lib")
26#pragma comment(lib,"DSR.lib")
27
28
29 /* Packet Size */
30#define DSR_OPTION_HEADER_SIZE 4
31#define DSR_RREQ_SIZE_FIXED 8
32#define DSR_RREQ_SIZE_IPV6_FIXED 20
33#define DSR_RREP_SIZE_FIXED 7
34#define DSR_SOURCEROUTE_SIZE_FIXED 4
35#define DSR_RERR_SIZE_FIXED 12+4/* type specific */
36#define DSR_ACK_OPTION_LEN 10
37#define DSR_ACK_REQUEST_LEN 4
38
39#define DSR_RREQ_OPT_LEN 6
40#define DSR_DISCOVERY_HOP_LIMIT 255
41#define DSR_MAX_REQUEST_REXMT 16
42#define DSR_MaxMaintRexmt 2
43
44
45#define NO_NEXT_HEADER 59 //rfc 1700
46#define NonpropRequestTimeout (30* MILLISECOND)
47#define DSR_REQUEST_PERIOD (500* MILLISECOND)
48#define DSR_MAX_REQUEST_PERIOD (10* SECOND)
49#define ROUTE_CACHE_TIMEOUT (300* SECOND)
50#define BROADCAST_JITTER (10* MILLISECOND)
51#define MAINT_HOLD_OFF_TIME (250* MILLISECOND)
52
53#define isDSRPACKET(packet) (packet->nControlDataType/100 == NW_PROTOCOL_DSR)
54
55
56 typedef enum enum_DSR_Subevent DSR_SUBEVENT;
57 typedef enum enum_DSR_ControlPacket DSR_CONTROL_PACKET;
58 typedef enum enum_DSR_OptionType DSR_OPTION_TYPE;
59
60 typedef struct stru_DSR_SendBuffer DSR_SEND_BUFFER;
61 typedef struct stru_DSR_RouteCache DSR_ROUTE_CACHE;
62 typedef struct stru_DSR_MaintBuffer DSR_MAINT_BUFFER;
63 typedef struct stru_DSR_DeviceVar DSR_DEVICE_VAR;
64
65 typedef struct stru_DSR_OptionHeader DSR_OPTION_HEADER;
66 typedef struct stru_NetSim_DSR_RREQ_Option DSR_RREQ_OPTION;
67 typedef struct stru_NetSim_DSR_RREP_Option DSR_RREP_OPTION;
68 typedef struct stru_NetSim_DSR_RERR_Option DSR_RERR_OPTION;
69 typedef struct stru_NetSim_DSR_SourceRouteOption DSR_SOURCE_ROUTE_OPTION;
70 typedef struct stru_DSR_Ack_Request_Option DSR_ACK_REQ_OPTION;
71 typedef struct stru_DSR_Ack_Option DSR_ACK_OPTION;
72 typedef struct stru_DSR_RouteRequestTable DSR_RREQ_TABLE;
73
74 typedef struct stru_DSR_Primitives DSR_PRIMITIVES;
75
76 ///Enumeration for DSR Subevents
77 enum enum_DSR_Subevent
78 {
79 subevent_RREQ_TIMEOUT=NW_PROTOCOL_DSR*100+1,
80 subevent_MAINT_TIMEOUT,
81 subevent_PROCESS_RERR,
82 };
83
84 ///Enumeration for DSR Control Packets.
85 enum enum_DSR_ControlPacket
86 {
87 ctrlPacket_ROUTE_REQUEST=NW_PROTOCOL_DSR*100+1,
88 ctrlPacket_ROUTE_REPLY,
89 ctrlPacket_ROUTE_ERROR,
90 ctrlPacket_ACK,
91 };
92
93 ///Enumeration for DSR option types.
94 enum enum_DSR_OptionType
95 {
96 optType_RouteRequest=1,
97 optType_RouteReply=2,
98 optType_RouteError=3,
99 optType_Ack=32,
100 optType_SourceRoute=96,
101 optType_AckRequest=160,
102 };
103
104
105 /**
106 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107 6.7. DSR Source Route Option
108
109 The DSR Source Route option in a DSR Options header is encoded as
110 follows:
111
112 0 1 2 3
113 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
114 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
115 | Option Type | Opt Data Len |F|L|Reservd|Salvage| Segs Left |
116 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
117 | Address[1] |
118 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119 | Address[2] |
120 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
121 | ... |
122 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
123 | Address[n] |
124 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
125 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
126 */
128 {
129 DSR_OPTION_TYPE nOptionType; /**<
130 nOptionType = 96
131 Nodes not understanding this option will drop the packet.*/
132
133 unsigned int nOptDataLen:8; /**<
134 8-bit unsigned integer. Length of the option, in octets,
135 excluding the Option Type and Opt Data Len fields. For the
136 format of the DSR Source Route option defined here, this field
137 MUST be set to the value (n * 4) + 2, where n is the number of
138 addresses present in the Address[i] fields.
139 */
140
141 unsigned int F:1; /**<
142 Set to indicate that the first hop indicated by the DSR Source
143 Route option is actually an arbitrary path in a network
144 external to the DSR network; the exact route outside the DSR network
145 is not represented in the DSR Source Route option.
146 Nodes caching this hop in their Route Cache MUST flag the
147 cached hop with the External flag. Such hops MUST NOT be
148 returned in a Route Reply generated from this Route Cache
149 entry, and selection of routes from the Route Cache to route a
150 packet being sent SHOULD prefer routes that contain no hops
151 flagged as External.
152 */
153
154 unsigned int L:1; /**<
155 Set to indicate that the last hop indicated by the DSR Source
156 Route option is actually an arbitrary path in a network
157 external to the DSR network; the exact route outside the DSR
158 network is not represented in the DSR Source Route option.
159 Nodes caching this hop in their Route Cache MUST flag the
160 cached hop with the External flag. Such hops MUST NOT be
161 returned in a Route Reply generated from this Route Cache
162 entry, and selection of routes from the Route Cache to route a
163 packet being sent SHOULD prefer routes that contain no hops
164 flagged as External.
165 */
166
167 unsigned int nReserved:4; /**<
168 MUST be sent as 0 and ignored on reception.
169 */
170 unsigned int nSalvage:4; /**<
171 A 4-bit unsigned integer. Count of number of times that this
172 packet has been salvaged as a part of DSR routing.
173 */
174
175 unsigned int nSegsLeft:4; /**<
176 Segments Left (Segs Left)
177 Number of route segments remaining, i.e., number of explicitly
178 listed intermediate nodes still to be visited before reaching
179 the final destination.
180 */
181
182 NETSIM_IPAddress* Address; /**<
183 The sequence of addresses of the source route. In routing and
184 forwarding the packet, the source route is processed as
185 described in Sections 8.1.3 and 8.1.5. The number of addresses
186 present in the Address[1..n] field is indicated by the Opt Data
187 Len field in the option (n = (Opt Data Len - 2) / 4).
188 */
189 };
190
191 /**
192 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193 6.2. Route Request Option
194
195 The Route Request option in a DSR Options header is encoded as
196 follows:
197
198 0 1 2 3
199 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
200 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
201 | Option Type | Opt Data Len | Identification |
202 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
203 | Target Address |
204 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
205 | Address[1] |
206 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
207 | Address[2] |
208 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
209 | ... |
210 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
211 | Address[n] |
212 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
213
214 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
215 */
217 {
218 DSR_OPTION_TYPE nOptionType; /**<
219 nOptionType = 1
220 Nodes not understanding this option will ignore this
221 option.
222 */
223
224 unsigned int nOptDataLen:8; /**<
225 8-bit unsigned integer. Length of the option, in octets,
226 excluding the Option Type and Opt Data Len fields. MUST be set
227 equal to (4 * n) + 6, where n is the number of addresses in the
228 Route Request Option.
229 */
230
231 unsigned int nIdentification:16; /**<
232 A unique value generated by the initiator (original sender) of
233 the Route Request. Nodes initiating a Route Request generate a
234 new Identification value for each Route Request, for example
235 based on a sequence number counter of all Route Requests
236 initiated by the node.<br/>
237
238 This value allows a receiving node to determine whether it has
239 recently seen a copy of this Route Request. If this
240 Identification value (for this IP Source address and Target
241 Address) is found by this receiving node in its Route Request
242 Table (in the cache of Identification values in the entry there
243 for this initiating node), this receiving node MUST discard the
244 Route Request. When a Route Request is propagated, this field
245 MUST be copied from the received copy of the Route Request
246 being propagated.
247 */
248
249 NETSIM_IPAddress targetAddress;
250
251 NETSIM_IPAddress* address; /**<
252 Address[i] is the IPv4 address of the i-th node recorded in the
253 Route Request option. The address given in the Source Address
254 field in the IP header is the address of the initiator of the
255 Route Discovery and MUST NOT be listed in the Address[i]
256 fields; the address given in Address[1] is thus the IPv4
257 address of the first node on the path after the initiator. The
258 number of addresses present in this field is indicated by the
259 Opt Data Len field in the option (n = (Opt Data Len - 6) / 4).
260 Each node propagating the Route Request adds its own address to
261 this list, increasing the Opt Data Len value by 4 octets.
262 */
263 };
264
265 /**
266 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
267 6.3 Route Reply Option
268
269 The Route Reply option in a DSR Options header is encoded as follows:
270 0 1 2 3
271 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
272 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
273 | Option Type | Opt Data Len |L| Reserved |
274 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
275 | Address[1] |
276 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
277 | Address[2] |
278 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
279 | ... |
280 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
281 | Address[n] |
282 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
283 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
284 */
286 {
287 DSR_OPTION_TYPE nOptionType; /**<
288 Option Type = 2
289 Nodes not understanding this option will ignore this
290 option.
291 */
292
293 unsigned int nOptDataLen:8; /**<
294 8-bit unsigned integer. Length of the option, in octets,
295 excluding the Option Type and Opt Data Len fields. MUST be set
296 equal to (4 * n) + 1, where n is the number of addresses in the
297 Route Reply Option.
298 */
299
300 unsigned int nLastHopExternal:1; /**<
301 Set to indicate that the last hop given by the Route Reply (the
302 link from Address[n-1] to Address[n]) is actually an arbitrary
303 path in a network external to the DSR network; the exact route
304 outside the DSR network is not represented in the Route Reply.
305 Nodes caching this hop in their Route Cache MUST flag the
306 cached hop with the External flag. Such hops MUST NOT be
307 returned in a cached Route Reply generated from this Route
308 Cache entry, and selection of routes from the Route Cache to
309 route a packet being sent SHOULD prefer routes that contain no
310 hops flagged as External.
311 */
312
313 unsigned int nReserved:7; /**<
314 MUST be sent as 0 and ignored on reception.
315 */
316
317 NETSIM_IPAddress* Address; /**<
318 The source route being returned by the Route Reply. The route
319 indicates a sequence of hops, originating at the source node
320 specified in the Destination Address field of the IP header of
321 the packet carrying the Route Reply, through each of the
322 Address[i] nodes in the order listed in the Route Reply, ending
323 at the node indicated by Address[n]. The number of addresses
324 present in the Address[1..n] field is indicated by the Opt Data
325 Len field in the option (n = (Opt Data Len - 1) / 4).
326 */
327 };
328
329 /**
330 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
331 6.4. Route Error Option
332
333 The Route Error option in a DSR Options header is encoded as follows:
334
335 0 1 2 3
336 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
337 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
338 | Option Type | Opt Data Len | Error Type |Reservd|Salvage|
339 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
340 | Error Source Address |
341 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
342 | Error Destination Address |
343 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
344 . .
345 . Type-Specific Information .
346 . .
347 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
348 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
349 */
351 {
352 DSR_OPTION_TYPE nOptionType; /**<
353 Nodes not understanding this option will ignore this
354 option.
355 */
356
357 unsigned int nOptDataLen:8; /**<
358 8-bit unsigned integer. Length of the option, in octets,
359 excluding the Option Type and Opt Data Len fields.
360 <br/>
361 For the current definition of the Route Error option,
362 this field MUST be set to 10, plus the size of any
363 Type-Specific Information present in the Route Error. Further
364 extensions to the Route Error option format may also be
365 included after the Type-Specific Information portion of the
366 Route Error option specified above. The presence of such
367 extensions will be indicated by the Opt Data Len field.
368 When the Opt Data Len is greater than that required for
369 the fixed portion of the Route Error plus the necessary
370 Type-Specific Information as indicated by the Option Type
371 value in the option, the remaining octets are interpreted as
372 extensions. Currently, no such further extensions have been
373 defined.
374 */
375 /**
376 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
377 Error Type
378 The type of error encountered. Currently, the following type
379 values are defined:
380 1 = NODE_UNREACHABLE
381 2 = FLOW_STATE_NOT_SUPPORTED
382 3 = OPTION_NOT_SUPPORTED
383 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
384 */
385 enum
386 {
387 NODE_UNREACHABLE=1,
388 FLOW_STATE_NOT_SUPPORTED,
389 OPTION_NOT_SUPPORTED,
391
392 unsigned int nReserved:4; /**<
393 Reserved. MUST be sent as 0 and ignored on reception.
394 */
395
396 unsigned int nSalvage:4; /**<
397 A 4-bit unsigned integer. Copied from the Salvage field in the
398 DSR Source Route option of the packet triggering the Route
399 Error.
400
401 The "total salvage count" of the Route Error option is derived
402 from the value in the Salvage field of this Route Error option
403 and all preceding Route Error options in the packet as follows:
404 the total salvage count is the sum of, for each such Route
405 Error option, one plus the value in the Salvage field of that
406 Route Error option.
407 */
408
409 NETSIM_IPAddress errorSourceAddress; /**<
410 The address of the node originating the Route Error (e.g., the
411 node that attempted to forward a packet and discovered the link
412 failure).
413 */
414
415 NETSIM_IPAddress errorDestinationAddress; /**<
416 The address of the node to which the Route Error must be
417 delivered. For example, when the Error Type field is set to
418 NODE_UNREACHABLE, this field will be set to the address of the
419 node that generated the routing information claiming that the
420 hop from the Error Source Address to Unreachable Node Address
421 (specified in the Type-Specific Information) was a valid hop.
422 */
423
425 Information specific to the Error Type of this Route Error
426 message.
427 */
428
429 //path
430 unsigned int length;
431 unsigned int nSegsLeft;
432 NETSIM_IPAddress* Address;
433 };
434
435 /**
436 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
437
438 6.5. Acknowledgement Request Option
439
440 The Acknowledgement Request option in a DSR Options header is encoded
441 as follows:
442
443 0 1 2 3
444 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
445 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
446 | Option Type | Opt Data Len | Identification |
447 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
448
449 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
450 */
452 {
453
454 DSR_OPTION_TYPE nOptionType; /**<
455 Nodes not understanding this option will remove the
456 option and return a Route Error.
457 */
458
459 unsigned int nOptionDataLen:8; /**<
460 8-bit unsigned integer. Length of the option, in octets,
461 excluding the Option Type and Opt Data Len fields.
462 */
463
464 unsigned int nIdentification:16; /**<
465 The Identification field is set to a unique value and is copied
466 into the Identification field of the Acknowledgement option
467 when returned by the node receiving the packet over this hop.
468 */
469 };
470
471 /**
472 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
473
474 6.6. Acknowledgement Option
475
476 The Acknowledgement option in a DSR Options header is encoded as
477 follows:
478
479 0 1 2 3
480 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
481 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
482 | Option Type | Opt Data Len | Identification |
483 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
484 | ACK Source Address |
485 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
486 | ACK Destination Address |
487 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
488
489 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
490 */
492 {
493
494 DSR_OPTION_TYPE nOptionType; /**<
495 Nodes not understanding this option will remove the
496 option.
497 */
498 unsigned int nOptionDataLen:8; /**<
499 8-bit unsigned integer. Length of the option, in octets,
500 excluding the Option Type and Opt Data Len fields.
501 */
502 unsigned int nIdentification:16; /**<
503 Copied from the Identification field of the Acknowledgement
504 Request option of the packet being acknowledged.
505 */
506 NETSIM_IPAddress sourceAddress; /**<
507 The address of the node originating the acknowledgement.
508 */
509 NETSIM_IPAddress DestAddress; /**<
510 The address of the node to which the acknowledgement is to be
511 delivered.
512 */
513 };
514
515 /**
516 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
517 6.1. Fixed Portion of DSR Options Header
518
519 The fixed portion of the DSR Options header is used to carry
520 information that must be present in any DSR Options header. This
521 fixed portion of the DSR Options header has the following format:
522
523 0 1 2 3
524 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
525 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
526 | Next Header |F| Reserved | Payload Length |
527 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
528 . .
529 . Options .
530 . .
531 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
532 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
533 */
535 {
536 unsigned int nNextHeader:8; /**<
537 8-bit selector. Identifies the type of header immediately
538 following the DSR Options header. Uses the same values as the
539 IPv4 Protocol field [RFC1700]. If no header follows, then Next
540 Header MUST have the value 59, "No Next Header" [RFC2460].
541 */
542
543 unsigned int nFlowState:1;/**<
544 Flag bit. MUST be set to 0. This bit is set in a DSR Flow
545 State header (Section 7.1) and clear in a DSR Options header.
546 */
547
548 unsigned int nReserved:7; /**<
549 MUST be sent as 0 and ignored on reception.
550 Payload Length
551 The length of the DSR Options header, excluding the 4-octet
552 fixed portion. The value of the Payload Length field defines
553 the total length of all options carried in the DSR Options
554 header.
555 */
556
557 unsigned int nPayloadLength:16;
558 DSR_OPTION_TYPE optType; /**<
559 Variable-length field; the length of the Options field is
560 specified by the Payload Length field in this DSR Options
561 header. Contains one or more pieces of optional information
562 (DSR options), encoded in type-length-value (TLV) format (with
563 the exception of the Pad1 option described in Section 6.8).
564 */
565 void* options;
566 DSR_ACK_REQ_OPTION* ackRequestOption;
567 };
568 /**
569 Every Device maintains a route cache which has an entry of the entire route to the
570 target.
571 */
573 {
574 double dTimeOutTime; /**<
575 dTimeOutTime - allows an entry to be deleted if not used within some time.
576 address - list of addresses in a route cache
577 ele - next route cache
578 */
579
580 unsigned int F:1;
581 unsigned int L:1;
582 unsigned int nLength:8;
583 NETSIM_IPAddress* address;
584 struct element* ele;
585 };
586 /**
587 Packets are added to send buffer if device doesn't have route to target
588 */
590 {
591 NETSIM_IPAddress target; ///< Target IP address
592 double dTime;
593 NetSim_PACKET* packet; ///< List of packets to a particular Dest IP
594 struct element* ele; ///< Next SendBuffer
595 };
596 /**
597 DSR Route Request Table
598 An Entry is made in the Route Request Table when a Route request is sent
599 */
601 {
602 unsigned int nTTL; ///< nTTL - Time to Live
603 double lastRequestTime; /**<
604 The time that this node last originated a Route Request for that
605 target node.
606 */
607 double dBackoff; /**<
608 The remaining amount of time before which this node MAY next
609 attempt at a Route Discovery for that target node
610 */
611 unsigned int nCount;
612 NETSIM_IPAddress target;
613 unsigned int nIdentification:16; ///< Identification value
614 //Netsim specific
615 unsigned long long int nEventId;
616 bool flag;
617 struct element* ele; ///< ele - next RouteRequestTable
618 };
619 /**
620 When a packet is forwarded to next HOP, it is added to the Maintanence Buffer. This is
621 added when the device has the route to target.
622 */
624 {
625 double dAckTime;
626 int count;
627 NETSIM_ID nextHop; ///< Next hop ID of a route
628 NETSIM_ID source;
629 NETSIM_ID dest;
630 NetSim_PACKET* packetList; ///< packetList - list of packets sent to the destination
631 struct element* ele; ///< Next MaintBuffer
632 };
633 /**
634 DSR Metrics structure contains various metrics like rrepSent, rrepForwarded etc.
635 */
637 {
638 unsigned int rreqSent;
639 unsigned int rreqForwarded;
640 unsigned int rrepSent;
641 unsigned int rrepForwarded;
642 unsigned int rerrSent;
643 unsigned int rerrForwarded;
644 unsigned int routeBreak;
645 unsigned int packetTransmitted;
646 unsigned int packetOrginated;
647 unsigned int packetReceived;
648 unsigned int packetDropped;
649 };
650 /**
651 DSR Device Variable
652 */
654 {
655
656 unsigned int nRREQIdentification;
657 struct stru_DSR_RouteCache* pstruRouteCache; ///< List of routes to particular destination
658 struct stru_DSR_SendBuffer* pstruSendBuffer; ///< Buffer in which packets are added if route to target is not known.
659 struct stru_DSR_RouteRequestTable* pstruRREQTable; ///< A table in which entry of RREQ initiated is made.
660 enum
661 {
662 LINK_LAYER_ACK,
663 NETWORK_LAYER_ACK,
664 }AckType;
665 DSR_MAINT_BUFFER* pstruMaintBuffer; ///< Buffer in which packets sent to next HOP are added.
666 struct stru_DSR_Metrics dsrMetrics;
667 };
668
669 DSR_ROUTE_CACHE* fn_NetSim_DSR_FindCache(DSR_DEVICE_VAR* devVar,NETSIM_IPAddress address,double dTime);
670 int fn_NetSim_DSR_GeneralPacketProcessing(NetSim_EVENTDETAILS* pstruEventDetails);
671 bool fn_NetSim_DSR_CheckRouteFound(NETSIM_IPAddress destAddress,DSR_DEVICE_VAR* devVar,NETSIM_IPAddress* nextHop,double dTime,DSR_ROUTE_CACHE** cache);
672 int fn_NetSim_DSR_AddSourceRouteOption(NetSim_PACKET* packet,DSR_ROUTE_CACHE* cache);
673 int fn_NetSim_DSR_ProcessSourceRouteOption(NetSim_EVENTDETAILS* pstruEventDetails);
674 int fn_NetSim_DSR_AddToMaintBuffer(NETSIM_ID nDeviceId,
675 NetSim_PACKET* pstruPacket,
676 double dTime);
677 int fn_NetSim_DSR_MaintTimeout(NetSim_EVENTDETAILS* pstruEventDetails);
678 int fn_NetSim_DSR_RetransmitBuffer(DSR_MAINT_BUFFER* maintBuffer,NetSim_EVENTDETAILS* pstruEventDetails);
679 int fn_NetSim_DSR_EmptyMaintBuffer(NETSIM_ID nDeviceId,NETSIM_ID nextHop);
680 bool fn_NetSim_DSR_AddToSendBuffer(DSR_SEND_BUFFER** sendBuffer,NetSim_PACKET* packet,double dTime);
681 void fn_NetSim_DSR_EmptySendBuffer(NETSIM_IPAddress targetAddress,NETSIM_ID nDeviceId);
682 void fn_NetSim_DSR_CheckSendBuffer(NETSIM_ID nDeviceId,double dTime);
683 int fn_NetSim_DSR_TransmitPacketFromSendBuffer(DSR_SEND_BUFFER* sendBuffer,
684 NETSIM_ID nDeviceId,
685 double dTime);
686 int fn_NetSim_DSR_UpdateRouteCache(unsigned int length,
687 NETSIM_IPAddress* address,
688 double dTime);
689 DSR_ROUTE_CACHE* fn_NetSim_DSR_FindCache(DSR_DEVICE_VAR* devVar,NETSIM_IPAddress address,double dTime);
690 bool fn_NetSim_DSR_ValidateRouteCache(DSR_ROUTE_CACHE* cache,NETSIM_IPAddress* addList,int count);
691 int fn_NetSim_DSR_DeleteEntryFromRouteCache(DSR_ROUTE_CACHE** ppcache,
692 NETSIM_IPAddress ip1,
693 NETSIM_IPAddress ip2);
694 int fn_NetSim_DSR_GenerateRREP(NetSim_PACKET* rreqPacket,NetSim_EVENTDETAILS* pstruEventDetails);
695 int fn_NetSim_DSR_ProcessRREP(NetSim_EVENTDETAILS* pstruEventDetails);
696 bool fn_NetSim_DSR_GenerateRREPUsingRouteCache(DSR_DEVICE_VAR* devVar,
697 NetSim_PACKET* rreqPacket,
698 double dTime,
699 NetSim_EVENTDETAILS* pstruEventDetails);
700 int fn_NetSim_DSR_ForwardRREP();
701 int fn_NetSim_DSR_GenerateRERR(DSR_MAINT_BUFFER* maintBuffer,NetSim_EVENTDETAILS* pstruEventDetails);
702 int fn_NetSim_DSR_ProcessRerr(NetSim_EVENTDETAILS* pstruEventDetails);
703 NetSim_PACKET* fn_NetSim_DSR_InitRouteRequest(NETSIM_IPAddress target, DSR_RREQ_TABLE** rreqTable,
704 NETSIM_ID nDeviceId,
705 double dTime,
706 NetSim_EVENTDETAILS* pstruEventDetails);
707 int fn_NetSim_DSR_RREQTimeout(NetSim_EVENTDETAILS* pstruEventDetails);
708 NetSim_PACKET* fn_NetSim_DSR_RetryRREQ(NETSIM_IPAddress targetAddress,
709 NETSIM_ID nDeviceId,
710 double dTime,
711 NetSim_EVENTDETAILS* pstruEventDetails);
712 int fn_NetSim_DSR_ProcessRREQ(NetSim_EVENTDETAILS* pstruEventDetails);
713 int fn_NetSim_DSR_Add_Ack_request_Option(NetSim_PACKET* packet,NetSim_EVENTDETAILS* pstruEventDetails);
714 int fn_NetSim_DSR_ProcessAckOption(NetSim_EVENTDETAILS* pstruEventDetails);
715 int fn_NetSim_DSR_Process_AckRequestOption(NetSim_PACKET* packet,NetSim_EVENTDETAILS* pstruEventDetails);
716
717#define DSR_PACKET_PROCESSING() fn_NetSim_DSR_GeneralPacketProcessing(pstruEventDetails)
718#define DSR_CHECK_ROUTE_FOUND(destAddress,devVar,nextHop,dTime,ppcache) fn_NetSim_DSR_CheckRouteFound(destAddress,devVar,nextHop,dTime,ppcache)
719 //Maint buffer
720#define DSR_ADD_TO_MAINT_BUFFER(nDeviceId,pstruPacket,dTime) fn_NetSim_DSR_AddToMaintBuffer(nDeviceId,pstruPacket,dTime);
721#define DSR_MAINT_TIMEOUT() fn_NetSim_DSR_MaintTimeout(pstruEventDetails)
722#define DSR_RETRANSMIT_BUFFER(maintBuffer) fn_NetSim_DSR_RetransmitBuffer(maintBuffer,pstruEventDetails)
723#define DSR_EMPTY_MAINT_BUFFER(nDeviceId,nextHop) fn_NetSim_DSR_EmptyMaintBuffer(nDeviceId,nextHop)
724 //Route cache
725#define DSR_UPDATE_ROUTE_CACHE(length,address,dTime) fn_NetSim_DSR_UpdateRouteCache(length,address,dTime)
726#define DSR_FIND_CACHE(devVar,address,dTime) fn_NetSim_DSR_FindCache(devVar,address,dTime)
727#define DSR_VALIDATE_CACHE(cache,addList,count) fn_NetSim_DSR_ValidateRouteCache(cache,addList,count)
728#define DSR_DELETE_ENTRY_CACHE(ppcache,ip1,ip2) fn_NetSim_DSR_DeleteEntryFromRouteCache(ppcache,ip1,ip2)
729 //Route error
730#define DSR_GENERATE_RERR(maintBuffer) fn_NetSim_DSR_GenerateRERR(maintBuffer,pstruEventDetails)
731#define DSR_PROCESS_RERR() fn_NetSim_DSR_ProcessRerr(pstruEventDetails)
732 //Route reply
733#define DSR_GENERATE_RREP(rreqPacket) fn_NetSim_DSR_GenerateRREP(rreqPacket,pstruEventDetails)
734#define DSR_PROCESS_RREP() fn_NetSim_DSR_ProcessRREP(pstruEventDetails)
735#define DSR_GENERATE_RREP_USING_CACHE(devVar,rreqPacket,dTime) fn_NetSim_DSR_GenerateRREPUsingRouteCache(devVar,rreqPacket,dTime,pstruEventDetails)
736 //Route request
737#define DSR_INIT_RREQ(target,pprreqTable,nDeviceId,dTime) fn_NetSim_DSR_InitRouteRequest(target,pprreqTable,nDeviceId,dTime,pstruEventDetails)
738#define DSR_RREQ_TIMEOUT() fn_NetSim_DSR_RREQTimeout(pstruEventDetails)
739#define DSR_RETRY_RREQ(targetAddress,nDeviceId,dTime) fn_NetSim_DSR_RetryRREQ(targetAddress,nDeviceId,dTime,pstruEventDetails)
740#define DSR_PROCESS_RREQ() fn_NetSim_DSR_ProcessRREQ(pstruEventDetails)
741 //Send buffer
742#define DSR_ADD_TO_SEND_BUFFER(ppsendBuffer,packet,dTime) fn_NetSim_DSR_AddToSendBuffer(ppsendBuffer,packet,dTime)
743#define DSR_EMPTY_SEND_BUFFER(targetAddress,nDeviceId) fn_NetSim_DSR_EmptySendBuffer(targetAddress,nDeviceId)
744#define DSR_CHECK_SEND_BUFFER(nDeviceId,dTime) fn_NetSim_DSR_CheckSendBuffer(nDeviceId,dTime)
745#define DSR_TRANSMIT_SEND_BUFFER(sendBuffer,nDeviceId,dTime) fn_NetSim_DSR_TransmitPacketFromSendBuffer(sendBuffer,nDeviceId,dTime)
746 //Source route
747#define DSR_ADD_SRC_ROUTE(packet,cache) fn_NetSim_DSR_AddSourceRouteOption(packet,cache)
748#define DSR_PROCESS_SRC_ROUTE() fn_NetSim_DSR_ProcessSourceRouteOption(pstruEventDetails)
749 //Network layer ack
750#define DSR_ADD_ACK_REQUEST(packet) fn_NetSim_DSR_Add_Ack_request_Option(packet,pstruEventDetails)
751#define DSR_PROCESS_ACK_REQUEST(packet) fn_NetSim_DSR_Process_AckRequestOption(packet,pstruEventDetails)
752#define DSR_PROCESS_ACK() fn_NetSim_DSR_ProcessAckOption(pstruEventDetails);
753
754 //DSR Lib function declaration
755 NetSim_PACKET* fn_NetSim_DSR_GenerateCtrlPacket(NETSIM_ID src,
756 NETSIM_ID dest,
757 NETSIM_ID recv,
758 double dTime,
759 DSR_CONTROL_PACKET type);
760 double fn_NetSim_DSR_GetBroadCastJitter();
761 int fn_NetSim_DSR_LinkLayerAck(NetSim_PACKET*);
762 unsigned int fn_NetSim_DSR_FillAddress(DSR_SOURCE_ROUTE_OPTION* srcOption,DSR_ROUTE_CACHE* cache,NETSIM_IPAddress src,NETSIM_IPAddress dest);
763 int fn_NetSim_DSR_Finish_F();
764 DSR_RREQ_TABLE* getRREQTable(NETSIM_IPAddress target,DSR_RREQ_TABLE* table);
765
766 void set_dsr_curr();
767 NETSIM_IPAddress dsr_get_curr_ip();
768 NETSIM_ID dsr_get_curr_if();
769 NETSIM_IPAddress dsr_get_dev_ip(NETSIM_ID d);
770 bool isDsrConfigured(NETSIM_ID d, NETSIM_ID in);
771
772#define DSR_DEV_VAR(dev) ((DSR_DEVICE_VAR*)NETWORK->ppstruDeviceList[dev-1]->pstruNetworkLayer->RoutingVar)
773#define DSR_RREQ_LEN(rreq) (int)(rreq->nOptDataLen-6)/4
774#define DSR_RREP_LEN(rrep) (int)(rrep->nOptDataLen-3)/4+1
775
776
777#define SENDBUFFER_ALLOC() list_alloc(sizeof(struct stru_DSR_SendBuffer),offsetof(struct stru_DSR_SendBuffer,ele))
778#define RREQTABLE_ALLOC() (DSR_RREQ_TABLE*)list_alloc(sizeof(struct stru_DSR_RouteRequestTable),offsetof(struct stru_DSR_RouteRequestTable,ele))
779#define ROUTECACHE_ALLOC() (DSR_ROUTE_CACHE*)list_alloc(sizeof(struct stru_DSR_RouteCache),offsetof(struct stru_DSR_RouteCache,ele))
780#define MAINTBUFFER_ALLOC() (DSR_MAINT_BUFFER*)list_alloc(sizeof(DSR_MAINT_BUFFER),offsetof(DSR_MAINT_BUFFER,ele))
781
782 _declspec(dllexport) int fn_NetSim_DSR_FreePacket(NetSim_PACKET* packet);
783#ifdef __cplusplus
784}
785#endif
786#endif
787
788
789
Definition List.h:43
unsigned int nIdentification
Definition DSR.h:502
NETSIM_IPAddress DestAddress
Definition DSR.h:509
NETSIM_IPAddress sourceAddress
Definition DSR.h:506
unsigned int nOptionDataLen
Definition DSR.h:498
DSR_OPTION_TYPE nOptionType
Definition DSR.h:494
unsigned int nOptionDataLen
Definition DSR.h:459
unsigned int nIdentification
Definition DSR.h:464
DSR_OPTION_TYPE nOptionType
Definition DSR.h:454
struct stru_DSR_RouteCache * pstruRouteCache
List of routes to particular destination.
Definition DSR.h:657
struct stru_DSR_SendBuffer * pstruSendBuffer
Buffer in which packets are added if route to target is not known.
Definition DSR.h:658
DSR_MAINT_BUFFER * pstruMaintBuffer
Buffer in which packets sent to next HOP are added.
Definition DSR.h:665
struct stru_DSR_RouteRequestTable * pstruRREQTable
A table in which entry of RREQ initiated is made.
Definition DSR.h:659
NetSim_PACKET * packetList
packetList - list of packets sent to the destination
Definition DSR.h:630
struct element * ele
Next MaintBuffer.
Definition DSR.h:631
NETSIM_ID nextHop
Next hop ID of a route.
Definition DSR.h:627
unsigned int nReserved
Definition DSR.h:548
unsigned int nNextHeader
Definition DSR.h:536
unsigned int nFlowState
Definition DSR.h:543
DSR_OPTION_TYPE optType
Definition DSR.h:558
double dTimeOutTime
Definition DSR.h:574
unsigned int nTTL
nTTL - Time to Live
Definition DSR.h:602
struct element * ele
ele - next RouteRequestTable
Definition DSR.h:617
unsigned int nIdentification
Identification value.
Definition DSR.h:613
struct element * ele
Next SendBuffer.
Definition DSR.h:594
NETSIM_IPAddress target
Target IP address.
Definition DSR.h:591
NetSim_PACKET * packet
List of packets to a particular Dest IP.
Definition DSR.h:593
unsigned int nSalvage
Definition DSR.h:396
DSR_OPTION_TYPE nOptionType
Definition DSR.h:352
void * TypeSpecificInformation
Definition DSR.h:424
unsigned int nOptDataLen
Definition DSR.h:357
enum stru_NetSim_DSR_RERR_Option::@234164063043207073373340307253340021156076321263 nErrorType
NETSIM_IPAddress errorSourceAddress
Definition DSR.h:409
unsigned int nReserved
Definition DSR.h:392
NETSIM_IPAddress errorDestinationAddress
Definition DSR.h:415
unsigned int nReserved
Definition DSR.h:313
NETSIM_IPAddress * Address
Definition DSR.h:317
unsigned int nOptDataLen
Definition DSR.h:293
DSR_OPTION_TYPE nOptionType
Definition DSR.h:287
unsigned int nLastHopExternal
Definition DSR.h:300
DSR_OPTION_TYPE nOptionType
Definition DSR.h:218
NETSIM_IPAddress * address
Definition DSR.h:251
unsigned int nOptDataLen
Definition DSR.h:224
unsigned int nIdentification
Definition DSR.h:231
NETSIM_IPAddress * Address
Definition DSR.h:182
DSR_OPTION_TYPE nOptionType
Definition DSR.h:129