NS3 hybrid point to point network with link failure

283 views
Skip to first unread message

Deb

unread,
Mar 21, 2017, 6:11:52 AM3/21/17
to ns-3-users
Hi, I tried to build a hybrid point-to-point network with 2 types of links between connected pairs - one with low delay and one with high delay. I tried to schedule a link failure after 5 seconds in order to use the failover link. But it seems that the path with high delay is neverr used. Hence after failure the network gets disconnected. Let me know if I am doing something wrong here:


#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"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE("FirstScriptExample");

void FailLink (Ptr<NetDevice> nd);

int
main(int argc, char *argv[]) {
    CommandLine cmd;
    cmd.Parse(argc, argv);

    int totLinks = 2;

    Time::SetResolution(Time::NS);
    LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
    LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);

    NodeContainer nodes;
    nodes.Create(3);

    NodeContainer* nc = new NodeContainer[totLinks];
    NetDeviceContainer* ndc = new NetDeviceContainer[totLinks];
    Ipv4InterfaceContainer* ic = new Ipv4InterfaceContainer[totLinks];
    
    NetDeviceContainer* fndc = new NetDeviceContainer[totLinks];
    Ipv4InterfaceContainer* fic = new Ipv4InterfaceContainer[totLinks];

    for (int i = 0; i < totLinks; i++) {
        nc[i] = NodeContainer(nodes.Get(i), nodes.Get(i + 1));

        PointToPointHelper pointToPoint;
        pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
        pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));

        ndc[i] = pointToPoint.Install(nc[i]);
        pointToPoint.EnablePcap ("myfirst", nodes.Get (1)->GetId (), false);
        
        
        PointToPointHelper fp2p;
        fp2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
        fp2p.SetChannelAttribute("Delay", StringValue("10ms"));
        
        fndc[i] = fp2p.Install(nc[i]);
        fp2p.EnablePcap ("mysecond", nodes.Get (1)->GetId (), false);
        
        
    }

    InternetStackHelper stack;
    stack.Install(nodes);

    for (int i = 0; i < totLinks; i++) {
        Ipv4AddressHelper address;
        std::string addressStr = "10.1."+std::to_string(i)+".0";
        const char * ip_addr = addressStr.c_str();
        address.SetBase(ip_addr, "255.255.255.0");
        
        ic[i] = address.Assign(ndc[i]);
        
        Ipv4AddressHelper faddress;
        std::string faddressStr = "172.16."+std::to_string(i)+".0";
        const char * fip_addr = faddressStr.c_str();
        faddress.SetBase(fip_addr, "255.255.255.0");
        
        fic[i] = faddress.Assign(fndc[i]);
    }

    Ipv4GlobalRoutingHelper::PopulateRoutingTables();

    UdpEchoServerHelper echoServer(9);

    ApplicationContainer serverApps = echoServer.Install(nodes.Get(0));
    serverApps.Start(Seconds(1.0));
    serverApps.Stop(Seconds(10.0));

    UdpEchoClientHelper echoClient(ic[0].GetAddress(0), 9);
    echoClient.SetAttribute("MaxPackets", UintegerValue(5));
    echoClient.SetAttribute("Interval", TimeValue(Seconds(1.0)));
    echoClient.SetAttribute("PacketSize", UintegerValue(1024));

    ApplicationContainer clientApps = echoClient.Install(nodes.Get(2));
    clientApps.Start(Seconds(2.0));
    Simulator::Schedule (Seconds (5.0), FailLink, nodes.Get (1)->GetDevice(0));
    clientApps.Stop(Seconds(10.0));

    Simulator::Run();
    Simulator::Destroy();
    return 0;
}

void
FailLink (Ptr<NetDevice> nd)
{
    Ptr<RateErrorModel> error = CreateObject<RateErrorModel> ();
    error->SetAttribute ("ErrorRate", DoubleValue (1.0));
    nd->SetAttribute ("ReceiveErrorModel", PointerValue (error));
}

pdbarnes

unread,
Mar 21, 2017, 9:01:28 PM3/21/17
to ns-3-users
When you FailLink you are setting the error rate to 1, which means packets won't be received, but that doesn't mean the link is down. Routing will still think the link is up, since it doesn't know about the error model. You should use Ipv4Interface::SetDown() instead.

In addition, you are using GlobalRouting, which isn't dynamic. When you fail a link you should flush the routing tables and re-populate.

Peter

Deb

unread,
Mar 22, 2017, 4:43:42 AM3/22/17
to ns-3-users
Thanks for the reply! The problem is that here I am using point-to-point devices. Is it possible to cast such an interface to IPv4Interface? Thanks!

Deb

unread,
Mar 22, 2017, 9:16:49 AM3/22/17
to ns-3-users
Hi,

now I know how to bring down an IPv4 interface using an IPv4 interface container. Here is the code:
std::pair<Ptr<Ipv4>, uint32_t> returnValue = ipv4InterfaceContainerInstance.Get(0);
    Ptr<Ipv4> ipv4 = returnValue.first;
    uint32_t index = returnValue.second;
    Ptr<Ipv4Interface> iface = ipv4->GetObject<Ipv4L3Protocol> ()->GetInterface(index);
    iface->SetDown();

But even after bringing the interface down, as I refresh the global routing table using Ipv4GlobalRoutingHelper::RecomputeRoutingTables(), the routing tables do not refresh. What can be the reason of this issue? Thanks!

Deb

unread,
Mar 22, 2017, 11:17:17 AM3/22/17
to ns-3-users
This works: Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true));
Reply all
Reply to author
Forward
0 new messages