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-passive-buff.h
"
71
#include "
dsr-option-header.h
"
72
#include "
dsr-fs-header.h
"
73
#include "
dsr-rsendbuff.h
"
74
#include "
dsr-errorbuff.h
"
75
#include "
dsr-gratuitous-reply-table.h
"
76
77
namespace
ns3 {
78
79
class
Packet;
80
class
Node;
81
class
Ipv4;
82
class
Ipv4Address;
83
class
Ipv4Header;
84
class
Ipv4Interface;
85
class
Ipv4L3Protocol;
86
class
Time;
87
88
namespace
dsr {
89
90
class
DsrOptions;
95
class
DsrRouting
:
public
IpL4Protocol
96
{
97
public
:
102
static
TypeId
GetTypeId
();
106
static
const
uint8_t
PROT_NUMBER
;
110
DsrRouting
();
114
virtual
~DsrRouting
();
119
Ptr<Node>
GetNode
()
const
;
124
void
SetNode
(
Ptr<Node>
node);
129
void
SetRouteCache
(
Ptr<dsr::RouteCache>
r);
134
Ptr<dsr::RouteCache>
GetRouteCache
()
const
;
139
void
SetRequestTable
(
Ptr<dsr::RreqTable>
r);
144
Ptr<dsr::RreqTable>
GetRequestTable
()
const
;
149
void
SetPassiveBuffer
(
Ptr<dsr::PassiveBuffer>
r);
154
Ptr<dsr::PassiveBuffer>
GetPassiveBuffer
()
const
;
155
157
//\{
158
bool
IsLinkCache
();
159
void
UseExtends
(
RouteCacheEntry::IP_VECTOR
rt);
160
bool
LookupRoute
(
Ipv4Address
id
,
RouteCacheEntry
& rt);
161
bool
AddRoute_Link
(
RouteCacheEntry::IP_VECTOR
nodelist,
Ipv4Address
source);
162
bool
AddRoute
(
RouteCacheEntry
& rt);
163
void
DeleteAllRoutesIncludeLink
(
Ipv4Address
errorSrc,
Ipv4Address
unreachNode,
Ipv4Address
node);
164
bool
UpdateRouteEntry
(
Ipv4Address
dst);
165
bool
FindSourceEntry
(
Ipv4Address
src,
Ipv4Address
dst, uint16_t
id
);
166
//\}
167
172
void
ConnectCallbacks
();
177
Ptr<NetDevice>
GetNetDeviceFromContext
(std::string context);
182
std::vector<std::string>
GetElementsFromContext
(std::string context);
187
uint16_t
GetIDfromIP
(
Ipv4Address
address);
192
Ipv4Address
GetIPfromID
(uint16_t
id
);
197
Ipv4Address
GetIPfromMAC
(
Mac48Address
address);
202
Ptr<Node>
GetNodeWithAddress
(
Ipv4Address
ipv4Address);
206
void
PrintVector
(std::vector<Ipv4Address>& vec);
211
Ipv4Address
SearchNextHop
(
Ipv4Address
ipv4Address, std::vector<Ipv4Address>& vec);
216
int
GetProtocolNumber
(
void
)
const
;
220
void
SendBuffTimerExpire
();
224
void
CheckSendBuffer
();
228
void
PacketNewRoute
(
Ptr<Packet>
packet,
229
Ipv4Address
source,
230
Ipv4Address
destination,
231
uint8_t protocol);
237
Ptr<Ipv4Route>
SetRoute
(
Ipv4Address
nextHop,
Ipv4Address
srcAddress);
242
uint32_t
GetPriority
(
DsrMessageType
messageType);
246
void
SendUnreachError
(
Ipv4Address
errorHop,
Ipv4Address
destination,
Ipv4Address
originalDst, uint8_t salvage, uint8_t protocol);
250
void
ForwardErrPacket
(
DsrOptionRerrUnreachHeader
&rerr,
251
DsrOptionSRHeader
&sourceRoute,
252
Ipv4Address
nextHop,
253
uint8_t protocol,
254
Ptr<Ipv4Route>
route);
258
void
Send
(
Ptr<Packet>
packet,
Ipv4Address
source,
259
Ipv4Address
destination, uint8_t protocol,
Ptr<Ipv4Route>
route);
263
uint16_t
AddAckReqHeader
(
Ptr<Packet>
&packet,
Ipv4Address
nextHop);
267
void
SendPacket
(
Ptr<Packet>
packet,
Ipv4Address
source,
Ipv4Address
nextHop, uint8_t protocol);
271
void
Scheduler
(uint32_t priority);
275
void
PriorityScheduler
(uint32_t priority,
bool
continueWithFirst);
279
void
IncreaseRetransTimer
();
283
bool
SendRealDown
(
DsrNetworkQueueEntry
& newEntry);
288
void
SendPacketFromBuffer
(
DsrOptionSRHeader
const
&sourceRoute,
289
Ipv4Address
nextHop,
290
uint8_t protocol);
294
bool
PassiveEntryCheck
(
Ptr<Packet>
packet,
Ipv4Address
source,
Ipv4Address
destination, uint8_t
segsLeft
,
295
uint16_t fragmentOffset, uint16_t identification,
bool
saveEntry);
299
bool
CancelPassiveTimer
(
Ptr<Packet>
packet,
Ipv4Address
source,
Ipv4Address
destination, uint8_t
segsLeft
);
303
void
CallCancelPacketTimer
(uint16_t ackId,
Ipv4Header
const
& ipv4Header,
Ipv4Address
realSrc,
Ipv4Address
realDst);
307
void
CancelNetworkPacketTimer
(
MaintainBuffEntry
& mb);
311
void
CancelPassivePacketTimer
(
MaintainBuffEntry
& mb);
315
void
CancelLinkPacketTimer
(
MaintainBuffEntry
& mb);
319
void
CancelPacketTimerNextHop
(
Ipv4Address
nextHop, uint8_t protocol);
323
void
SalvagePacket
(
Ptr<const Packet>
packet,
Ipv4Address
source,
Ipv4Address
dst, uint8_t protocol);
329
void
ScheduleLinkPacketRetry
(
MaintainBuffEntry
& mb,
330
uint8_t protocol);
336
void
SchedulePassivePacketRetry
(
MaintainBuffEntry
& mb,
337
uint8_t protocol);
344
void
ScheduleNetworkPacketRetry
(
MaintainBuffEntry
& mb,
345
bool
isFirst,
346
uint8_t protocol);
350
void
LinkScheduleTimerExpire
(
MaintainBuffEntry
& mb,
351
uint8_t protocol);
355
void
NetworkScheduleTimerExpire
(
MaintainBuffEntry
& mb,
356
uint8_t protocol);
360
void
PassiveScheduleTimerExpire
(
MaintainBuffEntry
& mb,
361
uint8_t protocol);
365
void
ForwardPacket
(
Ptr<const Packet>
packet,
366
DsrOptionSRHeader
&sourceRoute,
367
Ipv4Header
const
& ipv4Header,
368
Ipv4Address
source,
369
Ipv4Address
destination,
370
Ipv4Address
targetAddress,
371
uint8_t protocol,
372
Ptr<Ipv4Route>
route);
376
void
SendInitialRequest
(
Ipv4Address
source,
377
Ipv4Address
destination,
378
uint8_t protocol);
384
void
SendErrorRequest
(
DsrOptionRerrUnreachHeader
&rerr, uint8_t protocol);
391
void
SendRequestAndIncrement
(
Ptr<Packet>
packet,
392
Ipv4Address
source,
393
Ipv4Address
destination);
399
void
SendRequest
(
Ptr<Packet>
packet,
400
Ipv4Address
source);
407
void
ScheduleInterRequest
(
Ptr<Packet>
packet);
413
void
SendGratuitousReply
(
Ipv4Address
replyTo,
414
Ipv4Address
replyFrom,
415
std::vector<Ipv4Address> &nodeList,
416
uint8_t protocol);
420
void
SendReply
(
Ptr<Packet>
packet,
421
Ipv4Address
source,
422
Ipv4Address
nextHop,
423
Ptr<Ipv4Route>
route);
428
void
ScheduleInitialReply
(
Ptr<Packet>
packet,
429
Ipv4Address
source,
430
Ipv4Address
nextHop,
431
Ptr<Ipv4Route>
route);
435
void
ScheduleCachedReply
(
Ptr<Packet>
packet,
436
Ipv4Address
source,
437
Ipv4Address
destination,
438
Ptr<Ipv4Route>
route,
439
double
hops);
443
void
SendAck
(uint16_t ackId,
444
Ipv4Address
destination,
445
Ipv4Address
realSrc,
446
Ipv4Address
realDst,
447
uint8_t protocol,
448
Ptr<Ipv4Route>
route);
457
virtual
enum
IpL4Protocol::RxStatus
Receive
(
Ptr<Packet>
p,
458
Ipv4Header
const
&header,
459
Ptr<Ipv4Interface>
incomingInterface);
460
469
virtual
enum
IpL4Protocol::RxStatus
Receive
(
Ptr<Packet>
p,
470
Ipv6Header
const
&header,
471
Ptr<Ipv6Interface>
incomingInterface);
472
473
void
SetDownTarget
(
IpL4Protocol::DownTargetCallback
callback);
474
void
SetDownTarget6
(
IpL4Protocol::DownTargetCallback6
callback);
475
IpL4Protocol::DownTargetCallback
GetDownTarget
(
void
)
const
;
476
IpL4Protocol::DownTargetCallback6
GetDownTarget6
(
void
)
const
;
481
uint8_t
GetExtensionNumber
()
const
;
493
uint8_t
Process
(
Ptr<Packet>
& packet,
Ipv4Header
const
& ipv4Header,
Ipv4Address
dst, uint8_t *nextHeader, uint8_t protocol,
bool
& isDropped);
498
void
Insert
(
Ptr<dsr::DsrOptions>
option);
504
Ptr<dsr::DsrOptions>
GetOption
(
int
optionNumber);
510
void
CancelRreqTimer
(
Ipv4Address
dst,
bool
isRemove);
515
void
ScheduleRreqRetry
(
Ptr<Packet>
packet, std::vector<Ipv4Address> address,
bool
nonProp, uint32_t requestId, uint8_t protocol);
516
// / Handle route discovery timer
517
void
RouteRequestTimerExpire
(
Ptr<Packet>
packet, std::vector<Ipv4Address> address, uint32_t requestId, uint8_t protocol);
518
527
int64_t
AssignStreams
(int64_t stream);
528
529
protected
:
530
/*
531
* * This function will notify other components connected to the node that a new stack member is now connected
532
* * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
533
* */
534
virtual
void
NotifyNewAggregate
();
538
virtual
void
DoDispose
(
void
);
542
TracedCallback<Ptr<const Packet>
>
m_dropTrace
;
543
TracedCallback <const DsrOptionSRHeader &>
m_txPacketTrace
;
544
545
private
:
546
547
void
Start
();
552
void
NotifyDataReceipt
(std::string context,
Ptr<const Packet>
p);
556
void
SendRerrWhenBreaksLinkToNextHop
(
Ipv4Address
nextHop, uint8_t protocol);
566
bool
PromiscReceive
(
Ptr<NetDevice>
device,
Ptr<const Packet>
packet, uint16_t protocol,
const
Address
&from,
567
const
Address
&to,
NetDevice::PacketType
packetType);
571
typedef
std::list<Ptr<DsrOptions> >
DsrOptionList_t
;
575
DsrOptionList_t
m_options
;
576
577
Ptr<Ipv4L3Protocol>
m_ipv4
;
578
579
Ptr<Ipv4Route>
m_ipv4Route
;
580
581
Ptr<Ipv4>
m_ip
;
582
583
Ptr<Node>
m_node
;
584
585
Ipv4Address
m_mainAddress
;
586
587
uint8_t
segsLeft
;
588
589
IpL4Protocol::DownTargetCallback
m_downTarget
;
590
591
uint32_t
m_maxNetworkSize
;
592
593
Time
m_maxNetworkDelay
;
594
595
uint32_t
m_discoveryHopLimit
;
596
597
uint8_t
m_maxSalvageCount
;
598
599
Time
m_requestPeriod
;
600
601
Time
m_nonpropRequestTimeout
;
602
603
uint32_t
m_sendRetries
;
604
605
uint32_t
m_passiveRetries
;
606
607
uint32_t
m_linkRetries
;
608
609
uint32_t
m_rreqRetries
;
610
611
uint32_t
m_maxMaintRexmt
;
612
613
Time
m_nodeTraversalTime
;
614
615
uint32_t
m_maxSendBuffLen
;
616
617
Time
m_sendBufferTimeout
;
618
619
SendBuffer
m_sendBuffer
;
620
621
ErrorBuffer
m_errorBuffer
;
622
623
uint32_t
m_maxMaintainLen
;
624
625
Time
m_maxMaintainTime
;
626
627
uint32_t
m_maxCacheLen
;
628
629
Time
m_maxCacheTime
;
630
631
Time
m_maxRreqTime
;
632
633
uint32_t
m_maxEntriesEachDst
;
634
635
MaintainBuffer
m_maintainBuffer
;
636
637
uint32_t
m_requestId
;
638
639
uint16_t
m_ackId
;
640
641
uint32_t
m_requestTableSize
;
642
643
uint32_t
m_requestTableIds
;
644
645
uint32_t
m_maxRreqId
;
646
647
Time
m_blacklistTimeout
;
648
649
Ipv4Address
m_broadcast
;
650
651
uint32_t
m_broadcastJitter
;
652
653
Time
m_passiveAckTimeout
;
654
655
uint32_t
m_tryPassiveAcks
;
656
657
Time
m_linkAckTimeout
;
658
659
uint32_t
m_tryLinkAcks
;
660
661
Timer
m_sendBuffTimer
;
662
663
Time
m_sendBuffInterval
;
664
665
Time
m_gratReplyHoldoff
;
666
667
Time
m_maxRequestPeriod
;
668
669
uint32_t
m_graReplyTableSize
;
670
671
std::string
m_cacheType
;
672
673
std::string
m_routeSortType
;
674
675
uint32_t
m_stabilityDecrFactor
;
676
677
uint32_t
m_stabilityIncrFactor
;
678
679
Time
m_initStability
;
680
681
Time
m_minLifeTime
;
682
683
Time
m_useExtends
;
684
685
bool
m_subRoute
;
686
687
Time
m_retransIncr
;
688
689
std::vector<Ipv4Address>
m_finalRoute
;
690
691
std::map<Ipv4Address, Timer>
m_addressReqTimer
;
692
693
std::map<Ipv4Address, Timer>
m_nonPropReqTimer
;
694
695
std::map<NetworkKey, Timer>
m_addressForwardTimer
;
696
697
std::map<NetworkKey, uint32_t>
m_addressForwardCnt
;
698
699
std::map<PassiveKey, uint32_t>
m_passiveCnt
;
700
701
std::map<PassiveKey, Timer>
m_passiveAckTimer
;
702
703
std::map<LinkKey, uint32_t>
m_linkCnt
;
704
705
std::map<LinkKey, Timer>
m_linkAckTimer
;
706
707
Ptr<dsr::RouteCache>
m_routeCache
;
708
709
Ptr<dsr::RreqTable>
m_rreqTable
;
710
711
Ptr<dsr::PassiveBuffer>
m_passiveBuffer
;
712
713
uint32_t
m_numPriorityQueues
;
714
715
bool
m_linkAck
;
716
717
std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >
m_priorityQueue
;
718
719
GraReply
m_graReply
;
720
721
std::vector<Ipv4Address>
m_clearList
;
722
723
std::vector<Ipv4Address>
m_addresses
;
724
725
std::map <std::string, uint32_t>
m_macToNodeIdMap
;
726
727
Ptr<UniformRandomVariable>
m_uniformRandomVariable
;
728
};
729
}
/* namespace dsr */
730
}
/* namespace ns3 */
731
732
#endif
/* DSR_ROUTING_H */
src
dsr
model
dsr-routing.h
Generated on Tue May 14 2013 11:08:20 for ns-3 by
1.8.1.2