OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2011 Yufei Cheng | 3 * Copyright (c) 2011 Yufei Cheng |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 18 matching lines...) Expand all Loading... |
29 * US Department of Defense (DoD), and ITTC at The University of Kansas. | 29 * US Department of Defense (DoD), and ITTC at The University of Kansas. |
30 */ | 30 */ |
31 | 31 |
32 #ifndef DSR_RREQ_TABLE_H | 32 #ifndef DSR_RREQ_TABLE_H |
33 #define DSR_RREQ_TABLE_H | 33 #define DSR_RREQ_TABLE_H |
34 | 34 |
35 #include "ns3/simulator.h" | 35 #include "ns3/simulator.h" |
36 #include "ns3/timer.h" | 36 #include "ns3/timer.h" |
37 #include "ns3/ipv4-address.h" | 37 #include "ns3/ipv4-address.h" |
38 #include "ns3/callback.h" | 38 #include "ns3/callback.h" |
| 39 #include <list> |
39 #include <vector> | 40 #include <vector> |
40 #include <map> | 41 #include <map> |
41 | 42 |
42 namespace ns3 { | 43 namespace ns3 { |
43 namespace dsr { | 44 namespace dsr { |
44 | 45 |
45 enum LinkStates | 46 enum LinkStates |
46 { | 47 { |
47 PROBABLE = 0, // !< PROBABLE | 48 PROBABLE = 0, // !< PROBABLE |
48 QUESTIONABLE = 1, // !< QUESTIONABLE | 49 QUESTIONABLE = 1, // !< QUESTIONABLE |
(...skipping 10 matching lines...) Expand all Loading... |
59 m_expireTime (t), | 60 m_expireTime (t), |
60 m_linkStates (PROBABLE) | 61 m_linkStates (PROBABLE) |
61 { | 62 { |
62 } | 63 } |
63 }; | 64 }; |
64 /* | 65 /* |
65 * The route request table entries | 66 * The route request table entries |
66 */ | 67 */ |
67 struct RreqTableEntry | 68 struct RreqTableEntry |
68 { | 69 { |
69 Ipv4Address m_dst; | |
70 uint8_t m_ttl; | |
71 uint16_t m_reqNo; | 70 uint16_t m_reqNo; |
| 71 Time m_expire; |
72 }; | 72 }; |
73 /* | 73 /* |
74 * The route request table id for originators | 74 * The route request table id for originators |
75 * It is responsible for checking duplicate requests from a single source to a s
pecific destination | 75 * It is responsible for checking duplicate requests from a single source to a s
pecific destination |
76 */ | 76 */ |
77 struct SourceRreqEntry | 77 struct SourceRreqEntry |
78 { | 78 { |
79 uint16_t m_identification; | 79 uint16_t m_identification; |
80 Ipv4Address m_dst; | 80 Ipv4Address m_dst; |
| 81 Time m_expire; |
81 }; | 82 }; |
82 /** | 83 /** |
83 * \ingroup dsr | 84 * \ingroup dsr |
84 * \brief maintain list of RreqTable entry | 85 * \brief maintain list of RreqTable entry |
85 */ | 86 */ |
86 class RreqTable : public Object | 87 class RreqTable : public Object |
87 { | 88 { |
88 public: | 89 public: |
89 // / c-tor | 90 // / c-tor |
90 /** | 91 /** |
(...skipping 29 matching lines...) Expand all Loading... |
120 return m_requestTableSize; | 121 return m_requestTableSize; |
121 } | 122 } |
122 void SetRreqIdSize (uint32_t id) | 123 void SetRreqIdSize (uint32_t id) |
123 { | 124 { |
124 m_requestIdSize = id; | 125 m_requestIdSize = id; |
125 } | 126 } |
126 uint32_t GetRreqIdSize () const | 127 uint32_t GetRreqIdSize () const |
127 { | 128 { |
128 return m_requestIdSize; | 129 return m_requestIdSize; |
129 } | 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 |
130 // \} | 140 // \} |
131 // / Find the request table entry with destination address | 141 // / Remove the least used entry |
132 bool UpdateEntryTTL (Ipv4Address dst); | 142 void RemoveLeastExpire (std::map<Ipv4Address, RreqTableEntry > & rreqDstMap); |
133 // / Find the entry in the route request queue to see if already exists | 143 // / Find the entry in the route request queue to see if already exists |
134 bool Find (Ipv4Address dst); | 144 void FindAndUpdate (Ipv4Address dst); |
135 // / Update expire time for entry with address addr, if it exists, else add ne
w entry | |
136 void Update (RreqTableEntry & entry); | |
137 // / Remove route request entry for dst | 145 // / Remove route request entry for dst |
138 bool RemoveRreqEntry (Ipv4Address dst); | 146 void RemoveRreqEntry (Ipv4Address dst); |
139 // / Get the request count number for one destination address | 147 // / Get the request count number for one destination address |
140 uint16_t GetRreqCnt (Ipv4Address dst); | 148 uint16_t GetRreqCnt (Ipv4Address dst); |
141 // / Increase the request count number for one destination address | |
142 bool IncrementRreqCnt (Ipv4Address dst); | |
143 // / Remove all expired entries | |
144 void Purge (); | |
145 // / Remove all entries | |
146 void Clear () | |
147 { | |
148 m_rreqTable.clear (); | |
149 } | |
150 | 149 |
151 //----------------------------------------------------------------------------
------------------------------ | 150 //----------------------------------------------------------------------------
------------------------------ |
152 /* | 151 /* |
153 * The following code deals with duplicate request ids | 152 * The following code deals with duplicate request ids |
154 */ | 153 */ |
155 bool FindSrc (Ipv4Address source, Ipv4Address target, uint16_t id); | 154 bool FindSrc (Ipv4Address source, Ipv4Address target, uint16_t id); |
156 | 155 |
157 //----------------------------------------------------------------------------
------------------------------ | 156 //----------------------------------------------------------------------------
------------------------------ |
158 /* | 157 /* |
159 * The following code generates new request id for each destination | 158 * The following code generates new request id for each destination |
(...skipping 16 matching lines...) Expand all Loading... |
176 /** Mark entry as unidirectional (e.g. add this neighbor to "blacklist" for bl
acklistTimeout period) | 175 /** Mark entry as unidirectional (e.g. add this neighbor to "blacklist" for bl
acklistTimeout period) |
177 * \param neighbor - neighbor address link to which assumed to be unidirection
al | 176 * \param neighbor - neighbor address link to which assumed to be unidirection
al |
178 * \param blacklistTimeout - time for which the neighboring node is put into t
he blacklist | 177 * \param blacklistTimeout - time for which the neighboring node is put into t
he blacklist |
179 * \return true on success | 178 * \return true on success |
180 */ | 179 */ |
181 bool MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout); | 180 bool MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout); |
182 // / Remove all expired black list entries | 181 // / Remove all expired black list entries |
183 void PurgeNeighbor (); | 182 void PurgeNeighbor (); |
184 | 183 |
185 private: | 184 private: |
| 185 |
186 // / Timer for neighbor's list. Schedule Purge(). | 186 // / Timer for neighbor's list. Schedule Purge(). |
187 Timer m_ntimer; | 187 Timer m_ntimer; |
188 // / The max size of route request table size | |
189 uint32_t RequestTableSize; | |
190 // / The max size for route request IDs | |
191 uint32_t RequestTableIds; | |
192 // / The max # of requests to retransmit | 188 // / The max # of requests to retransmit |
193 uint32_t MaxRequestRexmt; | 189 uint32_t MaxRequestRexmt; |
194 // / The max request period among requests | 190 // / The max request period among requests |
195 Time MaxRequestPeriod; | 191 Time MaxRequestPeriod; |
196 // / The original request period | 192 // / The original request period |
197 Time RequestPeriod; | 193 Time RequestPeriod; |
198 // / The non-propagaton request timeout | 194 // / The non-propagaton request timeout |
199 Time NonpropRequestTimeout; | 195 Time NonpropRequestTimeout; |
200 // / The initial hop limit | 196 // / The initial hop limit |
201 uint8_t m_initHopLimit; | 197 uint8_t m_initHopLimit; |
202 // / The request table size | 198 // / The request table size |
203 uint32_t m_requestTableSize; | 199 uint32_t m_requestTableSize; |
204 // / The request id size | 200 // / The request source id size |
205 uint32_t m_requestIdSize; | 201 uint32_t m_requestIdSize; |
| 202 // / The unique request id for any destination |
| 203 uint16_t m_maxRreqId; |
206 // / The state of the unidirectional link | 204 // / The state of the unidirectional link |
207 LinkStates m_linkStates; | 205 LinkStates m_linkStates; |
208 // / Vector of entries | |
209 std::vector<RreqTableEntry> m_rreqTable; | |
210 // / Map of entries | 206 // / Map of entries |
211 std::vector<SourceRreqEntry> m_sourceRreq; | 207 std::list<SourceRreqEntry> m_sourceRreq; |
212 // / The id cache to ensure all the ids are unique | 208 // / The id cache to ensure all the ids are unique |
213 std::map<Ipv4Address, uint16_t> m_rreqIdCache; | 209 std::map<Ipv4Address, uint16_t> m_rreqIdCache; |
| 210 // / The cache to save route request table entries indexed with destination ad
dress |
| 211 std::map<Ipv4Address, RreqTableEntry > m_rreqDstMap; |
214 // / The cache to ensure all the route request from unique source | 212 // / The cache to ensure all the route request from unique source |
215 std::map<Ipv4Address, std::vector<SourceRreqEntry> > m_rreqMap; | 213 std::map<Ipv4Address, std::list<SourceRreqEntry> > m_rreqMap; |
216 // / The Black list | 214 // / The Black list |
217 std::vector<BlackList> m_blackList; | 215 std::vector<BlackList> m_blackList; |
218 // / Check if the entry is expired or not | 216 // / Check if the entry is expired or not |
219 struct IsExpired | 217 struct IsExpired |
220 { | 218 { |
221 bool operator() (const struct BlackList & b) const | 219 bool operator() (const struct BlackList & b) const |
222 { | 220 { |
223 return (b.m_expireTime < Simulator::Now ()); | 221 return (b.m_expireTime < Simulator::Now ()); |
224 } | 222 } |
225 }; | 223 }; |
226 }; | 224 }; |
227 } // namespace dsr | 225 } // namespace dsr |
228 } // namespace ns3 | 226 } // namespace ns3 |
229 | 227 |
230 #endif /* DSR_RREQ_TABLE_H */ | 228 #endif /* DSR_RREQ_TABLE_H */ |
OLD | NEW |