Kazi Mehedi Hasan
unread,Mar 31, 2011, 11:04:14 AM3/31/11Sign 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
Hello,
Considering the topology below,I am trying to simulate a Mesh network
where node 0 wants to send data to node
(0)--------------
>(1)------------------->(2)
node 2 via node 1.Node 0 does not have node 2 in its transmission
range so node 1 has to forward data to node 2.
The problem is, when the data rate in on-off application is in between
1 to 6mbps,the throughput is not decreasing in the second hop when
compared with the first hop,rather the throughput is increased in the
second hop.I find it very unusual because at second
hop,theoretically,the throughput should drop(near about 50% from its
first hop).
What might the reason behind this?
However,when I used data rate greater than 6 mbps,the throughput is
decreasing.Buffer-size might be responsible for this.I changed the
buffer size to different values and found that at a certain value the
throughput decreases almost to zero.I am attaching my code below.
Can anyone suggest why the network is behaving like this?
Thanks in advance.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#include "ns3/core-module.h"
#include "ns3/simulator-module.h"
#include "ns3/node-module.h"
#include "ns3/helper-module.h"
#include "ns3/global-routing-module.h"
#include "ns3/wifi-module.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/mesh-module.h"
#include "ns3/propagation-loss-model.h"
#include "ns3/propagation-delay-model.h"
#include "ns3/mobility-module.h"
#include "ns3/mesh-helper.h"
#include "ns3/constant-rate-wifi-manager.h"
#include "ns3/packet-socket-helper.h"
#include "ns3/flow-monitor.h"
#include <iostream>
#include <sstream>
#include <fstream>
using namespace ns3;
//Send info out on screen
NS_LOG_COMPONENT_DEFINE ("TestMeshScript");
//Declare broad class
class MeshTest
{
//Declare global functions
public:
/// Init test
MeshTest ();
/// Configure test from command line arguments
void Configure (int argc, char ** argv);
/// Run test
int Run ();
//Declare parameters only for particular use
private:
int m_nodes;
int m_channel;
uint16_t m_servPort;
double m_randomStart;
double m_totalTime;
double m_packetInterval;
uint32_t m_packetSize;
uint32_t m_nIfaces;
bool m_chan;
bool m_pcap;
bool m_enableFlowMonitor;
std::string m_stack;
std::string m_root;
/// List of network nodes
NodeContainer nodes;
/// List of all mesh point devices
NetDeviceContainer meshDevices;
//Addresses of interfaces:
Ipv4InterfaceContainer interfaces;
// MeshHelper. Report is not static methods
MeshHelper mesh;
//Declare functions for particular use
private:
/// Create nodes and setup their mobility
void CreateNodes ();
/// Install internet m_stack on nodes
void InstallInternetStack ();
/// Install applications
void InstallApplication ();
/// Print mesh devices diagnostics
void Report ();
};
static uint32_t m_bytesTotal;
static void
Throughput () // in Mbps calculated every 10s
{
double mbps = (((m_bytesTotal * 8.0) / 1000000/10));
Time time = Simulator::Now ();
m_bytesTotal = 0;
std::cout << "Time "<< time.GetSeconds() << " Throughput "<< mbps <<
"Mbps "<< std::endl;
Simulator::Schedule (Seconds (10), &Throughput);
}
void
PhyRxOkTrace (std::string context, Ptr<const Packet> packet, double
snr,
WifiMode mode, enum WifiPreamble preamble)//Function to be called when
the PHY layer of the considered device receives a frame
{
Ptr<Packet> m_currentPacket;
WifiMacHeader hdr;
m_currentPacket = packet->Copy();
m_currentPacket->RemoveHeader (hdr);
if (hdr.IsData()){
m_bytesTotal += m_currentPacket->GetSize ();
}
}
MeshTest::MeshTest () :
m_nodes(3),
m_randomStart (0.1),
m_servPort(5001),
m_totalTime (110.0),
m_channel (1),
m_packetInterval (0.1),
m_packetSize (1500),
m_nIfaces (1),
m_enableFlowMonitor(true),
//m_chan (true),
m_pcap (false),
m_stack ("ns3::Dot11sStack"),
m_root ("ff:ff:ff:ff:ff:ff")
{
}
void
MeshTest::Configure (int argc, char *argv[])
{
CommandLine cmd;
/*
* As soon as starting node means that it sends a beacon,
* simultaneous start is not good.
*/
//cmd.AddValue("nodes", "Number of nodes in the network", m_nodes);
//cmd.AddValue("server", "Node server", m_server);
//cmd.AddValue("client", "Node client", m_client);
//cmd.AddValue("start", "Maximum random start delay, seconds. [0.1
s]", m_randomStart);
//cmd.AddValue("time", "Simulation time, seconds [100 s]",
m_totalTime);
//cmd.AddValue("channel", "Select channel of transmision", m_channel);
//cmd.AddValue("pcap", "Enable PCAP traces on interfaces. [0]",
m_pcap);
//cmd.AddValue("seed", "Set the seed for random values", m_seed);
//cmd.AddValue("stack", "Type of protocol stack. ns3::Dot11sStack by
default", m_stack);
//cmd.AddValue("root", "Mac address of root mesh point in HWMP",
m_root);
//print the value of the asked attributes
cmd.Parse (argc, argv);
//To ouput a msg of level LOG_DEBUG
NS_LOG_DEBUG ("Simulation time: " << m_totalTime << " s");
}
void
MeshTest::CreateNodes ()
{
//Declare Propagation loss and physical layer parameters
double m_EnergyDet = -76;
double m_ccath = -99.0;
double m_TxGain = 5.0;
double m_RxGain = 5.0;
double m_txpower = 30 ;
//Create 8 nodes
nodes.Create (m_nodes);
// Configure YansWifiphy layer with default values
WifiHelper wifi ;
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
//wifi.SetRemoteStationManager
("ns3::ConstantRateWifiManager","DataMode", StringValue
("wifia-54mbs"));
wifiPhy.Set("EnergyDetectionThreshold", DoubleValue
(m_EnergyDet)); //defulat val is -96dBm
wifiPhy.Set("CcaMode1Threshold", DoubleValue (m_ccath)); //default
val is -99dBm
wifiPhy.Set("TxGain", DoubleValue (m_TxGain)); // Use 5.0 to extend
range to about 300 meters
wifiPhy.Set("RxGain", DoubleValue (m_RxGain)); // Use 5.0 to extend
range to about 300 meters
wifiPhy.Set("TxPowerLevels", UintegerValue (1) );
wifiPhy.Set("TxPowerEnd", DoubleValue (m_txpower) ); //default val
is 16.0206dBm
wifiPhy.Set("TxPowerStart", DoubleValue (m_txpower) ); //default val
is 16.0206dBm
wifiPhy.Set("RxNoiseFigure", DoubleValue (7.0) ); //defulat val is
7dB
wifiPhy.Set("ChannelNumber", UintegerValue(m_channel));
// Configure YansWifichannel with default values
YansWifiChannelHelper wifiChannel =
YansWifiChannelHelper::Default();
Config::SetDefault
("ns3::LogDistancePropagationLossModel::Exponent",DoubleValue(3.0));
Config::SetDefault
("ns3::LogDistancePropagationLossModel::ReferenceDistance",DoubleValue(1));
Config::SetDefault
("ns3::LogDistancePropagationLossModel::ReferenceLoss",DoubleValue(50.0));
//
wifiChannel.AddPropagationLoss("ns3::RandomPropagationLossModel","Variable",RandomVariableValue(NormalVariable(0,4)));
Config::SetDefault("ns3::RandomPropagationDelayModel::Variable",RandomVariableValue(UniformVariable(0,10)));
wifiPhy.SetChannel (wifiChannel.Create ());
/*
* Create mesh helper and set stack installer to it
* Stack installer creates all needed protocols and install them to
* mesh point device
*/
mesh = MeshHelper::Default ();
if (!Mac48Address (m_root.c_str ()).IsBroadcast ())
{
mesh.SetStackInstaller (m_stack, "Root", Mac48AddressValue
(Mac48Address (m_root.c_str ())));
}
else
{
//If root is not set, we do not use "Root" attribute, because it
//is specified only for 11s
mesh.SetStackInstaller (m_stack);
}
mesh.SetSpreadInterfaceChannels (MeshHelper::ZERO_CHANNEL);
mesh.SetMacType ("RandomStart", TimeValue
(Seconds(m_randomStart)));
// Set number of interfaces - default is single-interface mesh point
mesh.SetNumberOfInterfaces (m_nIfaces);
// Install protocols and return container if MeshPointDevices
meshDevices = mesh.Install (wifiPhy, nodes);
// Setup mobility - static grid topology
MobilityHelper mobility;
ns3::ListPositionAllocator *listPosNod = new
ns3::ListPositionAllocator();
listPosNod->Add(*new ns3::Vector3D(0.0,0.0,0.0));//------0
listPosNod->Add(*new ns3::Vector3D(150.0,0.0,0.0));//----1
listPosNod->Add(*new ns3::Vector3D(300.0,0.0,0.0));//----2
/*listPosNod->Add(*new ns3::Vector3D(450.0,0.0,0.0));//----3*/
mobility.SetPositionAllocator(listPosNod);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (nodes);
//Set channel 1 on first interface of device 0
Ptr<Node> node = nodes.Get(0);
NS_LOG_INFO("number of NICs " << node->GetNDevices());
Ptr<Object> interface1 = node->GetDevice(0);
Ptr<MeshPointDevice> mp1 = interface1-
>GetObject<MeshPointDevice>();
NS_LOG_INFO("Node Interface Index " << mp1->GetIfIndex());
Ptr<Object> wifiNetDeviceObject = mp1->GetInterface(1);
Ptr<WifiNetDevice> wifiNetDeviceInterface =
wifiNetDeviceObject->GetObject<WifiNetDevice>();
Ptr<Object> wifiMacObject = wifiNetDeviceInterface->GetMac();
Ptr<MeshWifiInterfaceMac> meshWifiInterfaceMac = wifiMacObject-
>GetObject<MeshWifiInterfaceMac>();
NS_LOG_INFO("Get Frequency Channel Id " <<
meshWifiInterfaceMac->GetFrequencyChannel());
meshWifiInterfaceMac->SwitchFrequencyChannel(1);
NS_LOG_INFO("Get Frequency Channel Id " <<
meshWifiInterfaceMac->GetFrequencyChannel());
//Setting channel 1 on device 1
node = nodes.Get(1);
NS_LOG_INFO("number of NICs " << node->GetNDevices());
interface1 = node->GetDevice(0);
mp1 = interface1->GetObject<MeshPointDevice>();
NS_LOG_INFO("Node Interface Index " << mp1->GetIfIndex());
wifiNetDeviceObject = mp1->GetInterface(1);
wifiNetDeviceInterface = wifiNetDeviceObject-
>GetObject<WifiNetDevice>();
Ptr<Object> wifiMacObject2 =wifiNetDeviceInterface->GetMac();
meshWifiInterfaceMac = wifiMacObject2-
>GetObject<MeshWifiInterfaceMac>();
NS_LOG_INFO("Get Frequency Channel Id " <<
meshWifiInterfaceMac->GetFrequencyChannel());
meshWifiInterfaceMac->SwitchFrequencyChannel(1);
NS_LOG_INFO("Get Frequency Channel Id " <<
meshWifiInterfaceMac->GetFrequencyChannel());
//Set channel 1 on first interface of device 2
node = nodes.Get(2);
NS_LOG_INFO("number of NICs " << node->GetNDevices());
interface1 = node->GetDevice(0);
mp1 = interface1->GetObject<MeshPointDevice>();
NS_LOG_INFO("Node Interface Index " << mp1->GetIfIndex());
wifiNetDeviceObject = mp1->GetInterface(1);
wifiNetDeviceInterface = wifiNetDeviceObject-
>GetObject<WifiNetDevice>();
Ptr<Object> wifiMacObject3 =wifiNetDeviceInterface->GetMac();
meshWifiInterfaceMac = wifiMacObject3-
>GetObject<MeshWifiInterfaceMac>();
NS_LOG_INFO("Get Frequency Channel Id " <<
meshWifiInterfaceMac->GetFrequencyChannel());
meshWifiInterfaceMac->SwitchFrequencyChannel(1);
NS_LOG_INFO("Get Frequency Channel Id " <<
meshWifiInterfaceMac->GetFrequencyChannel());
/*
//Set channel 1 on first interface of device 3
node = nodes.Get(3);
NS_LOG_INFO("number of NICs " << node->GetNDevices());
interface1 = node->GetDevice(0);
mp1 = interface1->GetObject<MeshPointDevice>();
NS_LOG_INFO("Node Interface Index " << mp1->GetIfIndex());
wifiNetDeviceObject = mp1->GetInterface(1);
wifiNetDeviceInterface = wifiNetDeviceObject-
>GetObject<WifiNetDevice>();
Ptr<Object> wifiMacObject4 =wifiNetDeviceInterface->GetMac();
meshWifiInterfaceMac = wifiMacObject4-
>GetObject<MeshWifiInterfaceMac>();
NS_LOG_INFO("Get Frequency Channel Id " <<
meshWifiInterfaceMac->GetFrequencyChannel());
meshWifiInterfaceMac->SwitchFrequencyChannel(1);
NS_LOG_INFO("Get Frequency Channel Id " <<
meshWifiInterfaceMac->GetFrequencyChannel());*/
if (m_pcap)
wifiPhy.EnablePcapAll (std::string ("line-"));
}
void
MeshTest::InstallInternetStack ()
{
InternetStackHelper internetStack;
internetStack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
interfaces = address.Assign (meshDevices);
}
void
MeshTest::InstallApplication ()
{
NS_LOG_INFO ("Create applications.");
// enable rts cts all the time.
Config::SetDefault
("ns3::WifiRemoteStationManager::RtsCtsThreshold",StringValue
("60000"));
// disable fragmentation
Config::SetDefault
("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue
("60000"));
Config::SetDefault ("ns3::TcpSocket::RcvBufSize",
UintegerValue(131072));
Config::SetDefault ("ns3::TcpSocket::InitialCwnd",
UintegerValue(1));
Config::SetDefault ("ns3::TcpSocket::SndBufSize",
UintegerValue(131072));
Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny
(),m_servPort));
PacketSinkHelper sinkHelper
("ns3::TcpSocketFactory",sinkLocalAddress);
ApplicationContainer sinkApp = sinkHelper.Install (nodes.Get(2));//
destination
sinkApp.Start (Seconds (5.0));
sinkApp.Stop (Seconds (110));
// Create the OnOff applications to send TCP to the server
OnOffHelper sourceHelper ("ns3::TcpSocketFactory", Address ());
AddressValue remoteAddress (InetSocketAddress
(interfaces.GetAddress(2), m_servPort));//destination
sourceHelper.SetAttribute ("Remote", remoteAddress);
sourceHelper.SetAttribute ("OnTime", RandomVariableValue
(ConstantVariable (10)));
sourceHelper.SetAttribute ("OffTime", RandomVariableValue
(ConstantVariable(0)));
sourceHelper.SetAttribute ("DataRate", DataRateValue (DataRate
(6e6)));
sourceHelper.SetAttribute ("PacketSize", UintegerValue (1500));
ApplicationContainer appsource;
appsource.Add (sourceHelper.Install (nodes.Get(0))); //source
appsource.Start (Seconds (10));
appsource.Stop (Seconds (110.0));
}
int
MeshTest::Run ()
{
CreateNodes ();
InstallInternetStack ();
InstallApplication ();
Simulator::Schedule (Seconds(m_totalTime), & MeshTest::Report,
this);
Config::Connect ("/NodeList/2/DeviceList/*/Phy/State/RxOk",
MakeCallback
(&PhyRxOkTrace));
Throughput ();
Simulator::Stop (Seconds (m_totalTime));
Ptr<FlowMonitor> flowmon;
FlowMonitorHelper flowmonHelper;
flowmon = flowmonHelper.InstallAll ();
flowmon->SetAttribute("DelayBinWidth", DoubleValue(0.1));
flowmon->SetAttribute("JitterBinWidth", DoubleValue(0.1));
flowmon->SetAttribute("PacketSizeBinWidth",
DoubleValue(20));
Simulator::Run ();
flowmon->SerializeToXmlFile ("parameters.xml", true, true);
Simulator::Destroy ();
return 0;
}
void
MeshTest::Report ()
{
unsigned n (0);
for (NetDeviceContainer::Iterator i = meshDevices.Begin (); i !=
meshDevices.End (); ++i, ++n)
{
std::ostringstream os;
os << "line-report-" << n << ".xml";
std::cerr << "Printing mesh point device #" << n << " diagnostics
to " << os.str () << "\n";
std::ofstream of;
of.open (os.str().c_str());
if (! of.is_open ())
{
std::cerr << "Error: Can't open file " << os.str() << "\n";
return;
}
mesh.Report (*i, of);
of.close ();
}
}
int
main (int argc, char *argv[])
{
MeshTest t;
t.Configure (argc, argv);
return t.Run();
}