simulation in ns3

504 views
Skip to first unread message

sahar h.

unread,
Apr 20, 2010, 3:45:14 AM4/20/10
to ns-3-...@googlegroups.com
hiii, i'm simulating a wireless network in which there are multiple nodes. those nodes have to send packets to a specific node(a) and then node (a )has to send all packets received from all other nodes to the base station. can any one help me to simluate this.
thanks in advance
sahar



The New Busy is not the old busy. Search, chat and e-mail from your inbox. Get started.

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.

Kim Højgaard-Hansen

unread,
Apr 20, 2010, 7:33:52 AM4/20/10
to ns-3-...@googlegroups.com
Look at the examples released with ns-3

there is some easy to understand Python examples, in examples/wireless/

/Kim

Craig Dowell

unread,
Apr 20, 2010, 12:32:51 PM4/20/10
to ns-3-...@googlegroups.com

> hiii, i'm simulating a wireless network in which there are multiple
> nodes. those nodes have to send packets to a specific node(a) and then
> node (a )has to send all packets received from all other nodes to the
> base station. can any one help me to simluate this.
> thanks in advance
> sahar

The first thing to do is understand the system. If you have not gone
through the ns-3 tutorial I would do that first. See,

http://www.nsnam.org/docs/tutorial.html

There are lots of example files in the distribution as well, some of
which will do almost what you want.

There are HOWTOs available to help you out:

http://www.nsnam.org/wiki/index.php/HOWTOs

and I think

http://www.nsnam.org/wiki/index.php/HOWTO_make_and_use_a_new_application

will probably be very helpful to you.

-- Craig

Sahar

unread,
Apr 22, 2010, 3:38:10 AM4/22/10
to ns-3-users
thanks for helping me.
i wrote my code but i dont know why there is no packets generated at
all.
please help me to find where is the error
my code is:
#include <string.h>
#include "ns3/node.h"
#include <fstream>
#include <iostream>
#include "ns3/core-module.h"
#include "ns3/helper-module.h"
#include "ns3/node-module.h"
#include "ns3/simulator-module.h"
#include "ns3/mobility-module.h"
#include "ns3/wifi-module.h"
#include "ns3/position-allocator.h"
#include "ns3/random-variable.h"
#include "ns3/contrib-module.h"
static bool g_verbose = true;
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("Algorithme");
void
DevTxTrace (std::string context, Ptr<const Packet> p)
{
if (g_verbose)
{
std::cout << " TX p: " << *p << std::endl;
}
}

void
DevRxTrace (std::string context, Ptr<const Packet> p)
{
if (g_verbose)
{
std::cout << " RX p: " << *p << std::endl;
}
}

void
PhyRxOkTrace (std::string context, Ptr<const Packet> packet, double
snr, WifiMode mode, enum WifiPreamble preamble)
{
if (g_verbose)
{
std::cout << "PHYRXOK mode=" << mode << " snr=" << snr << " "
<<
*packet << std::endl;
}
}

void
PhyRxErrorTrace (std::string context, Ptr<const Packet> packet,
double
snr)
{
if (g_verbose)
{
std::cout << "PHYRXERROR snr=" << snr << " " << *packet <<
std::endl;
}
}

void
PhyTxTrace (std::string context, Ptr<const Packet> packet, WifiMode
mode, WifiPreamble preamble, uint8_t txPower)
{
if (g_verbose)
{
std::cout << "PHYTX mode=" << mode << " " << *packet <<
std::endl;
}
}

void
PhyStateTrace (std::string context, Time start, Time duration, enum
WifiPhy::State state)
{
if (g_verbose)
{
std::cout << " state=" << state << " start=" << start << "
duration=" << duration << std::endl;
}
}

