Two-ray ground issue

741 views
Skip to first unread message

Jacqueline

unread,
May 24, 2012, 6:53:22 AM5/24/12
to ns-3-users, tomh...@mac.com
Hello there,

I'm a recent ns-3 user setting up a simple wireless communication
scenario with 9 nodes in a row, 100 meters apart, where node 0 is a
UDP echo client trying to communicate with node 8, using the GPSR
routing protocol. It works as expected until I add the Two-ray ground
propagation loss model (with all its default parameters). In the
latter case, when I check the .pcap files, no UDP echos or ARPs seem
to be transmitted. I can only find hello messages. Am I missing
something?

Just in case, my code is shown below:

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */

#include "ns3/gpsr-module.h"
#include "ns3/core-module.h"
#include "ns3/mobility-module.h"
#include "ns3/ns2-mobility-helper.h"
#include "ns3/wifi-module.h"
#include "ns3/network-module.h"
#include "ns3/config-store-module.h"
#include "ns3/internet-module.h"
#include "ns3/gpsr-helper.h"
#include "ns3/applications-module.h"
#include "ns3/packet.h"
#include "ns3/header.h"
#include "ns3/udp-header.h"
#include "ns3/ipv4-header.h"
#include "ns3/ipv4-address.h"
#include "ns3/packet-metadata.h"

#include "ns3/object.h"
#include "ns3/uinteger.h"
#include "ns3/traced-value.h"

#include <ns3/phy-signal-tag.h>
#include "ns3/netanim-module.h"

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

NS_LOG_COMPONENT_DEFINE ("static-example");

using namespace ns3;

class GpsrExample
{
public:
GpsrExample ();
/// Configure script parameters, \return true on successful
configuration
bool Configure (int argc, char **argv);
/// Run simulation
void Run ();
/// Report results
void Report (std::ostream & os);

private:
///\name parameters
//\{
/// Number of nodes
uint32_t size;
/// Width of the Node Grid
uint32_t gridWidth;
/// Distance between nodes, meters
double step;
/// Simulation time, seconds
double totalTime;
/// Write per-device PCAP traces if true
bool pcap;
//\}

///\name network
//\{
NodeContainer nodes;
NetDeviceContainer devices;
Ipv4InterfaceContainer interfaces;
//\}

private:
void CreateNodes ();
void CreateDevices ();
void InstallInternetStack ();
void InstallApplications ();
};

static void
WifiMacRxTrace (std::ostream *os, std::string context, Ptr<const
Packet> p)
{
Ptr<Packet> copy = p->Copy ();
PhySignalTag t;

if (p->PeekPacketTag (t))
{
*os << *p << " | ";
t.Print(*os);
*os << std::endl;
}
}

int main (int argc, char **argv)
{
GpsrExample test;

if (! test.Configure(argc, argv))
NS_FATAL_ERROR ("Configuration failed. Aborted.");

test.Run ();
test.Report (std::cout);

return 0;
}

//-----------------------------------------------------------------------------
GpsrExample::GpsrExample () :
// Number of Nodes
size (9),
// Grid Width
gridWidth(9),
// Distance between nodes
step (100),
// Simulation time
totalTime (180),
// Generate capture files for each node
pcap (true)

{
}

bool
GpsrExample::Configure (int argc, char **argv)
{
// Enable GPSR logs by default. Comment this if too noisy
//LogComponentEnable("GpsrRoutingProtocol", LOG_LEVEL_ALL);

Packet::EnablePrinting();

SeedManager::SetSeed(12345);
CommandLine cmd;

cmd.AddValue ("pcap", "Write PCAP traces.", pcap);
cmd.AddValue ("size", "Number of nodes.", size);
cmd.AddValue ("time", "Simulation time, s.", totalTime);
cmd.AddValue ("step", "Grid step, m", step);

cmd.Parse (argc, argv);
return true;
}

