Simple VoWiFi/VoWLAN model - plotting a graph for throughput against time

450 views
Skip to first unread message

Shuja Ansari

unread,
Feb 20, 2015, 11:13:20 AM2/20/15
to ns-3-...@googlegroups.com
Hi there!

I am new to NS-3. Started last week and since last week my days and nights are all in to NS-3, NetAnim and Eclipse. I have been scratching my head since the last five days in trying to figure out this small problem. I have worked with other graphic interface simulators like OPNET. So I was expecting results in graphs. I went through different topics in this group and many others to get a grip over basic NS-3. So I compiled this code below for VoIP traffic over a Wifi AP, this code is not mine but I got this by combining different codes I got my hand on from different topics and forums.

/*
 * VoWifi.cc
 *
 *  Created on: Feb 19, 2015
 *      Author: shujaansari
 */


// Network Topology
//           AP
//     *
//                  *
// *:VoIP nodes
//

#include "ns3/flow-monitor.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/internet-module.h"
#include "ns3/object.h"
#include "ns3/uinteger.h"
#include "ns3/traced-value.h"
#include "ns3/trace-source-accessor.h"
#include "ns3/random-variable-stream.h"
#include "ns3/type-id.h"
#include "ns3/object-base.h"
#include "ns3/scheduler.h"
#include "ns3/calendar-scheduler.h"
#include "ns3/callback.h"
#include "ns3/netanim-module.h"
#include "ns3/trace-helper.h"
#include "ns3/gnuplot.h"


#include <fstream>
#include <iostream>

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");

void CourseChange (std::string context, Ptr<const MobilityModel> model)
    {
      Vector position = model->GetPosition ();
      NS_LOG_UNCOND (context <<
                     " x = " <<
position.x <<
", y = " <<
position.y);
}

void SetTagTid ( uint8_t mytid ,Ptr<const Packet> pkt )
{
 QosTag  qosTag ;
 qosTag.SetTid (mytid);
 pkt->AddPacketTag ( qosTag );
}

int main (int argc, char *argv[])
{
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

NodeContainer wifiApNode;
wifiApNode.Create(1);
NodeContainer wifiStaNodes;
wifiStaNodes.Create(2);

// Create & setup wifi channel
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());

// Install wireless devices
WifiHelper wifi = WifiHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ArfWifiManager");

QosWifiMacHelper mac = QosWifiMacHelper::Default ();

Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid));

NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);

mac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid), "ActiveProbing", BooleanValue (true));

NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);

MobilityHelper mobility;

mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                "MinX", DoubleValue (0.0),
                                "MinY", DoubleValue (5.0),
                                "DeltaX", DoubleValue (5.0),
                                "DeltaY", DoubleValue (10.0),
                                "GridWidth", UintegerValue (3),
                                "LayoutType", StringValue ("RowFirst"));

mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
                            "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
mobility.Install (wifiStaNodes);

mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNode);

InternetStackHelper stack;
stack.Install (wifiApNode);
stack.Install (wifiStaNodes);