int
main (int argc, char *argv[])
{
uint32_t i;
Packet::EnablePrinting ();
// enable rts cts all the time.
Config::SetDefault
("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue
("0"));
// disable fragmentation
Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold",
StringValue("2200"));
CommandLine cmd;
cmd.AddValue ("verbose", "Print trace information if true",
g_verbose);
cmd.AddValue ("verbose", "Tell echo applications to log if true",
g_verbose);
cmd.Parse (argc,argv);
if (g_verbose)
{
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
WifiHelper wifi = WifiHelper::Default ();
NodeContainer wifiNodes;
NodeContainer basestation;
NetDeviceContainer wifiDevices,basestationDevices;
PacketSocketHelper packetSocket;
packetSocket.Install(wifiNodes);
packetSocket.Install(basestation);
wifiNodes.Create (7);
basestation.Create(1);
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default
();
wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss("ns3::LogDistancePropagationLossModel");
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
Ssid ssid = Ssid ("wifi-default");
wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
NqosWifiMacHelper macwifi = NqosWifiMacHelper::Default ();
macwifi.SetType ("ns3::NqstaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
wifiDevices = wifi.Install (wifiPhy, macwifi, wifiNodes);
macwifi.SetType ("ns3::NqapWifiMac", "Ssid", SsidValue (ssid),
"BeaconGeneration", BooleanValue (true),
"BeaconInterval", TimeValue (Seconds (2.5)));
basestationDevices = wifi.Install (wifiPhy, macwifi,basestation);
MobilityHelper mobility;
mobility.SetPositionAllocator("ns3::RandomRectanglePositionAllocator","X",R
andomVariableValue(UniformVariable(0.0,100.0)),"Y",RandomVariableValue(Unif
ormVariable(0.0,100.0)));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiNodes);
mobility.Install (basestation);
PacketSocketAddress socket;
socket.SetAllDevices();
socket.SetPhysicalAddress (basestationDevices.Get (0)->GetAddress
());
socket.SetProtocol (0);
InternetStackHelper internet;
internet.Install (NodeContainer::GetGlobal ());
Ipv4AddressHelper address;
address.SetBase ("10.1.0.0", "255.255.0.0");
Ipv4Address addr;
Ipv4InterfaceContainer wifiInterfaces;
Ipv4InterfaceContainer basestationInterfaces;
wifiInterfaces=address.Assign(wifiDevices);
i=0;
while(i<7)
{
addr=wifiInterfaces.GetAddress(i);
i++;
}

address.SetBase ("10.2.0.0", "255.255.0.0");
basestationInterfaces=address.Assign(basestationDevices);
i=0;
addr=basestationInterfaces.GetAddress(i);
i=0;
ApplicationContainer apps;
PacketSinkHelper sink("ns3::UdpSocketFactory",InetSocketAddress(addr,
1025));
sink.Install(basestation.Get(0));
while(i<7)
{addr=(wifiInterfaces.GetAddress(i));
OnOffHelper onoff ("ns3::UdpSocketFactory",InetSocketAddress(addr,
1025));
apps = onoff.Install (wifiNodes.Get (i));
i++;
apps.Start (Seconds (1.0));
apps.Stop (Seconds (300.0));
}

Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacTx", MakeCallback
(&DevTxTrace));
Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacRx", MakeCallback
(&DevRxTrace));
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxOk",
MakeCallback (&PhyRxOkTrace));
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxError",
MakeCallback (&PhyRxErrorTrace));
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/Tx",
MakeCallback (&PhyTxTrace));
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/State",
MakeCallback (&PhyStateTrace));
Simulator::Stop (Seconds (1000));
std::ofstream ascii;
ascii.open ("Algorithme.tr");
YansWifiPhyHelper::EnableAsciiAll (ascii);
InternetStackHelper::EnableAsciiAll(ascii);
wifiPhy.EnablePcapAll ("Algorithme");
Simulator::Run ();
Simulator::Destroy ();
return 0;
}

and the result of simulation is:
state=IDLE start=40000112000ns duration=2499888000ns
state=TX start=42500000000ns duration=112000ns
PHYTX mode=wifia-6mbs ns3::WifiMacHeader (MGT_BEACON ToDS=0,
FromDS=0,
MoreFrag=0, Retry=0, MoreData=0 Duration/ID=0us,
DA=ff:ff:ff:ff:ff:ff,
SA=00:00:00:00:00:08, BSSID=00:00:00:00:00:08, FragNumber=0,
SeqNumber=18) ns3::MgtProbeResponseHeader (ssid=wifi-default,
rates=[*6mbs 9mbs 12mbs 18mbs 24mbs 36mbs 48mbs 54mbs])
ns3::WifiMacTrailer ()
state=IDLE start=42500112000ns duration=2499888000ns
state=TX start=45000000000ns duration=112000ns
PHYTX mode=wifia-6mbs ns3::WifiMacHeader (MGT_BEACON ToDS=0,
FromDS=0,
MoreFrag=0, Retry=0, MoreData=0 Duration/ID=0us,
DA=ff:ff:ff:ff:ff:ff,
SA=00:00:00:00:00:08, BSSID=00:00:00:00:00:08, FragNumber=0,
SeqNumber=19) ns3::MgtProbeResponseHeader (ssid=wifi-default,
rates=[*6mbs 9mbs 12mbs 18mbs 24mbs 36mbs 48mbs 54mbs])
ns3::WifiMacTrailer ()...
thanks in advance

Craig Dowell

unread,
Apr 22, 2010, 5:24:44 PM4/22/10
to ns-3-...@googlegroups.com

> thanks for helping me.
> i wrote my code but i dont know why there is no packets generated at
> all.
> please help me to find where is the error

Take a look at

http://www.nsnam.org/wiki/index.php/HOWTO_use_NS_LOG_to_find_a_problem

Tabassum Muneer

unread,
May 12, 2018, 1:25:11 AM5/12/18
to ns-3-users

Hi Dear.I am working on Lbt coexistence for Outdoor Scenario.But unable to get Results folder in ns-3 phase-1.Problem which I am facing are shown in figures below. Can you help to resolve this problem
Reply all
Reply to author
Forward
0 new messages