static void phyTrace(std::string context, Ptr<const Packet> packet,uint16_t channelFreqMhz, WifiTxVector wifiTx, MpduInfo mpduInfo, SignalNoiseDbm signalNoise){
std::cout<<context<<"phyTrace...packet received with signal Dbm:"<<wifiTx.GetTxPowerLevel()<<std::endl;
}
int
main (int argc, char *argv[])
{
Time::SetResolution (Time::NS);
bool verbose = true;
uint32_t nWifi = 5;
NodeContainer wifiStaNodes;
wifiStaNodes.Create (nWifi); //STA
NodeContainer wifiApNode;
wifiApNode.Create(1); //AP
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::AarfWifiManager"); //wifihelper
//mac
WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-aqiao");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);
// MobilityHelper
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),// start in x
"MinY", DoubleValue (0.0),// start in y
"DeltaX", DoubleValue (5.0),// internal in x
"DeltaY", DoubleValue (10.0),// internal in y
"GridWidth", UintegerValue (2),//3 point every row
"LayoutType", StringValue ("RowFirst"));//row first
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (0,10, 0, 30)));
mobility.Install (wifiStaNodes);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNode);
InternetStackHelper stack;
stack.Install (wifiApNode);
stack.Install (wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer wifiInterfaces;
wifiInterfaces=address.Assign (staDevices);
address.Assign (apDevices);
//application
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (wifiStaNodes.Get (0));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (wifiInterfaces.GetAddress (0), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (5));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps =
echoClient.Install (wifiStaNodes.Get (nWifi - 1));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Simulator::Stop (Seconds (10.0));
phy.EnablePcap ("wifiwifi", apDevices.Get (0));
AnimationInterface anim("1.xml");
Config::Connect("/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Phy/MonitorSnifferRx",MakeCallback(&phyTrace));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}