8751
|
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_RREQ_TABLE_H
|
|
33 |
#define DSR_RREQ_TABLE_H
|
|
34 |
|
|
35 |
#include "ns3/simulator.h"
|
|
36 |
#include "ns3/timer.h"
|
|
37 |
#include "ns3/ipv4-address.h"
|
|
38 |
#include "ns3/callback.h"
|
|
39 |
#include <list>
|
|
40 |
#include <vector>
|
|
41 |
#include <map>
|
|
42 |
|
|
43 |
namespace ns3 {
|
|
44 |
namespace dsr {
|
|
45 |
|
|
46 |
enum LinkStates
|
|
47 |
{
|
|
48 |
PROBABLE = 0, // !< PROBABLE
|
|
49 |
QUESTIONABLE = 1, // !< QUESTIONABLE
|
|
50 |
};
|
|
51 |
// / BlackList description
|
|
52 |
struct BlackList
|
|
53 |
{
|
|
54 |
Ipv4Address m_neighborAddress;
|
|
55 |
Time m_expireTime;
|
|
56 |
LinkStates m_linkStates;
|
|
57 |
|
|
58 |
BlackList (Ipv4Address ip, Time t)
|
|
59 |
: m_neighborAddress (ip),
|
|
60 |
m_expireTime (t),
|
|
61 |
m_linkStates (PROBABLE)
|
|
62 |
{
|
|
63 |
}
|
|
64 |
};
|
|
65 |
/*
|
|
66 |
* The route request table entries
|
|
67 |
*/
|
|
68 |
struct RreqTableEntry
|
|
69 |
{
|
|
70 |
uint16_t m_reqNo;
|
|
71 |
Time m_expire;
|
|
72 |
};
|
|
73 |
/*
|
|
74 |
* The route request table id for originators
|
|
75 |
* It is responsible for checking duplicate requests from a single source to a specific destination
|
|
76 |
*/
|
|
77 |
struct SourceRreqEntry
|
|
78 |
{
|
|
79 |
uint16_t m_identification;
|
|
80 |
Ipv4Address m_dst;
|
|
81 |
Time m_expire;
|
|
82 |
};
|
|
83 |
/**
|
|
84 |
* \ingroup dsr
|
|
85 |
* \brief maintain list of RreqTable entry
|
|
86 |
*/
|
|
87 |
class RreqTable : public Object
|
|
88 |
{
|
|
89 |
public:
|
|
90 |
// / c-tor
|
|
91 |
/**
|
|
92 |
* \brief Get the type identificator.
|
|
93 |
* \return type identificator
|
|
94 |
*/
|
|
95 |
static TypeId GetTypeId ();
|
|
96 |
/**
|
|
97 |
* \brief Constructor.
|
|
98 |
*/
|
|
99 |
RreqTable ();
|
|
100 |
/**
|
|
101 |
* \brief Destructor.
|
|
102 |
*/
|
|
103 |
virtual ~RreqTable ();
|
|
104 |
|
|
105 |
// /\name Fields
|
|
106 |
// \{
|
|
107 |
void SetInitHopLimit (uint8_t hl)
|
|
108 |
{
|
|
109 |
m_initHopLimit = hl;
|
|
110 |
}
|
|
111 |
uint8_t GetInitHopLimit () const
|
|
112 |
{
|
|
113 |
return m_initHopLimit;
|
|
114 |
}
|
|
115 |
void SetRreqTableSize (uint32_t rt)
|
|
116 |
{
|
|
117 |
m_requestTableSize = rt;
|
|
118 |
}
|
|
119 |
uint32_t GetRreqTableSize () const
|
|
120 |
{
|
|
121 |
return m_requestTableSize;
|
|
122 |
}
|
|
123 |
void SetRreqIdSize (uint32_t id)
|
|
124 |
{
|
|
125 |
m_requestIdSize = id;
|
|
126 |
}
|
|
127 |
uint32_t GetRreqIdSize () const
|
|
128 |
{
|
|
129 |
return m_requestIdSize;
|
|
130 |
}
|
|
131 |
void SetUniqueRreqIdSize (uint16_t uid)
|
|
132 |
{
|
|
133 |
m_maxRreqId = uid;
|
|
134 |
}
|
|
135 |
uint16_t GetUniqueRreqIdSize () const
|
|
136 |
{
|
|
137 |
return m_maxRreqId;
|
|
138 |
}
|
|
139 |
|
|
140 |
// \}
|
|
141 |
// / Remove the least used entry
|
|
142 |
void RemoveLeastExpire (std::map<Ipv4Address, RreqTableEntry > & rreqDstMap);
|
|
143 |
// / Find the entry in the route request queue to see if already exists
|
|
144 |
void FindAndUpdate (Ipv4Address dst);
|
|
145 |
// / Remove route request entry for dst
|
|
146 |
void RemoveRreqEntry (Ipv4Address dst);
|
|
147 |
// / Get the request count number for one destination address
|
|
148 |
uint16_t GetRreqCnt (Ipv4Address dst);
|
|
149 |
|
|
150 |
//----------------------------------------------------------------------------------------------------------
|
|
151 |
/*
|
|
152 |
* The following code deals with duplicate request ids
|
|
153 |
*/
|
|
154 |
bool FindSrc (Ipv4Address source, Ipv4Address target, uint16_t id);
|
|
155 |
// / Purge the rreq table
|
|
156 |
void Purge ();
|
|
157 |
// / Set the source rreq expire time to the time of max route expire time
|
|
158 |
void SetRreqExpire (Time expire)
|
|
159 |
{
|
|
160 |
m_rreqEntryExpire = expire;
|
|
161 |
}
|
|
162 |
|
|
163 |
//----------------------------------------------------------------------------------------------------------
|
|
164 |
/*
|
|
165 |
* The following code generates new request id for each destination
|
|
166 |
*/
|
|
167 |
// / Check for duplicate ids and save new entries if the id is not present in the table
|
|
168 |
uint16_t CheckUniqueRreqId (Ipv4Address dst);
|
|
169 |
// / Get the request id size
|
|
170 |
uint16_t GetRreqSize ();
|
|
171 |
|
|
172 |
// ---------------------------------------------------------------------------------------------------------
|
|
173 |
/*
|
|
174 |
* set the unidirectional entry as QUESTIONABLE state
|
|
175 |
*/
|
|
176 |
void Invalidate ();
|
|
177 |
/** Verify if entry is unidirectional or not(e.g. add this neighbor to "blacklist" for blacklistTimeout period)
|
|
178 |
* \param neighbor - neighbor address link to which assumed to be unidirectional
|
|
179 |
* \return true on success
|
|
180 |
*/
|
|
181 |
BlackList* FindUnidirectional (Ipv4Address neighbor);
|
|
182 |
/** Mark entry as unidirectional (e.g. add this neighbor to "blacklist" for blacklistTimeout period)
|
|
183 |
* \param neighbor - neighbor address link to which assumed to be unidirectional
|
|
184 |
* \param blacklistTimeout - time for which the neighboring node is put into the blacklist
|
|
185 |
* \return true on success
|
|
186 |
*/
|
|
187 |
bool MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout);
|
|
188 |
// / Remove all expired black list entries
|
|
189 |
void PurgeNeighbor ();
|
|
190 |
|
|
191 |
private:
|
|
192 |
// / Timer for neighbor's list. Schedule Purge().
|
|
193 |
Timer m_ntimer;
|
|
194 |
// / The max # of requests to retransmit
|
|
195 |
uint32_t MaxRequestRexmt;
|
|
196 |
// / The max request period among requests
|
|
197 |
Time MaxRequestPeriod;
|
|
198 |
// / The original request period
|
|
199 |
Time RequestPeriod;
|
|
200 |
// / The non-propagaton request timeout
|
|
201 |
Time NonpropRequestTimeout;
|
|
202 |
// / The source route entry expire time
|
|
203 |
Time m_rreqEntryExpire;
|
|
204 |
// / The initial hop limit
|
|
205 |
uint8_t m_initHopLimit;
|
|
206 |
// / The request table size
|
|
207 |
uint32_t m_requestTableSize;
|
|
208 |
// / The request source id size
|
|
209 |
uint32_t m_requestIdSize;
|
|
210 |
// / The unique request id for any destination
|
|
211 |
uint16_t m_maxRreqId;
|
|
212 |
// / The state of the unidirectional link
|
|
213 |
LinkStates m_linkStates;
|
|
214 |
// / Map of entries
|
|
215 |
std::list<SourceRreqEntry> m_sourceRreq;
|
|
216 |
// / The id cache to ensure all the ids are unique
|
|
217 |
std::map<Ipv4Address, uint16_t> m_rreqIdCache;
|
|
218 |
// / The cache to save route request table entries indexed with destination address
|
|
219 |
std::map<Ipv4Address, RreqTableEntry > m_rreqDstMap;
|
|
220 |
// / The cache to ensure all the route request from unique source
|
|
221 |
std::map<Ipv4Address, std::list<SourceRreqEntry> > m_rreqMap;
|
|
222 |
// / The Black list
|
|
223 |
std::vector<BlackList> m_blackList;
|
|
224 |
// / Check if the entry is expired or not
|
|
225 |
struct IsExpired
|
|
226 |
{
|
|
227 |
bool operator() (const struct BlackList & b) const
|
|
228 |
{
|
|
229 |
return (b.m_expireTime < Simulator::Now ());
|
|
230 |
}
|
|
231 |
};
|
|
232 |
};
|
|
233 |
} // namespace dsr
|
|
234 |
} // namespace ns3
|
|
235 |
|
|
236 |
#endif /* DSR_RREQ_TABLE_H */
|