From 985f5594afd96c85ed3dfa142286b1191ff0d98f Mon Sep 17 00:00:00 2001 From: "Mohit P. Tahiliani" Date: Tue, 23 Feb 2016 22:23:46 +0530 Subject: [PATCH] reproduce-wns3-results --- scratch/burst0100.cc | 223 +++++++++++++++++++++++++++++ scratch/burst0200.cc | 220 +++++++++++++++++++++++++++++ scratch/burst100100.cc | 218 ++++++++++++++++++++++++++++ scratch/burst100200.cc | 218 ++++++++++++++++++++++++++++ scratch/pielight.cc | 213 ++++++++++++++++++++++++++++ scratch/piemix.cc | 251 +++++++++++++++++++++++++++++++++ scratch/piethrough.cc | 219 ++++++++++++++++++++++++++++ src/network/utils/pie-queue.cc | 68 ++++----- src/network/utils/pie-queue.h | 10 +- 9 files changed, 1595 insertions(+), 45 deletions(-) create mode 100755 scratch/burst0100.cc create mode 100755 scratch/burst0200.cc create mode 100755 scratch/burst100100.cc create mode 100755 scratch/burst100200.cc create mode 100755 scratch/pielight.cc create mode 100755 scratch/piemix.cc create mode 100755 scratch/piethrough.cc mode change 100644 => 100755 src/network/utils/pie-queue.cc mode change 100644 => 100755 src/network/utils/pie-queue.h diff --git a/scratch/burst0100.cc b/scratch/burst0100.cc new file mode 100755 index 0000000..21428c8 --- /dev/null +++ b/scratch/burst0100.cc @@ -0,0 +1,223 @@ +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-helper.h" +#include "ns3/point-to-point-module.h" +#include "ns3/applications-module.h" +#include +#include "ns3/internet-module.h" +#include "ns3/ipv6-static-routing-helper.h" +#include "ns3/ipv6-routing-table-entry.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-module.h" +#include "ns3/tcp-header.h" +#include + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("PieTests"); + + +std::stringstream filePlotQueueNoDrop; + +uint32_t i=0; + +void CheckCumulativeDrops (Ptr queue) +{ + uint32_t ndrop = StaticCast (queue)->GetDropCount (); + + // check queue size every 1/50 of a second + Simulator::Schedule (Seconds (0.001), &CheckCumulativeDrops, queue); + std::ofstream fPlotQueueNoDrop (filePlotQueueNoDrop.str ().c_str (), std::ios::out|std::ios::app); + fPlotQueueNoDrop << Simulator::Now ().GetSeconds () << " " << ndrop << std::endl; + fPlotQueueNoDrop.close (); + +} + + +int main (int argc, char *argv[]) +{ + +bool printPieStats=true; +bool isPcapEnabled=true; +std::string pathOut = "."; +bool writeForPlot=true; +std::string pcapFileName = "pcapFilePieQueue.pcap"; + + + + CommandLine cmd; + cmd.Parse(argc,argv); + +LogComponentEnable ("PieQueue", LOG_LEVEL_INFO); + +std::string bottleneckBandwidth = "10Mbps"; +std::string bottleneckDelay = "50ms"; + +std::string accessBandwidth ="50Mbps"; +std::string accessDelay = "5ms"; + +NodeContainer udpsource; +udpsource.Create(1); + +NodeContainer gateway; +gateway.Create (2); + +NodeContainer sink; +sink.Create(1); + + +// Create and configure access link and bottleneck link + PointToPointHelper accessLink; + accessLink.SetDeviceAttribute ("DataRate", StringValue (accessBandwidth)); + accessLink.SetChannelAttribute ("Delay", StringValue (accessDelay)); + accessLink.SetQueue ("ns3::DropTailQueue"); + + + PointToPointHelper bottleneckLink; + bottleneckLink.SetDeviceAttribute ("DataRate", StringValue (bottleneckBandwidth)); + bottleneckLink.SetChannelAttribute ("Delay", StringValue (bottleneckDelay)); + bottleneckLink.SetQueue ("ns3::PieQueue"); + + + Config::SetDefault ("ns3::PieQueue::MeanPktSize", UintegerValue (500)); + Config::SetDefault ("ns3::PieQueue::QueueLimit", UintegerValue (400)); + + // Config::SetDefault ("ns3::PieQueue::MeanPktSize", UintegerValue (1000)); + Config::SetDefault ("ns3::PieQueue::QueueDelayReference", TimeValue (Seconds(0.02))); + Config::SetDefault ("ns3::PieQueue::MaxBurstAllowance", TimeValue (Seconds(0))); + + InternetStackHelper stack; + stack.InstallAll (); + + Ipv4AddressHelper address; + address.SetBase ("10.0.0.0", "255.255.255.0"); + + // Configure the source and sink net devices + // and the channels between the source/sink and the gateway + Ipv4InterfaceContainer sink_Interfaces; + //Ipv4InterfaceContainer interfaces[5]; + Ipv4InterfaceContainer interfaces_sink; + Ipv4InterfaceContainer interfaces_gateway; + Ipv4InterfaceContainer udpinterfaces; + + + NetDeviceContainer udpdevices; + NetDeviceContainer devices_sink; + NetDeviceContainer devices_gateway; + + + + udpdevices = accessLink.Install (udpsource.Get (0), gateway.Get (0)); + address.NewNetwork(); + udpinterfaces=address.Assign(udpdevices); + + devices_gateway= bottleneckLink.Install (gateway.Get (0), gateway.Get (1)); + address.NewNetwork(); + interfaces_gateway = address.Assign (devices_gateway); + + devices_sink= accessLink.Install (gateway.Get (1), sink.Get (0)); + address.NewNetwork (); + interfaces_sink = address.Assign (devices_sink); + + sink_Interfaces.Add (interfaces_sink.Get (1)); + + NS_LOG_INFO ("Initialize Global Routing."); + Ipv4GlobalRoutingHelper::PopulateRoutingTables (); + + + uint16_t port = 50000; + + // Configure application + AddressValue remoteAddress1 (InetSocketAddress (sink_Interfaces.GetAddress (0, 0), port)); + // AddressValue remoteAddress1 (InetSocketAddress (sink_Interfaces.GetAddress (0, 0), port1)); + + OnOffHelper clientHelper6 ("ns3::UdpSocketFactory", Address ()); + clientHelper6.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); + clientHelper6.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); + clientHelper6.SetAttribute ("DataRate", DataRateValue (DataRate ("25Mbps"))); + clientHelper6.SetAttribute ("PacketSize", UintegerValue (500)); + + ApplicationContainer clientApps6; + // AddressValue remoteAddress1 (InetSocketAddress (udpinterfaces.GetAddress (0), port)); + clientHelper6.SetAttribute ("Remote", remoteAddress1); + clientApps6.Add (clientHelper6.Install (udpsource.Get (0))); + clientApps6.Start (Seconds (0.99)); + clientApps6.Stop (Seconds (1.1)); + + + + Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); + PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", sinkLocalAddress); + sinkHelper.SetAttribute ("Protocol", TypeIdValue (UdpSocketFactory::GetTypeId ())); + ApplicationContainer sinkApp = sinkHelper.Install (sink); + sinkApp.Start (Seconds (0)); + sinkApp.Stop (Seconds (1.1)); + + + + + + + if (writeForPlot) + { + + filePlotQueueNoDrop<< pathOut << "/" << "number of drop.plotme"; + remove (filePlotQueueNoDrop.str ().c_str ()); + + + Ptr nd = StaticCast (devices_gateway.Get (0)); + Ptr queue = nd->GetQueue (); + Simulator::ScheduleNow (&CheckCumulativeDrops, queue); + + } + + + if (isPcapEnabled) + { + bottleneckLink.EnablePcap (pcapFileName,gateway,false); + } + + + FlowMonitorHelper flowmon; + Ptr allMon ; + allMon= flowmon.InstallAll(); + + + flowmon.SerializeToXmlFile("PieQueue.xml", true, true); + + Simulator::Stop (Seconds (1.5)); + Simulator::Run (); + + if (printPieStats) + { + Ptr nd1 = StaticCast (devices_gateway.Get (0)); + PieQueue::Stats st1 = StaticCast (nd1->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st1.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st1.forcedDrop << " drops due queue full" << std::endl; + + + Ptr nd2 = StaticCast (devices_gateway.Get (1)); + PieQueue::Stats st2 = StaticCast (nd2->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st2.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st2.forcedDrop << " drops due queue full" << std::endl; + + } + + Simulator::Destroy (); + return 0; + +} + + + + + + + + + + + diff --git a/scratch/burst0200.cc b/scratch/burst0200.cc new file mode 100755 index 0000000..b87725e --- /dev/null +++ b/scratch/burst0200.cc @@ -0,0 +1,220 @@ +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-helper.h" +#include "ns3/point-to-point-module.h" +#include "ns3/applications-module.h" +#include +#include "ns3/internet-module.h" +#include "ns3/ipv6-static-routing-helper.h" +#include "ns3/ipv6-routing-table-entry.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-module.h" +#include "ns3/tcp-header.h" +#include + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("PieTests"); +std::stringstream filePlotQueueNoDrop; + +uint32_t i=0; + +void CheckCumulativeDrops (Ptr queue) +{ + uint32_t ndrop = StaticCast (queue)->GetDropCount (); + + // check queue size every 1/50 of a second + Simulator::Schedule (Seconds (0.001), &CheckCumulativeDrops, queue); + std::ofstream fPlotQueueNoDrop (filePlotQueueNoDrop.str ().c_str (), std::ios::out|std::ios::app); + fPlotQueueNoDrop << Simulator::Now ().GetSeconds () << " " << ndrop << std::endl; + fPlotQueueNoDrop.close (); + +} + + +int main (int argc, char *argv[]) +{ + +bool printPieStats=true; +bool isPcapEnabled=true; +std::string pathOut = "."; +bool writeForPlot=true; +std::string pcapFileName = "pcapFilePieQueue.pcap"; + + + + CommandLine cmd; + cmd.Parse(argc,argv); + +LogComponentEnable ("PieQueue", LOG_LEVEL_INFO); + +std::string bottleneckBandwidth = "10Mbps"; +std::string bottleneckDelay = "50ms"; + +std::string accessBandwidth ="50Mbps"; +std::string accessDelay = "5ms"; + +NodeContainer udpsource; +udpsource.Create(1); + +NodeContainer gateway; +gateway.Create (2); + +NodeContainer sink; +sink.Create(1); + + +// Create and configure access link and bottleneck link + PointToPointHelper accessLink; + accessLink.SetDeviceAttribute ("DataRate", StringValue (accessBandwidth)); + accessLink.SetChannelAttribute ("Delay", StringValue (accessDelay)); + accessLink.SetQueue ("ns3::DropTailQueue"); + + + PointToPointHelper bottleneckLink; + bottleneckLink.SetDeviceAttribute ("DataRate", StringValue (bottleneckBandwidth)); + bottleneckLink.SetChannelAttribute ("Delay", StringValue (bottleneckDelay)); + bottleneckLink.SetQueue ("ns3::PieQueue"); + + + Config::SetDefault ("ns3::PieQueue::MeanPktSize", UintegerValue (500)); + Config::SetDefault ("ns3::PieQueue::QueueLimit", UintegerValue (400)); + + // Config::SetDefault ("ns3::PieQueue::MeanPktSize", UintegerValue (1000)); + Config::SetDefault ("ns3::PieQueue::QueueDelayReference", TimeValue (Seconds(0.02))); + Config::SetDefault ("ns3::PieQueue::MaxBurstAllowance", TimeValue (Seconds(0))); + + InternetStackHelper stack; + stack.InstallAll (); + + Ipv4AddressHelper address; + address.SetBase ("10.0.0.0", "255.255.255.0"); + + // Configure the source and sink net devices + // and the channels between the source/sink and the gateway + Ipv4InterfaceContainer sink_Interfaces; + Ipv4InterfaceContainer interfaces_sink; + Ipv4InterfaceContainer interfaces_gateway; + Ipv4InterfaceContainer udpinterfaces; + + + NetDeviceContainer udpdevices; + NetDeviceContainer devices_sink; + NetDeviceContainer devices_gateway; + + + + udpdevices = accessLink.Install (udpsource.Get (0), gateway.Get (0)); + address.NewNetwork(); + udpinterfaces=address.Assign(udpdevices); + + devices_gateway= bottleneckLink.Install (gateway.Get (0), gateway.Get (1)); + address.NewNetwork(); + interfaces_gateway = address.Assign (devices_gateway); + + devices_sink= accessLink.Install (gateway.Get (1), sink.Get (0)); + address.NewNetwork (); + interfaces_sink = address.Assign (devices_sink); + + sink_Interfaces.Add (interfaces_sink.Get (1)); + + NS_LOG_INFO ("Initialize Global Routing."); + Ipv4GlobalRoutingHelper::PopulateRoutingTables (); + + + uint16_t port = 50000; + + // Configure application + AddressValue remoteAddress1 (InetSocketAddress (sink_Interfaces.GetAddress (0, 0), port)); + // AddressValue remoteAddress1 (InetSocketAddress (sink_Interfaces.GetAddress (0, 0), port1)); + + OnOffHelper clientHelper6 ("ns3::UdpSocketFactory", Address ()); + clientHelper6.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); + clientHelper6.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); + clientHelper6.SetAttribute ("DataRate", DataRateValue (DataRate ("25Mbps"))); + clientHelper6.SetAttribute ("PacketSize", UintegerValue (500)); + + ApplicationContainer clientApps6; + // AddressValue remoteAddress1 (InetSocketAddress (udpinterfaces.GetAddress (0), port)); + clientHelper6.SetAttribute ("Remote", remoteAddress1); + clientApps6.Add (clientHelper6.Install (udpsource.Get (0))); + clientApps6.Start (Seconds (0.99)); + clientApps6.Stop (Seconds (1.2)); + + + + Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); + PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", sinkLocalAddress); + sinkHelper.SetAttribute ("Protocol", TypeIdValue (UdpSocketFactory::GetTypeId ())); + ApplicationContainer sinkApp = sinkHelper.Install (sink); + sinkApp.Start (Seconds (0)); + sinkApp.Stop (Seconds (1.2)); + + + + + + + if (writeForPlot) + { + + filePlotQueueNoDrop<< pathOut << "/" << "number of drop.plotme"; + remove (filePlotQueueNoDrop.str ().c_str ()); + + + Ptr nd = StaticCast (devices_gateway.Get (0)); + Ptr queue = nd->GetQueue (); + Simulator::ScheduleNow (&CheckCumulativeDrops, queue); + + } + + + if (isPcapEnabled) + { + bottleneckLink.EnablePcap (pcapFileName,gateway,false); + } + + + FlowMonitorHelper flowmon; + Ptr allMon ; + allMon= flowmon.InstallAll(); + + + flowmon.SerializeToXmlFile("PieQueue.xml", true, true); + + Simulator::Stop (Seconds (1.5)); + Simulator::Run (); + + if (printPieStats) + { + Ptr nd1 = StaticCast (devices_gateway.Get (0)); + PieQueue::Stats st1 = StaticCast (nd1->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st1.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st1.forcedDrop << " drops due queue full" << std::endl; + + + Ptr nd2 = StaticCast (devices_gateway.Get (1)); + PieQueue::Stats st2 = StaticCast (nd2->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st2.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st2.forcedDrop << " drops due queue full" << std::endl; + + } + + Simulator::Destroy (); + return 0; + +} + + + + + + + + + + + diff --git a/scratch/burst100100.cc b/scratch/burst100100.cc new file mode 100755 index 0000000..e8a97fe --- /dev/null +++ b/scratch/burst100100.cc @@ -0,0 +1,218 @@ +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-helper.h" +#include "ns3/point-to-point-module.h" +#include "ns3/applications-module.h" +#include +#include "ns3/internet-module.h" +#include "ns3/ipv6-static-routing-helper.h" +#include "ns3/ipv6-routing-table-entry.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-module.h" +#include "ns3/tcp-header.h" +#include + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("PieTests"); +std::stringstream filePlotQueueNoDrop; + +uint32_t i=0; + +void CheckCumulativeDrops (Ptr queue) +{ + uint32_t ndrop = StaticCast (queue)->GetDropCount (); + + // check queue size every 1/50 of a second + Simulator::Schedule (Seconds (0.001), &CheckCumulativeDrops, queue); + std::ofstream fPlotQueueNoDrop (filePlotQueueNoDrop.str ().c_str (), std::ios::out|std::ios::app); + fPlotQueueNoDrop << Simulator::Now ().GetSeconds () << " " << ndrop << std::endl; + fPlotQueueNoDrop.close (); + +} + + +int main (int argc, char *argv[]) +{ + +bool printPieStats=true; +bool isPcapEnabled=true; +std::string pathOut = "."; +bool writeForPlot=true; +std::string pcapFileName = "pcapFilePieQueue.pcap"; + + + + CommandLine cmd; + cmd.Parse(argc,argv); + +LogComponentEnable ("PieQueue", LOG_LEVEL_INFO); + +std::string bottleneckBandwidth = "10Mbps"; +std::string bottleneckDelay = "50ms"; + +std::string accessBandwidth ="50Mbps"; +std::string accessDelay = "5ms"; + +NodeContainer udpsource; +udpsource.Create(1); + +NodeContainer gateway; +gateway.Create (2); + +NodeContainer sink; +sink.Create(1); + + +// Create and configure access link and bottleneck link + PointToPointHelper accessLink; + accessLink.SetDeviceAttribute ("DataRate", StringValue (accessBandwidth)); + accessLink.SetChannelAttribute ("Delay", StringValue (accessDelay)); + accessLink.SetQueue ("ns3::DropTailQueue"); + + + PointToPointHelper bottleneckLink; + bottleneckLink.SetDeviceAttribute ("DataRate", StringValue (bottleneckBandwidth)); + bottleneckLink.SetChannelAttribute ("Delay", StringValue (bottleneckDelay)); + bottleneckLink.SetQueue ("ns3::PieQueue"); + + + Config::SetDefault ("ns3::PieQueue::MeanPktSize", UintegerValue (500)); + Config::SetDefault ("ns3::PieQueue::QueueLimit", UintegerValue (400)); + Config::SetDefault ("ns3::PieQueue::QueueDelayReference", TimeValue (Seconds(0.02))); + Config::SetDefault ("ns3::PieQueue::MaxBurstAllowance", TimeValue (Seconds(0.1))); + + InternetStackHelper stack; + stack.InstallAll (); + + Ipv4AddressHelper address; + address.SetBase ("10.0.0.0", "255.255.255.0"); + + // Configure the source and sink net devices + // and the channels between the source/sink and the gateway + Ipv4InterfaceContainer sink_Interfaces; + Ipv4InterfaceContainer interfaces_sink; + Ipv4InterfaceContainer interfaces_gateway; + Ipv4InterfaceContainer udpinterfaces; + + + NetDeviceContainer udpdevices; + NetDeviceContainer devices_sink; + NetDeviceContainer devices_gateway; + + + + udpdevices = accessLink.Install (udpsource.Get (0), gateway.Get (0)); + address.NewNetwork(); + udpinterfaces=address.Assign(udpdevices); + + devices_gateway= bottleneckLink.Install (gateway.Get (0), gateway.Get (1)); + address.NewNetwork(); + interfaces_gateway = address.Assign (devices_gateway); + + devices_sink= accessLink.Install (gateway.Get (1), sink.Get (0)); + address.NewNetwork (); + interfaces_sink = address.Assign (devices_sink); + + sink_Interfaces.Add (interfaces_sink.Get (1)); + + NS_LOG_INFO ("Initialize Global Routing."); + Ipv4GlobalRoutingHelper::PopulateRoutingTables (); + + + uint16_t port = 50000; + + // Configure application + AddressValue remoteAddress1 (InetSocketAddress (sink_Interfaces.GetAddress (0, 0), port)); + // AddressValue remoteAddress1 (InetSocketAddress (sink_Interfaces.GetAddress (0, 0), port1)); + + OnOffHelper clientHelper6 ("ns3::UdpSocketFactory", Address ()); + clientHelper6.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); + clientHelper6.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); + clientHelper6.SetAttribute ("DataRate", DataRateValue (DataRate ("25Mbps"))); + clientHelper6.SetAttribute ("PacketSize", UintegerValue (500)); + + ApplicationContainer clientApps6; + // AddressValue remoteAddress1 (InetSocketAddress (udpinterfaces.GetAddress (0), port)); + clientHelper6.SetAttribute ("Remote", remoteAddress1); + clientApps6.Add (clientHelper6.Install (udpsource.Get (0))); + clientApps6.Start (Seconds (1.0)); + clientApps6.Stop (Seconds (1.1)); + + + + Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); + PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", sinkLocalAddress); + sinkHelper.SetAttribute ("Protocol", TypeIdValue (UdpSocketFactory::GetTypeId ())); + ApplicationContainer sinkApp = sinkHelper.Install (sink); + sinkApp.Start (Seconds (0)); + sinkApp.Stop (Seconds (1.1)); + + + + + + + if (writeForPlot) + { + + filePlotQueueNoDrop<< pathOut << "/" << "number of drop.plotme"; + remove (filePlotQueueNoDrop.str ().c_str ()); + + + Ptr nd = StaticCast (devices_gateway.Get (0)); + Ptr queue = nd->GetQueue (); + Simulator::ScheduleNow (&CheckCumulativeDrops, queue); + + } + + + if (isPcapEnabled) + { + bottleneckLink.EnablePcap (pcapFileName,gateway,false); + } + + + FlowMonitorHelper flowmon; + Ptr allMon ; + allMon= flowmon.InstallAll(); + + + flowmon.SerializeToXmlFile("PieQueue.xml", true, true); + + Simulator::Stop (Seconds (1.1)); + Simulator::Run (); + + if (printPieStats) + { + Ptr nd1 = StaticCast (devices_gateway.Get (0)); + PieQueue::Stats st1 = StaticCast (nd1->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st1.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st1.forcedDrop << " drops due queue full" << std::endl; + + + Ptr nd2 = StaticCast (devices_gateway.Get (1)); + PieQueue::Stats st2 = StaticCast (nd2->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st2.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st2.forcedDrop << " drops due queue full" << std::endl; + + } + + Simulator::Destroy (); + return 0; + +} + + + + + + + + + + + diff --git a/scratch/burst100200.cc b/scratch/burst100200.cc new file mode 100755 index 0000000..52f5c4e --- /dev/null +++ b/scratch/burst100200.cc @@ -0,0 +1,218 @@ +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-helper.h" +#include "ns3/point-to-point-module.h" +#include "ns3/applications-module.h" +#include +#include "ns3/internet-module.h" +#include "ns3/ipv6-static-routing-helper.h" +#include "ns3/ipv6-routing-table-entry.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-module.h" +#include "ns3/tcp-header.h" +#include + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("PieTests"); +std::stringstream filePlotQueueNoDrop; + +uint32_t i=0; + +void CheckCumulativeDrops (Ptr queue) +{ + uint32_t ndrop = StaticCast (queue)->GetDropCount (); + + // check queue size every 1/50 of a second + Simulator::Schedule (Seconds (0.001), &CheckCumulativeDrops, queue); + std::ofstream fPlotQueueNoDrop (filePlotQueueNoDrop.str ().c_str (), std::ios::out|std::ios::app); + fPlotQueueNoDrop << Simulator::Now ().GetSeconds () << " " << ndrop << std::endl; + fPlotQueueNoDrop.close (); + +} + + +int main (int argc, char *argv[]) +{ + +bool printPieStats=true; +bool isPcapEnabled=true; +std::string pathOut = "."; +bool writeForPlot=true; +std::string pcapFileName = "pcapFilePieQueue.pcap"; + + + + CommandLine cmd; + cmd.Parse(argc,argv); + +LogComponentEnable ("PieQueue", LOG_LEVEL_INFO); + +std::string bottleneckBandwidth = "10Mbps"; +std::string bottleneckDelay = "50ms"; + +std::string accessBandwidth ="50Mbps"; +std::string accessDelay = "5ms"; + +NodeContainer udpsource; +udpsource.Create(1); + +NodeContainer gateway; +gateway.Create (2); + +NodeContainer sink; +sink.Create(1); + + +// Create and configure access link and bottleneck link + PointToPointHelper accessLink; + accessLink.SetDeviceAttribute ("DataRate", StringValue (accessBandwidth)); + accessLink.SetChannelAttribute ("Delay", StringValue (accessDelay)); + accessLink.SetQueue ("ns3::DropTailQueue"); + + + PointToPointHelper bottleneckLink; + bottleneckLink.SetDeviceAttribute ("DataRate", StringValue (bottleneckBandwidth)); + bottleneckLink.SetChannelAttribute ("Delay", StringValue (bottleneckDelay)); + bottleneckLink.SetQueue ("ns3::PieQueue"); + + + Config::SetDefault ("ns3::PieQueue::MeanPktSize", UintegerValue (500)); + Config::SetDefault ("ns3::PieQueue::QueueLimit", UintegerValue (400)); + Config::SetDefault ("ns3::PieQueue::QueueDelayReference", TimeValue (Seconds(0.02))); + Config::SetDefault ("ns3::PieQueue::MaxBurstAllowance", TimeValue (Seconds(0.1))); + + InternetStackHelper stack; + stack.InstallAll (); + + Ipv4AddressHelper address; + address.SetBase ("10.0.0.0", "255.255.255.0"); + + // Configure the source and sink net devices + // and the channels between the source/sink and the gateway + Ipv4InterfaceContainer sink_Interfaces; + Ipv4InterfaceContainer interfaces_sink; + Ipv4InterfaceContainer interfaces_gateway; + Ipv4InterfaceContainer udpinterfaces; + + + NetDeviceContainer udpdevices; + NetDeviceContainer devices_sink; + NetDeviceContainer devices_gateway; + + + + udpdevices = accessLink.Install (udpsource.Get (0), gateway.Get (0)); + address.NewNetwork(); + udpinterfaces=address.Assign(udpdevices); + + devices_gateway= bottleneckLink.Install (gateway.Get (0), gateway.Get (1)); + address.NewNetwork(); + interfaces_gateway = address.Assign (devices_gateway); + + devices_sink= accessLink.Install (gateway.Get (1), sink.Get (0)); + address.NewNetwork (); + interfaces_sink = address.Assign (devices_sink); + + sink_Interfaces.Add (interfaces_sink.Get (1)); + + NS_LOG_INFO ("Initialize Global Routing."); + Ipv4GlobalRoutingHelper::PopulateRoutingTables (); + + + uint16_t port = 50000; + + // Configure application + AddressValue remoteAddress1 (InetSocketAddress (sink_Interfaces.GetAddress (0, 0), port)); + + + OnOffHelper clientHelper6 ("ns3::UdpSocketFactory", Address ()); + clientHelper6.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); + clientHelper6.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); + clientHelper6.SetAttribute ("DataRate", DataRateValue (DataRate ("25Mbps"))); + clientHelper6.SetAttribute ("PacketSize", UintegerValue (500)); + + ApplicationContainer clientApps6; + + clientHelper6.SetAttribute ("Remote", remoteAddress1); + clientApps6.Add (clientHelper6.Install (udpsource.Get (0))); + clientApps6.Start (Seconds (1.0)); + clientApps6.Stop (Seconds (1.2)); + + + + Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); + PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", sinkLocalAddress); + sinkHelper.SetAttribute ("Protocol", TypeIdValue (UdpSocketFactory::GetTypeId ())); + ApplicationContainer sinkApp = sinkHelper.Install (sink); + sinkApp.Start (Seconds (0)); + sinkApp.Stop (Seconds (1.2)); + + + + + + + if (writeForPlot) + { + + filePlotQueueNoDrop<< pathOut << "/" << "number of drop.plotme"; + remove (filePlotQueueNoDrop.str ().c_str ()); + + + Ptr nd = StaticCast (devices_gateway.Get (0)); + Ptr queue = nd->GetQueue (); + Simulator::ScheduleNow (&CheckCumulativeDrops, queue); + + } + + + if (isPcapEnabled) + { + bottleneckLink.EnablePcap (pcapFileName,gateway,false); + } + + + FlowMonitorHelper flowmon; + Ptr allMon ; + allMon= flowmon.InstallAll(); + + + flowmon.SerializeToXmlFile("PieQueue.xml", true, true); + + Simulator::Stop (Seconds (1.5)); + Simulator::Run (); + + if (printPieStats) + { + Ptr nd1 = StaticCast (devices_gateway.Get (0)); + PieQueue::Stats st1 = StaticCast (nd1->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st1.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st1.forcedDrop << " drops due queue full" << std::endl; + + + Ptr nd2 = StaticCast (devices_gateway.Get (1)); + PieQueue::Stats st2 = StaticCast (nd2->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st2.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st2.forcedDrop << " drops due queue full" << std::endl; + + } + + Simulator::Destroy (); + return 0; + +} + + + + + + + + + + + diff --git a/scratch/pielight.cc b/scratch/pielight.cc new file mode 100755 index 0000000..d7c10d5 --- /dev/null +++ b/scratch/pielight.cc @@ -0,0 +1,213 @@ +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-helper.h" +#include "ns3/point-to-point-module.h" +#include "ns3/applications-module.h" +#include +#include "ns3/internet-module.h" +#include "ns3/ipv6-static-routing-helper.h" +#include "ns3/ipv6-routing-table-entry.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-module.h" +#include "ns3/tcp-header.h" +#include + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("PieTests"); + +std::stringstream filePlotQueueDel; +uint32_t i=0; + + +void CheckQueueDel (Ptr queue) +{ + double qDel = StaticCast (queue)->GetQueueDelay ().GetSeconds(); + // check queue size every 1/50 of a second + Simulator::Schedule (Seconds (0.01), &CheckQueueDel, queue); + std::ofstream fPlotQueueDel (filePlotQueueDel.str ().c_str (), std::ios::out|std::ios::app); + fPlotQueueDel << Simulator::Now ().GetSeconds () << " " << (qDel*1000) << std::endl; + fPlotQueueDel.close (); +} + +int main (int argc, char *argv[]) +{ + +bool printPieStats=true; +bool isPcapEnabled=true; +float startTime = 0.0; +float simDuration = 100; //in seconds +std::string pathOut = "."; +bool writeForPlot=true; +std::string pcapFileName = "pcapFilePieQueue.pcap"; + +float stopTime = startTime + simDuration; + + CommandLine cmd; + cmd.Parse(argc,argv); + +LogComponentEnable ("PieQueue", LOG_LEVEL_INFO); + +std::string bottleneckBandwidth = "10Mbps"; +std::string bottleneckDelay = "50ms"; + +std::string accessBandwidth ="10Mbps"; +std::string accessDelay = "5ms"; + + +NodeContainer source; +source.Create(5); + +NodeContainer gateway; +gateway.Create (2); + +NodeContainer sink; +sink.Create(1); + + +// Create and configure access link and bottleneck link + PointToPointHelper accessLink; + accessLink.SetDeviceAttribute ("DataRate", StringValue (accessBandwidth)); + accessLink.SetChannelAttribute ("Delay", StringValue (accessDelay)); + accessLink.SetQueue ("ns3::DropTailQueue"); + + + PointToPointHelper bottleneckLink; + bottleneckLink.SetDeviceAttribute ("DataRate", StringValue (bottleneckBandwidth)); + bottleneckLink.SetChannelAttribute ("Delay", StringValue (bottleneckDelay)); + bottleneckLink.SetQueue ("ns3::PieQueue"); + + + Config::SetDefault ("ns3::PieQueue::MeanPktSize", UintegerValue (1000)); + Config::SetDefault ("ns3::PieQueue::QueueDelayReference", TimeValue (Seconds(0.02))); + + + InternetStackHelper stack; + stack.InstallAll (); + + Ipv4AddressHelper address; + address.SetBase ("10.0.0.0", "255.255.255.0"); + + // Configure the source and sink net devices + // and the channels between the source/sink and the gateway + Ipv4InterfaceContainer sink_Interfaces; + Ipv4InterfaceContainer interfaces[5]; + Ipv4InterfaceContainer interfaces_sink; + Ipv4InterfaceContainer interfaces_gateway; + + NetDeviceContainer devices[5]; + NetDeviceContainer devices_sink; + NetDeviceContainer devices_gateway; + + + +for(i=0;i<5;i++) +{ + devices[i] = accessLink.Install (source.Get (i), gateway.Get (0)); + address.NewNetwork (); + interfaces[i]=address.Assign(devices[i]); +} + + + devices_gateway= bottleneckLink.Install (gateway.Get (0), gateway.Get (1)); + address.NewNetwork(); + interfaces_gateway = address.Assign (devices_gateway); + + devices_sink= accessLink.Install (gateway.Get (1), sink.Get (0)); + address.NewNetwork (); + interfaces_sink = address.Assign (devices_sink); + + sink_Interfaces.Add (interfaces_sink.Get (1)); + + NS_LOG_INFO ("Initialize Global Routing."); + Ipv4GlobalRoutingHelper::PopulateRoutingTables (); + + + uint16_t port = 50000; + Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); + PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress); + + // Configure application + AddressValue remoteAddress (InetSocketAddress (sink_Interfaces.GetAddress (0, 0), port)); + for (uint16_t i = 0; i < source.GetN (); i++) + { + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); + BulkSendHelper ftp ("ns3::TcpSocketFactory", Address ()); + ftp.SetAttribute ("Remote", remoteAddress); + ftp.SetAttribute ("SendSize", UintegerValue (1000)); + + + ApplicationContainer sourceApp = ftp.Install (source.Get (i)); + sourceApp.Start (Seconds (0)); + sourceApp.Stop (Seconds (stopTime - 1)); + + sinkHelper.SetAttribute ("Protocol", TypeIdValue (TcpSocketFactory::GetTypeId ())); + ApplicationContainer sinkApp = sinkHelper.Install (sink); + sinkApp.Start (Seconds (0)); + sinkApp.Stop (Seconds (stopTime)); + + } + + + + + if (writeForPlot) + { + + filePlotQueueDel << pathOut << "/" << "delaylight.plotme"; + remove (filePlotQueueDel.str ().c_str ()); + + Ptr nd = StaticCast (devices_gateway.Get (0)); + Ptr queue = nd->GetQueue (); + Simulator::ScheduleNow (&CheckQueueDel, queue); + + } + + + if (isPcapEnabled) + { + bottleneckLink.EnablePcap (pcapFileName,gateway,false); + } + + + FlowMonitorHelper flowmon; + Ptr allMon ; + allMon= flowmon.InstallAll(); + flowmon.SerializeToXmlFile("PieQueue.xml", true, true); + + Simulator::Stop (Seconds (stopTime)); + Simulator::Run (); + + if (printPieStats) + { + Ptr nd1 = StaticCast (devices_gateway.Get (0)); + PieQueue::Stats st1 = StaticCast (nd1->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st1.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st1.forcedDrop << " drops due queue full" << std::endl; + + + Ptr nd2 = StaticCast (devices_gateway.Get (1)); + PieQueue::Stats st2 = StaticCast (nd2->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st2.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st2.forcedDrop << " drops due queue full" << std::endl; + + } + + Simulator::Destroy (); + return 0; + +} + + + + + + + + + + + diff --git a/scratch/piemix.cc b/scratch/piemix.cc new file mode 100755 index 0000000..283ca9d --- /dev/null +++ b/scratch/piemix.cc @@ -0,0 +1,251 @@ +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-helper.h" +#include "ns3/point-to-point-module.h" +#include "ns3/applications-module.h" +#include +#include "ns3/internet-module.h" +#include "ns3/ipv6-static-routing-helper.h" +#include "ns3/ipv6-routing-table-entry.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-module.h" +#include "ns3/tcp-header.h" +#include + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("PieTests"); + +std::stringstream filePlotQueueDel; +uint32_t i=0; + + +void CheckQueueDel (Ptr queue) +{ + double qDel = StaticCast (queue)->GetQueueDelay ().GetSeconds(); + // check queue size every 1/50 of a second + Simulator::Schedule (Seconds (0.05), &CheckQueueDel, queue); + std::ofstream fPlotQueueDel (filePlotQueueDel.str ().c_str (), std::ios::out|std::ios::app); + fPlotQueueDel << Simulator::Now ().GetSeconds () << " " << (qDel*1000) << std::endl; + fPlotQueueDel.close (); +} + +int main (int argc, char *argv[]) +{ + +bool printPieStats=true; +bool isPcapEnabled=true; +float startTime = 0.0; +float simDuration = 100; //in seconds +std::string pathOut = "."; +bool writeForPlot=true; +std::string pcapFileName = "pcapFilePieQueue.pcap"; + +float stopTime = startTime + simDuration; + + CommandLine cmd; + cmd.Parse(argc,argv); + +LogComponentEnable ("PieQueue", LOG_LEVEL_INFO); + +std::string bottleneckBandwidth = "10Mbps"; +std::string bottleneckDelay = "50ms"; + +std::string accessBandwidth ="10Mbps"; +std::string accessDelay = "5ms"; + + +NodeContainer source; +source.Create(5); + +NodeContainer udpsource; +udpsource.Create(2); + +NodeContainer gateway; +gateway.Create (2); + +NodeContainer sink; +sink.Create(1); + + +// Create and configure access link and bottleneck link + PointToPointHelper accessLink; + accessLink.SetDeviceAttribute ("DataRate", StringValue (accessBandwidth)); + accessLink.SetChannelAttribute ("Delay", StringValue (accessDelay)); + accessLink.SetQueue ("ns3::DropTailQueue"); + + + PointToPointHelper bottleneckLink; + bottleneckLink.SetDeviceAttribute ("DataRate", StringValue (bottleneckBandwidth)); + bottleneckLink.SetChannelAttribute ("Delay", StringValue (bottleneckDelay)); + bottleneckLink.SetQueue ("ns3::PieQueue"); + + + Config::SetDefault ("ns3::PieQueue::MeanPktSize", UintegerValue (1000)); + Config::SetDefault ("ns3::PieQueue::QueueDelayReference", TimeValue (Seconds(0.02))); + + + InternetStackHelper stack; + stack.InstallAll (); + + Ipv4AddressHelper address; + address.SetBase ("10.0.0.0", "255.255.255.0"); + + // Configure the source and sink net devices + // and the channels between the source/sink and the gateway + Ipv4InterfaceContainer sink_Interfaces; + Ipv4InterfaceContainer interfaces[5]; + Ipv4InterfaceContainer interfaces_sink; + Ipv4InterfaceContainer interfaces_gateway; + Ipv4InterfaceContainer udpinterfaces[2]; + + NetDeviceContainer devices[5]; + NetDeviceContainer udpdevices[2]; + NetDeviceContainer devices_sink; + NetDeviceContainer devices_gateway; + + + + +for(i=0;i<5;i++) +{ + devices[i] = accessLink.Install (source.Get (i), gateway.Get (0)); + address.NewNetwork (); + interfaces[i]=address.Assign(devices[i]); +} + + for(i=0;i<2;i++) +{ + udpdevices[i] = accessLink.Install (udpsource.Get (i), gateway.Get (0)); + address.NewNetwork(); + udpinterfaces[i]=address.Assign(udpdevices[i]); +} + devices_gateway= bottleneckLink.Install (gateway.Get (0), gateway.Get (1)); + address.NewNetwork(); + interfaces_gateway = address.Assign (devices_gateway); + + devices_sink= accessLink.Install (gateway.Get (1), sink.Get (0)); + address.NewNetwork (); + interfaces_sink = address.Assign (devices_sink); + + sink_Interfaces.Add (interfaces_sink.Get (1)); + + NS_LOG_INFO ("Initialize Global Routing."); + Ipv4GlobalRoutingHelper::PopulateRoutingTables (); + + + uint16_t port = 50000; + uint16_t port1 = 50001; + Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); + PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress); + + // Configure application + AddressValue remoteAddress (InetSocketAddress (sink_Interfaces.GetAddress (0, 0), port)); + AddressValue remoteAddress1 (InetSocketAddress (sink_Interfaces.GetAddress (0, 0), port1)); + for (uint16_t i = 0; i < source.GetN (); i++) + { + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); + BulkSendHelper ftp ("ns3::TcpSocketFactory", Address ()); + ftp.SetAttribute ("Remote", remoteAddress); + ftp.SetAttribute ("SendSize", UintegerValue (1000)); + + + ApplicationContainer sourceApp = ftp.Install (source.Get (i)); + sourceApp.Start (Seconds (0)); + sourceApp.Stop (Seconds (stopTime - 1)); + + sinkHelper.SetAttribute ("Protocol", TypeIdValue (TcpSocketFactory::GetTypeId ())); + ApplicationContainer sinkApp = sinkHelper.Install (sink); + sinkApp.Start (Seconds (0)); + sinkApp.Stop (Seconds (stopTime)); + + } + OnOffHelper clientHelper6 ("ns3::UdpSocketFactory", Address ()); + clientHelper6.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); + clientHelper6.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); + clientHelper6.SetAttribute ("DataRate", DataRateValue (DataRate ("10Mb/s"))); + clientHelper6.SetAttribute ("PacketSize", UintegerValue (1000)); + + ApplicationContainer clientApps6; + + clientHelper6.SetAttribute ("Remote", remoteAddress1); + clientApps6.Add (clientHelper6.Install (udpsource.Get (0))); + clientApps6.Start (Seconds (0)); + clientApps6.Stop (Seconds (stopTime-1)); + + OnOffHelper clientHelper7 ("ns3::UdpSocketFactory", Address ()); + clientHelper7.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); + clientHelper7.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); + clientHelper7.SetAttribute ("DataRate", DataRateValue (DataRate ("10Mb/s"))); + clientHelper7.SetAttribute ("PacketSize", UintegerValue (1000)); + + ApplicationContainer clientApps7; + clientHelper7.SetAttribute ("Remote", remoteAddress1); + clientApps7.Add (clientHelper7.Install (udpsource.Get (1))); + clientApps7.Start (Seconds (0)); + clientApps7.Stop (Seconds (stopTime-1)); + + + + + if (writeForPlot) + { + filePlotQueueDel << pathOut << "/" << "delaymix.plotme"; + remove (filePlotQueueDel.str ().c_str ()); + + Ptr nd = StaticCast (devices_gateway.Get (0)); + Ptr queue = nd->GetQueue (); + Simulator::ScheduleNow (&CheckQueueDel, queue); + + } + + + if (isPcapEnabled) + { + bottleneckLink.EnablePcap (pcapFileName,gateway,false); + } + + + FlowMonitorHelper flowmon; + Ptr allMon ; + allMon= flowmon.InstallAll(); + + + flowmon.SerializeToXmlFile("PieQueue.xml", true, true); + + Simulator::Stop (Seconds (stopTime)); + Simulator::Run (); + + if (printPieStats) + { + Ptr nd1 = StaticCast (devices_gateway.Get (0)); + PieQueue::Stats st1 = StaticCast (nd1->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st1.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st1.forcedDrop << " drops due queue full" << std::endl; + + + Ptr nd2 = StaticCast (devices_gateway.Get (1)); + PieQueue::Stats st2 = StaticCast (nd2->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st2.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st2.forcedDrop << " drops due queue full" << std::endl; + + } + + Simulator::Destroy (); + return 0; + +} + + + + + + + + + + + diff --git a/scratch/piethrough.cc b/scratch/piethrough.cc new file mode 100755 index 0000000..661ddb4 --- /dev/null +++ b/scratch/piethrough.cc @@ -0,0 +1,219 @@ +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-helper.h" +#include "ns3/point-to-point-module.h" +#include "ns3/applications-module.h" +#include +#include "ns3/internet-module.h" +#include "ns3/ipv6-static-routing-helper.h" +#include "ns3/ipv6-routing-table-entry.h" +#include "ns3/internet-module.h" +#include "ns3/flow-monitor-module.h" +#include "ns3/tcp-header.h" +#include + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("PieTests"); +std::stringstream filePlotQueueDel; + +uint32_t i=0; + + +void CheckQueueDel (Ptr queue) +{ + double qDel = StaticCast (queue)->GetQueueDelay ().GetSeconds(); + // check queue size every 1/50 of a second + Simulator::Schedule (Seconds (0.05), &CheckQueueDel, queue); + std::ofstream fPlotQueueDel (filePlotQueueDel.str ().c_str (), std::ios::out|std::ios::app); + fPlotQueueDel << Simulator::Now ().GetSeconds () << " " << (qDel*1000) << std::endl; + fPlotQueueDel.close (); +} + + +int main (int argc, char *argv[]) +{ + +bool printPieStats=true; +bool isPcapEnabled=true; +float startTime = 0.0; +float simDuration = 100; //in seconds +std::string pathOut = "."; +bool writeForPlot=true; +std::string pcapFileName = "pcapFilePieQueue.pcap"; + +float stopTime = startTime + simDuration; + + CommandLine cmd; + cmd.Parse(argc,argv); + +LogComponentEnable ("PieQueue", LOG_LEVEL_INFO); + + + +std::string bottleneckBandwidth = "10Mbps"; +std::string bottleneckDelay = "50ms"; + +std::string accessBandwidth ="10Mbps"; +std::string accessDelay = "5ms"; + + +NodeContainer source; +source.Create(50); + +NodeContainer gateway; +gateway.Create (2); + +NodeContainer sink; +sink.Create(1); + + +// Create and configure access link and bottleneck link + PointToPointHelper accessLink; + accessLink.SetDeviceAttribute ("DataRate", StringValue (accessBandwidth)); + accessLink.SetChannelAttribute ("Delay", StringValue (accessDelay)); + accessLink.SetQueue ("ns3::DropTailQueue"); + + + PointToPointHelper bottleneckLink; + bottleneckLink.SetDeviceAttribute ("DataRate", StringValue (bottleneckBandwidth)); + bottleneckLink.SetChannelAttribute ("Delay", StringValue (bottleneckDelay)); + bottleneckLink.SetQueue ("ns3::PieQueue"); + + + Config::SetDefault ("ns3::PieQueue::MeanPktSize", UintegerValue (1000)); + Config::SetDefault ("ns3::PieQueue::QueueDelayReference", TimeValue (Seconds(0.02))); + + + InternetStackHelper stack; + stack.InstallAll (); + + Ipv4AddressHelper address; + address.SetBase ("10.0.0.0", "255.255.255.0"); + + // Configure the source and sink net devices + // and the channels between the source/sink and the gateway + Ipv4InterfaceContainer sink_Interfaces; + Ipv4InterfaceContainer interfaces[50]; + Ipv4InterfaceContainer interfaces_sink; + Ipv4InterfaceContainer interfaces_gateway; + + NetDeviceContainer devices[50]; + NetDeviceContainer devices_sink; + NetDeviceContainer devices_gateway; + + + +for(i=0;i<50;i++) +{ + devices[i] = accessLink.Install (source.Get (i), gateway.Get (0)); + address.NewNetwork (); + interfaces[i]=address.Assign(devices[i]); +} + + + devices_gateway= bottleneckLink.Install (gateway.Get (0), gateway.Get (1)); + address.NewNetwork(); + interfaces_gateway = address.Assign (devices_gateway); + + devices_sink= accessLink.Install (gateway.Get (1), sink.Get (0)); + address.NewNetwork (); + interfaces_sink = address.Assign (devices_sink); + + sink_Interfaces.Add (interfaces_sink.Get (1)); + + NS_LOG_INFO ("Initialize Global Routing."); + Ipv4GlobalRoutingHelper::PopulateRoutingTables (); + + + uint16_t port = 50000; + Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); + PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress); + + // Configure application + AddressValue remoteAddress (InetSocketAddress (sink_Interfaces.GetAddress (0, 0), port)); + for (uint16_t i = 0; i < source.GetN (); i++) + { + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); + BulkSendHelper ftp ("ns3::TcpSocketFactory", Address ()); + ftp.SetAttribute ("Remote", remoteAddress); + ftp.SetAttribute ("SendSize", UintegerValue (1000)); + + + ApplicationContainer sourceApp = ftp.Install (source.Get (i)); + sourceApp.Start (Seconds (0)); + sourceApp.Stop (Seconds (stopTime - 1)); + + sinkHelper.SetAttribute ("Protocol", TypeIdValue (TcpSocketFactory::GetTypeId ())); + ApplicationContainer sinkApp = sinkHelper.Install (sink); + sinkApp.Start (Seconds (0)); + sinkApp.Stop (Seconds (stopTime)); + + } + + + + + if (writeForPlot) + { + + filePlotQueueDel << pathOut << "/" << "delay.plotme"; + + remove (filePlotQueueDel.str ().c_str ()); + + + Ptr nd = StaticCast (devices_gateway.Get (0)); + Ptr queue = nd->GetQueue (); + Simulator::ScheduleNow (&CheckQueueDel, queue); + + + } + + + if (isPcapEnabled) + { + bottleneckLink.EnablePcap (pcapFileName,gateway,false); + } + + + FlowMonitorHelper flowmon; + Ptr allMon ; + allMon= flowmon.InstallAll(); + flowmon.SerializeToXmlFile("PieQueue.xml", true, true); + + Simulator::Stop (Seconds (stopTime)); + Simulator::Run (); + + if (printPieStats) + { + Ptr nd1 = StaticCast (devices_gateway.Get (0)); + PieQueue::Stats st1 = StaticCast (nd1->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st1.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st1.forcedDrop << " drops due queue full" << std::endl; + + + Ptr nd2 = StaticCast (devices_gateway.Get (1)); + PieQueue::Stats st2 = StaticCast (nd2->GetQueue ())->GetStats (); + std::cout << "*** pie stats from Node 2 queue ***" << std::endl; + std::cout << "\t " << st2.unforcedDrop << " drops due to probability " << std::endl; + std::cout << "\t " << st2.forcedDrop << " drops due queue full" << std::endl; + + } + + Simulator::Destroy (); + return 0; + +} + + + + + + + + + + + diff --git a/src/network/utils/pie-queue.cc b/src/network/utils/pie-queue.cc old mode 100644 new mode 100755 index a5102be..2a65e66 --- a/src/network/utils/pie-queue.cc +++ b/src/network/utils/pie-queue.cc @@ -122,12 +122,7 @@ TypeId PieQueue::GetTypeId (void) .AddAttribute ("QueueLimit", "Queue limit in packets", UintegerValue (200), - MakeUintegerAccessor (&PieQueue::m_qLim_), - MakeUintegerChecker ()) - .AddAttribute ("CurrentQueuelength", - "Current Queue Length", - UintegerValue (0), - MakeUintegerAccessor (&PieQueue::m_curq), + MakeUintegerAccessor (&PieQueue::m_qLim), MakeUintegerChecker ()) .AddAttribute ("DequeueThreshold", "Dequeue Threshold", @@ -139,11 +134,11 @@ TypeId PieQueue::GetTypeId (void) TimeValue (Seconds (0.02)), MakeTimeAccessor (&PieQueue::m_qDelayRef), MakeTimeChecker ()) - .AddAttribute ("BurstAllowance", - "Current max burst size before random drop", - DoubleValue (0.1), - MakeDoubleAccessor (&PieQueue::m_maxBurst), - MakeDoubleChecker ()) + .AddAttribute ("MaxBurstAllowance", + "Current max burst allowance in seconds before random drop", + TimeValue (Seconds(0.1)), + MakeTimeAccessor (&PieQueue::m_maxBurst), + MakeTimeChecker()) ; return tid; @@ -156,6 +151,8 @@ PieQueue::PieQueue () m_hasPieStarted (false) { NS_LOG_FUNCTION (this); + + InitializeParams (); m_uv = CreateObject (); m_rtrsEvent = Simulator::Schedule (m_sUpdate, &PieQueue::CalculateP, this); } @@ -172,7 +169,6 @@ PieQueue::InitializeParams (void) m_inMeasurement = 0; m_dqCount = -1; m_dropProb = 0; - m_accuProb = 0; m_avgDqRate = 0.0; m_dqStart = 0; m_bytesInQueue = 0; @@ -180,14 +176,14 @@ PieQueue::InitializeParams (void) m_qDelayOld = Time (Seconds (0)); m_stats.forcedDrop = 0; m_stats.unforcedDrop = 0; - + } void PieQueue::SetQueueLimit (uint32_t lim) { NS_LOG_FUNCTION (this << lim); - m_qLim_ = lim; + m_qLim = lim; } uint32_t @@ -197,10 +193,11 @@ PieQueue::GetQueueSize (void) return m_bytesInQueue; } -double PieQueue::GetQueueDelay (void) +Time +PieQueue::GetQueueDelay (void) { NS_LOG_FUNCTION (this); - return m_qDelay.GetSeconds (); + return m_qDelay; } uint32_t @@ -229,13 +226,12 @@ PieQueue::Reset () { NS_LOG_FUNCTION (this); Ptr p; - m_dropProb = 0; - m_accuProb = 0.0; - m_curq = 0; + InitializeParams (); + Simulator::Remove(m_rtrsEvent); m_rtrsEvent = Simulator::Schedule (m_sUpdate, &PieQueue::CalculateP, this); while ((p = m_packets.front ()) != 0) { - m_packets.pop (); + m_packets.pop (); } m_bytesInQueue = 0; } @@ -254,20 +250,18 @@ PieQueue::DoEnqueue (Ptr pkt) NS_LOG_FUNCTION (this << pkt); if (!m_hasPieStarted ) { - InitializeParams (); m_hasPieStarted = true; } uint32_t QLen = m_bytesInQueue; m_curq = QLen; - uint32_t QLim = m_qLim_ * m_meanPktSize; + uint32_t QLim = m_qLim * m_meanPktSize; if (QLen >= QLim) { // Forced drop: reactive to full queue Drop (pkt); m_stats.forcedDrop++; - m_accuProb = 0; } else if (DropEarly (pkt, QLen)) { @@ -301,17 +295,12 @@ PieQueue::DoPeek () const bool PieQueue::DropEarly (Ptr pkt, uint32_t QLen) { NS_LOG_FUNCTION (this << pkt << QLen); - if (m_burstAllowance > 0) + if (m_burstAllowance.GetSeconds() > 0) { // If there is still burst_allowance left, skip random early drop. return false; } - if (m_dropProb == 0.0) - { - m_accuProb = 0.0; - } - if (m_burstState == NO_BURST) { m_burstState = IN_BURST_PROTECTING; @@ -325,7 +314,7 @@ bool PieQueue::DropEarly (Ptr pkt, uint32_t QLen) { p = p * packetSize / m_meanPktSize; } - int earlyDrop = 1; + bool earlyDrop = 1; double u = m_uv->GetValue (); if (m_qDelayOld.GetSeconds () < 0.5 * m_qDelayRef.GetSeconds () && m_dropProb < 0.2) @@ -338,14 +327,13 @@ bool PieQueue::DropEarly (Ptr pkt, uint32_t QLen) } if (u > p) { - earlyDrop = 0; + earlyDrop = false; } - if (earlyDrop == 0) + if (earlyDrop == false) { return false; } - m_accuProb = 0.0; return true; } @@ -381,8 +369,9 @@ Ptr PieQueue::DoDequeue () // done with a measurement cycle if (m_dqCount >= (m_dqThreshold)) { + double tmp = now - m_dqStart; - + if (m_avgDqRate == 0) { m_avgDqRate = m_dqCount / tmp; @@ -429,7 +418,7 @@ void PieQueue::CalculateP () m_qDelay = qDelay; - if (m_burstAllowance > 0) + if (m_burstAllowance.GetSeconds() > 0) { m_dropProb = 0; } @@ -480,13 +469,13 @@ void PieQueue::CalculateP () } m_dropProb = (p > 0) ? p : 0; - if (m_burstAllowance < m_tUpdate.GetSeconds ()) + if (m_burstAllowance < m_tUpdate) { - m_burstAllowance = 0; + m_burstAllowance = Time (Seconds (0)); } else { - m_burstAllowance -= m_tUpdate.GetSeconds (); + m_burstAllowance -= m_tUpdate; } uint32_t burstResetLimit = BURST_RESET_TIMEOUT / m_tUpdate.GetSeconds (); @@ -495,7 +484,7 @@ void PieQueue::CalculateP () m_dqCount = -1; m_avgDqRate = 0.0; } - if (qDelay.GetSeconds () < 0.5 * m_qDelayRef.GetSeconds () && m_qDelayOld.GetSeconds () < 0.5 * m_qDelayRef.GetSeconds () && m_dropProb == 0 && m_burstAllowance == 0) + if (qDelay.GetSeconds () < 0.5 * m_qDelayRef.GetSeconds () && m_qDelayOld.GetSeconds () < 0.5 * m_qDelayRef.GetSeconds () && m_dropProb == 0 && m_burstAllowance.GetSeconds() == 0) { if (m_burstState == IN_BURST_PROTECTING) { @@ -518,6 +507,7 @@ void PieQueue::CalculateP () } m_qDelayOld = qDelay; + Simulator::Remove(m_rtrsEvent); m_rtrsEvent = Simulator::Schedule (m_tUpdate, &PieQueue::CalculateP, this); } } //namespace ns3 diff --git a/src/network/utils/pie-queue.h b/src/network/utils/pie-queue.h old mode 100644 new mode 100755 index 0b7fb98..a461233 --- a/src/network/utils/pie-queue.h +++ b/src/network/utils/pie-queue.h @@ -148,7 +148,7 @@ class PieQueue : public Queue /** * \brief Get queue delay */ - double GetQueueDelay (void); + Time GetQueueDelay (void); /** * \brief Get the drop probability @@ -193,7 +193,6 @@ class PieQueue : public Queue * \brief Check if packet p needs to be dropped due to probability mark * \param pkt packet * \param qlen queue length - * \param qlim queue limit * \returns 0 for no drop/mark, 1 for drop */ bool DropEarly (Ptr pkt, uint32_t qlen); @@ -212,13 +211,13 @@ class PieQueue : public Queue // ** Variables supplied by user - int m_qLim_; //!< Maintains the maximum limit of the queue + int m_qLim; //!< Maintains the maximum limit of the queue bool m_queueInBytes; //!< Checks if queue is in byte mode Time m_sUpdate; //!< Time to start the update timer Time m_tUpdate; //!< sampling timer Time m_qDelayRef; //!< desired queue delay uint32_t m_meanPktSize; //!< avg pkt size, linked into Tcl - double m_maxBurst; //!< maximum burst allowed before random early dropping kicks in + Time m_maxBurst; //!< maximum burst allowed before random early dropping kicks in Time m_linkDelay; //!< Link delay DataRate m_linkBandwidth; //!< Link bandwidth double m_a; //!< parameters to pie controller @@ -228,10 +227,9 @@ class PieQueue : public Queue // ** Variables maintained by PIE double m_dropProb; //!< Variable used in calculation of drop probability - double m_accuProb; //!< Variable used in calculation of drop probability Time m_qDelayOld; //!< Measures the old value of queue delay Time m_qDelay; //!< Measures the value of queue delay - double m_burstAllowance; //!< current max burst size that is allowed before random drops kick in + Time m_burstAllowance; //!< current max burst value in seconds that is allowed before random drops kick in uint32_t m_burstReset; //!< Used to reset value of burst allowance BurstStateT m_burstState; //!< Used to determine the current state of burst uint32_t m_inMeasurement; //!< indicate whether we are in a measurement cycle