Since the code is all in one file, I'd better paste the content here saving the troubles of downloading to read.
---------------------------------------------------------------------------------------------------------------------------------------------------------
#include "ns3/core-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/internet-module.h"
#include "ns3/node-list.h"
#include "ns3/packet-socket-helper.h"
#include "ns3/packet-socket-address.h"
#include "ns3/packet-sink-helper.h"
#include "ns3/network-module.h"
#include "ns3/on-off-helper.h"
#include "ns3/ocb-wifi-mac.h"
#include "ns3/wifi-80211p-helper.h"
#include "ns3/wave-mac-helper.h"
#include "ns3/netanim-module.h"
#include <string.h>
#include <map>
#include <sstream>
#include <iostream>
#include <fstream>
#include <numeric>
using namespace ns3;
class Experiment {
public:
void
Run ()
{
std::string animFile = "htvanet1.xml";
SeedManager::SetSeed (1);
// Create network nodes
NodeContainer nodes;
nodes.Create(3);
std::string phyMode ("OfdmRate6MbpsBW10MHz");
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
Ptr<YansWifiChannel> channel = wifiChannel.Create ();
wifiPhy.SetChannel (channel);
NqosWaveMacHelper wifi80211pMac = NqosWaveMacHelper::Default ();
Wifi80211pHelper wifi80211p = Wifi80211pHelper::Default ();
wifi80211p.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue (phyMode));
NetDeviceContainer devices = wifi80211p.Install (wifiPhy, wifi80211pMac, nodes);
InternetStackHelper internet;
internet.Install (nodes);
Ipv4AddressHelper ipv4;
ipv4.SetBase ("192.168.1.0", "255.255.255.0");
ipv4.Assign (devices);
uint16_t port = 22229;
OnOffHelper beaconOnOff ("ns3::UdpSocketFactory",
Address (InetSocketAddress (Ipv4Address ("255.255.255.255"), port)));
beaconOnOff.SetConstantRate (DataRate ("500kb/s"));
ApplicationContainer app = beaconOnOff.Install (nodes);
app.Start (Seconds (1.0));
app.Stop (Seconds (10.0));
PacketSinkHelper sink ("ns3::UdpSocketFactory",
Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
app = sink.Install (nodes);
app.Start (Seconds (1.0));
app.Stop (Seconds (10.0));
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
positionAlloc->Add (Vector (1.0, 0.0, 0.0));
positionAlloc->Add (Vector (2.0, 0.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (nodes);
Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
MakeCallback (&Experiment::WifiMacTxTrace, this));
Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop",
MakeCallback (&Experiment::WifiMacTxDropTrace, this));
Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
MakeCallback (&Experiment::WifiMacRxTrace, this));
Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop",
MakeCallback (&Experiment::WifiMacRxDropTrace, this));
ns3::Simulator::Stop(ns3::Seconds(5.0));
AnimationInterface anim (animFile);
ns3::Simulator::Run ();
ns3::Simulator::Destroy ();
}
void
WifiMacTxTrace (std::string context, Ptr<const Packet> p)
{
std::cout << "Tx "<< context << std::endl;
}
void
WifiMacTxDropTrace (std::string context, Ptr<const Packet> p)
{
std::cout << "TxDrop "<< context << std::endl;
}
void
WifiMacRxTrace (std::string context, Ptr<const Packet> p)
{
std::cout << "Rx "<< context << std::endl;
}
void
WifiMacRxDropTrace (std::string context, Ptr<const Packet> p)
{
std::cout << "RxDrop "<< context << std::endl;
}
};
int main (int argc, char *argv[])
{
Experiment e;
e.Run();
return 0;
}