A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
dsr-routing.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2011 Yufei Cheng
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Yufei Cheng <yfcheng@ittc.ku.edu>
19
*
20
* James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21
* ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22
* Information and Telecommunication Technology Center (ITTC)
23
* and Department of Electrical Engineering and Computer Science
24
* The University of Kansas Lawrence, KS USA.
25
*
26
* Work supported in part by NSF FIND (Future Internet Design) Program
27
* under grant CNS-0626918 (Postmodern Internet Architecture),
28
* NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29
* US Department of Defense (DoD), and ITTC at The University of Kansas.
30
*/
31
32
#ifndef DSR_ROUTING_H
33
#define DSR_ROUTING_H
34
35
#include <map>
36
#include <list>
37
#include <vector>
38
#include <stdint.h>
39
#include <cassert>
40
#include <sys/types.h>
41
42
#include "ns3/callback.h"
43
#include "ns3/object.h"
44
#include "ns3/node.h"
45
#include "ns3/ptr.h"
46
#include "ns3/buffer.h"
47
#include "ns3/packet.h"
48
#include "ns3/ipv4.h"
49
#include "ns3/ip-l4-protocol.h"
50
#include "ns3/ipv4-l3-protocol.h"
51
#include "ns3/icmpv4-l4-protocol.h"
52
#include "ns3/ipv4-interface.h"
53
#include "ns3/ipv4-header.h"
54
#include "ns3/ipv4-address.h"
55
#include "ns3/traced-callback.h"
56
#include "ns3/random-variable-stream.h"
57
#include "ns3/ipv4-route.h"
58
#include "ns3/timer.h"
59
#include "ns3/net-device.h"
60
#include "ns3/output-stream-wrapper.h"
61
#include "ns3/wifi-mac.h"
62
#include "ns3/socket.h"
63
#include "ns3/event-garbage-collector.h"
64
#include "ns3/test.h"
65
66
#include "
dsr-network-queue.h
"
67
#include "
dsr-rcache.h
"
68
#include "
dsr-rreq-table.h
"
69
#include "
dsr-maintain-buff.h
"
70
#include "
dsr-option-header.h
"
71
#include "
dsr-fs-header.h
"
72
#include "
dsr-rsendbuff.h
"
73
#include "
dsr-errorbuff.h
"
74
#include "
dsr-gratuitous-reply-table.h
"
75
76
namespace
ns3 {
77
78
class
Packet;
79
class
Node;
80
class
Ipv4;
81
class
Ipv4Address;
82
class
Ipv4Header;
83
class
Ipv4Interface;
84
class
Ipv4L3Protocol;
85
class
Time;
86
87
namespace
dsr {
88
89
class
DsrOptions;
94
class
DsrRouting
:
public
IpL4Protocol
95
{
96
public
:
101
static
TypeId
GetTypeId
();
105
static
const
uint8_t
PROT_NUMBER
;
109
DsrRouting
();
113
virtual
~DsrRouting
();
118
Ptr<Node>
GetNode
()
const
;
123
void
SetNode
(
Ptr<Node>
node);
128
void
SetRouteCache
(
Ptr<dsr::RouteCache>
r);
133
Ptr<dsr::RouteCache>
GetRouteCache
()
const
;
138
void
SetRequestTable
(
Ptr<dsr::RreqTable>
r);
143
Ptr<dsr::RreqTable>
GetRequestTable
()
const
;
144
146
//\{
147
bool
IsLinkCache
();
148
void
UseExtends
(
RouteCacheEntry::IP_VECTOR
rt);
149
bool
LookupRoute
(
Ipv4Address
id
,
RouteCacheEntry
& rt);
150
bool
AddRoute_Link
(
RouteCacheEntry::IP_VECTOR
nodelist,
Ipv4Address
source);
151
bool
AddRoute
(
RouteCacheEntry
& rt);
152
void
DeleteAllRoutesIncludeLink
(
Ipv4Address
errorSrc,
Ipv4Address
unreachNode,
Ipv4Address
node);
153
bool
UpdateRouteEntry
(
Ipv4Address
dst);
154
//\}
155
160
uint16_t
GetIDfromIP
(
Ipv4Address
address);
165
Ipv4Address
GetIPfromID
(uint16_t
id
);
170
Ipv4Address
GetIPfromMAC
(
Mac48Address
address);
174
void
PrintVector
(std::vector<Ipv4Address>& vec);
179
Ipv4Address
SearchNextHop
(
Ipv4Address
ipv4Address, std::vector<Ipv4Address>& vec);
184
int
GetProtocolNumber
(
void
)
const
;
188
void
SendBuffTimerExpire
();
192
void
CheckSendBuffer
();
196
void
PacketNewRoute
(
Ptr<Packet>
packet,
197
Ipv4Address
source,
198
Ipv4Address
destination,
199
uint8_t protocol);
200
/*
201
* \brief Set the route to use for data packets
202
* \return the route
203
* \used by the option headers when sending data/control packets
204
*/
205
Ptr<Ipv4Route>
SetRoute
(
Ipv4Address
nextHop,
Ipv4Address
srcAddress);
206
/*
207
* \brief Set the priority of the packet in network queue
208
* \return the priority value
209
*/
210
uint32_t
GetPriority
(
DsrMessageType
messageType);
211
/*
212
* \brief This function is responsible for sending error packets in case of break link to next hop
213
*/
214
void
SendUnreachError
(
Ipv4Address
errorHop,
Ipv4Address
destination,
Ipv4Address
originalDst, uint8_t salvage, uint8_t protocol);
215
/*
216
* \brief This function is responsible for forwarding error packets along the route
217
*/
218
void
ForwardErrPacket
(
DsrOptionRerrUnreachHeader
&rerr,
219
DsrOptionSRHeader
&sourceRoute,
220
Ipv4Address
nextHop,
221
uint8_t protocol,
222
Ptr<Ipv4Route>
route);
223
/*
224
* \brief This function is called by higher layer protocol when sending packets
225
*/
226
void
Send
(
Ptr<Packet>
packet,
Ipv4Address
source,
227
Ipv4Address
destination, uint8_t protocol,
Ptr<Ipv4Route>
route);
228
/*
229
* \brief This function is called to add ack request header for network acknowledgement
230
*/
231
uint16_t
AddAckReqHeader
(
Ptr<Packet>
&packet,
Ipv4Address
nextHop);
232
/*
233
* \brief This function is called by when really sending out the packet
234
*/
235
void
SendPacket
(
Ptr<Packet>
packet,
Ipv4Address
source,
Ipv4Address
nextHop, uint8_t protocol);
236
/*
237
* \brief This function is called to schedule sending packets from the network queue
238
*/
239
void
Scheduler
(uint32_t priority);
240
/*
241
* \brief This function is called to schedule sending packets from the network queue by priority
242
*/
243
void
PriorityScheduler
(uint32_t priority,
bool
continueWithFirst);
244
/*
245
* \brief This function is called to increase the retransmission timer for data packet in the network queue
246
*/
247
void
IncreaseRetransTimer
();
248
/*
249
* \brief This function is called to send packets down stack
250
*/
251
bool
SendRealDown
(
DsrNetworkQueueEntry
& newEntry);
252
/*
253
* This function is responsible for sending out data packets when have route, if no route found, it will
254
* cache the packet and send out route requests
255
*/
256
void
SendPacketFromBuffer
(
DsrOptionSRHeader
const
&sourceRoute,
257
Ipv4Address
nextHop,
258
uint8_t protocol);
259
/*
260
* \brief Find the similar entries in the maintenance buffer
261
*/
262
bool
FindSamePackets
(
Ptr<Packet>
packet,
Ipv4Address
source,
Ipv4Address
destination, uint8_t
segsLeft
);
263
/*
264
* Call the cancel packet retransmission timer function
265
*/
266
void
CallCancelPacketTimer
(uint16_t ackId,
Ipv4Header
const
& ipv4Header,
Ipv4Address
realSrc,
Ipv4Address
realDst);
267
/*
268
* Cancel the network packet retransmission timer for a specific maintenance entry
269
*/
270
void
CancelNetworkPacketTimer
(
MaintainBuffEntry
& mb);
271
/*
272
* Cancel the passive packet retransmission timer for a specific maintenance entry
273
*/
274
void
CancelPassivePacketTimer
(
MaintainBuffEntry
& mb);
275
/*
276
* Cancel the packet retransmission timer for a all maintenance entries with nextHop address
277
*/
278
void
CancelPacketTimerNextHop
(
Ipv4Address
nextHop, uint8_t protocol);
279
/*
280
* Salvage the packet which has been transmitted for 3 times
281
*/
282
void
SalvagePacket
(
Ptr<const Packet>
packet,
Ipv4Address
source,
Ipv4Address
dst, uint8_t protocol);
283
/*
284
* Schedule the packet retransmission when the packet has not reached to the next hop address
285
*/
286
void
SchedulePassivePacketRetry
(
MaintainBuffEntry
& mb,
287
bool
onlyPassive,
288
uint8_t protocol);
289
/*
290
* Schedule the packet retransmission when the packet has not reached to the next hop address
291
*/
292
void
ScheduleNetworkPacketRetry
(
MaintainBuffEntry
& mb,
293
bool
isFirst,
294
uint8_t protocol);
295
/*
296
* This function deals with packet retransmission timer expire
297
*/
298
void
NetworkScheduleTimerExpire
(
MaintainBuffEntry
& mb,
299
uint8_t protocol);
300
/*
301
* This function deals with packet retransmission timer expire
302
*/
303
void
PassiveScheduleTimerExpire
(
MaintainBuffEntry
& mb,
304
bool
onlyPassive,
305
uint8_t protocol);
306
/*
307
* Forward the packet using the route saved in the source route option header
308
*/
309
void
ForwardPacket
(
Ptr<const Packet>
packet,
310
DsrOptionSRHeader
&sourceRoute,
311
Ipv4Header
const
& ipv4Header,
312
Ipv4Address
source,
313
Ipv4Address
destination,
314
Ipv4Address
targetAddress,
315
uint8_t protocol,
316
Ptr<Ipv4Route>
route);
317
/*
318
* Broadcast the route request packet in subnet
319
*/
320
void
SendInitialRequest
(
Ipv4Address
source,
321
Ipv4Address
destination,
322
uint8_t protocol);
323
/*
324
* \brief Send the error request packet
325
* \param the route error header
326
* \param the protocol number
327
*/
328
void
SendErrorRequest
(
DsrOptionRerrUnreachHeader
&rerr, uint8_t protocol);
329
/*
330
* \brief Send the route request and increment the request count
331
* \param the original packet
332
* \param source address
333
* \param destination address
334
*/
335
void
SendRequestAndIncrement
(
Ptr<Packet>
packet,
336
Ipv4Address
source,
337
Ipv4Address
destination);
338
/*
339
* \brief Forward the route request if the node is not the destination
340
* \param the original packet
341
* \param source address
342
*/
343
void
SendRequest
(
Ptr<Packet>
packet,
344
Ipv4Address
source);
345
/*
346
* \brief Schedule the intermediate route request
347
* \param the original packet
348
* \param source The source address
349
* \param destination The destination address
350
*/
351
void
ScheduleInterRequest
(
Ptr<Packet>
packet);
352
/*
353
* \brief Send the gratuitous reply
354
* \param replyTo The destination address to send the reply to
355
* \param replyFrom The source address sending the reply
356
*/
357
void
SendGratuitousReply
(
Ipv4Address
replyTo,
358
Ipv4Address
replyFrom,
359
std::vector<Ipv4Address> &nodeList,
360
uint8_t protocol);
361
/*
362
* Send the route reply back to the request originator with the cumulated route
363
*/
364
void
SendReply
(
Ptr<Packet>
packet,
365
Ipv4Address
source,
366
Ipv4Address
nextHop,
367
Ptr<Ipv4Route>
route);
368
/*
369
* this is a generating the initial route reply from the destination address, a random delay time
370
* [0, m_broadcastJitter] is used before unicasting back the route reply packet
371
*/
372
void
ScheduleInitialReply
(
Ptr<Packet>
packet,
373
Ipv4Address
source,
374
Ipv4Address
nextHop,
375
Ptr<Ipv4Route>
route);
376
/*
377
* Schedule the cached reply to a random start time to avoid possible route reply storm
378
*/
379
void
ScheduleCachedReply
(
Ptr<Packet>
packet,
380
Ipv4Address
source,
381
Ipv4Address
destination,
382
Ptr<Ipv4Route>
route,
383
double
hops);
384
/*
385
* Send network layer acknowledgment back to the earlier hop to notify the receipt of data packet
386
*/
387
void
SendAck
(uint16_t ackId,
388
Ipv4Address
destination,
389
Ipv4Address
realSrc,
390
Ipv4Address
realDst,
391
uint8_t protocol,
392
Ptr<Ipv4Route>
route);
393
/*
394
* Get the node using the ip address
395
*/
396
Ptr<Node>
GetNodeWithAddress
(
Ipv4Address
ipv4Address);
405
virtual
enum
IpL4Protocol::RxStatus
Receive
(
Ptr<Packet>
p,
406
Ipv4Header
const
&header,
407
Ptr<Ipv4Interface>
incomingInterface);
408
418
virtual
enum
IpL4Protocol::RxStatus
Receive
(
Ptr<Packet>
p,
419
Ipv6Address
&src,
420
Ipv6Address
&dst,
421
Ptr<Ipv6Interface>
incomingInterface);
422
423
void
SetDownTarget
(
IpL4Protocol::DownTargetCallback
callback);
424
void
SetDownTarget6
(
IpL4Protocol::DownTargetCallback6
callback);
425
IpL4Protocol::DownTargetCallback
GetDownTarget
(
void
)
const
;
426
IpL4Protocol::DownTargetCallback6
GetDownTarget6
(
void
)
const
;
431
uint8_t
GetExtensionNumber
()
const
;
443
uint8_t
Process
(
Ptr<Packet>
& packet,
Ipv4Header
const
& ipv4Header,
Ipv4Address
dst, uint8_t *nextHeader, uint8_t protocol,
bool
& isDropped);
448
void
Insert
(
Ptr<dsr::DsrOptions>
option);
454
Ptr<dsr::DsrOptions>
GetOption
(
int
optionNumber);
460
void
CancelRreqTimer
(
Ipv4Address
dst,
bool
isRemove);
465
void
ScheduleRreqRetry
(
Ptr<Packet>
packet, std::vector<Ipv4Address> address,
bool
nonProp, uint32_t requestId, uint8_t protocol);
466
// / Handle route discovery timer
467
void
RouteRequestTimerExpire
(
Ptr<Packet>
packet, std::vector<Ipv4Address> address, uint32_t requestId, uint8_t protocol);
468
477
int64_t
AssignStreams
(int64_t stream);
478
479
protected
:
480
/*
481
* * This function will notify other components connected to the node that a new stack member is now connected
482
* * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
483
* */
484
virtual
void
NotifyNewAggregate
();
488
virtual
void
DoDispose
(
void
);
489
/*
490
* The trace for drop, receive and send data packets
491
*/
492
TracedCallback<Ptr<const Packet>
>
m_dropTrace
;
493
TracedCallback <const DsrOptionSRHeader &>
m_txPacketTrace
;
494
495
private
:
496
void
Start
();
500
void
SendRerrWhenBreaksLinkToNextHop
(
Ipv4Address
nextHop, uint8_t protocol);
504
bool
PromiscReceive
(
Ptr<NetDevice>
device,
Ptr<const Packet>
packet, uint16_t protocol,
const
Address
&from,
505
const
Address
&to,
NetDevice::PacketType
packetType);
509
typedef
std::list<Ptr<DsrOptions> >
DsrOptionList_t
;
513
DsrOptionList_t
m_options
;
514
515
Ptr<Ipv4L3Protocol>
m_ipv4
;
// / Ipv4l3Protocol
516
517
Ptr<Ipv4Route>
m_ipv4Route
;
// / Ipv4 Route
518
519
Ptr<Ipv4>
m_ip
;
// / The ip ptr
520
521
Ptr<Node>
m_node
;
// / The node ptr
522
523
Ipv4Address
m_mainAddress
;
// / Our own Ip address
524
525
uint8_t
segsLeft
;
// / The segment left value from SR header
526
527
IpL4Protocol::DownTargetCallback
m_downTarget
;
// The callback for down layer
528
529
uint32_t
m_maxNetworkSize
;
// / Maximum network queue size
530
531
Time
m_maxNetworkDelay
;
// / Maximum network delay
532
533
uint32_t
m_discoveryHopLimit
;
// / Maximum hops to go for route request
534
535
uint8_t
m_maxSalvageCount
;
// / Maximum # times to salvage a packet
536
537
Time
m_requestPeriod
;
// / The base time interval between route requests
538
539
Time
m_nonpropRequestTimeout
;
// / The non-propagation request timeout
540
541
uint32_t
m_sendRetries
;
// / # of retries have been sent for network acknowledgment
542
543
uint32_t
m_passiveRetries
;
// / # of retries have been sent for passive acknowledgment
544
545
uint32_t
m_rreqRetries
;
// /< Maximum number of retransmissions of RREQ with TTL = NetDiameter to discover a route
546
547
uint32_t
m_maxMaintRexmt
;
// /< Maximum number of retransmissions of data packets
548
549
Time
m_nodeTraversalTime
;
// / Time estimated for packet to travel between two nodes
550
551
uint32_t
m_maxSendBuffLen
;
// /< The maximum number of packets that we allow a routing protocol to buffer.
552
553
Time
m_sendBufferTimeout
;
// /< The maximum period of time that a routing protocol is allowed to buffer a packet for.
554
555
SendBuffer
m_sendBuffer
;
// / The send buffer
556
557
ErrorBuffer
m_errorBuffer
;
// / The error buffer to save the error messages
558
559
uint32_t
m_maxMaintainLen
;
// / Max # of entries for maintainance buffer
560
561
Time
m_maxMaintainTime
;
// / Time out for maintainance buffer
562
563
uint32_t
m_maxCacheLen
;
// / Max # of cache entries for route cache
564
565
Time
m_maxCacheTime
;
// / Max time for caching the route cache entry
566
567
Time
m_maxRreqTime
;
// / Max time for caching the route request entry
568
569
uint32_t
m_maxEntriesEachDst
;
// / Max number of route entries to save for each destination
570
571
MaintainBuffer
m_maintainBuffer
;
// / The declaration of maintain buffer
572
573
uint32_t
m_requestId
;
// / The id assigned to each route request
574
575
uint16_t
m_ackId
;
// / The ack id assigned to each acknowledge
576
577
uint32_t
m_requestTableSize
;
// / The max size of the request table size
578
579
uint32_t
m_requestTableIds
;
// / The request table identifiers
580
581
uint32_t
m_maxRreqId
;
// / The max number of request ids for a single destination
582
583
Time
m_blacklistTimeout
;
// / The black list time out
584
585
Ipv4Address
m_broadcast
;
// / The broadcast IP address
586
587
uint32_t
m_broadcastJitter
;
// / The max time to delay route request broadcast.
588
589
Time
m_passiveAckTimeout
;
// / The timeout value for passive acknowledge
590
591
uint32_t
m_tryPassiveAcks
;
// /< Maximum number of packet transmission using passive acknowledgment
592
593
Timer
m_sendBuffTimer
;
// / The send buffer timer
594
595
Time
m_sendBuffInterval
;
// / how often to check send buffer
596
597
Time
m_gratReplyHoldoff
;
// / The max gratuitous reply hold off time
598
599
Time
m_maxRequestPeriod
;
// / The max request period
600
601
uint32_t
m_graReplyTableSize
;
// / Set the gratuitous reply table size
602
603
std::string
m_cacheType
;
// / The type of route cache
604
605
std::string
m_routeSortType
;
// / The type of route sort methods
606
607
uint64_t
m_stabilityDecrFactor
;
// / The initial decrease factor for link cache
608
609
uint64_t
m_stabilityIncrFactor
;
// / The initial increase factor for link cache
610
611
Time
m_initStability
;
// / The initial stability value for link cache
612
613
Time
m_minLifeTime
;
// / The min life time
614
615
Time
m_useExtends
;
// / The use extension of the life time for link cache
616
617
bool
m_subRoute
;
// / Whether to save sub route or not
618
619
Time
m_retransIncr
;
// / the increase time for retransmission timer when face network congestion
620
621
std::vector<Ipv4Address>
m_finalRoute
;
// / The route cache
622
623
std::map<Ipv4Address, Timer>
m_addressReqTimer
;
// / Map IP address + RREQ timer.
624
625
std::map<Ipv4Address, Timer>
m_nonPropReqTimer
;
// / Map IP address + RREQ timer.
626
627
std::map<NetworkKey, Timer>
m_addressForwardTimer
;
// / Map network key + forward timer.
628
629
std::map<NetworkKey, uint32_t>
m_addressForwardCnt
;
// / Map network key + forward counts.
630
631
std::map<PassiveKey, uint32_t>
m_passiveCnt
;
// / Map packet key + passive forward counts.
632
633
std::map<PassiveKey, Timer>
m_passiveAckTimer
;
// / The timer for passive acknowledgment
634
635
Ptr<dsr::RouteCache>
m_routeCache
;
// / A "drop-front" queue used by the routing layer to cache routes found.
636
637
Ptr<dsr::RreqTable>
m_rreqTable
;
// / A "drop-front" queue used by the routing layer to cache route request sent.
638
639
uint32_t
m_numPriorityQueues
;
640
641
std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >
m_priorityQueue
;
// / priority queueus
642
643
GraReply
m_graReply
;
// / The gratuitous route reply.
644
645
std::vector<Ipv4Address>
m_clearList
;
// / The node that is clear to send packet to
646
647
std::vector<Ipv4Address>
m_addresses
;
// / The bind ipv4 addresses with next hop, src, destination address in sequence
648
650
Ptr<UniformRandomVariable>
m_uniformRandomVariable
;
651
};
652
}
/* namespace dsr */
653
}
/* namespace ns3 */
654
655
#endif
/* DSR_ROUTING_H */
src
dsr
model
dsr-routing.h
Generated on Tue Nov 13 2012 10:32:13 for ns-3 by
1.8.1.2