View | Details | Raw Unified | Return to bug 253
Collapse All | Expand All

(-)a/src/internet-stack/arp-cache.cc (-2 / +42 lines)
 Lines 47-56   ArpCache::GetTypeId (void) Link Here 
47
                   MakeTimeAccessor (&ArpCache::m_deadTimeout),
47
                   MakeTimeAccessor (&ArpCache::m_deadTimeout),
48
                   MakeTimeChecker ())
48
                   MakeTimeChecker ())
49
    .AddAttribute ("WaitReplyTimeout",
49
    .AddAttribute ("WaitReplyTimeout",
50
                   "When this timeout expires, the matching cache entry is marked dead",
50
                   "When this timeout expires, the matching cache entry will retry the ArpRequest unless MaxRetries has been exceeded, in which case it is marked dead",
51
                   TimeValue (Seconds (1)),
51
                   TimeValue (Seconds (1)),
52
                   MakeTimeAccessor (&ArpCache::m_waitReplyTimeout),
52
                   MakeTimeAccessor (&ArpCache::m_waitReplyTimeout),
53
                   MakeTimeChecker ())
53
                   MakeTimeChecker ())
54
    .AddAttribute ("MaxRetries",
55
                   "Number of retransmissions of ArpRequest before marking dead",
56
                   UintegerValue (3),
57
                   MakeUintegerAccessor (&ArpCache::m_maxRetries),
58
                   MakeUintegerChecker<uint32_t> ())
54
    .AddAttribute ("PendingQueueSize",
59
    .AddAttribute ("PendingQueueSize",
55
                   "The size of the queue for packets pending an arp reply.",
60
                   "The size of the queue for packets pending an arp reply.",
56
                   UintegerValue (3),
61
                   UintegerValue (3),
 Lines 142-147   ArpCache::GetWaitReplyTimeout (void) con Link Here 
142
  return m_waitReplyTimeout;
147
  return m_waitReplyTimeout;
143
}
148
}
144
149
150
uint32_t
151
ArpCache::GetMaxRetries (void) const
152
{
153
  NS_LOG_FUNCTION_NOARGS ();
154
  return m_maxRetries;
155
}
156
145
void 
157
void 
146
ArpCache::Flush (void)
158
ArpCache::Flush (void)
147
{
159
{
 Lines 178-184   ArpCache::Add (Ipv4Address to) Link Here 
178
190
179
ArpCache::Entry::Entry (ArpCache *arp)
191
ArpCache::Entry::Entry (ArpCache *arp)
180
  : m_arp (arp),
192
  : m_arp (arp),
181
    m_state (ALIVE)
193
    m_state (ALIVE),
194
    m_retries (0),
195
    m_waitTimer (Timer::CANCEL_ON_DESTROY)
182
{
196
{
183
  NS_LOG_FUNCTION_NOARGS ();
197
  NS_LOG_FUNCTION_NOARGS ();
184
}
198
}
 Lines 218-223   ArpCache::Entry::MarkAlive (Address macA Link Here 
218
  NS_ASSERT (m_state == WAIT_REPLY);
232
  NS_ASSERT (m_state == WAIT_REPLY);
219
  m_macAddress = macAddress;
233
  m_macAddress = macAddress;
220
  m_state = ALIVE;
234
  m_state = ALIVE;
235
  m_retries = 0;
221
  UpdateSeen ();
236
  UpdateSeen ();
222
}
237
}
223
238
 Lines 308-312   ArpCache::Entry::UpdateSeen (void) Link Here 
308
  m_lastSeen = Simulator::Now ();
323
  m_lastSeen = Simulator::Now ();
309
}
324
}
310
325
326
uint32_t
327
ArpCache::Entry::GetRetries (void) const
328
{
329
  NS_LOG_FUNCTION_NOARGS ();
330
  return m_retries;
331
}
332
void
333
ArpCache::Entry::IncrementRetries (void)
334
{
335
  NS_LOG_FUNCTION_NOARGS ();
336
  m_retries++;
337
  UpdateSeen ();
338
}
339
void
340
ArpCache::Entry::ClearRetries (void)
341
{
342
  NS_LOG_FUNCTION_NOARGS ();
343
  m_retries = 0;
344
}
345
Timer* 
346
ArpCache::Entry::GetWaitTimer (void) 
347
{ 
348
  return &m_waitTimer; 
349
}
350
311
} // namespace ns3
351
} // namespace ns3
312
352
(-)a/src/internet-stack/arp-cache.h (-2 / +23 lines)
 Lines 24-29    Link Here 
