|
|
| 22 |
#include "ns3/simulator.h" |
22 |
#include "ns3/simulator.h" |
| 23 |
#include "ns3/uinteger.h" |
23 |
#include "ns3/uinteger.h" |
| 24 |
#include "ns3/log.h" |
24 |
#include "ns3/log.h" |
|
|
25 |
#include "ns3/node.h" |
| 26 |
#include "ns3/trace-source-accessor.h" |
| 25 |
|
27 |
|
| 26 |
#include "arp-cache.h" |
28 |
#include "arp-cache.h" |
| 27 |
#include "arp-header.h" |
29 |
#include "arp-header.h" |
|
Lines 47-61
ArpCache::GetTypeId (void)
|
Link Here
|
|---|
|
| 47 |
MakeTimeAccessor (&ArpCache::m_deadTimeout), |
49 |
MakeTimeAccessor (&ArpCache::m_deadTimeout), |
| 48 |
MakeTimeChecker ()) |
50 |
MakeTimeChecker ()) |
| 49 |
.AddAttribute ("WaitReplyTimeout", |
51 |
.AddAttribute ("WaitReplyTimeout", |
| 50 |
"When this timeout expires, the matching cache entry is marked dead", |
52 |
"When this timeout expires, the cache entries will be scanned and entries in WaitReply state will resend ArpRequest unless MaxRetries has been exceeded, in which case the entry is marked dead", |
| 51 |
TimeValue (Seconds (1)), |
53 |
TimeValue (Seconds (1)), |
| 52 |
MakeTimeAccessor (&ArpCache::m_waitReplyTimeout), |
54 |
MakeTimeAccessor (&ArpCache::m_waitReplyTimeout), |
| 53 |
MakeTimeChecker ()) |
55 |
MakeTimeChecker ()) |
|
|
56 |
.AddAttribute ("MaxRetries", |
| 57 |
"Number of retransmissions of ArpRequest before marking dead", |
| 58 |
UintegerValue (3), |
| 59 |
MakeUintegerAccessor (&ArpCache::m_maxRetries), |
| 60 |
MakeUintegerChecker<uint32_t> ()) |
| 54 |
.AddAttribute ("PendingQueueSize", |
61 |
.AddAttribute ("PendingQueueSize", |
| 55 |
"The size of the queue for packets pending an arp reply.", |
62 |
"The size of the queue for packets pending an arp reply.", |
| 56 |
UintegerValue (3), |
63 |
UintegerValue (3), |
| 57 |
MakeUintegerAccessor (&ArpCache::m_pendingQueueSize), |
64 |
MakeUintegerAccessor (&ArpCache::m_pendingQueueSize), |
| 58 |
MakeUintegerChecker<uint32_t> ()) |
65 |
MakeUintegerChecker<uint32_t> ()) |
|
|
66 |
.AddTraceSource ("Drop", |
| 67 |
"Packet dropped due to ArpCache entry in WaitReply expiring.", |
| 68 |
MakeTraceSourceAccessor (&ArpCache::m_dropTrace)) |
| 59 |
; |
69 |
; |
| 60 |
return tid; |
70 |
return tid; |
| 61 |
} |
71 |
} |
|
Lines 79-84
ArpCache::DoDispose (void)
|
Link Here
|
|---|
|
| 79 |
Flush (); |
89 |
Flush (); |
| 80 |
m_device = 0; |
90 |
m_device = 0; |
| 81 |
m_interface = 0; |
91 |
m_interface = 0; |
|
|
92 |
if (!m_waitReplyTimer.IsRunning ()) |
| 93 |
{ |
| 94 |
Simulator::Remove (m_waitReplyTimer); |
| 95 |
} |
| 82 |
Object::DoDispose (); |
96 |
Object::DoDispose (); |
| 83 |
} |
97 |
} |
| 84 |
|
98 |
|
|
Lines 143-148
ArpCache::GetWaitReplyTimeout (void) con
|
Link Here
|
|---|
|
| 143 |
} |
157 |
} |
| 144 |
|
158 |
|
| 145 |
void |
159 |
void |
|
|
160 |
ArpCache::SetArpRequestCallback (Callback<void, Ptr<const ArpCache>, |
| 161 |
Ipv4Address> arpRequestCallback) |
| 162 |
{ |
| 163 |
NS_LOG_FUNCTION_NOARGS (); |
| 164 |
m_arpRequestCallback = arpRequestCallback; |
| 165 |
} |
| 166 |
|
| 167 |
void |
| 168 |
ArpCache::StartWaitReplyTimer (void) |
| 169 |
{ |
| 170 |
NS_LOG_FUNCTION_NOARGS (); |
| 171 |
if (!m_waitReplyTimer.IsRunning ()) |
| 172 |
{ |
| 173 |
NS_LOG_LOGIC ("Starting WaitReplyTimer at " << Simulator::Now ().GetSeconds ()); |
| 174 |
m_waitReplyTimer = Simulator::Schedule (m_waitReplyTimeout, |
| 175 |
&ArpCache::HandleWaitReplyTimeout, this); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
void |
| 180 |
ArpCache::HandleWaitReplyTimeout (void) |
| 181 |
{ |
| 182 |
NS_LOG_FUNCTION_NOARGS (); |
| 183 |
ArpCache::Entry* entry; |
| 184 |
bool restartWaitReplyTimer = false; |
| 185 |
for (CacheI i = m_arpCache.begin (); i != m_arpCache.end (); i++) |
| 186 |
{ |
| 187 |
entry = (*i).second; |
| 188 |
if (entry != 0 && entry->IsWaitReply () && entry->IsExpired ()) |
| 189 |
{ |
| 190 |
if (entry->GetRetries () < m_maxRetries) |
| 191 |
{ |
| 192 |
NS_LOG_LOGIC ("node="<< m_device->GetNode ()->GetId () << |
| 193 |
", ArpWaitTimeout for " << entry->GetIpv4Address () << |
| 194 |
" expired -- retransmitting arp request since retries = " << |
| 195 |
entry->GetRetries ()); |
| 196 |
m_arpRequestCallback (this, entry->GetIpv4Address ()); |
| 197 |
restartWaitReplyTimer = true; |
| 198 |
entry->IncrementRetries (); |
| 199 |
} |
| 200 |
else |
| 201 |
{ |
| 202 |
NS_LOG_LOGIC ("node="<<m_device->GetNode ()->GetId () << |
| 203 |
", wait reply for " << entry->GetIpv4Address () << |
| 204 |
" expired -- drop since max retries exceeded: " << |
| 205 |
entry->GetRetries ()); |
| 206 |
entry->MarkDead (); |
| 207 |
entry->ClearRetries (); |
| 208 |
Ptr<Packet> pending = entry->DequeuePending(); |
| 209 |
while (pending != 0) |
| 210 |
{ |
| 211 |
m_dropTrace (pending); |
| 212 |
pending = entry->DequeuePending(); |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
} |
| 218 |
if (restartWaitReplyTimer) |
| 219 |
{ |
| 220 |
NS_LOG_LOGIC ("Restarting WaitReplyTimer at " << Simulator::Now ().GetSeconds ()); |
| 221 |
m_waitReplyTimer = Simulator::Schedule (m_waitReplyTimeout, |
| 222 |
&ArpCache::HandleWaitReplyTimeout, this); |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
void |
| 146 |
ArpCache::Flush (void) |
227 |
ArpCache::Flush (void) |
| 147 |
{ |
228 |
{ |
| 148 |
NS_LOG_FUNCTION_NOARGS (); |
229 |
NS_LOG_FUNCTION_NOARGS (); |
|
Lines 173-184
ArpCache::Add (Ipv4Address to)
|
Link Here
|
|---|
|
| 173 |
|
254 |
|
| 174 |
ArpCache::Entry *entry = new ArpCache::Entry (this); |
255 |
ArpCache::Entry *entry = new ArpCache::Entry (this); |
| 175 |
m_arpCache[to] = entry; |
256 |
m_arpCache[to] = entry; |
|
|
257 |
entry->SetIpv4Address (to); |
| 176 |
return entry; |
258 |
return entry; |
| 177 |
} |
259 |
} |
| 178 |
|
260 |
|
| 179 |
ArpCache::Entry::Entry (ArpCache *arp) |
261 |
ArpCache::Entry::Entry (ArpCache *arp) |
| 180 |
: m_arp (arp), |
262 |
: m_arp (arp), |
| 181 |
m_state (ALIVE) |
263 |
m_state (ALIVE), |
|
|
264 |
m_retries (0) |
| 182 |
{ |
265 |
{ |
| 183 |
NS_LOG_FUNCTION_NOARGS (); |
266 |
NS_LOG_FUNCTION_NOARGS (); |
| 184 |
} |
267 |
} |
|
Lines 209-214
ArpCache::Entry::MarkDead (void)
|
Link Here
|
|---|
|
| 209 |
{ |
292 |
{ |
| 210 |
NS_LOG_FUNCTION_NOARGS (); |
293 |
NS_LOG_FUNCTION_NOARGS (); |
| 211 |
m_state = DEAD; |
294 |
m_state = DEAD; |
|
|
295 |
ClearRetries (); |
| 212 |
UpdateSeen (); |
296 |
UpdateSeen (); |
| 213 |
} |
297 |
} |
| 214 |
void |
298 |
void |
|
Lines 218-223
ArpCache::Entry::MarkAlive (Address macA
|
Link Here
|
|---|
|
| 218 |
NS_ASSERT (m_state == WAIT_REPLY); |
302 |
NS_ASSERT (m_state == WAIT_REPLY); |
| 219 |
m_macAddress = macAddress; |
303 |
m_macAddress = macAddress; |
| 220 |
m_state = ALIVE; |
304 |
m_state = ALIVE; |
|
|
305 |
ClearRetries (); |
| 221 |
UpdateSeen (); |
306 |
UpdateSeen (); |
| 222 |
} |
307 |
} |
| 223 |
|
308 |
|
|
Lines 246-260
ArpCache::Entry::MarkWaitReply (Ptr<Pack
|
Link Here
|
|---|
|
| 246 |
m_state = WAIT_REPLY; |
331 |
m_state = WAIT_REPLY; |
| 247 |
m_pending.push_back (waiting); |
332 |
m_pending.push_back (waiting); |
| 248 |
UpdateSeen (); |
333 |
UpdateSeen (); |
|
|
334 |
m_arp->StartWaitReplyTimer (); |
| 249 |
} |
335 |
} |
| 250 |
|
336 |
|
| 251 |
Address |
337 |
Address |
| 252 |
ArpCache::Entry::GetMacAddress (void) |
338 |
ArpCache::Entry::GetMacAddress (void) const |
| 253 |
{ |
339 |
{ |
| 254 |
NS_LOG_FUNCTION_NOARGS (); |
340 |
NS_LOG_FUNCTION_NOARGS (); |
| 255 |
NS_ASSERT (m_state == ALIVE); |
341 |
NS_ASSERT (m_state == ALIVE); |
| 256 |
return m_macAddress; |
342 |
return m_macAddress; |
| 257 |
} |
343 |
} |
|
|
344 |
Ipv4Address |
| 345 |
ArpCache::Entry::GetIpv4Address (void) const |
| 346 |
{ |
| 347 |
NS_LOG_FUNCTION_NOARGS (); |
| 348 |
return m_ipv4Address; |
| 349 |
} |
| 350 |
void |
| 351 |
ArpCache::Entry::SetIpv4Address (Ipv4Address destination) |
| 352 |
{ |
| 353 |
NS_LOG_FUNCTION (this << destination); |
| 354 |
m_ipv4Address = destination; |
| 355 |
} |
| 356 |
|
| 258 |
bool |
357 |
bool |
| 259 |
ArpCache::Entry::IsExpired (void) |
358 |
ArpCache::Entry::IsExpired (void) |
| 260 |
{ |
359 |
{ |
|
Lines 307-312
ArpCache::Entry::UpdateSeen (void)
|
Link Here
|
|---|
|
| 307 |
NS_LOG_FUNCTION_NOARGS (); |
406 |
NS_LOG_FUNCTION_NOARGS (); |
| 308 |
m_lastSeen = Simulator::Now (); |
407 |
m_lastSeen = Simulator::Now (); |
| 309 |
} |
408 |
} |
|
|
409 |
uint32_t |
| 410 |
ArpCache::Entry::GetRetries (void) const |
| 411 |
{ |
| 412 |
NS_LOG_FUNCTION_NOARGS (); |
| 413 |
return m_retries; |
| 414 |
} |
| 415 |
void |
| 416 |
ArpCache::Entry::IncrementRetries (void) |
| 417 |
{ |
| 418 |
NS_LOG_FUNCTION_NOARGS (); |
| 419 |
m_retries++; |
| 420 |
UpdateSeen (); |
| 421 |
} |
| 422 |
void |
| 423 |
ArpCache::Entry::ClearRetries (void) |
| 424 |
{ |
| 425 |
NS_LOG_FUNCTION_NOARGS (); |
| 426 |
m_retries = 0; |
| 427 |
} |
| 310 |
|
428 |
|
| 311 |
} // namespace ns3 |
429 |
} // namespace ns3 |
| 312 |
|
430 |
|