Vehicular Ad-hoc NETwork(VANET) beacon broadcast cannot receive

584 views
Skip to first unread message

Rui ZOU

unread,
Oct 28, 2014, 10:33:59 PM10/28/14
to ns-3-...@googlegroups.com
Hi there, I want to simulate the VANET beacon using the onoff application to generate broadcast and the PacketSink to receive the beacon, but in the trace I can only see the sending from the mac layer. I wonder why the broadcast cannot be received. I am using 3.21. The code is attached, please help me. Thanks!
htvanet1.cc

Rui ZOU

unread,
Oct 28, 2014, 11:28:45 PM10/28/14
to ns-3-...@googlegroups.com
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;
}

Konstantinos

unread,
Oct 29, 2014, 6:43:37 AM10/29/14
to ns-3-...@googlegroups.com
Please do not post the code. It is easier for the users to download a single file and test it than looking in a lengthy unstructured post.

Your problem is most probably collisions. All nodes start their broadcast exactly at the same time. See the mailing list and examples for wireless for possible solutions.

Rui ZOU

unread,
Oct 29, 2014, 7:44:03 AM10/29/14
to ns-3-...@googlegroups.com
Thank you so much. It's the first time I put a post, so sorry for posting the code. When I install the broadcast application on only one node, the other two can receive the broadcast, so it's probably because of the collision.
Now I got another question. Since the concurrent transmission happens at the APP layer, shouldn't there be some collision avoidance mechanism at lower layers, especially the MAC layer to assure the transmission?

Konstantinos

unread,
Oct 29, 2014, 8:07:18 AM10/29/14
to ns-3-...@googlegroups.com
The actual problem is related to the ARP mechanism and the not-so-random timers (lack of jitter). So the solution is to give yourself some jitter in the start of the application.
Indeed for MAC layer, there is solution of collision avoidance with DCF but as I said, it is the ARP which causes this particular problem.

Rui ZOU

unread,
Oct 29, 2014, 8:09:58 AM10/29/14
to ns-3-...@googlegroups.com
Thank you again!

Fatma Marzouk

unread,
Feb 22, 2015, 7:13:46 PM2/22/15
to ns-3-...@googlegroups.com
Hello ,

I am really a beginner in ns3 .I tested the CAM broadcast given above code.The problem is that netanim terminated so quickly the visualization saying that simulation was completed,

Thank you in advance  if anyone would help me to know the reason 

Konstantinos

unread,
Feb 23, 2015, 4:01:24 AM2/23/15
to ns-3-...@googlegroups.com
you can increase the simulation time.

Fatma Marzouk

unread,
Feb 28, 2015, 10:57:06 AM2/28/15
to ns-3-...@googlegroups.com
Thank you for the answer and sorry for the delay .
It worked when I installed a mobility model with ns2mobilityhelper .So the problem was using the constant position one
Reply all
Reply to author
Forward
0 new messages