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