Ipv4AddressHelper address;
NS_LOG_INFO ("Assign IP Addresses.");
address.SetBase ("10.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer wifiApInterfaces;
wifiApInterfaces = address.Assign (apDevices);
Ipv4InterfaceContainer wifiInterfaces;
wifiInterfaces = address.Assign (staDevices);

//Installing applications
//CBR = VoIP ==============================
//first VoIP traffic
 // VoIP receiver---
Address remoteAddress1 = InetSocketAddress(wifiInterfaces.GetAddress (0), 4000);
PacketSinkHelper receiver1 ("ns3::UdpSocketFactory", remoteAddress1);
ApplicationContainer receiverapp1 =receiver1.Install(wifiStaNodes.Get (0));
receiverapp1.Start (Seconds (5.0));
receiverapp1.Stop (Seconds (8.0));

// VoIP receiver AP
Address remoteAddress2 = InetSocketAddress(wifiApInterfaces.GetAddress (0), 4000);
PacketSinkHelper receiver2 ("ns3::UdpSocketFactory", remoteAddress2);
ApplicationContainer receiverapp2 =receiver2.Install(wifiApNode.Get(0));
receiverapp2.Start (Seconds (2.0));
receiverapp2.Stop (Seconds(5.0));
 // VoIP Sender ----
OnOffHelper sender2("ns3::UdpSocketFactory", remoteAddress2);
sender2.SetConstantRate( DataRate("68.8Kbps") , 172); // 160 byte(G.711) + 12 byte (RTP header) = 172 byte/ for 20ms packet generation intervall is 68.8kbps
sender2.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
sender2.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
ApplicationContainer senderapps2;
senderapps2  = sender2.Install(wifiStaNodes.Get(1));
Config::ConnectWithoutContext("/NodeList/1/ApplicationList/3/$ns3::OnOffApplication/Rx",  MakeCallback (&SetTagTid));
Ptr<OnOffApplication> onoffappVO1;
onoffappVO1 = DynamicCast<OnOffApplication>(senderapps2.Get(0));
onoffappVO1->TraceConnectWithoutContext("Tx",  MakeBoundCallback (&SetTagTid, AC_VO));
senderapps2.Start(Seconds(2.0));
senderapps2.Stop(Seconds(5.0));
OnOffHelper sender1("ns3::UdpSocketFactory", remoteAddress1);
sender1.SetConstantRate( DataRate("68.8Kbps") , 172); // 160 byte(G.711) + 12 byte (RTP header) = 172 byte/ for 20ms packet generation intervall is 68.8kbps
sender1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
sender1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
ApplicationContainer senderapps1;
senderapps1  = sender1.Install(wifiStaNodes.Get(1));
Config::ConnectWithoutContext("/NodeList/0/ApplicationList/3/$ns3::OnOffApplication/Rx",  MakeCallback (&SetTagTid));
Ptr<OnOffApplication> onoffappVO;
onoffappVO = DynamicCast<OnOffApplication>(senderapps1.Get(0));
onoffappVO->TraceConnectWithoutContext("Tx",  MakeBoundCallback (&SetTagTid, AC_VO));
senderapps1.Start(Seconds(5.0));
senderapps1.Stop(Seconds(8.0));


Ipv4GlobalRoutingHelper::PopulateRoutingTables ();


std::string fileName = "FlowVSThroughput";
std::string graphicsFileName = fileName + ".png";
std::string plotFileName = fileName + ".plt";
std::string plotTitle = "Flow Vs Throughput";
std::string dataTitle = "Throughput";

Gnuplot gnuplot (graphicsFileName);
gnuplot.SetTitle(plotTitle);
gnuplot.SetTerminal("png");
gnuplot.SetLegend("Flow","Throughput");

Gnuplot2dDataset dataset;
dataset.SetTitle (dataTitle);
dataset.SetStyle (Gnuplot2dDataset::LINES_POINTS);

FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
NS_LOG_INFO("Run Simulation");

Simulator::Stop (Seconds (10.0));

 //output================

 phy.EnablePcap ("VoWifi", apDevices);
 phy.EnablePcap ("VoWifi" , staDevices);
 phy.EnableAscii ("VoWifi" , apDevices);
 phy.EnableAscii ("VoWifi" , staDevices);
 stack.EnableAsciiIpv4 ("VoWifi" , wifiApInterfaces); //output tr file for trace of internet stack
 stack.EnableAsciiIpv4 ("VoWifi" , wifiInterfaces); //output tr file for trace of internet stack

AnimationInterface anim("VoWifi.xml");

Simulator::Run ();
NS_LOG_UNCOND("Flow Monitor Statistics: ");
monitor->CheckForLostPackets();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
double Throughput=0.0;

for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator iter = stats.begin(); iter != stats.end (); ++iter)
{
 Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(iter->first);

 NS_LOG_UNCOND ("Flow IF: " << iter->first << "  Src Addr "<<t.sourceAddress<<"Dst Addr "<<t.destinationAddress);
 NS_LOG_UNCOND ("Tx Pkts= " << iter->second.txPackets);
 NS_LOG_UNCOND ("Rx Pkts= " << iter->second.rxPackets);
 Throughput= iter->second.rxBytes * 8.0 / (iter->second.timeLastRxPacket.GetSeconds()-iter->second.timeFirstTxPacket.GetSeconds())/1024;
 NS_LOG_UNCOND ("Throughput: " << Throughput <<"Kbps");
 dataset.Add((double)iter->first ,(double) Throughput);
}
NS_LOG_UNCOND("Done");

gnuplot.AddDataset(dataset);
std::ofstream plotFile (plotFileName.c_str());
gnuplot.GenerateOutput(plotFile);

plotFile.close();

monitor->SerializeToXmlFile("VoWifi.flowmon", true, true);
Simulator::Destroy ();
return 0;

}



This code is running fine. NetAnim is showing what I want. Flowmon file have one flow with the desired output parameters. The plot is there as well. Now there are two problems

1. There is only 1 flow. What does that mean? 

2. My plot has only one point and that's because of that one flow I believe against throughput. 

What do I have to do to get a graph for any one station's throughput against time? 

Any sort of help would be much appreciated.

Thanks in advance

Shuja

Konstantinos

unread,
Feb 20, 2015, 12:59:15 PM2/20/15
to ns-3-...@googlegroups.com
Hi,

