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