tests: Adding extra test case for ndn-link-control-helper

Change-Id: I471023fc23ffaebe04d9668426b4c1b03e4972ba
Refs: #2783
diff --git a/tests/unit-tests/helper/ndn-link-control-helper.t.cpp b/tests/unit-tests/helper/ndn-link-control-helper.t.cpp
index 31ac2f2..736987d 100644
--- a/tests/unit-tests/helper/ndn-link-control-helper.t.cpp
+++ b/tests/unit-tests/helper/ndn-link-control-helper.t.cpp
@@ -22,21 +22,10 @@
 #include "model/ndn-net-device-face.hpp"
 #include "model/ndn-app-face.hpp"
 #include "NFD/daemon/fw/forwarder.hpp"
+#include "NFD/core/scheduler.hpp"
 
 #include <ndn-cxx/management/nfd-face-status.hpp>
 
-#include "ns3/assert.h"
-#include "ns3/names.h"
-#include "ns3/point-to-point-net-device.h"
-#include "ns3/point-to-point-channel.h"
-#include "ns3/channel.h"
-#include "ns3/log.h"
-#include "ns3/error-model.h"
-#include "ns3/string.h"
-#include "ns3/boolean.h"
-#include "ns3/double.h"
-#include "ns3/pointer.h"
-
 #include "ns3/core-module.h"
 #include "ns3/network-module.h"
 #include "ns3/point-to-point-module.h"
@@ -49,18 +38,22 @@
 
 BOOST_FIXTURE_TEST_SUITE(HelperNdnLinkControlHelper, CleanupFixture)
 
-BOOST_AUTO_TEST_CASE(FailLink)
+BOOST_AUTO_TEST_CASE(TwoNodeTopology)
 {
+  // setting default parameters for PointToPoint links and channels
+  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
+  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
+  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
+
   NodeContainer nodes;
   nodes.Create(2);
 
   PointToPointHelper p2p;
-  p2p.Install(nodes.Get(0), nodes.Get(1));
+  auto link0_1 = p2p.Install(nodes.Get(0), nodes.Get(1));
 
   StackHelper ndnHelper;
   ndnHelper.SetDefaultRoutes(true);
-
-  Ptr<FaceContainer> node0_faceContainer = ndnHelper.InstallAll();
+  ndnHelper.InstallAll();
 
   AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
 
@@ -74,18 +67,115 @@
   producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
   ApplicationContainer producerAppContainer = producerHelper.Install(nodes.Get(1));
 
-  FaceContainer::Iterator node2Face_it = node0_faceContainer->Begin() + 1;
+  auto netDeviceFace1_0 = nodes.Get(1)->GetObject<L3Protocol>()->getFaceByNetDevice(link0_1.Get(1));
 
-  auto node1_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node2Face_it));
+  Simulator::Schedule(Seconds(5.1), ndn::LinkControlHelper::FailLink, nodes.Get(0), nodes.Get(1));
+  Simulator::Schedule(Seconds(10.1), ndn::LinkControlHelper::UpLink, nodes.Get(0), nodes.Get(1));
 
