//Topology
// ------> denotes a Wifi Link
u0 u1 u2 ..... ------> AP1
..............
.............. ------> AP2 -----> Server
..............
...u58 u59 u60 ------> AP3
int nWifi = 60;
int nAP = 3;
NodeContainer allNodes;
NodeContainer wifiStaNodes; //User Nodes
wifiStaNodes.Create (nWifi);
allNodes.Add (wifiStaNodes);
NodeContainer wifiApNodes ; //Access Points
wifiApNodes.Create (nAP);
allNodes.Add (wifiApNodes);
NodeContainer wifiServer; //Server
wifiServer.Create (1);
allNodes.Add(wifiServer.Get(0));
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode", StringValue("VhtMcs9"), "ControlMode", StringValue("VhtMcs9"));
wifi.SetStandard (WIFI_PHY_STANDARD_80211af);
channel.AddPropagationLoss("ns3::TwoRayGroundPropagationLossModel","Frequency",DoubleValue(300e+06));
//Setting Physical layer parameters for the User Nodes
phy.Set("TxPowerStart",DoubleValue(20)); // 40mW = 16.02dBm
phy.Set("TxPowerEnd",DoubleValue(20));
phy.Set("TxPowerLevels", UintegerValue(1));
phy.Set("TxGain",DoubleValue(0));
phy.Set("RxGain",DoubleValue(-3));
phy.Set("EnergyDetectionThreshold",DoubleValue(-88));
phy.SetChannel (channel.Create ());
WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-ssid");
NetDeviceContainer staDevices;
mac.SetType ("ns3::StaWifiMac","Ssid", SsidValue (ssid),"ActiveProbing", BooleanValue (false));
staDevices = wifi.Install (phy, mac, wifiStaNodes);
//Setting Physical Layer parameters for Access Points and Server
phy.Set("TxPowerStart",DoubleValue(20)); // 40mW = 16.02dBm
phy.Set("TxPowerEnd",DoubleValue(20));
phy.Set("TxPowerLevels", UintegerValue(1));
phy.Set("TxGain",DoubleValue(30));
phy.Set("RxGain",DoubleValue(0));
phy.Set("EnergyDetectionThreshold",DoubleValue(-78));
NetDeviceContainer apDevices,serverDevice,ap_staDevices;
mac.SetType ("ns3::ApWifiMac","Ssid", SsidValue (ssid));
apDevices = wifi.Install (phy, mac, wifiApNodes); // The APs
serverDevice = wifi.Install (phy, mac, wifiServer); // The Server
mac.SetType ("ns3::StaWifiMac","Ssid", SsidValue (ssid),"ActiveProbing", BooleanValue (false))
ap_staDevices = wifi.Install (phy, mac, wifiApNodes);
// The devices in the APs that are stations to the superior AP
Ptr<BasicEnergySource> energySource = CreateObject<BasicEnergySource>();
Ptr<SimpleDeviceEnergyModel> energyModel = CreateObject<SimpleDeviceEnergyModel>();
energySource->SetInitialEnergy (100);
energyModel->SetEnergySource (energySource);
energySource->AppendDeviceEnergyModel (energyModel);
energyModel->SetCurrentA (20);
// aggregate energy source to node
wifiServer.Get(0)->AggregateObject (energySource);
// Install internet stack
InternetStackHelper stack;
stack.Install (allNodes);
// Install Ipv4 addresses
Ipv4AddressHelper address;
address.SetBase ("10.1.0.0", "255.255.192.0");
address.Assign (staDevices);
address.Assign (apDevices);
address.SetBase ("10.2.0.0", "255.255.192.0");
Ipv4InterfaceContainer serverInterface;
serverInterface = address.Assign (serverDevice);
address.Assign (ap_staDevices);
// Install applications
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (wifiServer.Get(0));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (5.0));
UdpEchoClientHelper echoClient (serverInterface.GetAddress(0), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (10));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (3)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (wifiStaNodes);
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (5.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Simulator::Stop (Seconds (4.0));