tests: Refactor LinkControlHelper tests

Change-Id: Ifdee178d03df55422d532b9fed87e06510e0b090
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 736987d..a36715a 100644
--- a/tests/unit-tests/helper/ndn-link-control-helper.t.cpp
+++ b/tests/unit-tests/helper/ndn-link-control-helper.t.cpp
@@ -18,25 +18,14 @@
  **/
 
 #include "helper/ndn-link-control-helper.hpp"
-#include "model/ndn-l3-protocol.hpp"
-#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/core-module.h"
-#include "ns3/network-module.h"
-#include "ns3/point-to-point-module.h"
-#include "ns3/ndnSIM-module.h"
-
 #include "../tests-common.hpp"
 
 namespace ns3 {
 namespace ndn {
 
-BOOST_FIXTURE_TEST_SUITE(HelperNdnLinkControlHelper, CleanupFixture)
+BOOST_FIXTURE_TEST_SUITE(HelperNdnLinkControlHelper, ScenarioHelperWithCleanupFixture)
 
 BOOST_AUTO_TEST_CASE(TwoNodeTopology)
 {
@@ -45,42 +34,38 @@
   Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
   Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
 
-  NodeContainer nodes;
-  nodes.Create(2);
+  createTopology({
+      {"1", "2"},
+    });
 
-  PointToPointHelper p2p;
-  auto link0_1 = p2p.Install(nodes.Get(0), nodes.Get(1));
+  addRoutes({
+      {"1", "2", "/prefix", 1},
+    });
 
-  StackHelper ndnHelper;
-  ndnHelper.SetDefaultRoutes(true);
-  ndnHelper.InstallAll();
+  addApps({
+      {"1", "ns3::ndn::ConsumerCbr",
+          {{"Prefix", "/prefix"}, {"Frequency", "1"}},
+          "0s", "100s"},
+      {"2", "ns3::ndn::Producer",
+          {{"Prefix", "/prefix"}, {"PayloadSize", "1024"}},
+          "0s", "100s"}
+    });
 
-  AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
-
-  consumerHelper.SetPrefix("/prefix");
-  consumerHelper.SetAttribute("Frequency", StringValue("1"));
-  ApplicationContainer consumerAppContainer = consumerHelper.Install(nodes.Get(0));
-
-  AppHelper producerHelper("ns3::ndn::Producer");
-
-  producerHelper.SetPrefix("/prefix");
-  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
-  ApplicationContainer producerAppContainer = producerHelper.Install(nodes.Get(1));
-
-  auto netDeviceFace1_0 = nodes.Get(1)->GetObject<L3Protocol>()->getFaceByNetDevice(link0_1.Get(1));
-
-  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(5.1), ndn::LinkControlHelper::FailLink, getNode("1"), getNode("2"));
+  Simulator::Schedule(Seconds(10.1), ndn::LinkControlHelper::UpLink, getNode("1"), getNode("2"));
 
   nfd::scheduler::schedule(time::milliseconds(5200), [&] {
-      BOOST_CHECK_EQUAL(netDeviceFace1_0->getFaceStatus().getNInInterests(), 6);
+      BOOST_CHECK_EQUAL(getFace("2", "1")->getFaceStatus().getNInInterests(), 6);
+      BOOST_CHECK_EQUAL(getFace("1", "2")->getFaceStatus().getNInDatas(), 6);
     });
 
   nfd::scheduler::schedule(time::milliseconds(10200), [&] {
-      BOOST_CHECK_EQUAL(netDeviceFace1_0->getFaceStatus().getNInInterests(), 6);
+      BOOST_CHECK_EQUAL(getFace("2", "1")->getFaceStatus().getNInInterests(), 6);
+      BOOST_CHECK_EQUAL(getFace("1", "2")->getFaceStatus().getNInDatas(), 6);
     });
   nfd::scheduler::schedule(time::milliseconds(15100), [&] {
-      BOOST_CHECK_EQUAL(netDeviceFace1_0->getFaceStatus().getNInInterests(), 11);
+      BOOST_CHECK_EQUAL(getFace("2", "1")->getFaceStatus().getNInInterests(), 11);
+      BOOST_CHECK_EQUAL(getFace("1", "2")->getFaceStatus().getNInDatas(), 11);
     });
 
   Simulator::Stop(Seconds(15.2));
@@ -94,88 +79,73 @@
   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 | -+                         //
+  //                            +---+                            //
 
+  createTopology({
+      {"0", "1"},
+      {"1", "2"}, {"1", "3"},
+      {"2", "4"}, {"3", "4"},
+      {"4", "5"},
+    });
 
-  // 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();
+  addRoutes({
+      {"0", "1", "/prefix", 1},
+      {"1", "2", "/prefix", 1}, {"1", "3", "/prefix", 1},
+      {"2", "4", "/prefix", 1}, {"3", "4", "/prefix", 1},
+      {"4", "5", "/prefix", 1},
+    });
 
   // 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));
+  addApps({
+      {"0", "ns3::ndn::ConsumerCbr",
+          {{"Prefix", "/prefix"}, {"Frequency", "1"}},
+          "0s", "100s"},
+      {"5", "ns3::ndn::Producer",
+          {{"Prefix", "/prefix"}, {"PayloadSize", "1024"}},
+          "0s", "100s"}
+    });
 
   nfd::scheduler::schedule(time::milliseconds(10100), [&] {
-      LinkControlHelper::FailLink(nodes.Get(1), nodes.Get(2));
+      LinkControlHelper::FailLink(getNode("1"), getNode("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);
+      BOOST_CHECK_EQUAL(getFace("2", "1")->getFaceStatus().getNInInterests(), 11);
+      BOOST_CHECK_EQUAL(getFace("3", "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);
+      BOOST_CHECK_EQUAL(getFace("2", "1")->getFaceStatus().getNInInterests(), 11);
+      BOOST_CHECK_EQUAL(getFace("3", "1")->getFaceStatus().getNInInterests(), 21);
     });
 
   nfd::scheduler::schedule(time::milliseconds(20100), [&] {
-      LinkControlHelper::UpLink(nodes.Get(1), nodes.Get(2));
+      LinkControlHelper::UpLink(getNode("1"), getNode("2"));
     });
 
   nfd::scheduler::schedule(time::milliseconds(30050), [&] {
-      BOOST_CHECK_EQUAL(netDeviceFace2_1->getFaceStatus().getNInInterests(), 21);
-      BOOST_CHECK_EQUAL(netDeviceFace3_1->getFaceStatus().getNInInterests(), 31);
+      BOOST_CHECK_EQUAL(getFace("2", "1")->getFaceStatus().getNInInterests(), 21);
+      BOOST_CHECK_EQUAL(getFace("3", "1")->getFaceStatus().getNInInterests(), 31);
     });
 
   Simulator::Stop(Seconds(30.1));
-
   Simulator::Run();
-  Simulator::Destroy();
 }
 
 BOOST_AUTO_TEST_SUITE_END()