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

(-)a/src/network/utils/queue.cc (-7 / +24 lines)
 Lines 97-115   bool Link Here 
97
Queue::Enqueue (Ptr<QueueItem> item)
97
Queue::Enqueue (Ptr<QueueItem> item)
98
{
98
{
99
  NS_LOG_FUNCTION (this << item);
99
  NS_LOG_FUNCTION (this << item);
100
  Ptr<Packet> p = item->GetPacket ();
101
100
102
  if (m_mode == QUEUE_MODE_PACKETS && (m_nPackets.Get () >= m_maxPackets))
101
  if (m_mode == QUEUE_MODE_PACKETS && (m_nPackets.Get () >= m_maxPackets))
103
    {
102
    {
104
      NS_LOG_LOGIC ("Queue full (at max packets) -- dropping pkt");
103
      NS_LOG_LOGIC ("Queue full (at max packets) -- dropping pkt");
105
      Drop (p);
104
      Drop (item);
106
      return false;
105
      return false;
107
    }
106
    }
108
107
109
  if (m_mode == QUEUE_MODE_BYTES && (m_nBytes.Get () + item->GetPacketSize () > m_maxBytes))
108
  if (m_mode == QUEUE_MODE_BYTES && (m_nBytes.Get () + item->GetPacketSize () > m_maxBytes))
110
    {
109
    {
111
      NS_LOG_LOGIC ("Queue full (packet would exceed max bytes) -- dropping pkt");
110
      NS_LOG_LOGIC ("Queue full (packet would exceed max bytes) -- dropping pkt");
112
      Drop (p);
111
      Drop (item);
113
      return false;
112
      return false;
114
    }
113
    }
115
114
 Lines 319-333   Queue::GetMaxBytes (void) const Link Here 
319
}
318
}
320
319
321
void
320
void
322
Queue::Drop (Ptr<Packet> p)
321
Queue::SetDropCallback (DropCallback cb)
323
{
322
{
324
  NS_LOG_FUNCTION (this << p);
323
  m_dropCallback = cb;
324
}
325
326
void
327
Queue::NotifyDrop (Ptr<QueueItem> item)
328
{
329
  NS_LOG_FUNCTION (this << item);
330
331
  if (!m_dropCallback.IsNull ())
332
    {
333
      m_dropCallback (item);
334
    }
335
}
336
337
void
338
Queue::Drop (Ptr<QueueItem> item)
339
{
340
  NS_LOG_FUNCTION (this << item);
325
341
326
  m_nTotalDroppedPackets++;
342
  m_nTotalDroppedPackets++;
327
  m_nTotalDroppedBytes += p->GetSize ();
343
  m_nTotalDroppedBytes += item->GetPacketSize ();
328
344
329
  NS_LOG_LOGIC ("m_traceDrop (p)");
345
  NS_LOG_LOGIC ("m_traceDrop (p)");
330
  m_traceDrop (p);
346
  m_traceDrop (item->GetPacket ());
347
  NotifyDrop (item);
331
}
348
}
332
349
333
} // namespace ns3
350
} // namespace ns3
(-)a/src/network/utils/queue.h (-2 / +21 lines)
 Lines 190-205   public: Link Here 
190
  double GetDroppedPacketsPerSecondVariance (void);
190
  double GetDroppedPacketsPerSecondVariance (void);
191
#endif
191
#endif
192
192
193
  /// Callback set by the object (e.g., a queue disc) that wants to be notified of a packet drop
194
  typedef Callback<void, Ptr<QueueItem> > DropCallback;
195
196
  /**
197
   * \brief Set the drop callback
198
   * \param cb the callback to set
199
   *
200
   * Called when a queue is added to a queue disc in order to set a
201
   * callback to the Drop method of the queue disc.
202
   */
203
  virtual void SetDropCallback (DropCallback cb);
204
193
protected:
205
protected:
194
  /**
206
  /**
195
   * \brief Drop a packet
207
   * \brief Drop a packet
196
   * \param p packet that was dropped
208
   * \param item item that was dropped
197
   *
209
   *
198
   * This method is called by the base class when a packet is dropped because
210
   * This method is called by the base class when a packet is dropped because
199
   * the queue is full and by the subclasses to notify parent (this class) that
211
   * the queue is full and by the subclasses to notify parent (this class) that
200
   * a packet has been dropped for other reasons.
212
   * a packet has been dropped for other reasons.
201
   */
213
   */
202
  void Drop (Ptr<Packet> p);
214
  void Drop (Ptr<QueueItem> item);
203
215
204
private:
216
private:
205
  /**
217
  /**
 Lines 219-224   private: Link Here 
219
   */
231
   */
220
  virtual Ptr<const QueueItem> DoPeek (void) const = 0;
232
  virtual Ptr<const QueueItem> DoPeek (void) const = 0;
221
233
234
  /**
235
   *  \brief Notification of a packet drop
236
   *  \param item item that was dropped
237
   */
