PfifoFastQueueDisc Test

[Topology]

 

 

test-pfifo0.cc (put this under scratch)

#include <fstream>

#include <string.h>

 

#include "ns3/core-module.h"

#include "ns3/internet-module.h"

#include "ns3/point-to-point-module.h"

#include "ns3/packet-sink.h"

#include "ns3/packet-sink-helper.h"

#include "ns3/on-off-helper.h"

#include "ns3/traffic-control-module.h"

 

 

using namespace ns3;

 

NS_LOG_COMPONENT_DEFINE ("test-pfifo0");

 

const int no=2;

Ptr<PacketSink> sink[no];                   /* Pointer to the packet sink application */

uint64_t lastTotalRx[no];                   /* The value of the last total received bytes */

double cur[no];

 

QueueDiscContainer queueDiscs;

 

void PrintCurrentQueueSize() {  

    std::cout << queueDiscs.Get(0)->GetNPackets() << std::endl;

    Simulator::Schedule (MilliSeconds (1), &PrintCurrentQueueSize);

}

 

void

CalculateThroughput ()

{

  Time now = Simulator::Now ();                  

  std::cout << now.GetSeconds ();

  for(int j=0;j<no;j++){

    cur[j] = (sink[j]->GetTotalRx () - lastTotalRx[j]) * (double) 8 / 1e3;  

    std::cout << "\t" << cur[j];

    lastTotalRx[j] = sink[j]->GetTotalRx ();

  }

 

  std::cout << std::endl;

  Simulator::Schedule (MilliSeconds (1000), &CalculateThroughput);

}

 

int

main (int argc, char *argv[])

{

  NodeContainer term_0;

  term_0.Create (1);

  NodeContainer term_1;

  term_1.Create (1);

  NodeContainer term_2;

  term_2.Create (1);

  NodeContainer term_3;

  term_3.Create (1);

 

  TrafficControlHelper tch;

  tch.SetRootQueueDisc ("ns3::PfifoFastQueueDisc");

 

  /* Build link. */

  PointToPointHelper p2p_p2p_0;

  p2p_p2p_0.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));

  p2p_p2p_0.SetChannelAttribute ("Delay", StringValue ("1ms"));

  PointToPointHelper p2p_p2p_1;

  p2p_p2p_1.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));

  p2p_p2p_1.SetChannelAttribute ("Delay", StringValue ("1ms"));

  PointToPointHelper p2p_p2p_2;

  p2p_p2p_2.SetDeviceAttribute ("DataRate", StringValue ("1Mbps"));

  p2p_p2p_2.SetChannelAttribute ("Delay", StringValue ("1ms"));

   

  /* Build link net device container. */

  NodeContainer all_p2p_0;

  all_p2p_0.Add (term_0);

  all_p2p_0.Add (term_2);

  NetDeviceContainer ndc_p2p_0 = p2p_p2p_0.Install (all_p2p_0);

  NodeContainer all_p2p_1;

  all_p2p_1.Add (term_1);

  all_p2p_1.Add (term_2);

  NetDeviceContainer ndc_p2p_1 = p2p_p2p_1.Install (all_p2p_1);

  NodeContainer all_p2p_2;

  all_p2p_2.Add (term_2);

  all_p2p_2.Add (term_3);

  NetDeviceContainer ndc_p2p_2 = p2p_p2p_2.Install (all_p2p_2);

 

  /* Install the IP stack. */

  InternetStackHelper internetStackH;

  internetStackH.Install (term_0);

  internetStackH.Install (term_1);

  internetStackH.Install (term_2);

  internetStackH.Install (term_3);

 

  queueDiscs = tch.Install (ndc_p2p_2.Get(0));

 

  /* IP assign. */

  Ipv4AddressHelper ipv4;

  ipv4.SetBase ("10.0.0.0", "255.255.255.0");

  Ipv4InterfaceContainer iface_ndc_p2p_0 = ipv4.Assign (ndc_p2p_0);

  ipv4.SetBase ("10.0.1.0", "255.255.255.0");

  Ipv4InterfaceContainer iface_ndc_p2p_1 = ipv4.Assign (ndc_p2p_1);

  ipv4.SetBase ("10.0.2.0", "255.255.255.0");

  Ipv4InterfaceContainer iface_ndc_p2p_2 = ipv4.Assign (ndc_p2p_2);

 

  /* Generate Route. */

  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

 

  NS_LOG_INFO ("Create Applications.");

  PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), 9));

  ApplicationContainer sinkApp = sinkHelper.Install (term_3.Get(0));

  sink[0] = StaticCast<PacketSink> (sinkApp.Get (0));

 

  InetSocketAddress sinkSocket (InetSocketAddress (iface_ndc_p2p_2.GetAddress (1), 9));

  sinkSocket.SetTos (16);

  OnOffHelper server ("ns3::UdpSocketFactory", sinkSocket);

  server.SetAttribute ("PacketSize", UintegerValue (1000));

  server.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));

  server.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));

  server.SetAttribute ("DataRate", DataRateValue (DataRate ("600Kbps")));

  ApplicationContainer serverApp = server.Install (term_0.Get(0));

 

  sinkApp.Start (Seconds (0.0));

  serverApp.Start (Seconds (1.0));

  serverApp.Stop (Seconds (20.0));

 

  PacketSinkHelper sinkHelper2 ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), 10));

  ApplicationContainer sinkApp2 = sinkHelper2.Install (term_3.Get(0));

  sink[1] = StaticCast<PacketSink> (sinkApp2.Get (0));

 

  InetSocketAddress sinkSocket2 (InetSocketAddress (iface_ndc_p2p_2.GetAddress (1), 10));

  sinkSocket2.SetTos (0);

  OnOffHelper server2 ("ns3::UdpSocketFactory", sinkSocket2);

  server2.SetAttribute ("PacketSize", UintegerValue (1000));

  server2.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));

  server2.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));

  server2.SetAttribute ("DataRate", DataRateValue (DataRate ("900Kbps")));

  ApplicationContainer serverApp2 = server2.Install (term_1.Get(0));

 

  sinkApp2.Start (Seconds (0.0));

  serverApp2.Start (Seconds (5.0));

  serverApp2.Stop (Seconds (15.0));

 

  Simulator::Schedule (Seconds (1.0), &CalculateThroughput);

  //Simulator::Schedule (MilliSeconds (1), &PrintCurrentQueueSize);

 

 

  Simulator::Stop (Seconds (25.0));

  //pointToPoint.EnablePcapAll("test-pfifo0");

  NS_LOG_INFO ("Run Simulation.");

  Simulator::Run ();

  Simulator::Destroy ();

  NS_LOG_INFO ("Done.");

 

}

 

Execution

The first column is time, the second is the throughput for flow1, and the third is the throughput for flow2.

We can see that the flow1 can get around 600kbps (higher priority).

 

If we change the code, sinkSocket.SetTos (16); à sinkSocket.SetTos (0);

The same priority for flow1 and flow2.

From the following the results, the flow1 get lower throughput. Because the sending speeding for flow2 is higher than that of flow1.

 

References

https://www.nsnam.org/doxygen/classns3_1_1_socket.html#a81564620cc94d291f1dc5d79b2f13b4a

https://www.nsnam.org/doxygen/socket_8cc_source.html

https://github.com/nsnam/ns-3-dev-git/blob/master/src/traffic-control/model/pfifo-fast-queue-disc.cc

 

Back to NS3 Learning Guide

Last Modified: 2022/2/7 done

 

[Author]

Dr. Chih-Heng Ke

Department of Computer Science and Information Engineering, National Quemoy University, Kinmen, Taiwan

Email: smallko@gmail.com