LEFT | RIGHT |
(no file at all) | |
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 /* | 49 /* |
50 * The packet timer key for controlling data packet retransmission | 50 * The packet timer key for controlling data packet retransmission |
51 */ | 51 */ |
52 struct PacketKey | 52 struct PacketKey |
53 { | 53 { |
54 uint16_t m_ackId; | 54 uint16_t m_ackId; |
55 Ipv4Address m_ourAdd; | 55 Ipv4Address m_ourAdd; |
56 Ipv4Address m_nextHop; | 56 Ipv4Address m_nextHop; |
57 Ipv4Address m_source; | 57 Ipv4Address m_source; |
58 Ipv4Address m_destination; | 58 Ipv4Address m_destination; |
59 uint16_t m_sendRetries; | |
60 uint8_t m_segsLeft; | 59 uint8_t m_segsLeft; |
61 uint16_t m_id; | |
62 uint16_t m_fragmentOffset; | |
63 | 60 |
64 /** | 61 /** |
65 * Compare maintain Buffer entries | 62 * Compare maintain Buffer entries |
66 * \return true if equal | 63 * \return true if equal |
67 */ | 64 */ |
68 bool operator < (PacketKey const & o) const | 65 bool operator < (PacketKey const & o) const |
69 { | 66 { |
70 return ((m_ackId < o.m_ackId) && (m_ourAdd < o.m_ourAdd) && (m_nextHop < o.m
_nextHop) && (m_source < o.m_source) | 67 return ((m_ackId < o.m_ackId) && (m_ourAdd < o.m_ourAdd) && (m_nextHop < o.m
_nextHop) && (m_source < o.m_source) |
71 && (m_destination < o.m_destination) && (m_sendRetries < o.m_sendRet
ries) && (m_segsLeft < o.m_segsLeft) | 68 && (m_destination < o.m_destination) && (m_segsLeft < o.m_segsLeft) |
72 && (m_id < o.m_id) && (m_fragmentOffset < o.m_fragmentOffset) | |
73 ); | 69 ); |
74 } | 70 } |
75 }; | 71 }; |
76 /** | 72 /** |
77 * \ingroup dsr | 73 * \ingroup dsr |
78 * \brief DSR Maintain Buffer Entry | 74 * \brief DSR Maintain Buffer Entry |
79 */ | 75 */ |
80 class MaintainBuffEntry | 76 class MaintainBuffEntry |
81 { | 77 { |
82 public: | 78 public: |
83 // / c-tor | 79 // / c-tor |
84 MaintainBuffEntry (Ptr<const Packet> pa = 0, Ipv4Header const & ip = Ipv4Heade
r (), Ipv4Address us = Ipv4Address (), | 80 MaintainBuffEntry (Ptr<const Packet> pa = 0, Ipv4Address us = Ipv4Address (), |
85 Ipv4Address n = Ipv4Address (), Ipv4Address s = Ipv4Address
(), Ipv4Address dst = Ipv4Address (), | 81 Ipv4Address n = Ipv4Address (), Ipv4Address s = Ipv4Address
(), Ipv4Address dst = Ipv4Address (), |
86 uint16_t id = 0, uint8_t segs = 0, uint8_t sal = 0, uint8_t
r = 0, Time exp = Simulator::Now ()) | 82 uint16_t ackId = 0, uint8_t segs = 0, Time exp = Simulator:
:Now ()) |
87 : m_packet (pa), | 83 : m_packet (pa), |
88 m_ipHeader (ip), | |
89 m_ourAdd (us), | 84 m_ourAdd (us), |
90 m_nextHop (n), | 85 m_nextHop (n), |
91 m_src (s), | 86 m_src (s), |
92 m_dst (dst), | 87 m_dst (dst), |
93 m_ackId (id), | 88 m_ackId (ackId), |
94 m_segsLeft (segs), | 89 m_segsLeft (segs), |
95 m_salvage (sal), | |
96 m_routeSize (r), | |
97 m_forwardCount (0), | |
98 m_isPassive (true), | 90 m_isPassive (true), |
99 m_expire (exp + Simulator::Now ()) | 91 m_expire (exp + Simulator::Now ()) |
100 { | 92 { |
101 } | |
102 /** | |
103 * Compare maintain Buffer entries | |
104 * \return true if equal | |
105 */ | |
106 bool operator== (MaintainBuffEntry const & o) const | |
107 { | |
108 return ((m_packet == o.m_packet) && (m_ourAdd == o.m_ourAdd) && (m_nextHop =
= o.m_nextHop) && (m_src == o.m_src) && (m_dst == o.m_dst) && (m_segsLeft >= o.m
_segsLeft) | |
109 ); | |
110 } | 93 } |
111 | 94 |
112 // /\name Fields | 95 // /\name Fields |
113 // \{ | 96 // \{ |
114 Ptr<const Packet> GetPacket () const | 97 Ptr<const Packet> GetPacket () const |
115 { | 98 { |
116 return m_packet; | 99 return m_packet; |
117 } | 100 } |
118 void SetPacket (Ptr<const Packet> p) | 101 void SetPacket (Ptr<const Packet> p) |
119 { | 102 { |
(...skipping 28 matching lines...) Expand all Loading... |
148 return m_src; | 131 return m_src; |
149 } | 132 } |
150 void SetSrc (Ipv4Address s) | 133 void SetSrc (Ipv4Address s) |
151 { | 134 { |
152 m_src = s; | 135 m_src = s; |
153 } | 136 } |
154 uint16_t GetAckId () const | 137 uint16_t GetAckId () const |
155 { | 138 { |
156 return m_ackId; | 139 return m_ackId; |
157 } | 140 } |
158 void SetAckId (uint16_t id) | 141 void SetAckId (uint16_t ackId) |
159 { | 142 { |
160 m_ackId = id; | 143 m_ackId = ackId; |
161 } | 144 } |
162 uint8_t GetSegsLeft () const | 145 uint8_t GetSegsLeft () const |
163 { | 146 { |
164 return m_segsLeft; | 147 return m_segsLeft; |
165 } | 148 } |
166 void SetSegsLeft (uint8_t segs) | 149 void SetSegsLeft (uint8_t segs) |
167 { | 150 { |
168 m_segsLeft = segs; | 151 m_segsLeft = segs; |
169 } | 152 } |
170 uint8_t GetSalvage () const | |
171 { | |
172 return m_salvage; | |
173 } | |
174 void SetSalvage (uint8_t sal) | |
175 { | |
176 m_salvage = sal; | |
177 } | |
178 uint16_t GetForwardCount () const | |
179 { | |
180 return m_forwardCount; | |
181 } | |
182 void SetForwardCount (uint16_t count) | |
183 { | |
184 m_forwardCount = count; | |
185 } | |
186 uint8_t GetRouteSize () const | |
187 { | |
188 return m_routeSize; | |
189 } | |
190 void SetRouteSize (uint8_t r) | |
191 { | |
192 m_routeSize = r; | |
193 } | |
194 bool GetPassive () const | 153 bool GetPassive () const |
195 { | 154 { |
196 return m_isPassive; | 155 return m_isPassive; |
197 } | 156 } |
198 void SetPassive (bool pa) | 157 void SetPassive (bool pa) |
199 { | 158 { |
200 m_isPassive = pa; | 159 m_isPassive = pa; |
201 } | 160 } |
202 void SetExpireTime (Time exp) | 161 void SetExpireTime (Time exp) |
203 { | 162 { |
204 m_expire = exp + Simulator::Now (); | 163 m_expire = exp + Simulator::Now (); |
205 } | 164 } |
206 Time GetExpireTime () const | 165 Time GetExpireTime () const |
207 { | 166 { |
208 return m_expire - Simulator::Now (); | 167 return m_expire - Simulator::Now (); |
209 } | |
210 uint16_t GetId () const | |
211 { | |
212 return m_ipHeader.GetIdentification (); | |
213 } | |
214 uint16_t GetFragmentOffset () const | |
215 { | |
216 return m_ipHeader.GetFragmentOffset (); | |
217 } | 168 } |
218 // \} | 169 // \} |
219 private: | 170 private: |
220 // / Data packet | 171 // / Data packet |
221 Ptr<const Packet> m_packet; | 172 Ptr<const Packet> m_packet; |
222 /// IP header | |
223 Ipv4Header m_ipHeader; | |
224 // / our own ip address | 173 // / our own ip address |
225 Ipv4Address m_ourAdd; | 174 Ipv4Address m_ourAdd; |
226 // / Next hop Ip address | 175 // / Next hop Ip address |
227 Ipv4Address m_nextHop; | 176 Ipv4Address m_nextHop; |
228 // / The source address | 177 // / The source address |
229 Ipv4Address m_src; | 178 Ipv4Address m_src; |
230 // / The destination address | 179 // / The destination address |
231 Ipv4Address m_dst; | 180 Ipv4Address m_dst; |
232 // / The data ack id | 181 // / The data ack id |
233 uint16_t m_ackId; | 182 uint16_t m_ackId; |
| 183 // / The ipv4 id |
| 184 uint16_t m_id; |
234 // / The segments left field | 185 // / The segments left field |
235 uint8_t m_segsLeft; | 186 uint8_t m_segsLeft; |
236 // / The salvage count for packet | 187 // / The fragment offset of ipv4 header |
237 uint8_t m_salvage; | 188 uint16_t m_fragment; |
238 // / The size of the route | |
239 uint8_t m_routeSize; | |
240 // / The forward count | |
241 uint16_t m_forwardCount; | |
242 // / if the ack metric is passive ack or not | 189 // / if the ack metric is passive ack or not |
243 bool m_isPassive; | 190 bool m_isPassive; |
244 // / Expire time for queue entry | 191 // / Expire time for queue entry |
245 Time m_expire; | 192 Time m_expire; |
246 }; | 193 }; |
247 /** | 194 /** |
248 * \ingroup dsr | 195 * \ingroup dsr |
249 * \brief DSR maintain buffer | 196 * \brief DSR maintain buffer |
250 */ | 197 */ |
251 /*******************************************************************************
*****************************************/ | 198 /*******************************************************************************
*****************************************/ |
252 class MaintainBuffer | 199 class MaintainBuffer |
253 { | 200 { |
254 public: | 201 public: |
255 // / Default c-tor | 202 // / Default c-tor |
256 MaintainBuffer () | 203 MaintainBuffer () |
257 { | 204 { |
258 } | 205 } |
259 // / Push entry in queue, if there is no entry with the same packet and destin
ation address in queue. | 206 // / Push entry in queue, if there is no entry with the same packet and destin
ation address in queue. |
260 bool Enqueue (MaintainBuffEntry & entry); | 207 bool Enqueue (MaintainBuffEntry & entry); |
261 // / Return first found (the earliest) entry for given destination | 208 // / Return first found (the earliest) entry for given destination |
262 bool Dequeue (Ipv4Address dst, MaintainBuffEntry & entry); | 209 bool Dequeue (Ipv4Address dst, MaintainBuffEntry & entry); |
263 // / erase the exact entry from the maintenance buffer | |
264 void EraseEntry (MaintainBuffEntry & entry); | |
265 // / Remove all packets with destination IP address dst | 210 // / Remove all packets with destination IP address dst |
266 void DropPacketWithNextHop (Ipv4Address nextHop); | 211 void DropPacketWithNextHop (Ipv4Address nextHop); |
267 // / Finds whether a packet with destination dst exists in the queue | 212 // / Finds whether a packet with destination dst exists in the queue |
268 bool Find (Ipv4Address dst); | 213 bool Find (Ipv4Address nextHop); |
269 // / Find number of packets with destination dst in the queue | |
270 uint32_t FindPacketsWithNextHop (Ipv4Address nextHop); | |
271 // / Number of entries | 214 // / Number of entries |
272 uint32_t GetSize (); | 215 uint32_t GetSize (); |
273 // /\name Fields | 216 // /\name Fields |
274 // \{ | 217 // \{ |
275 uint32_t GetMaxQueueLen () const | 218 uint32_t GetMaxQueueLen () const |
276 { | 219 { |
277 return m_maxLen; | 220 return m_maxLen; |
278 } | 221 } |
279 void SetMaxQueueLen (uint32_t len) | 222 void SetMaxQueueLen (uint32_t len) |
280 { | 223 { |
281 m_maxLen = len; | 224 m_maxLen = len; |
282 } | 225 } |
283 Time GetMaintainBufferTimeout () const | 226 Time GetMaintainBufferTimeout () const |
284 { | 227 { |
285 return m_maintainBufferTimeout; | 228 return m_maintainBufferTimeout; |
286 } | 229 } |
287 void SetMaintainBufferTimeout (Time t) | 230 void SetMaintainBufferTimeout (Time t) |
288 { | 231 { |
289 m_maintainBufferTimeout = t; | 232 m_maintainBufferTimeout = t; |
290 } | 233 } |
291 // / Verify if the maintain buffer entry is the same in every field | 234 // / Verify if the maintain buffer entry is the same in every field for networ
k ack |
292 bool AllEqual (MaintainBuffEntry & entry); | 235 bool AllEqual (MaintainBuffEntry & entry); |
| 236 // / Verify if the maintain buffer entry is the same in every field for promis
cuous ack |
| 237 bool PromiscEqual (MaintainBuffEntry & entry); |
293 // \} | 238 // \} |
294 | 239 |
295 private: | 240 private: |
296 // / The vector of maintain buffer entries | 241 // / The vector of maintain buffer entries |
297 std::vector<MaintainBuffEntry> m_maintainBuffer; | 242 std::vector<MaintainBuffEntry> m_maintainBuffer; |
298 // / Remove all expired entries | 243 // / Remove all expired entries |
299 void Purge (); | 244 void Purge (); |
300 // / The maximum number of packets that we allow a routing protocol to buffer. | 245 // / The maximum number of packets that we allow a routing protocol to buffer. |
301 uint32_t m_maxLen; | 246 uint32_t m_maxLen; |
302 // / The maximum period of time that a routing protocol is allowed to buffer a
packet for, seconds. | 247 // / The maximum period of time that a routing protocol is allowed to buffer a
packet for, seconds. |
303 Time m_maintainBufferTimeout; | 248 Time m_maintainBufferTimeout; |
304 // / Verify if the maintain buffer is equal or not | 249 // / Verify if the maintain buffer is equal or not |
305 static bool IsEqual (MaintainBuffEntry en, const Ipv4Address nextHop) | 250 static bool IsEqual (MaintainBuffEntry en, const Ipv4Address nextHop) |
306 { | 251 { |
307 return (en.GetNextHop () == nextHop); | 252 return (en.GetNextHop () == nextHop); |
308 } | 253 } |
309 }; | 254 }; |
310 /*******************************************************************************
************************************************/ | 255 /*******************************************************************************
************************************************/ |
311 } // namespace dsr | 256 } // namespace dsr |
312 } // namespace ns3 | 257 } // namespace ns3 |
313 #endif /* DSR_MAINTAIN_BUFF_H */ | 258 #endif /* DSR_MAINTAIN_BUFF_H */ |
LEFT | RIGHT |