I am trying to simulate wireless communication using WiFi with the topology shown in the attached file with ns-3.
int main (int argc, char *argv[])
{
std::string phyMode ("DsssRate1Mbps");
uint32_t staNum = 3;// consumer
int apNum = 3;// number of AP nodes
int range = 10;// meter
double endtime = 2000.0;
CommandLine cmd;
cmd.Parse (argc, argv);
////// Reading file for topology setup
AnnotatedTopologyReader topologyReader("", 1);
topologyReader.SetFileName("src/ndnSIM/examples/LScale-topo.txt");
topologyReader.Read();
////// Getting containers for the producer/wifi-ap
Ptr<Node> producer = Names::Find<Node>("root");
Ptr<Node> wifiApNodes[3] = {Names::Find<Node>("ap1"),
Names::Find<Node>("ap2"),
Names::Find<Node>("ap3")};
Ptr<Node> routers[4] = {Names::Find<Node>("r1"),
Names::Find<Node>("r2"),
Names::Find<Node>("r3"),
Names::Find<Node>("r0")};
////// disable fragmentation, RTS/CTS for frames below 2200 bytes and fix non-unicast data rate
Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue("2200"));
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200"));
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue(phyMode));
////// The below set of helpers will help us to put together the wifi NICs we want
WifiHelper wifi;
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
////// This is one parameter that matters when using FixedRssLossModel
////// set it to zero; otherwise, gain will be added
// wifiPhy.Set ("RxGain", DoubleValue (0) );
////// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
// wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel");
////// The below FixedRssLossModel will cause the rss to be fixed regardless of the distance between the two stations, and the transmit power
// wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue(rss));
////// the following has an absolute cutoff at distance > range (range == radius)
wifiChannel.AddPropagationLoss ("ns3::RangePropagationLossModel",
"MaxRange", DoubleValue(range));
wifiPhy.SetChannel (wifiChannel.Create ());
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue (phyMode),
"ControlMode", StringValue (phyMode));
////// Setup the rest of the upper mac
////// Setting SSID, optional. Modified net-device to get Bssid, mandatory for AP unicast
Ssid ssid = Ssid ("wifi-default");
// wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
////// Add a non-QoS upper mac of STAs, and disable rate control
NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default ();
////// Active associsation of STA to AP via probing.
wifiMacHelper.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (true),
"ProbeRequestTimeout", TimeValue(Seconds(0.25)));
////// Creating 2 mobile nodes
NodeContainer consumers;
consumers.Create(staNum);
// 1. Install WiFi
NetDeviceContainer staDevice = wifi.Install (wifiPhy, wifiMacHelper, consumers);
NetDeviceContainer devices = staDevice;
//NetDeviceContainer staDevice1 = wifi.Install (wifiPhy, wifiMacHelper, consumers[1]);
//devices.Add (staDevice1);
////// Setup AP.
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid),
"BeaconGeneration", BooleanValue(false));
for (int i = 0; i < apNum; i++)
{
NetDeviceContainer apDevice = wifi.Install (wifiPhy, wifiMac, wifiApNodes[i]);
devices.Add (apDevice);
}
////// Note that with FixedRssLossModel, the positions below are not
////// used for received signal strength.
////// set positions for APs
MobilityHelper sessile;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
int XposAp = 0;
for (int i=0; i < apNum; i++) {
positionAlloc->Add(Vector(10+XposAp, -10, 0.0));
XposAp += 20;
}
sessile.SetPositionAllocator (positionAlloc);
for (int i = 0; i < apNum; i++) {
sessile.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
sessile.Install (wifiApNodes[i]);
}
////// Setting mobility model and movement parameters for mobile nodes
////// ConstantVelocityMobilityModel is a subclass of MobilityModel
MobilityHelper sessileConsumer;
Ptr<ListPositionAllocator> positionConsumer = CreateObject<ListPositionAllocator> ();
int XposSta = 0;
for (int i=0; i<int(staNum); i++){
positionConsumer->Add(Vector(10+XposSta, 0.0, 0.0));
XposSta += 20;
}
sessileConsumer.SetPositionAllocator (positionConsumer);
for (int i=0; i<int(staNum); i++){
sessileConsumer.SetMobilityModel("ns3::ConstantVelocityMobilityModel");
sessileConsumer.Install(consumers.Get(i));
}
/*
////// Setting each sessileConsumer 100m apart from each other
int nxt = 0;
for (uint32_t i=0; i<staNum ; i++) {
Ptr<ConstantVelocityMobilityModel> cvmm = consumers.Get(i)->GetObject<ConstantVelocityMobilityModel> ();
Vector pos (0-nxt, 0, 0);
Vector vel (speed, 0, 0);
cvmm->SetPosition(pos);
cvmm->SetVelocity(vel);
nxt += 100;
}
*/