238
  void NotifyDrop (Ptr<QueueItem> item);
239
222
  /// Traced callback: fired when a packet is enqueued
240
  /// Traced callback: fired when a packet is enqueued
223
  TracedCallback<Ptr<const Packet> > m_traceEnqueue;
241
  TracedCallback<Ptr<const Packet> > m_traceEnqueue;
224
  /// Traced callback: fired when a packet is dequeued
242
  /// Traced callback: fired when a packet is dequeued
 Lines 236-241   private: Link Here 
236
  uint32_t m_maxPackets;              //!< max packets in the queue
254
  uint32_t m_maxPackets;              //!< max packets in the queue
237
  uint32_t m_maxBytes;                //!< max bytes in the queue
255
  uint32_t m_maxBytes;                //!< max bytes in the queue
238
  QueueMode m_mode;                   //!< queue mode (packets or bytes limited)
256
  QueueMode m_mode;                   //!< queue mode (packets or bytes limited)
257
  DropCallback m_dropCallback;        //!< drop callback
239
};
258
};
240
259
241
} // namespace ns3
260
} // namespace ns3
(-)a/src/traffic-control/model/codel-queue-disc.cc (-3 / +6 lines)
 Lines 296-308   CoDelQueueDisc::DoEnqueue (Ptr<QueueDiscItem> item) Link Here 
296
  // Tag packet with current time for DoDequeue() to compute sojourn time
296
  // Tag packet with current time for DoDequeue() to compute sojourn time
297
  CoDelTimestampTag tag;
297
  CoDelTimestampTag tag;
298
  p->AddPacketTag (tag);
298
  p->AddPacketTag (tag);
299
  
299
300
  GetInternalQueue (0)->Enqueue (item);
300
  bool retval = GetInternalQueue (0)->Enqueue (item);
301
302
  // If Queue::Enqueue fails, QueueDisc::Drop is called by the internal queue
303
  // because QueueDisc::AddInternalQueue sets the drop callback
301
304
302
  NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ());
305
  NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ());
303
  NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ());
306
  NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ());
304
307
305
  return true;
308
  return retval;
306
}
309
}
307
310
308
bool
311
bool
(-)a/src/traffic-control/model/pfifo-fast-queue-disc.cc (-7 / +6 lines)
 Lines 87-101   PfifoFastQueueDisc::DoEnqueue (Ptr<QueueDiscItem> item) Link Here 
87
      band = ret;
87
      band = ret;
88
    }
88
    }
89
89
90
  if (!GetInternalQueue(band)->Enqueue (item))
90
  bool retval = GetInternalQueue(band)->Enqueue (item);
91
    {
91
92
      NS_LOG_LOGIC ("Enqueue failed -- dropping pkt");
92
  // If Queue::Enqueue fails, QueueDisc::Drop is called by the internal queue
93
      Drop (item);
93
  // because QueueDisc::AddInternalQueue sets the drop callback
94
      return false;
94
95
    }
96
  NS_LOG_LOGIC ("Number packets band " << band << ": " << GetInternalQueue(band)->GetNPackets ());
95
  NS_LOG_LOGIC ("Number packets band " << band << ": " << GetInternalQueue(band)->GetNPackets ());
97
96
98
  return true;
97
  return retval;
99
}
98
}
100
99
101
Ptr<QueueDiscItem>
100
Ptr<QueueDiscItem>
(-)a/src/traffic-control/model/queue-disc.cc (+3 lines)
 Lines 313-318   void Link Here 
313
QueueDisc::AddInternalQueue (Ptr<Queue> queue)
313
QueueDisc::AddInternalQueue (Ptr<Queue> queue)
314
{
314
{
315
  NS_LOG_FUNCTION (this);
315
  NS_LOG_FUNCTION (this);
316
  // set the drop callback on the internal queue, so that the queue disc is
317
  // notified of packets dropped by the internal queue
318
  queue->SetDropCallback (MakeCallback (&QueueDisc::Drop, this));
316
  m_queues.push_back (queue);
319
  m_queues.push_back (queue);
317
}
320
}
318
321
(-)a/src/traffic-control/model/red-queue-disc.cc (-2 / +5 lines)
 Lines 410-421   RedQueueDisc::DoEnqueue (Ptr<QueueDiscItem> item) Link Here 
410
      return false;
410
      return false;
411
    }
411
    }
412
412
413
  GetInternalQueue (0)->Enqueue (item);
413
  bool retval = GetInternalQueue (0)->Enqueue (item);
414
415
  // If Queue::Enqueue fails, QueueDisc::Drop is called by the internal queue
416
  // because QueueDisc::AddInternalQueue sets the drop callback
414
417
415
  NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ());
418
  NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ());
416
  NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ());
419
  NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ());
417
420
418
  return true;
421
  return retval;
419
}
422
}
420
423
421
/*
424
/*

Return to bug 2389