Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 40 additions & 117 deletions src/traffic-control/model/red-queue-disc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,7 @@ RedQueueDisc::DoEnqueue (Ptr<QueueDiscItem> item)
{
NS_LOG_DEBUG ("RED Queue Disc is idle.");
Time now = Simulator::Now ();

if (m_cautious == 3)
{
double ptc = m_ptc * m_meanPktSize / m_idlePktSize;
m = uint32_t (ptc * (now - m_idleTime).GetSeconds ());
}
else
{
m = uint32_t (m_ptc * (now - m_idleTime).GetSeconds ());
}

m = uint32_t (m_pktTimeConst * (now - m_idleTime).GetSeconds ());
m_idle = 0;
}

Expand Down Expand Up @@ -455,8 +445,7 @@ RedQueueDisc::InitializeParams (void)
NS_LOG_FUNCTION (this);
NS_LOG_INFO ("Initializing RED params.");

m_cautious = 0;
m_ptc = m_linkBandwidth.GetBitRate () / (8.0 * m_meanPktSize);
m_pktTimeConst = m_linkBandwidth.GetBitRate () / (8.0 * m_meanPktSize);

if (m_isARED)
{
Expand All @@ -480,7 +469,7 @@ RedQueueDisc::InitializeParams (void)
m_minTh = 5.0;

// set m_minTh to max(m_minTh, targetqueue/2.0) [Ref: http://www.icir.org/floyd/papers/adaptiveRed.pdf]
double targetqueue = m_targetDelay.GetSeconds() * m_ptc;
double targetqueue = m_targetDelay.GetSeconds() * m_pktTimeConst;

if (m_minTh < targetqueue / 2.0 )
{
Expand Down Expand Up @@ -519,37 +508,6 @@ RedQueueDisc::InitializeParams (void)
}
m_idleTime = NanoSeconds (0);

/*
* If m_qW=0, set it to a reasonable value of 1-exp(-1/C)
* This corresponds to choosing m_qW to be of that value for
* which the packet time constant -1/ln(1-m)qW) per default RTT
* of 100ms is an order of magnitude more than the link capacity, C.
*
* If m_qW=-1, then the queue weight is set to be a function of
* the bandwidth and the link propagation delay. In particular,
* the default RTT is assumed to be three times the link delay and
* transmission delay, if this gives a default RTT greater than 100 ms.
*
* If m_qW=-2, set it to a reasonable value of 1-exp(-10/C).
*/
if (m_qW == 0.0)
{
m_qW = 1.0 - std::exp (-1.0 / m_ptc);
}
else if (m_qW == -1.0)
{
double rtt = 3.0 * (m_linkDelay.GetSeconds () + 1.0 / m_ptc);

if (rtt < 0.1)
{
rtt = 0.1;
}
m_qW = 1.0 - std::exp (-1.0 / (10 * rtt * m_ptc));
}
else if (m_qW == -2.0)
{
m_qW = 1.0 - std::exp (-10.0 / m_ptc);
}

if (m_bottom == 0)
{
Expand All @@ -565,7 +523,7 @@ RedQueueDisc::InitializeParams (void)
}

NS_LOG_DEBUG ("\tm_delay " << m_linkDelay.GetSeconds () << "; m_isWait "
<< m_isWait << "; m_qW " << m_qW << "; m_ptc " << m_ptc
<< m_isWait << "; m_qW " << m_qW << "; m_pktTimeConst " << m_pktTimeConst
<< "; m_minTh " << m_minTh << "; m_maxTh " << m_maxTh
<< "; m_isGentle " << m_isGentle << "; th_diff " << th_diff
<< "; lInterm " << m_lInterm << "; va " << m_vA << "; cur_max_p "
Expand Down Expand Up @@ -655,44 +613,8 @@ RedQueueDisc::DropEarly (Ptr<QueueDiscItem> item, uint32_t qSize)

double prob1 = CalculatePNew ();
m_vProb = ModifyP (prob1, item->GetSize ());

// Drop probability is computed, pick random number and act
if (m_cautious == 1)
{
/*
* Don't drop/mark if the instantaneous queue is much below the average.
* For experimental purposes only.
* pkts: the number of packets arriving in 50 ms
*/
double pkts = m_ptc * 0.05;
double fraction = std::pow ((1 - m_qW), pkts);

if ((double) qSize < fraction * m_qAvg)
{
// Queue could have been empty for 0.05 seconds
return 0;
}
}

double u = m_uv->GetValue ();

if (m_cautious == 2)
{
/*
* Decrease the drop probability if the instantaneous
* queue is much below the average.
* For experimental purposes only.
* pkts: the number of packets arriving in 50 ms
*/
double pkts = m_ptc * 0.05;
double fraction = std::pow ((1 - m_qW), pkts);
double ratio = qSize / (fraction * m_qAvg);

if (ratio < 1.0)
{
u *= 1.0 / ratio;
}
}

if (u <= m_vProb)
{
Expand Down Expand Up @@ -760,39 +682,27 @@ double
RedQueueDisc::ModifyP (double p, uint32_t size)
{
NS_LOG_FUNCTION (this << p << size);
double count1 = (double) m_count;
double count = (double) m_count;

if (GetMaxSize ().GetUnit () == QueueSizeUnit::BYTES)
{
count1 = (double) (m_countBytes / m_meanPktSize);
count = (double) (m_countBytes / m_meanPktSize);
}

if (m_isWait)
{
if (count1 * p < 1.0)
{
p = 0.0;
}
else if (count1 * p < 2.0)
{
p /= (2.0 - count1 * p);
}
else
{
p = 1.0;
}
}
else
{
if (count1 * p < 1.0)
{
p /= (1.0 - count1 * p);
}
else
{
p = 1.0;
}
}

if (count * p < 1.0)
{
p = 0.0;
}
else if (count * p < 2.0)
{
p /= (2.0 - count * p);
}
else
{
p = 1.0;
}


if ((GetMaxSize ().GetUnit () == QueueSizeUnit::BYTES) && (p < 1.0))
{
Expand All @@ -807,29 +717,42 @@ RedQueueDisc::ModifyP (double p, uint32_t size)
return p;
}

int RedQueueDisc::IsQueueEmpty()
{
if (GetInternalQueue (0)->IsEmpty ())
{
NS_LOG_LOGIC ("Queue empty");
m_idle = true;
m_idleTime = Simulator::Now ();

return 1;
}
return 0;
}

Ptr<QueueDiscItem>
RedQueueDisc::DoDequeue (void)
{
NS_LOG_FUNCTION (this);

if (GetInternalQueue (0)->IsEmpty ())

if (GetInternalQueue (0)->IsEmpty ())
{
NS_LOG_LOGIC ("Queue empty");
m_idle = 1;
m_idleTime = Simulator::Now ();

return 0;
}
else

else
{
m_idle = 0;
Ptr<QueueDiscItem> item = GetInternalQueue (0)->Dequeue ();

NS_LOG_LOGIC ("Popped " << item);

NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ());
NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ());

//checking if queue becomes empty after dequeue
IsQueueEmpty();

return item;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/traffic-control/model/red-queue-disc.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class RedQueueDisc : public QueueDisc
uint32_t m_countBytes; //!< Number of bytes since last drop
uint32_t m_old; //!< 0 when average queue first exceeds threshold
uint32_t m_idle; //!< 0/1 idle status
double m_ptc; //!< packet time constant in packets/second
double m_pktTimeConst; //!< packet time constant in packets/second
double m_qAvg; //!< Average queue length
uint32_t m_count; //!< Number of packets since last random number generation
FengStatus m_fengStatus; //!< For use in Feng's Adaptive RED
Expand All @@ -308,7 +308,6 @@ class RedQueueDisc : public QueueDisc
* 2 experimental (see red-queue-disc.cc)
* 3 use Idle packet size in the ptc
*/
uint32_t m_cautious;
Time m_idleTime; //!< Start of current idle period

Ptr<UniformRandomVariable> m_uv; //!< rng stream
Expand Down