Reputation: 11
I'm new to ns3 and I'm trying to develop and simulate a wireless load balancer schema with a random
algorithm using ns3. I'm using IEEE 802.11 standard for the simulation; Also, I'm using release 3.35 of ns3.
More precisely, I'm trying to implement:
[IEEE 802.11 links]
[Sender0] --| |--[Receiver0]
[Sender1] --| |--[Receiver1]
[Sender2] --|--(UDP)--> [Load Balancer] --(TCP)-->|--[Receiver2]
[Sender3] --| |--[Receiver3]
[Sender4] --| |--[Receiver4]
Senders use UDP
in order to send their packets to the load balancer. The load balancer use TCP
in order to send received packets to the receivers.
It's obvious that the load balancer should send each packet to just one of the receivers. random
load balancing algorithm is used in this simulation (load balancer randomly chooses one of the receivers and send the received packet to that).
I should calculate the throughput and average end-to-end delay of the network.
Moreover, error rate of the receiver nodes is 0.0001 and bandwidth is 1Mbps.
I've developed the following code so far:
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/internet-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/random-variable-stream.h"
#include "ns3/command-line.h"
#include "ns3/config.h"
#include "ns3/uinteger.h"
#include "ns3/boolean.h"
#include "ns3/string.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/internet-stack-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/udp-echo-helper.h"
#include "ns3/yans-wifi-channel.h"
#include "ns3/constant-position-mobility-model.h"
#include "ns3/propagation-loss-model.h"
#include "ns3/propagation-delay-model.h"
#include "ns3/on-off-helper.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/ipv4-flow-classifier.h"
using namespace ns3;
// Run single 10 seconds experiment
void experiment(bool enableCtsRts, std::string wifiManager)
{
// 0. Enable or disable CTS/RTS
UintegerValue ctsThr = (enableCtsRts ? UintegerValue (100) : UintegerValue (2200));
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", ctsThr);
// 1. Create left, right, and load balancer nodes
NodeContainer router_node;
router_node.Create (1);
NodeContainer left_nodes;
left_nodes.Create (5);
NodeContainer right_nodes;
right_nodes.Create (5);
// 2. Place nodes somehow, this is required by every wireless simulation
for (uint8_t i = 0; i < 5; ++i) {
left_nodes.Get (i)->AggregateObject (CreateObject<ConstantPositionMobilityModel> ());
}
router_node.Get (0)->AggregateObject (CreateObject<ConstantPositionMobilityModel> ());
for (uint8_t i = 0; i < 5; ++i) {
right_nodes.Get (i)->AggregateObject (CreateObject<ConstantPositionMobilityModel> ());
}
// 3. Create propagation loss matrix
Ptr<MatrixPropagationLossModel> lossModel = CreateObject<MatrixPropagationLossModel> ();
lossModel->SetDefaultLoss (60); // set default loss to 60 dB (no link)
lossModel->SetLoss (left_nodes.Get (0)->GetObject<MobilityModel> (), router_node.Get (0)->GetObject<MobilityModel> (), 50); // set symmetric loss l0 <-> r to 50 dB
lossModel->SetLoss (left_nodes.Get (1)->GetObject<MobilityModel> (), router_node.Get (0)->GetObject<MobilityModel> (), 50); // set symmetric loss l1 <-> r to 50 dB
lossModel->SetLoss (left_nodes.Get (2)->GetObject<MobilityModel> (), router_node.Get (0)->GetObject<MobilityModel> (), 50); // set symmetric loss l2 <-> r to 50 dB
lossModel->SetLoss (left_nodes.Get (3)->GetObject<MobilityModel> (), router_node.Get (0)->GetObject<MobilityModel> (), 50); // set symmetric loss l3 <-> r to 50 dB
lossModel->SetLoss (left_nodes.Get (4)->GetObject<MobilityModel> (), router_node.Get (0)->GetObject<MobilityModel> (), 50); // set symmetric loss 14 <-> r to 50 dB
lossModel->SetLoss (right_nodes.Get (0)->GetObject<MobilityModel> (), router_node.Get (0)->GetObject<MobilityModel> (), 50); // set symmetric loss r <-> r0 to 50 dB
lossModel->SetLoss (right_nodes.Get (1)->GetObject<MobilityModel> (), router_node.Get (0)->GetObject<MobilityModel> (), 50); // set symmetric loss r <-> r1 to 50 dB
lossModel->SetLoss (right_nodes.Get (2)->GetObject<MobilityModel> (), router_node.Get (0)->GetObject<MobilityModel> (), 50); // set symmetric loss r <-> r2 to 50 dB
lossModel->SetLoss (right_nodes.Get (3)->GetObject<MobilityModel> (), router_node.Get (0)->GetObject<MobilityModel> (), 50); // set symmetric loss r <-> r3 to 50 dB
lossModel->SetLoss (right_nodes.Get (4)->GetObject<MobilityModel> (), router_node.Get (0)->GetObject<MobilityModel> (), 50); // set symmetric loss r <-> r4 to 50 dB
// 4. Create & setup wifi channel
Ptr<YansWifiChannel> wifiChannel = CreateObject <YansWifiChannel> ();
wifiChannel->SetPropagationLossModel (lossModel);
wifiChannel->SetPropagationDelayModel (CreateObject <ConstantSpeedPropagationDelayModel> ());
// 5. Install wireless devices
WifiHelper wifi;
wifi.SetStandard (WIFI_STANDARD_80211b);
wifi.SetRemoteStationManager ("ns3::" + wifiManager + "WifiManager");
YansWifiPhyHelper wifiPhy;
wifiPhy.SetChannel (wifiChannel);
WifiMacHelper staWifiMac, apWifiMac;
staWifiMac.SetType ("ns3::StaWifiMac");
apWifiMac.SetType ("ns3::ApWifiMac");
NetDeviceContainer left_devices = wifi.Install (wifiPhy, staWifiMac, left_nodes);
NetDeviceContainer router_device = wifi.Install (wifiPhy, apWifiMac, router_node);
NetDeviceContainer right_devices = wifi.Install (wifiPhy, staWifiMac, right_nodes);
// 6. Install TCP/IP stack & assign IP addresses
InternetStackHelper internet;
internet.Install (left_nodes);
internet.Install (router_node);
internet.Install (right_nodes);
Ipv4AddressHelper ipv4_le, ipv4_ro, ipv4_ri;
// Ipv4Address
ipv4_le.SetBase ("10.0.0.0", "255.255.255.0");
ipv4_ro.SetBase ("10.0.1.0", "255.255.255.0");
ipv4_ri.SetBase ("10.0.2.0", "255.255.255.0");
Ipv4InterfaceContainer left_addresses = ipv4_le.Assign (left_devices);
Ipv4InterfaceContainer router_address = ipv4_ro.Assign (router_device);
Ipv4InterfaceContainer right_addresses = ipv4_ri.Assign (right_devices);
// Configure IPv4 address
Ipv4Address addr;
for(int i = 0 ; i < 5; i++)
{
addr = left_addresses.GetAddress(i);
std::cout << " Left Node " << i+1 << "\t "<< "IP Address "<< addr << std::endl;
}
for(int i = 0 ; i < 5; i++)
{
addr = right_addresses.GetAddress(i);
std::cout << " Right Node " << i+1 << "\t "<< "IP Address "<< addr << std::endl;
}
addr = router_address.GetAddress(0);
std::cout << "Internet Stack & IPv4 address configured.." << '\n';
// TODO
}
int main (int argc, char **argv)
{
std::string wifiManager ("Arf");
CommandLine cmd (__FILE__);
cmd.AddValue ("wifiManager", "Set wifi rate manager (Aarf, Aarfcd, Amrr, Arf, Cara, Ideal, Minstrel, Onoe, Rraa)", wifiManager);
cmd.Parse (argc, argv);
std::cout << "Hidden station experiment with RTS/CTS disabled:\n" << std::flush;
experiment (false, wifiManager);
std::cout << "------------------------------------------------\n";
std::cout << "Hidden station experiment with RTS/CTS enabled:\n";
experiment (true, wifiManager);
return 0;
}
But my main problem is that I can't configure my nodes as the problem description and simulate the load balancing algorithm and this is actually because of the lack of tutorials and sample codes like this problem. Could someone help me?
Upvotes: 1
Views: 139