I have been trying to run this code.
It gets built but then nothing happens after that. I get no GNU plots, nor anything comes on the screen.
Please help me with this.
#include "ns3/netanim-module.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/stats-module.h"
#include "ns3/wifi-module.h"
#include "ns3/config-store-module.h"
#include "ns3/internet-module.h"
#include <fstream>
#include <vector>
#include <string>
#include <iostream>
NS_LOG_COMPONENT_DEFINE ("Main");
using namespace ns3;
class Infra_g
{
public:
Infra_g ();
Infra_g (std::string name);
Gnuplot2dDataset Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel);
private:
void ReceivePacket (Ptr<Socket> socket);
void SetPosition (Ptr<Node> node, Vector position);
Vector GetPosition (Ptr<Node> node);
void AdvancePosition (Ptr<Node> node);
Ptr<Socket> SetupPacketReceive (Ptr<Node> node);
uint32_t m_bytesTotal;
Gnuplot2dDataset m_output;
};
Infra_g::Infra_g ()
{
}
Infra_g::Infra_g (std::string name)
: m_output (name)
{
m_output.SetStyle (Gnuplot2dDataset::LINES);
}
void
Infra_g::SetPosition (Ptr<Node> node, Vector position)
{
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
mobility->SetPosition (position);
}
Vector
Infra_g::GetPosition (Ptr<Node> node)
{
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
return mobility->GetPosition ();
}
void
Infra_g::AdvancePosition (Ptr<Node> node)
{
Vector pos = GetPosition (node);
double mbs = ((m_bytesTotal * 8.0) / 1000000);
m_bytesTotal = 0;
m_output.Add (pos.x, mbs);
pos.x += 1.0;
if (pos.x >= 210.0)
{
return;
}
SetPosition (node, pos);
//std::cout << "x="<<pos.x << std::endl;
Simulator::Schedule (Seconds (1.0), &Infra_g::AdvancePosition, this, node);
}
void
Infra_g::ReceivePacket (Ptr<Socket> socket)
{
Ptr<Packet> packet;
while ((packet = socket->Recv ()))
{
m_bytesTotal += packet->GetSize ();
}
}
Ptr<Socket>
Infra_g::SetupPacketReceive (Ptr<Node> node)
{
TypeId tid = TypeId::LookupByName ("ns3::PacketSocketFactory");
Ptr<Socket> sink = Socket::CreateSocket (node, tid);
sink->Bind ();
sink->SetRecvCallback (MakeCallback (&Infra_g::ReceivePacket, this));
return sink;
}
Gnuplot2dDataset
Infra_g::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel)
{
m_bytesTotal = 0;
NodeContainer c;
c.Create (2);
PacketSocketHelper packetSocket;
packetSocket.Install (c);
YansWifiPhyHelper phy = wifiPhy;
phy.SetChannel (wifiChannel.Create ());
NqosWifiMacHelper mac = wifiMac;
// NetDeviceContainer devices = wifi.Install (phy, mac, c);
Ssid ssid = Ssid ("wifi-default");
// setup sta.
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevice = wifi.Install (phy, mac, c.Get (0));
NetDeviceContainer devices = staDevice;
// setup ap.
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevice = wifi.Install (phy, mac, c.Get (1));
devices.Add (apDevice);
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
positionAlloc->Add (Vector (5.0, 0.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (c);
PacketSocketAddress socket;
socket.SetSingleDevice (devices.Get (0)->GetIfIndex ());
socket.SetPhysicalAddress (devices.Get (1)->GetAddress ());
socket.SetProtocol (1);
OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
onoff.SetConstantRate (DataRate (60000000));
onoff.SetAttribute ("PacketSize", UintegerValue (2000));
ApplicationContainer apps = onoff.Install (c.Get (0));
apps.Start (Seconds (0.5));
apps.Stop (Seconds (250.0));
Simulator::Schedule (Seconds (1.5), &Infra_g::AdvancePosition, this, c.Get (1));
Ptr<Socket> recvSink = SetupPacketReceive (c.Get (1));
Simulator::Run ();
Simulator::Destroy ();
return m_output;
}
int main (int argc, char *argv[])
{
// disable fragmentation
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
CommandLine cmd;
cmd.Parse (argc, argv);
Gnuplot gnuplot = Gnuplot ("reference-rates_a.png");
Infra_g experiment;
WifiHelper wifi = WifiHelper::Default ();
wifi.SetStandard (WIFI_PHY_STANDARD_80211g);
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
Gnuplot2dDataset dataset;
wifiMac.SetType ("ns3::AdhocWifiMac");
NS_LOG_DEBUG ("54");
experiment = Infra_g ("54mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("OfdmRate54Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("48");
experiment = Infra_g ("48mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("OfdmRate48Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("36");
experiment = Infra_g ("36mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("OfdmRate36Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("24");
experiment = Infra_g ("24mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("OfdmRate24Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("18");
experiment = Infra_g ("18mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("OfdmRate18Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("12");
experiment = Infra_g ("12mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("OfdmRate12Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("9");
experiment = Infra_g ("9mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("OfdmRate9Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("6");
experiment = Infra_g ("6mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("OfdmRate6Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
gnuplot.GenerateOutput (std::cout);
/*
gnuplot = Gnuplot ("rate-control_a.png");
wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
NS_LOG_DEBUG ("arf");
experiment = Infra_g ("arf");
wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("aarf");
experiment = Infra_g ("aarf");
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("aarf-cd");
experiment = Infra_g ("aarf-cd");
wifi.SetRemoteStationManager ("ns3::AarfcdWifiManager");
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("cara");
experiment = Infra_g ("cara");
wifi.SetRemoteStationManager ("ns3::CaraWifiManager");
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("rraa");
experiment = Infra_g ("rraa");
wifi.SetRemoteStationManager ("ns3::RraaWifiManager");
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("ideal");
experiment = Infra_g ("ideal");
wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
gnuplot.GenerateOutput (std::cout);
*/
return 0;
}