Jacqueline
unread,May 24, 2012, 6:53:22 AM5/24/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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 :)