Please do not put large amount of code (>10 lines) in the message text. You can use attachments.
Now, on your questions:
1) What do you mean one flow? I just run your code and I got this output 
Flow Monitor Statistics:
Flow IF: 1  Src Addr 10.1.3.3Dst Addr 10.1.3.1
Tx Pkts= 149
Rx Pkts= 149
Throughput: 78.651Kbps
Flow IF: 2  Src Addr 10.1.3.3Dst Addr 10.1.3.2
Tx Pkts= 149
Rx Pkts= 149
Throughput: 78.6468Kbps
Done

I can see clearly TWO flows, as expected. The source node is the same (Sta_1) and the destinations are two, Sta_0 and AP.

2. The plot also has two points, but they are very close to differentiate (78.651 and 78.6468). 


In order to get throughput over time, you need to create the corresponding 'monitoring' functionality, i.e. check the throughput every second.
This has been discussed in the mailing list and example code is provided. Basically, you need to place the 'throughput calculations' in a method that will be called periodically using Simulator::Schedule().

Shuja Ansari

unread,
Feb 20, 2015, 1:28:59 PM2/20/15
to ns-3-...@googlegroups.com

Thanks very much for your quick reply. 

I am sorry for the long code. Will not do that again. 

Yes I'm sorry I forgot to mention I added a new flow between the sta and ap. I wanted to know what the flow is? Is it a single connection between the two nodes?

Regarding throughput I will try using the monitoring functionality. Appreciate your help. 
--
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/Y7-FfV8_l1o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.


--
Regards,
Shuja Ansari

Konstantinos

unread,
Feb 20, 2015, 1:33:48 PM2/20/15
to ns-3-...@googlegroups.com
A flow is characterised by a tuple (source-ip, destination-ip, protocol, source-port, destination-port).
To unsubscribe from this group and all its topics, send an email to ns-3-users+unsubscribe@googlegroups.com.

To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.


--
Regards,
Shuja Ansari

Shuja Ansari

unread,
Feb 20, 2015, 4:40:41 PM2/20/15
to ns-3-...@googlegroups.com
Hey! 

Thanks a lot for the help. I got it working as I wanted. Just need to play with the gnuplot now to get a good picture out. I got the throughput plotted against time for both the flows separately. But my programming skills are not very good. I have attached the code just in case any one would suggest improvements in this simple network.

Thanks again sir.

SA
VoWifi.cc

Sridhar S

unread,
Sep 29, 2015, 3:40:33 AM9/29/15
to ns-3-users



Sir,

I am new to ns-3 , i just download your code and put it in scratch folder .
when i run your program i got errors like this
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Waf: Leaving directory `/home/tcemdu/Documents/ns-allinone-3.23/ns-3.23/build'
Build failed
 -> task in 'voip' failed (exit status 1):
    {task 140358035828816: cxxprogram voip.cc.2.o -> voip}
['/usr/bin/g++', '-pthread', 'scratch/voip.cc.2.o', '-o', '/home/tcemdu/Documents/ns-allinone-3.23/ns-3.23/build/scratch/voip', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-Wl,--no-as-needed', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-lns3.23-lr-wpan-debug', '-lns3.23-netanim-debug', '-lns3.23-lte-debug', '-lns3.23-spectrum-debug', '-lns3.23-antenna-debug', '-lns3.23-aodv-debug', '-lns3.23-mesh-debug', '-lns3.23-olsr-debug', '-lns3.23-test-debug', '-lns3.23-wave-debug', '-lns3.23-applications-debug', '-lns3.23-csma-layout-debug', '-lns3.23-dsdv-debug', '-lns3.23-dsr-debug', '-lns3.23-flow-monitor-debug', '-lns3.23-wimax-debug', '-lns3.23-nix-vector-routing-debug', '-lns3.23-point-to-point-layout-debug', '-lns3.23-sixlowpan-debug', '-lns3.23-tap-bridge-debug', '-lns3.23-internet-debug', '-lns3.23-bridge-debug', '-lns3.23-point-to-point-debug', '-lns3.23-mpi-debug', '-lns3.23-uan-debug', '-lns3.23-energy-debug', '-lns3.23-wifi-debug', '-lns3.23-buildings-debug', '-lns3.23-propagation-debug', '-lns3.23-mobility-debug', '-lns3.23-config-store-debug', '-lns3.23-csma-debug', '-lns3.23-fd-net-device-debug', '-lns3.23-virtual-net-device-debug', '-lns3.23-topology-read-debug', '-lns3.23-network-debug', '-lns3.23-stats-debug', '-lns3.23-core-debug', '-lrt']


i don't know what i do now? please help me

Thanks in advance

Konstantinos

unread,
Sep 29, 2015, 5:32:13 AM9/29/15
to ns-3-users
Hi Sridhar,

There seems to be an error when you copied the file from the mailing list.
Search the error you get and you can find possible solutions such as 

Regards,
K.
Reply all
Reply to author
Forward
0 new messages