tests+ci: Add and enable a partial unit test coverage
Change-Id: I6dbc5cf4d68679bd6f943322f572313884c8aef7
Refs: #2369
diff --git a/.jenkins.d/01-deps.sh b/.jenkins.d/01-deps.sh
index 6b9e10a..d05e767 100755
--- a/.jenkins.d/01-deps.sh
+++ b/.jenkins.d/01-deps.sh
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
-set -x
set -e
-IS_OSX=$( python -c "print 'yes' if 'OSX' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
-IS_UBUNTU=$( python -c "print 'yes' if 'Ubuntu' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
-if [[ $IS_OSX == "yes" ]]; then
+if has OSX $NODE_LABELS; then
+ set -x
brew update
brew upgrade
brew install boost cryptopp pkg-config libxml2
@@ -13,13 +13,13 @@
brew cleanup
fi
-if [[ $IS_UBUNTU == "yes" ]]; then
+if has Ubuntu $NODE_LABELS; then
+ set -x
sudo apt-get update -qq -y
sudo apt-get -qq -y install build-essential
sudo apt-get -qq -y install libssl-dev libsqlite3-dev libcrypto++-dev
- IS_12_04=$( python -c "print 'yes' if 'Ubuntu-12.04' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
- if [[ $IS_12_04 == "yes" ]]; then
+ if has Ubuntu-12.04 $NODE_LABELS; then
sudo apt-get install -qq -y python-software-properties
sudo add-apt-repository -y ppa:boost-latest/ppa
sudo apt-get update -qq -y
diff --git a/.jenkins.d/02-deps-ndn-cxx.sh b/.jenkins.d/02-deps-ndn-cxx.sh
index 6e81cca..bcd5364 100755
--- a/.jenkins.d/02-deps-ndn-cxx.sh
+++ b/.jenkins.d/02-deps-ndn-cxx.sh
@@ -2,51 +2,43 @@
set -x
set -e
-if [[ $USE_NDN_PPA == "yes" ]]; then
- sudo apt-get install -y python-software-properties
- sudo add-apt-repository -qq -y ppa:named-data/ppa
- sudo apt-get update -qq
- sudo apt-get install -qq -y ndn-cxx-dev
- exit 0
-fi
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
-cd /tmp
-BUILD="no"
-if [ ! -d ndn-cxx ]; then
- git clone git://github.com/named-data/ndn-cxx
- cd ndn-cxx
- BUILD="yes"
+pushd /tmp >/dev/null
+
+INSTALLED_VERSION=$((cd ndn-cxx && git rev-parse HEAD) 2>/dev/null || echo NONE)
+
+sudo rm -Rf ndn-cxx-latest
+git clone --depth 1 git://github.com/named-data/ndn-cxx ndn-cxx-latest
+LATEST_VERSION=$((cd ndn-cxx-latest && git rev-parse HEAD) 2>/dev/null || echo UNKNOWN)
+
+if [[ $INSTALLED_VERSION != $LATEST_VERSION ]]; then
+ sudo rm -Rf ndn-cxx
+ mv ndn-cxx-latest ndn-cxx
else
- cd ndn-cxx
- INSTALLED_VERSION=`git rev-parse HEAD || echo NONE`
- sudo rm -Rf latest-version
- git clone git://github.com/named-data/ndn-cxx latest-version
- cd latest-version
- LATEST_VERSION=`git rev-parse HEAD || echo UNKNOWN`
- cd ..
- rm -Rf latest-version
- if [ "$INSTALLED_VERSION" != "$LATEST_VERSION" ]; then
- cd ..
- sudo rm -Rf ndn-cxx
- git clone --depth 1 git://github.com/named-data/ndn-cxx
- cd ndn-cxx
- BUILD="yes"
- fi
+ sudo rm -Rf ndn-cxx-latest
fi
sudo rm -Rf /usr/local/include/ndn-cxx
sudo rm -f /usr/local/lib/libndn-cxx*
sudo rm -f /usr/local/lib/pkgconfig/libndn-cxx*
-if [ "$BUILD" = "yes" ]; then
- sudo ./waf distclean -j1 --color=yes
-fi
+pushd ndn-cxx >/dev/null
-IS_UBUNTU_12_04=$( python -c "print 'yes' if 'Ubuntu-12.04' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
-if [[ $IS_UBUNTU_12_04 == "yes" ]]; then
+if has Ubuntu-12.04 $NODE_LABELS; then
EXTRA_FLAGS=" --boost-libs=/usr/lib/x86_64-linux-gnu"
fi
./waf configure -j1 --color=yes --enable-shared --disable-static --without-osx-keychain $EXTRA_FLAGS
./waf -j1 --color=yes
sudo ./waf install -j1 --color=yes
+
+popd >/dev/null
+popd >/dev/null
+
+if has Linux $NODE_LABELS; then
+ sudo ldconfig
+elif has FreeBSD $NODE_LABELS; then
+ sudo ldconfig -a
+fi
diff --git a/.jenkins.d/10-build.sh b/.jenkins.d/10-build.sh
index 93e7d79..da977d5 100755
--- a/.jenkins.d/10-build.sh
+++ b/.jenkins.d/10-build.sh
@@ -2,38 +2,27 @@
set -x
set -e
-# git submodule init
-# git submodule sync
-# git submodule update
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
-# COVERAGE=$( python -c "print '--with-coverage' if 'code-coverage' in '$JOB_NAME' else ''" )
-IS_UBUNTU_12_04=$( python -c "print 'yes' if 'Ubuntu-12.04' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
-if [[ $IS_UBUNTU_12_04 == "yes" ]]; then
- EXTRA_FLAGS=" --boost-libs=/usr/lib/x86_64-linux-gnu"
-fi
+git submodule update --init
# Cleanup
sudo ./waf -j1 distclean
+if has Ubuntu-12.04 $NODE_LABELS; then
+ EXTRA_FLAGS=" --boost-libs=/usr/lib/x86_64-linux-gnu"
+fi
+
# Configure/build in debug mode
-./waf -j1 configure --enable-modules=ndnSIM --enable-examples --enable-tests $EXTRA_FLAGS
+./waf -j1 configure -d debug --enable-modules=ndnSIM --enable-examples --enable-tests $EXTRA_FLAGS
./waf -j1 build
-# # Cleanup
-# sudo ./waf -j1 --color=yes distclean
+# Install
+sudo ./waf -j1 install
-# # Configure/build in optimized mode without tests with precompiled headers
-# ./waf -j1 --color=yes configure
-# ./waf -j1 --color=yes build
-
-# # Cleanup
-# sudo ./waf -j1 --color=yes distclean
-
-# # Configure/build in optimized mode
-# ./waf -j1 --color=yes configure --with-tests --without-pch $COVERAGE
-# ./waf -j1 --color=yes build
-
-# # (tests will be run against optimized version)
-
-# # Install
-# sudo ./waf -j1 --color=yes install
+if has Linux $NODE_LABELS; then
+ sudo ldconfig
+elif has FreeBSD $NODE_LABELS; then
+ sudo ldconfig -a
+fi
diff --git a/.jenkins.d/20-tests.sh b/.jenkins.d/20-tests.sh
new file mode 100755
index 0000000..01ce1a2
--- /dev/null
+++ b/.jenkins.d/20-tests.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+set -x
+set -e
+
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
+
+# Run unit tests
+if [[ -n "$XUNIT" ]]; then
+ ./build/src/ndnSIM/tests/ns3-dev-ndnSIM-unit-tests-debug --log_format=XML --log_sink=build/xunit-report.xml --log_level=all --report_level=no
+else
+ ./build/src/ndnSIM/tests/ns3-dev-ndnSIM-unit-tests-debug -l test_suite
+fi
diff --git a/.jenkins.d/util.sh b/.jenkins.d/util.sh
new file mode 100755
index 0000000..81c8931
--- /dev/null
+++ b/.jenkins.d/util.sh
@@ -0,0 +1,9 @@
+has() {
+ local p=$1
+ shift
+ local x
+ for x in "$@"; do
+ [[ "${x}" == "${p}" ]] && return 0
+ done
+ return 1
+}
diff --git a/model/ndn-global-router.cpp b/model/ndn-global-router.cpp
index 136c388..de853b7 100644
--- a/model/ndn-global-router.cpp
+++ b/model/ndn-global-router.cpp
@@ -89,11 +89,11 @@
return m_localPrefixes;
}
-// void
-// GlobalRouter::AddIncidencyChannel (Ptr< NdnFace > face, Ptr< Channel > channel)
-// {
-// m_incidenciesChannel.push_back (make_tuple (face, channel));
-// }
+void
+GlobalRouter::clear()
+{
+ m_idCounter = 0;
+}
} // namespace ndn
} // namespace ns3
diff --git a/model/ndn-global-router.hpp b/model/ndn-global-router.hpp
index 4713a5b..f19e8f4 100644
--- a/model/ndn-global-router.hpp
+++ b/model/ndn-global-router.hpp
@@ -108,7 +108,12 @@
const LocalPrefixList&
GetLocalPrefixes() const;
- // ??
+ /**
+ * @brief Clear global state
+ */
+ static void
+ clear();
+
protected:
virtual void
NotifyNewAggregate(); ///< @brief Notify when the object is aggregated to another object (e.g.,
diff --git a/tests/unit-tests/helper/ndn-face-container.t.cpp b/tests/unit-tests/helper/ndn-face-container.t.cpp
new file mode 100644
index 0000000..59df4b9
--- /dev/null
+++ b/tests/unit-tests/helper/ndn-face-container.t.cpp
@@ -0,0 +1,61 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "helper/ndn-face-container.hpp"
+
+#include "ns3/node-container.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/node.h"
+#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(HelperNdnFaceContainer, CleanupFixture)
+
+BOOST_AUTO_TEST_CASE(AddAll)
+{
+ NodeContainer nodes;
+ nodes.Create(4);
+
+ PointToPointHelper p2p;
+ p2p.Install(nodes.Get(0), nodes.Get(1));
+ p2p.Install(nodes.Get(0), nodes.Get(2));
+ p2p.Install(nodes.Get(0), nodes.Get(3));
+
+ StackHelper ndnHelper;
+ ndnHelper.SetDefaultRoutes(true);
+
+ Ptr<FaceContainer> a = ndnHelper.InstallAll();
+ FaceContainer b;
+ b.AddAll(a);
+
+ BOOST_CHECK_EQUAL_COLLECTIONS(a->Begin(), a->Begin() + a->GetN(),
+ b.Begin(), b.End());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace ndn
+} // namespace ns3
diff --git a/tests/unit-tests/helper/ndn-fib-helper.t.cpp b/tests/unit-tests/helper/ndn-fib-helper.t.cpp
new file mode 100644
index 0000000..6d4ab1a
--- /dev/null
+++ b/tests/unit-tests/helper/ndn-fib-helper.t.cpp
@@ -0,0 +1,77 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "helper/ndn-fib-helper.hpp"
+#include "model/ndn-net-device-face.hpp"
+
+#include "ns3/node-container.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/node.h"
+#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(HelperNdnFibHelper, CleanupFixture)
+
+BOOST_AUTO_TEST_CASE(AddRoute)
+{
+ NodeContainer nodes;
+ nodes.Create(2);
+
+ PointToPointHelper p2p;
+ p2p.Install(nodes.Get(0), nodes.Get(1));
+
+ StackHelper ndnHelper;
+ Ptr<FaceContainer> node0_faceContainer = ndnHelper.InstallAll();
+
+ ndn::FibHelper::AddRoute(nodes.Get(0), "/prefix/1", nodes.Get(1), 1);
+ // Installing applications
+ ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
+ consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
+
+ ndn::AppHelper producerHelper("ns3::ndn::Producer");
+ producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
+
+ consumerHelper.SetPrefix("/prefix/1");
+ consumerHelper.Install(nodes.Get(0));
+
+ producerHelper.SetPrefix("/prefix/1");
+ producerHelper.Install(nodes.Get(1));
+
+ FaceContainer::Iterator node1Face_iterator = node0_faceContainer->Begin() + 1;
+
+ auto node1_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node1Face_iterator));
+
+ Simulator::Stop(Seconds(20.0));
+ Simulator::Run();
+
+ ::ndn::nfd::FaceStatus faceStatus = node1_netDeviceFace->getFaceStatus();
+ BOOST_CHECK_EQUAL(faceStatus.getNInInterests(), 200);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace ndn
+} // namespace ns3
diff --git a/tests/unit-tests/helper/ndn-global-routing-helper.t.cpp b/tests/unit-tests/helper/ndn-global-routing-helper.t.cpp
new file mode 100644
index 0000000..318c824
--- /dev/null
+++ b/tests/unit-tests/helper/ndn-global-routing-helper.t.cpp
@@ -0,0 +1,140 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "helper/ndn-global-routing-helper.hpp"
+
+#include "model/ndn-global-router.hpp"
+#include "model/ndn-l3-protocol.hpp"
+#include "model/ndn-face.hpp"
+#include "model/ndn-net-device-face.hpp"
+
+#include "ns3/channel.h"
+#include "ns3/net-device.h"
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/ndnSIM-module.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/point-to-point-layout-module.h"
+
+#include "../tests-common.hpp"
+
+namespace ns3 {
+namespace ndn {
+
+BOOST_FIXTURE_TEST_SUITE(HelperGlobalRoutingHelper, CleanupFixture)
+
+BOOST_AUTO_TEST_CASE(CalculateRouteCase1)
+{
+ ofstream file1("/tmp/topo1.txt");
+ file1 << "router\n\n"
+ << "#node city y x mpi-partition\n"
+ << "A1 NA 1 1 1\n"
+ << "B1 NA 80 -40 1\n"
+ << "C1 NA 80 40 1\n\n"
+ << "link\n\n"
+ << "# from to capacity metric delay queue\n"
+ << "A1 B1 10Mbps 100 1ms 100\n"
+ << "A1 C1 10Mbps 50 1ms 100\n"
+ << "B1 C1 10Mbps 1 1ms 100\n";
+ file1.close();
+
+ AnnotatedTopologyReader topologyReader("");
+ topologyReader.SetFileName("/tmp/topo1.txt");
+ topologyReader.Read();
+
+ // Install NDN stack on all nodes
+ ndn::StackHelper ndnHelper;
+ ndnHelper.InstallAll();
+
+ topologyReader.ApplyOspfMetric();
+
+ ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
+ BOOST_CHECK_NO_THROW(ndnGlobalRoutingHelper.InstallAll());
+
+ ndnGlobalRoutingHelper.AddOrigins("/test/prefix", Names::Find<Node>("C1"));
+ BOOST_CHECK_NO_THROW(ndn::GlobalRoutingHelper::CalculateRoutes());
+
+ auto ndn = Names::Find<Node>("A1")->GetObject<ndn::L3Protocol>();
+ for (const auto& entry : ndn->getForwarder()->getFib()) {
+ bool isFirst = true;
+ for (auto& nextHop : entry.getNextHops()) {
+ auto face = dynamic_pointer_cast<ndn::NetDeviceFace>(nextHop.getFace());
+ if (face == nullptr)
+ continue;
+ BOOST_CHECK_EQUAL(Names::FindName(face->GetNetDevice()->GetChannel()->GetDevice(1)->GetNode()), "C1");
+ isFirst = false;
+ }
+ }
+
+ Simulator::Stop(Seconds(20.0));
+ Simulator::Run();
+}
+
+BOOST_AUTO_TEST_CASE(CalculateRouteCase2)
+{
+ ofstream file1("/tmp/topo2.txt");
+ file1 << "router\n\n"
+ << "#node city y x mpi-partition\n"
+ << "A2 NA 1 1 1\n"
+ << "B2 NA 80 -40 1\n"
+ << "C2 NA 80 40 1\n\n"
+ << "link\n\n"
+ << "# from to capacity metric delay queue\n"
+ << "A2 B2 10Mbps 100 1ms 100\n"
+ << "A2 C2 10Mbps 500 1ms 100\n"
+ << "B2 C2 10Mbps 1 1ms 100\n";
+ file1.close();
+
+ AnnotatedTopologyReader topologyReader("");
+ topologyReader.SetFileName("/tmp/topo2.txt");
+ topologyReader.Read();
+
+ // Install NDN stack on all nodes
+ ndn::StackHelper ndnHelper;
+ ndnHelper.InstallAll();
+
+ topologyReader.ApplyOspfMetric();
+
+ ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
+ ndnGlobalRoutingHelper.InstallAll();
+
+ ndnGlobalRoutingHelper.AddOrigins("/prefix", Names::Find<Node>("C2"));
+ ndn::GlobalRoutingHelper::CalculateRoutes();
+
+ auto ndn = Names::Find<Node>("A2")->GetObject<ndn::L3Protocol>();
+ for (const auto& entry : ndn->getForwarder()->getFib()) {
+ bool isFirst = true;
+ for (auto& nextHop : entry.getNextHops()) {
+ auto face = dynamic_pointer_cast<ndn::NetDeviceFace>(nextHop.getFace());
+ if (face == nullptr)
+ continue;
+ BOOST_CHECK_EQUAL(Names::FindName(face->GetNetDevice()->GetChannel()->GetDevice(1)->GetNode()), "B2");
+ isFirst = false;
+ }
+ }
+
+ Simulator::Stop(Seconds(20.0));
+ Simulator::Run();
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace ndn
+} // namespace ns3
diff --git a/tests/unit-tests/helper/ndn-link-control-helper.t.cpp b/tests/unit-tests/helper/ndn-link-control-helper.t.cpp
new file mode 100644
index 0000000..31ac2f2
--- /dev/null
+++ b/tests/unit-tests/helper/ndn-link-control-helper.t.cpp
@@ -0,0 +1,94 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#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 <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"
+#include "ns3/ndnSIM-module.h"
+
+#include "../tests-common.hpp"
+
+namespace ns3 {
+namespace ndn {
+
+BOOST_FIXTURE_TEST_SUITE(HelperNdnLinkControlHelper, CleanupFixture)
+
+BOOST_AUTO_TEST_CASE(FailLink)
+{
+ NodeContainer nodes;
+ nodes.Create(2);
+
+ PointToPointHelper p2p;
+ p2p.Install(nodes.Get(0), nodes.Get(1));
+
+ StackHelper ndnHelper;
+ ndnHelper.SetDefaultRoutes(true);
+
+ Ptr<FaceContainer> node0_faceContainer = ndnHelper.InstallAll();
+
+ 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));
+
+ FaceContainer::Iterator node2Face_it = node0_faceContainer->Begin() + 1;
+
+ auto node1_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node2Face_it));
+
+ 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));
+
+ Simulator::Run();
+
+ ::ndn::nfd::FaceStatus faceStatus = node1_netDeviceFace->getFaceStatus();
+ BOOST_CHECK_EQUAL(faceStatus.getNInInterests(), 5);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace ndn
+} // namespace ns3
diff --git a/tests/unit-tests/helper/ndn-strategy-choice-helper.t.cpp b/tests/unit-tests/helper/ndn-strategy-choice-helper.t.cpp
new file mode 100644
index 0000000..c4f1ebc
--- /dev/null
+++ b/tests/unit-tests/helper/ndn-strategy-choice-helper.t.cpp
@@ -0,0 +1,136 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "helper/ndn-strategy-choice-helper.hpp"
+#include "helper/ndn-face-container.hpp"
+#include "model/ndn-net-device-face.hpp"
+
+#include "ns3/node-container.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/point-to-point-grid.h"
+#include "ns3/node.h"
+#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(TestStrategyChoiceHelper, CleanupFixture)
+
+BOOST_AUTO_TEST_CASE(GridScenario)
+{
+ ofstream file("/tmp/topo3.txt");
+ file << "router\n\n"
+ << "#node city y x mpi-partition\n"
+ << "A3 NA 10 10 1\n"
+ << "B3 NA 20 10 1\n"
+ << "C3 NA 10 20 1\n"
+ << "D3 NA 20 20 1\n\n"
+ << "link\n\n"
+ << "# from to capacity metric delay queue\n"
+ << "A3 B3 10Mbps 100 1ms 500\n"
+ << "A3 C3 10Mbps 200 1ms 500\n"
+ << "B3 D3 10Mbps 100 1ms 500\n"
+ << "C3 D3 10Mbps 200 1ms 500\n";
+ file.close();
+
+ AnnotatedTopologyReader topologyReader("");
+ topologyReader.SetFileName("/tmp/topo3.txt");
+ topologyReader.Read();
+
+ // Install NDN stack on all nodes
+ ndn::StackHelper ndnHelper;
+ Ptr<FaceContainer> node_faceContainer = ndnHelper.InstallAll();
+ GlobalRoutingHelper ndnGlobalRoutingHelper;
+ ndnGlobalRoutingHelper.InstallAll();
+
+ // Install different forwarding strategies
+ StrategyChoiceHelper::Install(Names::Find<Node>("A3"), "/prefix",
+ "/localhost/nfd/strategy/broadcast");
+ StrategyChoiceHelper::Install(Names::Find<Node>("B3"), "/prefix",
+ "/localhost/nfd/strategy/best-route");
+ StrategyChoiceHelper::Install(Names::Find<Node>("C3"), "/prefix",
+ "/localhost/nfd/strategy/broadcast");
+ StrategyChoiceHelper::Install(Names::Find<Node>("D3"), "/prefix",
+ "/localhost/nfd/strategy/best-route");
+
+ AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
+ consumerHelper.SetPrefix("/prefix");
+ consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
+ consumerHelper.Install(Names::Find<Node>("A3"));
+
+ AppHelper producerHelper("ns3::ndn::Producer");
+ producerHelper.SetPrefix("/prefix");
+ producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
+ producerHelper.Install(Names::Find<Node>("D3"));
+
+ // Add /prefix origins to ndn::GlobalRouter
+ ndnGlobalRoutingHelper.AddOrigins("/prefix", Names::Find<Node>("D3"));
+
+ // Calculate and install FIBs
+ GlobalRoutingHelper::CalculateRoutes();
+
+ // Node0 is consumer which is connected to intermediate Node1 and Node2
+
+ FaceContainer::Iterator IntermediateNode1Face1Iterator = node_faceContainer->Begin() + 2; // Node1 with strategy broadcast
+ FaceContainer::Iterator IntermediateNode1Face2Iterator = node_faceContainer->Begin() + 3;
+
+ FaceContainer::Iterator IntermediateNode2Face1Iterator = node_faceContainer->Begin() + 4; // Node2 with strategy best route
+ FaceContainer::Iterator IntermediateNode2Face2Iterator = node_faceContainer->Begin() + 5;
+
+ FaceContainer::Iterator ProducerFaceIterator1 = node_faceContainer->Begin() + 6;
+ FaceContainer::Iterator ProducerFaceIterator2 = node_faceContainer->Begin() + 7;
+
+ auto Producer_netDeviceFace1 = std::dynamic_pointer_cast<NetDeviceFace>(node_faceContainer->Get(ProducerFaceIterator1));
+ auto Producer_netDeviceFace2 = std::dynamic_pointer_cast<NetDeviceFace>(node_faceContainer->Get(ProducerFaceIterator2));
+
+ auto IntermediateNode1_netDeviceFace1 = std::dynamic_pointer_cast<NetDeviceFace>(node_faceContainer->Get(IntermediateNode1Face1Iterator));
+ auto IntermediateNode1_netDeviceFace2 = std::dynamic_pointer_cast<NetDeviceFace>(node_faceContainer->Get(IntermediateNode1Face2Iterator));
+
+ auto IntermediateNode2_netDeviceFace1 = std::dynamic_pointer_cast<NetDeviceFace>(node_faceContainer->Get(IntermediateNode2Face1Iterator));
+ auto IntermediateNode2_netDeviceFace2 = std::dynamic_pointer_cast<NetDeviceFace>(node_faceContainer->Get(IntermediateNode2Face2Iterator));
+
+ Simulator::Stop(Seconds(5.0));
+ Simulator::Run();
+
+ ::ndn::nfd::FaceStatus producerFace1Status = Producer_netDeviceFace1->getFaceStatus();
+ ::ndn::nfd::FaceStatus producerFace2Status = Producer_netDeviceFace2->getFaceStatus();
+
+ ::ndn::nfd::FaceStatus IntermediateNode1Face1Status = IntermediateNode1_netDeviceFace1->getFaceStatus();
+ ::ndn::nfd::FaceStatus IntermediateNode1Face2Status = IntermediateNode1_netDeviceFace2->getFaceStatus();
+
+ ::ndn::nfd::FaceStatus IntermediateNode2Face1Status = IntermediateNode2_netDeviceFace1->getFaceStatus();
+ ::ndn::nfd::FaceStatus IntermediateNode2Face2Status = IntermediateNode2_netDeviceFace2->getFaceStatus();
+
+ BOOST_CHECK_EQUAL(producerFace1Status.getNInInterests(), 500);
+ BOOST_CHECK_EQUAL(producerFace2Status.getNInInterests(), 0);
+ BOOST_CHECK_EQUAL(IntermediateNode1Face1Status.getNInInterests(), 500);
+ BOOST_CHECK_EQUAL(IntermediateNode1Face2Status.getNInInterests(), 0);
+ BOOST_CHECK_EQUAL(IntermediateNode2Face1Status.getNInInterests(), 0);
+ BOOST_CHECK_EQUAL(IntermediateNode2Face2Status.getNInInterests(), 0);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace ndn
+} // namespace ns3
diff --git a/tests/unit-tests/model/ndn-header.t.cpp b/tests/unit-tests/model/ndn-header.t.cpp
new file mode 100644
index 0000000..3776c8a
--- /dev/null
+++ b/tests/unit-tests/model/ndn-header.t.cpp
@@ -0,0 +1,53 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "model/ndn-header.hpp"
+#include "model/ndn-ns3.hpp"
+#include "helper/ndn-stack-helper.hpp"
+
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/data.hpp>
+
+#include "../tests-common.hpp"
+
+namespace ns3 {
+namespace ndn {
+
+BOOST_FIXTURE_TEST_SUITE(ModelNdnHeader, CleanupFixture)
+
+BOOST_AUTO_TEST_CASE(TypeId)
+{
+ auto interest = make_shared<ndn::Interest>("/prefix");
+ PacketHeader<Interest> interestPktHeader(*interest);
+ BOOST_CHECK_EQUAL(interestPktHeader.GetTypeId().GetName().c_str(), "ns3::ndn::Interest");
+
+ auto data = make_shared<ndn::Data>();
+ data->setFreshnessPeriod(ndn::time::milliseconds(1000));
+ data->setContent(std::make_shared< ::ndn::Buffer>(1024));
+ ndn::StackHelper::getKeyChain().sign(*data);
+ PacketHeader<Data> dataPktHeader(*data);
+
+ BOOST_CHECK_EQUAL(dataPktHeader.GetTypeId().GetName().c_str(), "ns3::ndn::Data");
+ BOOST_CHECK_EQUAL(dataPktHeader.GetSerializedSize(), 1354); // 328 + 1024
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace ndn
+} // namespace ns3
diff --git a/tests/unit-tests/model/ndn-net-device-face.t.cpp b/tests/unit-tests/model/ndn-net-device-face.t.cpp
new file mode 100644
index 0000000..23a6406
--- /dev/null
+++ b/tests/unit-tests/model/ndn-net-device-face.t.cpp
@@ -0,0 +1,138 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "model/ndn-net-device-face.hpp"
+#include "model/ndn-l3-protocol.hpp"
+#include "model/ndn-ns3.hpp"
+#include "NFD/daemon/face/face-counters.hpp"
+
+#include <ndn-cxx/management/nfd-face-status.hpp>
+
+#include "ns3/net-device.h"
+#include "ns3/log.h"
+#include "ns3/packet.h"
+#include "ns3/node.h"
+#include "ns3/pointer.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/channel.h"
+#include "ndn-face-container.hpp"
+#include "ns3/node-container.h"
+
+#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(ModelNdnNetDeviceFace, CleanupFixture)
+
+BOOST_AUTO_TEST_CASE(SendInterest)
+{
+ NodeContainer nodes;
+ nodes.Create(2);
+ PointToPointHelper p2p;
+ p2p.Install(nodes.Get(0), nodes.Get(1));
+
+ StackHelper ndnHelper;
+ ndnHelper.SetDefaultRoutes(true);
+
+ Ptr<FaceContainer> node0_faceContainer = ndnHelper.InstallAll();
+
+ ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
+ consumerHelper.SetPrefix("/prefix");
+ consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
+ consumerHelper.Install(nodes.Get(0));
+
+ ndn::AppHelper producerHelper("ns3::ndn::Producer");
+ producerHelper.SetPrefix("/prefix");
+ producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
+ producerHelper.Install(nodes.Get(1));
+
+ FaceContainer::Iterator node1Face_iterator = node0_faceContainer->Begin() + 1;
+
+ auto node1_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node1Face_iterator));
+
+ Simulator::Stop(Seconds(20.0));
+ Simulator::Run();
+
+ ::ndn::nfd::FaceStatus faceStatus = node1_netDeviceFace->getFaceStatus();
+ BOOST_CHECK_EQUAL(faceStatus.getNInInterests(), 2000);
+ Simulator::Destroy();
+}
+
+BOOST_AUTO_TEST_CASE(SendData)
+{
+
+ NodeContainer nodes;
+ nodes.Create(2);
+ PointToPointHelper p2p;
+ p2p.Install(nodes.Get(0), nodes.Get(1));
+
+
+ StackHelper ndnHelper;
+ ndnHelper.SetDefaultRoutes(true);
+
+ Ptr<FaceContainer> node0_faceContainer = ndnHelper.InstallAll();
+
+ ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
+ consumerHelper.SetPrefix("/prefix");
+ consumerHelper.SetAttribute("Frequency", StringValue("10"));
+ consumerHelper.Install(nodes.Get(0));
+
+ ndn::AppHelper producerHelper("ns3::ndn::Producer");
+ producerHelper.SetPrefix("/prefix");
+ producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
+ producerHelper.Install(nodes.Get(1));
+
+ FaceContainer::Iterator node0Face_iterator = node0_faceContainer->Begin();
+ FaceContainer::Iterator node1Face_iterator = node0_faceContainer->Begin() + 1;
+
+ auto node0_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node0Face_iterator));
+ auto node1_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node1Face_iterator));
+
+ auto interest = std::make_shared<ndn::Interest>("/prefix");
+ UniformVariable rand(0, std::numeric_limits<uint32_t>::max());
+ interest->setNonce(rand.GetValue());
+ interest->setInterestLifetime(ndn::time::seconds(1));
+
+ auto data = std::make_shared<ndn::Data>(interest->getName());
+ data->setFreshnessPeriod(ndn::time::milliseconds(1000));
+ data->setContent(std::make_shared< ::ndn::Buffer>(1024));
+ ndn::StackHelper::getKeyChain().sign(*data);
+
+ node1_netDeviceFace->sendData(*data);
+
+ Simulator::Stop(Seconds(20.0));
+ Simulator::Run();
+
+ ::ndn::nfd::FaceStatus node0faceStatus = node0_netDeviceFace->getFaceStatus();
+ ::ndn::nfd::FaceStatus node1faceStatus = node1_netDeviceFace->getFaceStatus();
+ BOOST_CHECK_EQUAL(node1faceStatus.getNOutDatas(), 201);
+ Simulator::Destroy();
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace ndn
+} // namespace ns3
diff --git a/tests/unit-tests/model/ndn-ns3.t.cpp b/tests/unit-tests/model/ndn-ns3.t.cpp
new file mode 100644
index 0000000..bd94360
--- /dev/null
+++ b/tests/unit-tests/model/ndn-ns3.t.cpp
@@ -0,0 +1,60 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "model/ndn-ns3.hpp"
+#include "helper/ndn-stack-helper.hpp"
+#include "model/ndn-header.hpp"
+#include "utils/ndn-ns3-packet-tag.hpp"
+
+#include <ndn-cxx/encoding/block.hpp>
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/data.hpp>
+#include <ndn-cxx/name.hpp>
+
+#include "../tests-common.hpp"
+
+namespace ns3 {
+namespace ndn {
+
+BOOST_FIXTURE_TEST_SUITE(ModelNdnNs3, CleanupFixture)
+
+BOOST_AUTO_TEST_CASE(ToPacket)
+{
+ auto interest = make_shared<ndn::Interest>("/prefix");
+ Ptr<Packet> interestPacket = Convert::ToPacket(*interest);
+ uint32_t type1;
+ type1 = Convert::getPacketType(interestPacket);
+
+ BOOST_CHECK_EQUAL(type1, ::ndn::tlv::Interest);
+
+ auto data = std::make_shared<ndn::Data>(interest->getName());
+ data->setFreshnessPeriod(ndn::time::milliseconds(1000));
+ data->setContent(std::make_shared< ::ndn::Buffer>(1024));
+ ndn::StackHelper::getKeyChain().sign(*data);
+ Ptr<Packet> DataPacket = Convert::ToPacket(*data);
+ uint32_t type2;
+ type2 = Convert::getPacketType(DataPacket);
+
+ BOOST_CHECK_EQUAL(type2, ::ndn::tlv::Data);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace ndn
+} // namespace ns3
diff --git a/tests/unit-tests/tests-common.hpp b/tests/unit-tests/tests-common.hpp
new file mode 100644
index 0000000..1c51eae
--- /dev/null
+++ b/tests/unit-tests/tests-common.hpp
@@ -0,0 +1,44 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#ifndef NDNSIM_TESTS_UNIT_TESTS_TESTS_COMMON_HPP
+#define NDNSIM_TESTS_UNIT_TESTS_TESTS_COMMON_HPP
+
+#include "ns3/core-module.h"
+#include "boost-test.hpp"
+#include "model/ndn-global-router.hpp"
+
+namespace ns3 {
+namespace ndn {
+
+class CleanupFixture
+{
+public:
+ ~CleanupFixture()
+ {
+ Simulator::Destroy();
+ Names::Clear();
+ GlobalRouter::clear();
+ }
+};
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // NDNSIM_TESTS_UNIT_TESTS_TESTS_COMMON_HPP