Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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) 2013 Mohammed J.F. Alenazi | 3 * Copyright (c) 2013 Mohammed J.F. Alenazi |
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Mohammed J.F. Alenazi <malenazi@ittc.ku.edu> | 18 * Author: Mohammed J.F. Alenazi <malenazi@ittc.ku.edu> |
19 * | 19 * |
20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director | 20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director |
21 * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets | 21 * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets |
22 * Information and Telecommunication Technology Center (ITTC) | 22 * Information and Telecommunication Technology Center (ITTC) |
23 * and Department of Electrical Engineering and Computer Science | 23 * and Department of Electrical Engineering and Computer Science |
24 * The University of Kansas Lawrence, KS USA. | 24 * The University of Kansas Lawrence, KS USA. |
25 * | 25 * |
26 * Work supported by King Saud University and the ITTC at The University of Kans as. | 26 * Work supported by King Saud University and |
27 * the ITTC at The University of Kansas. | |
27 */ | 28 */ |
28 | 29 |
29 | 30 |
30 #include "epidemic-packet-queue.h" | 31 #include "epidemic-packet-queue.h" |
31 #include <algorithm> | 32 #include <algorithm> |
32 #include <functional> | 33 #include <functional> |
33 #include "ns3/ipv4-route.h" | 34 #include "ns3/ipv4-route.h" |
34 #include "ns3/socket.h" | 35 #include "ns3/socket.h" |
35 #include "ns3/log.h" | 36 #include "ns3/log.h" |
36 #include "epidemic-packet.h" | 37 #include "epidemic-packet.h" |
37 | 38 |
38 using namespace std; | 39 using namespace std; |
39 | 40 |
41 | |
42 | |
40 namespace ns3 { | 43 namespace ns3 { |
44 NS_LOG_COMPONENT_DEFINE ("EpidemicPacketQueue"); | |
45 | |
46 /** | |
47 * \file | |
48 * \ingroup epidemic | |
49 * ns3::Epidemic::QueueEntry and ns3::Epidemic::PacketQueue declarations. | |
50 */ | |
Peter Barnes
2015/04/28 23:42:32
This block should be before "namespace ns3"
mjf.alenazi
2017/05/13 23:57:06
Done.
| |
51 | |
41 namespace Epidemic { | 52 namespace Epidemic { |
42 | 53 |
43 NS_LOG_COMPONENT_DEFINE ("EpidemicPacketQueue"); | |
Peter Barnes
2014/09/23 22:54:26
Should be before any namespaces.
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
44 | |
45 | |
46 typedef Ipv4RoutingProtocol::UnicastForwardCallback UnicastForwardCallback; | |
47 typedef Ipv4RoutingProtocol::ErrorCallback ErrorCallback; | |
Peter Barnes
2014/09/23 22:54:26
Delete these two lines; they are already defined i
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
48 | |
49 | |
50 | 54 |
51 | 55 |
Peter Barnes
2015/04/28 23:42:32
See the .h for steps 1. and 2.
3. Insert the con
mjf.alenazi
2017/05/13 23:57:06
Done.
| |
52 bool | 56 bool |
53 QueueEntry::operator== (QueueEntry const & o) const | 57 QueueEntry::operator== (QueueEntry const & o) const |
54 { | 58 { |
55 return (m_packetID == o.m_packetID); | 59 return (m_packetID == o.m_packetID); |
56 } | 60 } |
57 | 61 |
58 UnicastForwardCallback | 62 QueueEntry::UnicastForwardCallback |
Peter Barnes
2014/09/23 22:54:26
QueueEntry::UnicastForwardCallback
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
59 QueueEntry::GetUnicastForwardCallback () const | 63 QueueEntry::GetUnicastForwardCallback () const |
60 { | 64 { |
61 return m_ucb; | 65 return m_ucb; |
62 } | 66 } |
63 | 67 |
64 void | 68 void |
65 QueueEntry::SetUnicastForwardCallback (UnicastForwardCallback ucb) | 69 QueueEntry::SetUnicastForwardCallback (QueueEntry::UnicastForwardCallback ucb) |
66 { | 70 { |
67 m_ucb = ucb; | 71 m_ucb = ucb; |
68 } | 72 } |
69 | 73 |
70 ErrorCallback | 74 QueueEntry::ErrorCallback |
Peter Barnes
2014/09/23 22:54:26
QueueEntry::ErrorCallback
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
71 QueueEntry::GetErrorCallback () const | 75 QueueEntry::GetErrorCallback () const |
72 { | 76 { |
73 return m_ecb; | 77 return m_ecb; |
74 } | 78 } |
75 | 79 |
76 void | 80 void |
77 QueueEntry::SetErrorCallback (ErrorCallback ecb) | 81 QueueEntry::SetErrorCallback (QueueEntry::ErrorCallback ecb) |
78 { | 82 { |
79 m_ecb = ecb; | 83 m_ecb = ecb; |
80 } | 84 } |
81 | 85 |
82 Ptr<const Packet> | 86 Ptr<const Packet> |
83 QueueEntry::GetPacket () const | 87 QueueEntry::GetPacket () const |
84 { | 88 { |
85 return m_packet; | 89 return m_packet; |
86 } | 90 } |
87 | 91 |
88 void | 92 void |
89 QueueEntry::SetPacket (Ptr<const Packet> p) | 93 QueueEntry::SetPacket (Ptr<const Packet> p) |
90 { | 94 { |
Peter Barnes
2014/09/23 22:54:27
NS_LOG_FUNCTION (this << p);
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
95 NS_LOG_FUNCTION (this << p); | |
91 m_packet = p; | 96 m_packet = p; |
92 } | 97 } |
93 | 98 |
94 Ipv4Header | 99 Ipv4Header |
95 QueueEntry::GetIpv4Header () const | 100 QueueEntry::GetIpv4Header () const |
96 { | 101 { |
97 return m_header; | 102 return m_header; |
98 } | 103 } |
99 | 104 |
100 void | 105 void |
101 QueueEntry::SetIpv4Header (Ipv4Header h) | 106 QueueEntry::SetIpv4Header (Ipv4Header h) |
102 { | 107 { |
Peter Barnes
2014/09/23 22:54:26
NS_LOG_FUNCTION (this << h);
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
108 NS_LOG_FUNCTION (this << h); | |
103 m_header = h; | 109 m_header = h; |
104 } | 110 } |
105 | 111 |
106 void | 112 void |
107 QueueEntry::SetExpireTime (Time exp) | 113 QueueEntry::SetExpireTime (Time exp) |
108 { | 114 { |
Peter Barnes
2014/09/23 22:54:27
NS_LOG_FUNCTION (this << exp);
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
115 NS_LOG_FUNCTION (this << exp); | |
109 m_expire = exp; | 116 m_expire = exp; |
110 } | 117 } |
111 | 118 |
112 Time | 119 Time |
113 QueueEntry::GetExpireTime () const | 120 QueueEntry::GetExpireTime () const |
114 { | 121 { |
115 return m_expire; | 122 return m_expire; |
116 } | 123 } |
117 | 124 |
118 uint32_t | 125 uint32_t |
119 QueueEntry::GetPacketID () const | 126 QueueEntry::GetPacketID () const |
120 { | 127 { |
121 return m_packetID; | 128 return m_packetID; |
122 } | 129 } |
123 | 130 |
124 void | 131 void |
125 QueueEntry::SetPacketID (uint32_t id) | 132 QueueEntry::SetPacketID (uint32_t id) |
126 { | 133 { |
Peter Barnes
2014/09/23 22:54:27
NS_LOG_FUNCTION (this << id);
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
134 NS_LOG_FUNCTION (this << id); | |
127 m_packetID = id; | 135 m_packetID = id; |
128 } | 136 } |
129 | 137 |
130 uint32_t | 138 uint32_t |
131 PacketQueue::GetSize () | 139 PacketQueue::GetSize () |
132 { | 140 { |
133 return m_map.size (); | 141 return m_map.size (); |
134 } | 142 } |
135 | 143 |
136 bool | 144 bool |
137 PacketQueue::Enqueue (QueueEntry & entry) | 145 PacketQueue::Enqueue (QueueEntry & entry) |
138 { | 146 { |
139 NS_LOG_FUNCTION (this ); | 147 NS_LOG_FUNCTION (this << entry.GetPacketID ()); |
Peter Barnes
2014/09/23 22:54:27
NS_LOG_FUNCTION (this << entry);
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
140 // Add or update the entry | 148 // Add or update the entry |
141 m_map[entry.GetPacketID ()] = entry; | 149 m_map[entry.GetPacketID ()] = entry; |
142 Purge (true); | 150 Purge (true); |
143 return true; | 151 return true; |
144 } | 152 } |
145 | 153 |
146 bool | 154 bool |
147 PacketQueue::Dequeue (QueueEntry& entry) | 155 PacketQueue::Dequeue (QueueEntry& entry) |
148 { | 156 { |
149 NS_LOG_FUNCTION (this ); | 157 NS_LOG_FUNCTION (this << entry.GetPacketID ()); |
Peter Barnes
2014/09/23 22:54:26
NS_LOG_FUNCTION (this << entry);
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
150 if (m_map.size () > 0) | 158 if (m_map.size () > 0) |
151 { | 159 { |
152 PacketIdMap::iterator entry_map = m_map.begin (); | 160 PacketIdMap::iterator entry_map = m_map.begin (); |
153 entry = entry_map->second; | 161 entry = entry_map->second; |
154 m_map.erase (entry_map); | 162 m_map.erase (entry_map); |
155 return true; | 163 return true; |
156 } | 164 } |
157 return false; | 165 return false; |
158 } | 166 } |
159 | 167 |
160 uint32_t | 168 uint32_t |
161 PacketQueue::GetMaxQueueLen () const | 169 PacketQueue::GetMaxQueueLen () const |
162 { | 170 { |
163 NS_LOG_FUNCTION (this ); | 171 NS_LOG_FUNCTION (this ); |
164 return m_maxLen; | 172 return m_maxLen; |
165 } | 173 } |
166 | 174 |
167 void | 175 void |
168 PacketQueue::SetMaxQueueLen (uint32_t len) | 176 PacketQueue::SetMaxQueueLen (uint32_t len) |
169 { | 177 { |
170 NS_LOG_FUNCTION (this ); | 178 NS_LOG_FUNCTION (this << len); |
Peter Barnes
2014/09/23 22:54:26
NS_LOG_FUNCTION (this << len);
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
171 m_maxLen = len; | 179 m_maxLen = len; |
172 } | 180 } |
173 | 181 |
174 QueueEntry | 182 QueueEntry |
175 PacketQueue::Find (uint32_t packetID) | 183 PacketQueue::Find (uint32_t packetID) |
176 { | 184 { |
177 NS_LOG_FUNCTION (this ); | 185 NS_LOG_FUNCTION (this << packetID); |
Peter Barnes
2014/09/23 22:54:27
NS_LOG_FUNCTION (this << packetId);
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
178 PacketIdMap::iterator entry = m_map.find (packetID); | 186 PacketIdMap::iterator entry = m_map.find (packetID); |
179 if (entry != m_map.end ()) | 187 if (entry != m_map.end ()) |
180 { | 188 { |
181 return entry->second; | 189 return entry->second; |
182 } | 190 } |
183 return QueueEntry (); | 191 return QueueEntry (); |
184 } | 192 } |
185 | 193 |
186 | 194 |
187 // static | 195 // static |
188 bool | 196 bool |
189 PacketQueue::IsEarlier (const PacketIdMapPair & e1, | 197 PacketQueue::IsEarlier (const PacketIdMapPair & e1, |
190 const PacketIdMapPair & e2) | 198 const PacketIdMapPair & e2) |
191 { | 199 { |
192 return (e1.second.GetExpireTime () < e2.second.GetExpireTime ()); | 200 return (e1.second.GetExpireTime () < e2.second.GetExpireTime ()); |
193 } | 201 } |
194 | 202 |
195 | 203 |
196 void | 204 void |
197 PacketQueue::Purge (bool oldestOnly /* = false */) | 205 PacketQueue::Purge (bool oldestOnly /* = false */) |
198 { | 206 { |
199 NS_LOG_FUNCTION (this ); | 207 NS_LOG_FUNCTION (this << oldestOnly); |
Peter Barnes
2014/09/23 22:54:27
NS_LOG_FUNCTION (this << oldestOnly);
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
200 if (oldestOnly && m_map.size () > m_maxLen) | 208 if (oldestOnly && m_map.size () > m_maxLen) |
201 { | 209 { |
202 Drop (std::min_element (m_map.begin (), m_map.end (), IsEarlier), | 210 Drop (std::min_element (m_map.begin (), m_map.end (), IsEarlier), |
203 "Drop the oldest packet"); | 211 "Drop the oldest packet"); |
204 } | 212 } |
205 else | 213 else |
206 { | 214 { |
207 for (PacketIdMap::iterator i = m_map.begin (); | 215 for (PacketIdMap::iterator i = m_map.begin (); |
208 i != m_map.end (); ++i) | 216 i != m_map.end (); ++i) |
209 { | 217 { |
210 if (i->second.GetExpireTime () < Now ()) | 218 if (i->second.GetExpireTime () < Now ()) |
211 { | 219 { |
212 Drop (i, "Drop outdated packet "); | 220 Drop (i, "Drop outdated packet "); |
213 } | 221 } |
214 } | 222 } |
215 } | 223 } |
216 } | 224 } |
217 | 225 |
218 void | 226 void |
219 PacketQueue::Drop (PacketIdMap::iterator en, std::string reason) | 227 PacketQueue::Drop (PacketIdMap::iterator en, std::string reason) |
220 { | 228 { |
221 NS_LOG_FUNCTION (this ); | 229 NS_LOG_FUNCTION (this << en->second.GetPacketID () << reason); |
Peter Barnes
2014/09/23 22:54:26
NS_LOG_FUNCTION (this << en->second.GetPacketId ()
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
222 NS_LOG_INFO ("dropping packet with ID: " << en->second.GetPacketID () << ", re ason: " << reason); | |
Peter Barnes
2014/09/23 22:54:26
Delete this line.
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
223 m_map.erase (en->second.GetPacketID ()); | 230 m_map.erase (en->second.GetPacketID ()); |
224 } | 231 } |
225 | 232 |
226 | 233 |
227 | 234 |
228 EpidemicSummaryVectorHeader | 235 SummaryVectorHeader |
229 PacketQueue::GetSummaryVector () | 236 PacketQueue::GetSummaryVector () |
230 { | 237 { |
231 NS_LOG_FUNCTION (this ); | 238 NS_LOG_FUNCTION (this ); |
232 Purge (true); | 239 Purge (true); |
233 EpidemicSummaryVectorHeader sm (m_map.size ()); | 240 SummaryVectorHeader sm (m_map.size ()); |
234 for (PacketIdMap::iterator i = m_map.begin (); i != m_map.end (); ++i) | 241 for (PacketIdMap::iterator i = m_map.begin (); i != m_map.end (); ++i) |
235 { | 242 { |
236 sm.Add (i->first); | 243 sm.Add (i->first); |
237 } | 244 } |
238 return sm; | 245 return sm; |
239 } | 246 } |
240 | 247 |
241 | 248 |
242 EpidemicSummaryVectorHeader | 249 SummaryVectorHeader |
243 PacketQueue::FindDisjointPackets (EpidemicSummaryVectorHeader list) | 250 PacketQueue::FindDisjointPackets (SummaryVectorHeader list) |
244 { | 251 { |
245 NS_LOG_FUNCTION (this ); | 252 NS_LOG_FUNCTION (this << list); |
Peter Barnes
2014/09/23 22:54:27
NS_LOG_FUNCTION (this << list);
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
246 EpidemicSummaryVectorHeader sm (std::min (m_map.size (), list.Size ())); | 253 SummaryVectorHeader sm (std::min (m_map.size (), list.Size ())); |
247 for (PacketIdMap::iterator i = m_map.begin (); i != m_map.end (); ++i) | 254 for (PacketIdMap::iterator i = m_map.begin (); i != m_map.end (); ++i) |
248 { | 255 { |
249 if (!list.Contains (i->first)) | 256 if (!list.Contains (i->first)) |
250 { | 257 { |
251 sm.Add (i->first); | 258 sm.Add (i->first); |
252 } | 259 } |
253 } | 260 } |
254 return sm; | 261 return sm; |
255 } | 262 } |
256 | 263 |
257 | 264 |
258 void | 265 void |
259 PacketQueue::DropExpiredPackets () | 266 PacketQueue::DropExpiredPackets () |
260 { | 267 { |
261 NS_LOG_FUNCTION (this ); | 268 NS_LOG_FUNCTION (this ); |
262 Purge (true); | 269 Purge (true); |
263 } | 270 } |
264 | 271 |
265 } //end namespace epidemic | 272 } //end namespace epidemic |
266 } //end namespace ns3 | 273 } //end namespace ns3 |
LEFT | RIGHT |