traffic-control: fix the RED examples

This commit is contained in:
Pasquale Imputato
2016-03-08 10:48:13 -08:00
parent 24881696d2
commit 586d3d9e37
3 changed files with 103 additions and 65 deletions

View File

@@ -14,6 +14,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: John Abraham <john.abraham@gatech.edu>
* Modified by: Pasquale Imputato <p.imputato@gmail.com>
*
*/
@@ -24,6 +25,7 @@
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/point-to-point-layout-module.h"
#include "ns3/traffic-control-module.h"
#include <iostream>
#include <iomanip>
@@ -37,65 +39,64 @@ int main (int argc, char *argv[])
uint32_t nLeaf = 5;
uint32_t maxPackets = 100;
uint32_t modeBytes = 0;
uint32_t queueDiscLimitPackets = 1000;
double minTh = 50;
double maxTh = 80;
uint32_t pktSize = 512;
std::string appDataRate = "10Mbps";
std::string queueType = "DropTail";
std::string queueDiscType = "PfifoFast";
uint16_t port = 5001;
std::string bottleNeckLinkBw = "1Mbps";
std::string bottleNeckLinkDelay = "50ms";
CommandLine cmd;
cmd.AddValue ("nLeaf", "Number of left and right side leaf nodes", nLeaf);
cmd.AddValue ("maxPackets","Max Packets allowed in the queue", maxPackets);
cmd.AddValue ("queueType", "Set Queue type to DropTail or RED", queueType);
cmd.AddValue ("maxPackets","Max Packets allowed in the device queue", maxPackets);
cmd.AddValue ("queueDiscLimitPackets","Max Packets allowed in the queue disc", queueDiscLimitPackets);
cmd.AddValue ("queueDiscType", "Set QueueDisc type to PfifoFast or RED", queueDiscType);
cmd.AddValue ("appPktSize", "Set OnOff App Packet Size", pktSize);
cmd.AddValue ("appDataRate", "Set OnOff App DataRate", appDataRate);
cmd.AddValue ("modeBytes", "Set Queue mode to Packets <0> or bytes <1>", modeBytes);
cmd.AddValue ("modeBytes", "Set QueueDisc mode to Packets <0> or bytes <1>", modeBytes);
cmd.AddValue ("redMinTh", "RED queue minimum threshold", minTh);
cmd.AddValue ("redMaxTh", "RED queue maximum threshold", maxTh);
cmd.Parse (argc,argv);
if ((queueType != "RED") && (queueType != "DropTail"))
if ((queueDiscType != "RED") && (queueDiscType != "PfifoFast"))
{
NS_ABORT_MSG ("Invalid queue type: Use --queueType=RED or --queueType=DropTail");
NS_ABORT_MSG ("Invalid queue disc type: Use --queueDiscType=RED or --queueDiscType=PfifoFast");
}
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (pktSize));
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue (appDataRate));
Config::SetDefault ("ns3::Queue::Mode", StringValue ("QUEUE_MODE_PACKETS"));
Config::SetDefault ("ns3::Queue::MaxPackets", UintegerValue (maxPackets));
if (!modeBytes)
{
Config::SetDefault ("ns3::DropTailQueue::Mode", StringValue ("QUEUE_MODE_PACKETS"));
Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (maxPackets));
Config::SetDefault ("ns3::RedQueue::Mode", StringValue ("QUEUE_MODE_PACKETS"));
Config::SetDefault ("ns3::RedQueue::QueueLimit", UintegerValue (maxPackets));
}
{
Config::SetDefault ("ns3::RedQueueDisc::Mode", StringValue ("QUEUE_MODE_PACKETS"));
Config::SetDefault ("ns3::RedQueueDisc::QueueLimit", UintegerValue (queueDiscLimitPackets));
Config::SetDefault ("ns3::PfifoFastQueueDisc::Limit", UintegerValue (queueDiscLimitPackets));
}
else
{
Config::SetDefault ("ns3::DropTailQueue::Mode", StringValue ("QUEUE_MODE_BYTES"));
Config::SetDefault ("ns3::DropTailQueue::MaxBytes", UintegerValue (maxPackets * pktSize));
Config::SetDefault ("ns3::RedQueue::Mode", StringValue ("QUEUE_MODE_BYTES"));
Config::SetDefault ("ns3::RedQueue::QueueLimit", UintegerValue (maxPackets * pktSize));
minTh *= pktSize;
maxTh *= pktSize;
}
{
Config::SetDefault ("ns3::RedQueueDisc::Mode", StringValue ("QUEUE_MODE_BYTES"));
Config::SetDefault ("ns3::RedQueueDisc::QueueLimit", UintegerValue (queueDiscLimitPackets * pktSize));
minTh *= pktSize;
maxTh *= pktSize;
}
Config::SetDefault ("ns3::RedQueueDisc::MinTh", DoubleValue (minTh));
Config::SetDefault ("ns3::RedQueueDisc::MaxTh", DoubleValue (maxTh));
Config::SetDefault ("ns3::RedQueueDisc::LinkBandwidth", StringValue (bottleNeckLinkBw));
Config::SetDefault ("ns3::RedQueueDisc::LinkDelay", StringValue (bottleNeckLinkDelay));
// Create the point-to-point link helpers
PointToPointHelper bottleNeckLink;
bottleNeckLink.SetDeviceAttribute ("DataRate", StringValue (bottleNeckLinkBw));
bottleNeckLink.SetChannelAttribute ("Delay", StringValue (bottleNeckLinkDelay));
if (queueType == "RED")
{
bottleNeckLink.SetQueue ("ns3::RedQueue",
"MinTh", DoubleValue (minTh),
"MaxTh", DoubleValue (maxTh),
"LinkBandwidth", StringValue (bottleNeckLinkBw),
"LinkDelay", StringValue (bottleNeckLinkDelay));
}
PointToPointHelper pointToPointLeaf;
pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms"));
@@ -106,7 +107,29 @@ int main (int argc, char *argv[])
// Install Stack
InternetStackHelper stack;
d.InstallStack (stack);
for (uint32_t i = 0; i < d.LeftCount (); ++i)
{
stack.Install (d.GetLeft (i));
}
for (uint32_t i = 0; i < d.RightCount (); ++i)
{
stack.Install (d.GetRight (i));
}
if (queueDiscType == "PfifoFast")
{
stack.Install (d.GetLeft ());
stack.Install (d.GetRight ());
}
else if (queueDiscType == "RED")
{
stack.Install (d.GetLeft ());
stack.Install (d.GetRight ());
TrafficControlHelper tchBottleneck;
tchBottleneck.SetRootQueueDisc ("ns3::RedQueueDisc");
tchBottleneck.Install (d.GetLeft ()->GetDevice (0));
tchBottleneck.Install (d.GetRight ()->GetDevice (0));
}
// Assign IP Addresses
d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
@@ -150,8 +173,8 @@ int main (int argc, char *argv[])
Ptr <PacketSink> pktSink = DynamicCast <PacketSink> (app);
totalRxBytesCounter += pktSink->GetTotalRx ();
}
NS_LOG_UNCOND ("----------------------------\nQueue Type:"
<< queueType
NS_LOG_UNCOND ("----------------------------\nQueueDisc Type:"
<< queueDiscType
<< "\nGoodput Bytes/sec:"
<< totalRxBytesCounter/Simulator::Now ().GetSeconds ());
NS_LOG_UNCOND ("----------------------------");

View File

@@ -15,6 +15,7 @@
*
* Authors: Marcos Talau <talau@users.sourceforge.net>
* Duy Nguyen <duy@soe.ucsc.edu>
* Modified by: Pasquale Imputato <p.imputato@gmail.com>
*
*/
@@ -43,6 +44,7 @@
#include "ns3/flow-monitor-helper.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/traffic-control-module.h"
using namespace ns3;
@@ -75,9 +77,9 @@ std::stringstream filePlotQueue;
std::stringstream filePlotQueueAvg;
void
CheckQueueSize (Ptr<Queue> queue)
CheckQueueSize (Ptr<QueueDisc> queue)
{
uint32_t qSize = StaticCast<RedQueue> (queue)->GetQueueSize ();
uint32_t qSize = StaticCast<RedQueueDisc> (queue)->GetQueueSize ();
avgQueueSize += qSize;
checkTimes++;
@@ -253,7 +255,7 @@ BuildAppsTest (uint32_t test)
int
main (int argc, char *argv[])
{
LogComponentEnable ("RedQueue", LOG_LEVEL_INFO);
LogComponentEnable ("RedQueueDisc", LOG_LEVEL_INFO);
uint32_t redTest;
std::string redLinkDataRate = "1.5Mbps";
@@ -315,33 +317,42 @@ main (int argc, char *argv[])
// RED params
NS_LOG_INFO ("Set RED params");
Config::SetDefault ("ns3::RedQueue::Mode", StringValue ("QUEUE_MODE_PACKETS"));
Config::SetDefault ("ns3::RedQueue::MeanPktSize", UintegerValue (meanPktSize));
Config::SetDefault ("ns3::RedQueue::Wait", BooleanValue (true));
Config::SetDefault ("ns3::RedQueue::Gentle", BooleanValue (true));
Config::SetDefault ("ns3::RedQueue::QW", DoubleValue (0.002));
Config::SetDefault ("ns3::RedQueue::MinTh", DoubleValue (5));
Config::SetDefault ("ns3::RedQueue::MaxTh", DoubleValue (15));
Config::SetDefault ("ns3::RedQueue::QueueLimit", UintegerValue (25));
Config::SetDefault ("ns3::RedQueueDisc::Mode", StringValue ("QUEUE_MODE_PACKETS"));
Config::SetDefault ("ns3::RedQueueDisc::MeanPktSize", UintegerValue (meanPktSize));
Config::SetDefault ("ns3::RedQueueDisc::Wait", BooleanValue (true));
Config::SetDefault ("ns3::RedQueueDisc::Gentle", BooleanValue (true));
Config::SetDefault ("ns3::RedQueueDisc::QW", DoubleValue (0.002));
Config::SetDefault ("ns3::RedQueueDisc::MinTh", DoubleValue (5));
Config::SetDefault ("ns3::RedQueueDisc::MaxTh", DoubleValue (15));
Config::SetDefault ("ns3::RedQueueDisc::QueueLimit", UintegerValue (1000));
if (redTest == 3) // test like 1, but with bad params
{
Config::SetDefault ("ns3::RedQueue::MaxTh", DoubleValue (10));
Config::SetDefault ("ns3::RedQueue::QW", DoubleValue (0.003));
Config::SetDefault ("ns3::RedQueueDisc::MaxTh", DoubleValue (10));
Config::SetDefault ("ns3::RedQueueDisc::QW", DoubleValue (0.003));
}
else if (redTest == 5) // test 5, same of test 4, but in byte mode
{
Config::SetDefault ("ns3::RedQueue::Mode", StringValue ("QUEUE_MODE_BYTES"));
Config::SetDefault ("ns3::RedQueue::Ns1Compat", BooleanValue (true));
Config::SetDefault ("ns3::RedQueue::MinTh", DoubleValue (5 * meanPktSize));
Config::SetDefault ("ns3::RedQueue::MaxTh", DoubleValue (15 * meanPktSize));
Config::SetDefault ("ns3::RedQueue::QueueLimit", UintegerValue (25 * meanPktSize));
Config::SetDefault ("ns3::RedQueueDisc::Mode", StringValue ("QUEUE_MODE_BYTES"));
Config::SetDefault ("ns3::RedQueueDisc::Ns1Compat", BooleanValue (true));
Config::SetDefault ("ns3::RedQueueDisc::MinTh", DoubleValue (5 * meanPktSize));
Config::SetDefault ("ns3::RedQueueDisc::MaxTh", DoubleValue (15 * meanPktSize));
Config::SetDefault ("ns3::RedQueueDisc::QueueLimit", UintegerValue (1000 * meanPktSize));
}
NS_LOG_INFO ("Install internet stack on all nodes.");
InternetStackHelper internet;
internet.Install (c);
TrafficControlHelper tchPfifo;
uint16_t handle = tchPfifo.SetRootQueueDisc ("ns3::PfifoFastQueueDisc");
tchPfifo.AddInternalQueues (handle, 3, "ns3::DropTailQueue", "MaxPackets", UintegerValue (1000));
tchPfifo.AddPacketFilter (handle, "ns3::PfifoFastIpv4PacketFilter");
TrafficControlHelper tchRed;
tchRed.SetRootQueueDisc ("ns3::RedQueueDisc", "LinkBandwidth", StringValue (redLinkDataRate),
"LinkDelay", StringValue (redLinkDelay));
NS_LOG_INFO ("Create channels");
PointToPointHelper p2p;
@@ -349,28 +360,32 @@ main (int argc, char *argv[])
p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer devn0n2 = p2p.Install (n0n2);
tchPfifo.Install (devn0n2);
p2p.SetQueue ("ns3::DropTailQueue");
p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("3ms"));
NetDeviceContainer devn1n2 = p2p.Install (n1n2);
tchPfifo.Install (devn1n2);
p2p.SetQueue ("ns3::RedQueue", // only backbone link has RED queue
"LinkBandwidth", StringValue (redLinkDataRate),
"LinkDelay", StringValue (redLinkDelay));
p2p.SetQueue ("ns3::DropTailQueue");
p2p.SetDeviceAttribute ("DataRate", StringValue (redLinkDataRate));
p2p.SetChannelAttribute ("Delay", StringValue (redLinkDelay));
NetDeviceContainer devn2n3 = p2p.Install (n2n3);
// only backbone link has RED queue disc
QueueDiscContainer queueDiscs = tchRed.Install (devn2n3);
p2p.SetQueue ("ns3::DropTailQueue");
p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("4ms"));
NetDeviceContainer devn3n4 = p2p.Install (n3n4);
tchPfifo.Install (devn3n4);
p2p.SetQueue ("ns3::DropTailQueue");
p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("5ms"));
NetDeviceContainer devn3n5 = p2p.Install (n3n5);
tchPfifo.Install (devn3n5);
NS_LOG_INFO ("Assign IP Addresses");
Ipv4AddressHelper ipv4;
@@ -396,12 +411,11 @@ main (int argc, char *argv[])
if (redTest == 5)
{
// like in ns2 test, r2 -> r1, have a queue in packet mode
Ptr<PointToPointNetDevice> nd = StaticCast<PointToPointNetDevice> (devn2n3.Get (1));
Ptr<Queue> queue = nd->GetQueue ();
Ptr<QueueDisc> queue = queueDiscs.Get (1);
StaticCast<RedQueue> (queue)->SetMode (RedQueue::QUEUE_MODE_PACKETS);
StaticCast<RedQueue> (queue)->SetTh (5, 15);
StaticCast<RedQueue> (queue)->SetQueueLimit (25);
StaticCast<RedQueueDisc> (queue)->SetMode (Queue::QUEUE_MODE_PACKETS);
StaticCast<RedQueueDisc> (queue)->SetTh (5, 15);
StaticCast<RedQueueDisc> (queue)->SetQueueLimit (1000);
}
BuildAppsTest (redTest);
@@ -428,8 +442,7 @@ main (int argc, char *argv[])
remove (filePlotQueue.str ().c_str ());
remove (filePlotQueueAvg.str ().c_str ());
Ptr<PointToPointNetDevice> nd = StaticCast<PointToPointNetDevice> (devn2n3.Get (0));
Ptr<Queue> queue = nd->GetQueue ();
Ptr<QueueDisc> queue = queueDiscs.Get (0);
Simulator::ScheduleNow (&CheckQueueSize, queue);
}
@@ -446,15 +459,13 @@ main (int argc, char *argv[])
if (printRedStats)
{
Ptr<PointToPointNetDevice> nd = StaticCast<PointToPointNetDevice> (devn2n3.Get (0));
RedQueue::Stats st = StaticCast<RedQueue> (nd->GetQueue ())->GetStats ();
RedQueueDisc::Stats st = StaticCast<RedQueueDisc> (queueDiscs.Get (0))->GetStats ();
std::cout << "*** RED stats from Node 2 queue ***" << std::endl;
std::cout << "\t " << st.unforcedDrop << " drops due prob mark" << std::endl;
std::cout << "\t " << st.forcedDrop << " drops due hard mark" << std::endl;
std::cout << "\t " << st.qLimDrop << " drops due queue full" << std::endl;
nd = StaticCast<PointToPointNetDevice> (devn2n3.Get (1));
st = StaticCast<RedQueue> (nd->GetQueue ())->GetStats ();
st = StaticCast<RedQueueDisc> (queueDiscs.Get (1))->GetStats ();
std::cout << "*** RED stats from Node 3 queue ***" << std::endl;
std::cout << "\t " << st.unforcedDrop << " drops due prob mark" << std::endl;
std::cout << "\t " << st.forcedDrop << " drops due hard mark" << std::endl;

View File

@@ -2,6 +2,10 @@
def build(bld):
pass
# obj = bld.create_ns3_program('traffic-control-example', ['traffic-control'])
# obj.source = 'traffic-control-example.cc'
obj = bld.create_ns3_program('red-tests', ['point-to-point', 'internet', 'applications', 'flow-monitor', 'traffic-control'])
obj.source = 'red-tests.cc'
obj = bld.create_ns3_program('pfifo-vs-red', ['point-to-point', 'point-to-point-layout', 'internet', 'applications', 'traffic-control'])
obj.source = 'pfifo-vs-red.cc'