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) 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 22 matching lines...) Expand all Loading... |
33 #include <algorithm> | 33 #include <algorithm> |
34 #include <functional> | 34 #include <functional> |
35 #include "ns3/ipv4-route.h" | 35 #include "ns3/ipv4-route.h" |
36 #include "ns3/socket.h" | 36 #include "ns3/socket.h" |
37 #include "ns3/log.h" | 37 #include "ns3/log.h" |
38 | 38 |
39 NS_LOG_COMPONENT_DEFINE ("DsrSendBuffer"); | 39 NS_LOG_COMPONENT_DEFINE ("DsrSendBuffer"); |
40 | 40 |
41 namespace ns3 { | 41 namespace ns3 { |
42 namespace dsr { | 42 namespace dsr { |
| 43 |
43 uint32_t | 44 uint32_t |
44 SendBuffer::GetSize () | 45 SendBuffer::GetSize () |
45 { | 46 { |
46 Purge (); | 47 Purge (); |
47 return m_sendBuffer.size (); | 48 return m_sendBuffer.size (); |
48 } | 49 } |
49 | 50 |
50 bool | 51 bool |
51 SendBuffer::Enqueue (SendBuffEntry & entry) | 52 SendBuffer::Enqueue (SendBuffEntry & entry) |
52 { | 53 { |
53 Purge (); | 54 Purge (); |
54 for (std::vector<SendBuffEntry>::const_iterator i = m_sendBuffer.begin (); i | 55 for (std::vector<SendBuffEntry>::const_iterator i = m_sendBuffer.begin (); i |
55 != m_sendBuffer.end (); ++i) | 56 != m_sendBuffer.end (); ++i) |
56 { | 57 { |
| 58 NS_LOG_INFO ("packet id " << i->GetPacket ()->GetUid () << " " << entry.Ge
tPacket ()->GetUid () |
| 59 << " dst " << i->GetDestination () << " " << entry.GetDestina
tion ()); |
| 60 |
57 if ((i->GetPacket ()->GetUid () == entry.GetPacket ()->GetUid ()) | 61 if ((i->GetPacket ()->GetUid () == entry.GetPacket ()->GetUid ()) |
58 && (i->GetDestination () | 62 && (i->GetDestination () == entry.GetDestination ())) |
59 == entry.GetDestination ())) | |
60 { | 63 { |
61 return false; | 64 return false; |
62 } | 65 } |
63 } | 66 } |
64 | 67 |
65 entry.SetExpireTime (m_sendBufferTimeout); // Initialize the send buffer t
imeout | 68 entry.SetExpireTime (m_sendBufferTimeout); // Initialize the send buffer t
imeout |
66 /* | 69 /* |
67 * Drop the most aged packet when buffer reaches to max | 70 * Drop the most aged packet when buffer reaches to max |
68 */ | 71 */ |
69 if (m_sendBuffer.size () >= m_maxLen) | 72 if (m_sendBuffer.size () >= m_maxLen) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 118 } |
116 } | 119 } |
117 return false; | 120 return false; |
118 } | 121 } |
119 | 122 |
120 bool | 123 bool |
121 SendBuffer::Find (Ipv4Address dst) | 124 SendBuffer::Find (Ipv4Address dst) |
122 { | 125 { |
123 /* | 126 /* |
124 * Make sure if the send buffer contains entry with certain dst | 127 * Make sure if the send buffer contains entry with certain dst |
125 * Used for test case | |
126 */ | 128 */ |
127 for (std::vector<SendBuffEntry>::const_iterator i = m_sendBuffer.begin (); i | 129 for (std::vector<SendBuffEntry>::const_iterator i = m_sendBuffer.begin (); i |
128 != m_sendBuffer.end (); ++i) | 130 != m_sendBuffer.end (); ++i) |
129 { | 131 { |
130 if (i->GetDestination () == dst) | 132 if (i->GetDestination () == dst) |
131 { | 133 { |
132 NS_LOG_DEBUG ("Found the packet"); | 134 NS_LOG_DEBUG ("Found the packet"); |
133 return true; | 135 return true; |
134 } | 136 } |
135 } | 137 } |
136 return false; | 138 return false; |
137 } | |
138 | |
139 uint32_t | |
140 SendBuffer::FindPacketsWithDst (Ipv4Address dst) | |
141 { | |
142 uint32_t count = 0; | |
143 for (std::vector<SendBuffEntry>::const_iterator i = m_sendBuffer.begin (); i | |
144 != m_sendBuffer.end (); ++i) | |
145 { | |
146 if (i->GetDestination () == dst) | |
147 { | |
148 NS_LOG_DEBUG ("Found the packet"); | |
149 count++; | |
150 } | |
151 } | |
152 return count; | |
153 } | 139 } |
154 | 140 |
155 struct IsExpired | 141 struct IsExpired |
156 { | 142 { |
157 bool | 143 bool |
158 operator() (SendBuffEntry const & e) const | 144 operator() (SendBuffEntry const & e) const |
159 { | 145 { |
160 // NS_LOG_DEBUG("Expire time for packet in req queue: "<<e.GetExpireTime ())
; | 146 // NS_LOG_DEBUG("Expire time for packet in req queue: "<<e.GetExpireTime ())
; |
161 return (e.GetExpireTime () < Seconds (0)); | 147 return (e.GetExpireTime () < Seconds (0)); |
162 } | 148 } |
163 }; | 149 }; |
164 | 150 |
165 void | 151 void |
166 SendBuffer::Purge () | 152 SendBuffer::Purge () |
167 { | 153 { |
168 /* | 154 /* |
169 * Purge the buffer to eliminate expired entries | 155 * Purge the buffer to eliminate expired entries |
170 */ | 156 */ |
| 157 NS_LOG_DEBUG ("The send buffer size " << m_sendBuffer.size ()); |
171 IsExpired pred; | 158 IsExpired pred; |
172 for (std::vector<SendBuffEntry>::iterator i = m_sendBuffer.begin (); i | 159 for (std::vector<SendBuffEntry>::iterator i = m_sendBuffer.begin (); i |
173 != m_sendBuffer.end (); ++i) | 160 != m_sendBuffer.end (); ++i) |
174 { | 161 { |
175 if (pred (*i)) | 162 if (pred (*i)) |
176 { | 163 { |
177 NS_LOG_DEBUG ("Dropping Queue Packets"); | 164 NS_LOG_DEBUG ("Dropping Queue Packets"); |
178 Drop (*i, "Drop out-dated packet "); | 165 Drop (*i, "Drop out-dated packet "); |
179 } | 166 } |
180 } | 167 } |
181 m_sendBuffer.erase (std::remove_if (m_sendBuffer.begin (), m_sendBuffer.end ()
, pred), | 168 m_sendBuffer.erase (std::remove_if (m_sendBuffer.begin (), m_sendBuffer.end ()
, pred), |
182 m_sendBuffer.end ()); | 169 m_sendBuffer.end ()); |
183 } | 170 } |
184 | 171 |
185 void | 172 void |
186 SendBuffer::Drop (SendBuffEntry en, std::string reason) | 173 SendBuffer::Drop (SendBuffEntry en, std::string reason) |
187 { | 174 { |
188 NS_LOG_LOGIC (reason << en.GetPacket ()->GetUid () << " " << en.GetDestination
()); | 175 NS_LOG_LOGIC (reason << en.GetPacket ()->GetUid () << " " << en.GetDestination
()); |
189 // en.GetErrorCallback () (en.GetPacket (), en.GetDestination (), | 176 // en.GetErrorCallback () (en.GetPacket (), en.GetDestination (), |
190 // Socket::ERROR_NOROUTETOHOST); | 177 // Socket::ERROR_NOROUTETOHOST); |
191 return; | 178 return; |
192 } | 179 } |
193 } // namespace dsr | 180 } // namespace dsr |
194 } // namespace ns3 | 181 } // namespace ns3 |
LEFT | RIGHT |