How to switch traffic to a different route

298 views
Skip to first unread message

Yang Wei

unread,
Sep 19, 2016, 10:24:20 PM9/19/16
to ns-3-users
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?
Thank you so much!

My code is as following, anyone has suggestions to how to modify it or add something?
Any suggestion is highly appreciated! Thank you!

#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;
}

topology.png

Natale Patriciello

unread,
Sep 20, 2016, 5:34:57 AM9/20/16
to ns-3-...@googlegroups.com
On 19/09/16 at 07:24pm, Yang Wei wrote:
> 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?
> Thank you so much!
>

Your routing protocol should return a different interface as output
interface when the previous one is overloaded.

Nat

Yang Wei

unread,
Sep 20, 2016, 9:06:44 AM9/20/16
to ns-3-users
Hi Nat:
       Thank you so much for your suggestion.
       Now I find it so difficult to realize the situation of overload for one node.The reason is NS3 can not simulate the processing time for one packet, 
       it seems for a receiver, it can pass all the received packets to the next hop directly using 0 seconds, without putting them in its queue to wait.
       Therefore, do you have any idea how to simulate the queue delay and the packets drop ratio for a receiver? The ErrorModel doesn't help.
       Thank you so much!
       Best,
                       Wei

Natale Patriciello

unread,
Sep 20, 2016, 10:40:35 AM9/20/16
to ns-3-...@googlegroups.com
On 20/09/16 at 06:06am, Yang Wei wrote:
> Hi Nat:
> Thank you so much for your suggestion.
> Now I find it so difficult to realize the situation of overload for
> one node.The reason is NS3 can not simulate the processing time for one
> packet,
> it seems for a receiver, it can pass all the received packets to the
> next hop directly using 0 seconds, without putting them in its queue to
> wait.
> Therefore, do you have any idea how to simulate the queue delay and
> the packets drop ratio for a receiver? The ErrorModel doesn't help.
> Thank you so much!
> Best,
> Wei

This is a very basic question. Have you read the tutorial? You can setup
three p2p link, with the parameters you want, with a router in the middle.
In the router you can setup an appropriate routing protocol, and a
packet scheduler in the traffic control layer module. One of the two p2p
link should be a bottleneck for the other two.

Nat

Yang Wei

unread,
Sep 20, 2016, 11:09:54 AM9/20/16
to ns-3-users
Hi Nat, thank you so much for your prompt reply.
I am new to NS3, so I am confused about a lot of things, sorry about that.
1. Yes, I do read the tutorial. I do not remember the tutorial mentions how to setup an appropriate routing protocol, and how to set up packet scheduler in the traffic control layer module for a router.
    I appreciate so much if you can make it clearer for me.
2. Would you please tell me what kind of existing NS3 materials that I can directly use and modify for my simulation?
3. Last, do you mean setting a topology like the following?
Thank you very much for your time and efforts for my problems.
All the best to you!

                     node 0
                               \
                                \
                                 \                            
                                  node 2----------node 3
                                 /
                                /
                               /
                     node 1

Natale Patriciello

unread,
Sep 21, 2016, 3:50:00 AM9/21/16
to ns-3-...@googlegroups.com
On 20/09/16 at 08:09am, Yang Wei wrote:
> Hi Nat, thank you so much for your prompt reply.
> I am new to NS3, so I am confused about a lot of things, sorry about that.
> 1. Yes, I do read the tutorial. I do not remember the tutorial mentions how
> to setup an appropriate routing protocol, and how to set up packet
> scheduler in the traffic control layer module for a router.

Maybe it's not in the tutorial (it's an advanced thing) but for sure you
have the manual, in which it is written (check the internet module).

> 2. Would you please tell me what kind of existing NS3 materials that I can
> directly use and modify for my simulation?

I don't know, but any example which use a custom routing protocol (e.g.
olsr or aodv) should work.

> 3. Last, do you mean setting a topology like the following?
> Thank you very much for your time and efforts for my problems.
> All the best to you!
>
> node 0
> \
> \
> \
> node 2----------node 3
> /
> /
> /
> node 1

To do what? It's your research, you want to show something.. How I could
know if it's ok? Don't waste time on replying to that, just think what
in node 2 should happen and try to write it down in an "algorithmic"
way.

Nat

Yang Wei

unread,
Sep 21, 2016, 11:42:13 AM9/21/16
to ns-3-users
Yes, you are right. Thank you!
Reply all
Reply to author
Forward
0 new messages