24
#include <list>
24
#include <list>
25
#include "ns3/packet.h"
25
#include "ns3/packet.h"
26
#include "ns3/nstime.h"
26
#include "ns3/nstime.h"
27
#include "ns3/timer.h"
27
#include "ns3/net-device.h"
28
#include "ns3/net-device.h"
28
#include "ns3/ipv4-address.h"
29
#include "ns3/ipv4-address.h"
29
#include "ns3/address.h"
30
#include "ns3/address.h"
 Lines 70-75   public: Link Here 
70
  Time GetAliveTimeout (void) const;
71
  Time GetAliveTimeout (void) const;
71
  Time GetDeadTimeout (void) const;
72
  Time GetDeadTimeout (void) const;
72
  Time GetWaitReplyTimeout (void) const;
73
  Time GetWaitReplyTimeout (void) const;
74
  uint32_t GetMaxRetries (void) const;
73
75
74
  /**
76
  /**
75
   * \brief Do lookup in the ARP chache against an IP address
77
   * \brief Do lookup in the ARP chache against an IP address
 Lines 127-133   public: Link Here 
127
     * \return True if the state of this entry is wait_reply; false otherwise.
129
     * \return True if the state of this entry is wait_reply; false otherwise.
128
     */
130
     */
129
    bool IsWaitReply (void);
131
    bool IsWaitReply (void);
130
    
131
    /**
132
    /**
132
     * \return The MacAddress of this entry
133
     * \return The MacAddress of this entry
133
     */
134
     */
 Lines 136-147   public: Link Here 
136
     * \return True if this entry has timedout; false otherwise.
137
     * \return True if this entry has timedout; false otherwise.
137
     */
138
     */
138
    bool IsExpired (void);
139
    bool IsExpired (void);
139
140
    /**
140
    /**
141
     * \returns 0 is no packet is pending, the next packet to send if 
141
     * \returns 0 is no packet is pending, the next packet to send if 
142
     *            packets are pending.
142
     *            packets are pending.
143
     */
143
     */
144
    Ptr<Packet> DequeuePending (void);
144
    Ptr<Packet> DequeuePending (void);
145
    /**
146
     * \returns number of retries that have been sent for an ArpRequest
147
     *  in WaitReply state.
148
     */
149
    uint32_t GetRetries (void) const;
150
    /**
151
     * \brief Increment the counter of number of retries for an entry
152
     */
153
    void IncrementRetries (void);
154
    /**
155
     * \brief Zero the counter of number of retries for an entry
156
     */
157
    void ClearRetries (void);
158
    /**
159
     * \brief Get raw pointer to Timer associated with WAIT_REPLY
160
     *        state.  For internal use by ArpL3Protocol.
161
     */
162
    Timer* GetWaitTimer (void);
145
  private:
163
  private:
146
    enum ArpCacheEntryState_e {
164
    enum ArpCacheEntryState_e {
147
      ALIVE,
165
      ALIVE,
 Lines 155-160   public: Link Here 
155
    Time m_lastSeen;
173
    Time m_lastSeen;
156
    Address m_macAddress;
174
    Address m_macAddress;
157
    std::list<Ptr<Packet> > m_pending;
175
    std::list<Ptr<Packet> > m_pending;
176
    uint32_t m_retries;
177
    Timer m_waitTimer; 
158
  };
178
  };
159
179
160
private:
180
private:
 Lines 170-175   private: Link Here 
170
  Time m_waitReplyTimeout;
190
  Time m_waitReplyTimeout;
171
  uint32_t m_pendingQueueSize;
191
  uint32_t m_pendingQueueSize;
172
  Cache m_arpCache;
192
  Cache m_arpCache;
193
  uint32_t m_maxRetries;
173
};
194
};
174
195
175
196
(-)a/src/internet-stack/arp-l3-protocol.cc (+44 lines)
 Lines 159-164   ArpL3Protocol::Receive(Ptr<NetDevice> de Link Here 
159
                     << " for waiting entry -- flush");
159
                     << " for waiting entry -- flush");
160
              Address from_mac = arp.GetSourceHardwareAddress ();
160
              Address from_mac = arp.GetSourceHardwareAddress ();
161
              entry->MarkAlive (from_mac);
161
              entry->MarkAlive (from_mac);
162
              entry->ClearRetries ();
163
              entry->GetWaitTimer ()->Cancel ();
162
              Ptr<Packet> pending = entry->DequeuePending();
164
              Ptr<Packet> pending = entry->DequeuePending();
163
              while (pending != 0)
165
              while (pending != 0)
164
                {
166
                {
 Lines 190-195   ArpL3Protocol::Receive(Ptr<NetDevice> de Link Here 
190
                arp.GetDestinationIpv4Address () << " -- drop");
192
                arp.GetDestinationIpv4Address () << " -- drop");
191
    }
193
    }