void
GpsrExample::Run ()
{
// Config::SetDefault
("ns3::WifiRemoteStationManager::RtsCtsThreshold", UintegerValue
(1)); // enable rts cts all the time.
CreateNodes ();
CreateDevices ();
InstallInternetStack ();
InstallApplications ();

GpsrHelper gpsr;
gpsr.Install ();

std::cout << "Starting simulation for " << totalTime << " s ...\n";

// Enable logging
// LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_DEBUG);

std::string logFile = "/home/jacqueline/Desktop/gpsr/ns3-gpsr/mylogs/
static-tests/logs/static-example.log";

// open log file for output
std::ofstream os;
os.open (logFile.c_str());

Config::Connect ("NodeList/8/DeviceList/*/$ns3::WifiNetDevice/Mac/
MacRx", MakeBoundCallback (&WifiMacRxTrace, &os));

// Creates the animation object and configure for specified output
AnimationInterface anim ("animation.xml");

Simulator::Stop (Seconds (totalTime));
Simulator::Run ();
Simulator::Destroy ();
}

void
GpsrExample::Report (std::ostream &)
{
}

void
GpsrExample::CreateNodes ()
{
std::cout << "Creating " << (unsigned)size << " nodes.\n";
nodes.Create (size);

for (uint32_t i = 0; i < size; ++i)
{
std::ostringstream os;
os << "node-" << i;
Names::Add (os.str (), nodes.Get (i));
}

MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (step),
"DeltaY", DoubleValue (step),
"GridWidth", UintegerValue
(gridWidth),
"LayoutType", StringValue
("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (nodes);
}

void
GpsrExample::CreateDevices ()
{
WifiHelper wifi = WifiHelper::Default ();
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default
();

wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss
("ns3::TwoRayGroundPropagationLossModel");
wifiPhy.SetChannel (wifiChannel.Create ());

NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifiMac.SetType ("ns3::AdhocWifiMac");

wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold",
UintegerValue (0));
devices = wifi.Install (wifiPhy, wifiMac, nodes);

if (pcap)
{
wifiPhy.EnablePcapAll (std::string ("gpsr"));
}
}

void
GpsrExample::InstallInternetStack ()
{
GpsrHelper gpsr;
InternetStackHelper stack;
stack.SetRoutingHelper (gpsr);
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.0.0.0", "255.0.0.0");
interfaces = address.Assign (devices);
}

void
GpsrExample::InstallApplications ()
{
uint16_t port = 4000;
uint32_t packetSize = 512;
uint32_t maxPacketCount = 1000;
Time interPacketInterval = Seconds (0.5);

// Set-up a server Application on node 8.
UdpEchoServerHelper server1 (port);
uint16_t server1Position = 8;
ApplicationContainer apps = server1.Install
(nodes.Get(server1Position));
apps.Start (Seconds (1.0));
apps.Stop (Seconds (totalTime-0.1));

// Set-up a client Application, connected to 'server1', on node 0.
UdpEchoClientHelper client (interfaces.GetAddress (server1Position),
port);
client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
client.SetAttribute ("Interval", TimeValue (interPacketInterval));
client.SetAttribute ("PacketSize", UintegerValue (packetSize));
uint16_t clientPosition = 0;
apps = client.Install (nodes.Get (clientPosition));
apps.Start (Seconds (2.0));
apps.Stop (Seconds (totalTime-0.1));
}

Thank you in advance :)

Konstantinos

unread,
May 24, 2012, 9:59:37 AM5/24/12
to ns-3-...@googlegroups.com, tomh...@mac.com


On Thursday, 24 May 2012 11:53:22 UTC+1, Jacqueline wrote:
Hello there,

I'm a recent ns-3 user setting up a simple wireless communication
scenario with 9 nodes in a row, 100 meters apart, where node 0 is a
UDP echo client trying to communicate with node 8, using the GPSR
routing protocol. It works as expected until I add the Two-ray ground
propagation loss model (with all its default parameters). In the
latter case, when I check the .pcap files, no UDP echos or ARPs seem
to be transmitted. I can only find hello messages. Am I missing
something?

Perhaps you haven't set up TwoRayGround parameters correctly in order to have connectivity between two nodes (they might be out of range).
The HELLO messages you say are received from the neighboring nodes?

The default values of TwoRayGround prog. model might not allow 100m communication range.
You have to adjust Tx/Rx gains and/or Rx sensitivity and/or other parameters of the model.

Jacqueline Jardim

unread,
May 24, 2012, 1:04:30 PM5/24/12
to Tom Hewer - .Mac, ns-3-users
Tom, first of all, thank you for your quick response.

I did try it but it did not do the trick. Is there anything else that might be influencing/increasing the packet loss?
I've been trying and trying, and can't seem to get there.

Cheers,
Jacqueline

On Thu, May 24, 2012 at 2:47 PM, Tom Hewer - .Mac <tomh...@mac.com> wrote:
Hi,

Having had a brief look at your code, it could be the default instantiation of the wifiChannel.

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();

Looking at the code (yans-wifi-helper.cc) the default constructor adds a log distance propagation loss model ("helper.AddPropagationLoss ("ns3::LogDistancePropagationLossModel");" on line 95).
When you then add a two ray ground model to this, they work together, and so I imagine the propagation loss is large.

If you create a wifiChannel object and then manually set the propagation loss and delay manually, it should work.

YansWifiChannelHelper wifiChannel;
wifiChannel.AddPropagationLoss("ns3::TwoRayGroundPropagationLossModel");
wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
  
Hope that points you in the right direction,

Thanks,

Tom.

Jacqueline Jardim

unread,
May 28, 2012, 4:55:48 PM5/28/12
to Tom Hewer - .Mac, ns-3-users
Hi there Tom,

No problem. Thank you for your reply.

You were right about the default instantiation of the wifiChannel. In the meantime, I realized that my nodes do not have a Z coordinate value defined + the default "HeightAboveZ" attribute is set to 0. So all I had to do was add some height to the antenna and it works just fine.

Thank you for your time, greatly appreciated!

Kind regards,
Jacqueline

On Mon, May 28, 2012 at 12:53 PM, Tom Hewer - .Mac <tomh...@mac.com> wrote:
Hi,

Sorry I haven't come back to you sooner.  The only thing I can suggest is adding the trace sources to the MAC and PHY models, to see whether the packets are being dropped.

Also bear in mind that the two-ray ground reflection model only uses the two-ray equation above the crossover distance, which depends upon the lambda of the frequency being used and the distance between nodes (as described in http://www.nsnam.org/doxygen-release/classns3_1_1_two_ray_ground_propagation_loss_model.html).

Sorry not to be more helpful, but I am no longer working with the latest version of NS3 so it could be down to a change since v.3.9.

Best Regards,

Tom.
Reply all
Reply to author
Forward
0 new messages