-  Simulator::Schedule(Seconds(0.0), ndn::LinkControlHelper::FailLink, nodes.Get(0), nodes.Get(1));
-  Simulator::Schedule(Seconds(5.0), ndn::LinkControlHelper::UpLink, nodes.Get(0), nodes.Get(1));
-  Simulator::Stop(Seconds(10.0));
+  nfd::scheduler::schedule(time::milliseconds(5200), [&] {
+      BOOST_CHECK_EQUAL(netDeviceFace1_0->getFaceStatus().getNInInterests(), 6);
+    });
+
+  nfd::scheduler::schedule(time::milliseconds(10200), [&] {
+      BOOST_CHECK_EQUAL(netDeviceFace1_0->getFaceStatus().getNInInterests(), 6);
+    });
+  nfd::scheduler::schedule(time::milliseconds(15100), [&] {
+      BOOST_CHECK_EQUAL(netDeviceFace1_0->getFaceStatus().getNInInterests(), 11);
+    });
+
+  Simulator::Stop(Seconds(15.2));
+  Simulator::Run();
+}
+
+BOOST_AUTO_TEST_CASE(SixNodeTopology) // Bug #2783
+{
+  // setting default parameters for PointToPoint links and channels
+  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
+  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
+  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
+
+  // Creating nodes
+  NodeContainer nodes;
+  nodes.Create(6);
+
+
+  // Connecting nodes in 6 node topology:
+  //
+  //                            +---+
+  //                         +- | 2 | -+
+  //                        /   +---+   \
+  //              +---+    /             \    +---+
+  // +---+        |   | --+               +-- |   |        +---+
+  // | 0 | ------ | 1 |                       | 4 | ------ | 5 |
+  // +---+        |   | --+               +-- |   |        +---+
+  //              +---+    \             /    +---+
+  //                        \   +---+   /
+  //                         +- | 3 | -+
+  //                            +---+
+  PointToPointHelper p2p;
+  p2p.Install(nodes.Get(0), nodes.Get(1));
+  auto link1_2 = p2p.Install(nodes.Get(1), nodes.Get(2));
+  auto link1_3 = p2p.Install(nodes.Get(1), nodes.Get(3));
+  p2p.Install(nodes.Get(2), nodes.Get(4));
+  p2p.Install(nodes.Get(3), nodes.Get(4));
+  p2p.Install(nodes.Get(4), nodes.Get(5));
+
+  // Install NDN stack on all nodes
+  ndn::StackHelper ndnHelper;
+  ndnHelper.SetDefaultRoutes(true);
+  ndnHelper.InstallAll();
+
+  // Choosing forwarding strategy
+  ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/broadcast");
+
+  // Installing applications
+
+  // Consumer
+  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
+  // Consumer will request /prefix/0, /prefix/1, ...
+  consumerHelper.SetPrefix("/prefix");
+  consumerHelper.SetAttribute("Frequency", StringValue("1")); // 1 interests a second
+  consumerHelper.Install(nodes.Get(0));                       // first node
+
+  // Producer
+  ndn::AppHelper producerHelper("ns3::ndn::Producer");
+  // Producer will reply to all requests starting with /prefix
+  producerHelper.SetPrefix("/prefix");
+  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
+  producerHelper.Install(nodes.Get(5)); // last node
+
+  auto netDeviceFace2_1 = nodes.Get(2)->GetObject<L3Protocol>()->getFaceByNetDevice(link1_2.Get(1));
+  auto netDeviceFace3_1 = nodes.Get(3)->GetObject<L3Protocol>()->getFaceByNetDevice(link1_3.Get(1));
+
+  nfd::scheduler::schedule(time::milliseconds(10100), [&] {
+      LinkControlHelper::FailLink(nodes.Get(1), nodes.Get(2));
+    });
+
+  // just before link failure
+  nfd::scheduler::schedule(time::milliseconds(10050), [&] {
+      BOOST_CHECK_EQUAL(netDeviceFace2_1->getFaceStatus().getNInInterests(), 11);
+      BOOST_CHECK_EQUAL(netDeviceFace3_1->getFaceStatus().getNInInterests(), 11);
+    });
+
+  // just before link recovery
+  nfd::scheduler::schedule(time::milliseconds(20050), [&] {
+      BOOST_CHECK_EQUAL(netDeviceFace2_1->getFaceStatus().getNInInterests(), 11);
+      BOOST_CHECK_EQUAL(netDeviceFace3_1->getFaceStatus().getNInInterests(), 21);
+    });
+
+  nfd::scheduler::schedule(time::milliseconds(20100), [&] {
+      LinkControlHelper::UpLink(nodes.Get(1), nodes.Get(2));
+    });
+
+  nfd::scheduler::schedule(time::milliseconds(30050), [&] {
+      BOOST_CHECK_EQUAL(netDeviceFace2_1->getFaceStatus().getNInInterests(), 21);
+      BOOST_CHECK_EQUAL(netDeviceFace3_1->getFaceStatus().getNInInterests(), 31);
+    });
+
+  Simulator::Stop(Seconds(30.1));
 
   Simulator::Run();
-
-  ::ndn::nfd::FaceStatus faceStatus = node1_netDeviceFace->getFaceStatus();
-  BOOST_CHECK_EQUAL(faceStatus.getNInInterests(), 5);
+  Simulator::Destroy();
 }
 
 BOOST_AUTO_TEST_SUITE_END()