192
}
194
}
195
196
void
197
ArpL3Protocol::HandleWaitTimeout (Ptr<ArpCache> cache, Ipv4Address destination)
198
{
199
  NS_LOG_FUNCTION_NOARGS ();
200
  ArpCache::Entry *entry = cache->Lookup (destination);
201
  if (entry != 0 && entry->IsWaitReply ())
202
    {
203
      if (entry->GetRetries () < cache->GetMaxRetries () )
204
        {
205
          NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
206
                    ", ArpWaitTimeout for " << destination << " expired -- send arp request since retries = " << entry->GetRetries ());
207
          SendArpRequest (cache, destination);
208
          entry->GetWaitTimer ()->Schedule ();
209
          entry->IncrementRetries ();
210
        }
211
      else
212
        {
213
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
214
                        ", wait reply for " << destination << " expired -- drop since max retries exceeded: " << entry->GetRetries ());
215
              entry->MarkDead ();
216
              Ptr<Packet> pending = entry->DequeuePending();
217
              while (pending != 0)
218
                {
219
                  m_dropTrace (pending);
220
                  pending = entry->DequeuePending();
221
                }
222
        }
223
    }
224
}
225
193
bool 
226
bool 
194
ArpL3Protocol::Lookup (Ptr<Packet> packet, Ipv4Address destination, 
227
ArpL3Protocol::Lookup (Ptr<Packet> packet, Ipv4Address destination, 
195
                       Ptr<NetDevice> device,
228
                       Ptr<NetDevice> device,
 Lines 208-213   ArpL3Protocol::Lookup (Ptr<Packet> packe Link Here 
208
                        ", dead entry for " << destination << " expired -- send arp request");
241
                        ", dead entry for " << destination << " expired -- send arp request");
209
              entry->MarkWaitReply (packet);
242
              entry->MarkWaitReply (packet);
210
              SendArpRequest (cache, destination);
243
              SendArpRequest (cache, destination);
244
              // Timer already seeded, so just reschedule
245
              entry->GetWaitTimer ()->Schedule ();
211
            } 
246
            } 
212
          else if (entry->IsAlive ()) 
247
          else if (entry->IsAlive ()) 
213
            {
248
            {
 Lines 215-223   ArpL3Protocol::Lookup (Ptr<Packet> packe Link Here 
215
                        ", alive entry for " << destination << " expired -- send arp request");
250
                        ", alive entry for " << destination << " expired -- send arp request");
216
              entry->MarkWaitReply (packet);
251
              entry->MarkWaitReply (packet);
217
              SendArpRequest (cache, destination);
252
              SendArpRequest (cache, destination);
253
              // Timer already seeded, so just reschedule
254
              entry->GetWaitTimer ()->Schedule ();
218
            } 
255
            } 
219
          else if (entry->IsWaitReply ()) 
256
          else if (entry->IsWaitReply ()) 
220
            {
257
            {
258
              // Is this dead code branch?
259
              NS_ASSERT (false);
221
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
260
              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
222
                        ", wait reply for " << destination << " expired -- drop");
261
                        ", wait reply for " << destination << " expired -- drop");
223
              entry->MarkDead ();
262
              entry->MarkDead ();
 Lines 264-269   ArpL3Protocol::Lookup (Ptr<Packet> packe Link Here 
264
      entry = cache->Add (destination);
303
      entry = cache->Add (destination);
265
      entry->MarkWaitReply (packet);
304
      entry->MarkWaitReply (packet);
266
      SendArpRequest (cache, destination);
305
      SendArpRequest (cache, destination);
306
      // Set up the wait timer to handle possible retransmissions
307
      entry->GetWaitTimer ()->SetFunction (&ns3::ArpL3Protocol::HandleWaitTimeout, this);
308
      entry->GetWaitTimer ()->SetArguments (cache, destination);
309
      entry->GetWaitTimer ()->SetDelay (cache->GetWaitReplyTimeout ());
310
      entry->GetWaitTimer ()->Schedule ();
267
    }
311
    }
268
  return false;
312
  return false;
269
}
313
}
(-)a/src/internet-stack/arp-l3-protocol.h (+3 lines)
 Lines 69-74   public: Link Here 
69
	       Ptr<NetDevice> device,
69
	       Ptr<NetDevice> device,
70
               Ptr<ArpCache> cache,
70
               Ptr<ArpCache> cache,
71
	       Address *hardwareDestination);
71
	       Address *hardwareDestination);
72
73
  void HandleWaitTimeout (Ptr<ArpCache> cache, Ipv4Address destination);
74
72
protected:
75
protected:
73
  virtual void DoDispose (void);
76
  virtual void DoDispose (void);
74
private:
77
private:

Return to bug 253