Hi all, I am doing a load balancing project using NS3. As can be seen from my attached figure, node 0 and node 1 are in charge of sending packets, I hope the node 2 can act as a dispatcher to balance the incoming traffic.
Therefore, when node 3 is overloaded, the traffic can be rerouted to node 4. When node 4 is overloaded, the traffic can be rerouted to node 5, and so on......
But my problem is that the traffic only goes to node 3, Anyone has an idea to how to reroute the traffic to other nodes like node 4, node 5..... to balance the load on each node?
My code is as following, anyone has suggestions to how to modify it or add something?
#include <fstream>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/node.h"
#include "ns3/csma-module.h"
#include "ns3/queue.h"
#include "ns3/stats-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/ipv4-list-routing-helper.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
int
main (int argc, char *argv[])
{
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create (11);
InternetStackHelper stack;
stack.Install (nodes);
Config::SetDefault("ns3::Ipv4GlobalRouting::RandomEcmpRouting", BooleanValue(true)); // enable multi-path routing
PointToPointHelper p2p1;
p2p1.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p1.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p2;
p2p2.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p2.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p3;
p2p3.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p3.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p4;
p2p4.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p4.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p5;
p2p5.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p5.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p6;
p2p6.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p6.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p7;
p2p7.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p7.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p8;
p2p8.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p8.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p9;
p2p9.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p9.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p10;
p2p10.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p10.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p11;
p2p11.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p11.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p12;
p2p12.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p12.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p13;
p2p13.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p13.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p14;
p2p14.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p14.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointHelper p2p15;
p2p15.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p15.SetChannelAttribute ("Delay", StringValue ("2ms"));
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
NetDeviceContainer devices;
devices = p2p1.Install (nodes.Get (0), nodes.Get (2));
Ipv4InterfaceContainer interfaces = address.Assign (devices);
devices = p2p2.Install (nodes.Get (1), nodes.Get (2));
address.SetBase ("10.1.2.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p3.Install (nodes.Get (2), nodes.Get (3));
address.SetBase ("10.1.3.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p4.Install (nodes.Get (2), nodes.Get (4));
address.SetBase ("10.1.4.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p5.Install (nodes.Get (2), nodes.Get (5));
address.SetBase ("10.1.5.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p6.Install (nodes.Get (2), nodes.Get (6));
address.SetBase ("10.1.6.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p7.Install (nodes.Get (2), nodes.Get (7));
address.SetBase ("10.1.7.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p8.Install (nodes.Get (2), nodes.Get (8));
address.SetBase ("10.1.8.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p9.Install (nodes.Get (3), nodes.Get (9));
address.SetBase ("10.1.9.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p10.Install (nodes.Get (4), nodes.Get (9));
address.SetBase ("10.1.10.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p11.Install (nodes.Get (5), nodes.Get (9));
address.SetBase ("10.1.11.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p12.Install (nodes.Get (6), nodes.Get (9));
address.SetBase ("10.1.12.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p13.Install (nodes.Get (7), nodes.Get (9));
address.SetBase ("10.1.13.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p14.Install (nodes.Get (8), nodes.Get (9));
address.SetBase ("10.1.14.0", "255.255.255.0");
interfaces = address.Assign (devices);
devices = p2p15.Install (nodes.Get (9), nodes.Get (10));
address.SetBase ("10.1.15.0", "255.255.255.0");
interfaces = address.Assign (devices);
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (10));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (100.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1000));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.001)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer client1Apps = echoClient.Install (nodes.Get (0));
ApplicationContainer client2Apps = echoClient.Install (nodes.Get (1));
client1Apps.Start (Seconds (2.0));
client1Apps.Stop (Seconds (100.0));
client2Apps.Start (Seconds (2.0));
client2Apps.Stop (Seconds (100.0));
AnimationInterface anim ("2000.xml");
anim.SetConstantPosition (nodes.Get(0), 1.0, 3.0);
anim.SetConstantPosition (nodes.Get(1), 1.0, 5.0);
anim.SetConstantPosition (nodes.Get(2), 2.0, 4.0);
anim.SetConstantPosition (nodes.Get(3), 3.0, 1.0);
anim.SetConstantPosition (nodes.Get(4), 3.0, 2.0);
anim.SetConstantPosition (nodes.Get(5), 3.0, 3.0);
anim.SetConstantPosition (nodes.Get(6), 3.0, 5.0);
anim.SetConstantPosition (nodes.Get(7), 3.0, 6.0);
anim.SetConstantPosition (nodes.Get(8), 3.0, 7.0);
anim.SetConstantPosition (nodes.Get(9), 4.0, 4.0);
anim.SetConstantPosition (nodes.Get(10), 5.0, 4.0);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}