face: use IncomingFaceId, NextHopFaceId, CachePolicy tags
This commit replaces all LocalControlHeader usages with these tags,
and deletes LocalFace.
This commit also does minor improvements in RIB test suites.
refs #3339
Change-Id: I14cbfc296a6723a5860bf8bd95d9804d3bac3da5
diff --git a/tests/rib/rib-manager.t.cpp b/tests/rib/rib-manager.t.cpp
index 94a37af..1287284 100644
--- a/tests/rib/rib-manager.t.cpp
+++ b/tests/rib/rib-manager.t.cpp
@@ -28,29 +28,25 @@
#include "rib/rib-status-publisher-common.hpp"
#include "tests/test-common.hpp"
-#include "tests/limited-io.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
namespace nfd {
namespace rib {
namespace tests {
-class RibManagerFixture : public nfd::tests::BaseFixture
+using namespace nfd::tests;
+
+class RibManagerFixture : public UnitTestTimeFixture
{
public:
RibManagerFixture()
- : COMMAND_PREFIX("/localhost/nfd/rib")
- , ADD_NEXTHOP_VERB("add-nexthop")
- , REMOVE_NEXTHOP_VERB("remove-nexthop")
- , REGISTER_COMMAND("/localhost/nfd/rib/register")
- , UNREGISTER_COMMAND("/localhost/nfd/rib/unregister")
{
- face = ndn::util::makeDummyClientFace();
+ face = ndn::util::makeDummyClientFace(g_io);
manager = make_shared<RibManager>(*face, keyChain);
manager->registerWithNfd();
- face->processEvents(time::milliseconds(1));
+ advanceClocks(time::milliseconds(1));
face->sentInterests.clear();
}
@@ -73,18 +69,20 @@
}
void
- receiveCommandInterest(const Name& name, ControlParameters& parameters)
+ receiveCommandInterest(const Name& name, ControlParameters& parameters,
+ uint64_t incomingFaceId = DEFAULT_INCOMING_FACE_ID)
{
Name commandName = name;
commandName.append(parameters.wireEncode());
Interest commandInterest(commandName);
+ commandInterest.setTag(make_shared<lp::IncomingFaceIdTag>(incomingFaceId));
manager->m_managedRib.m_onSendBatchFromQueue = bind(&RibManagerFixture::onSendBatchFromQueue,
this, _1, parameters);
face->receive(commandInterest);
- face->processEvents(time::milliseconds(1));
+ advanceClocks(time::milliseconds(1));
}
void
@@ -109,14 +107,23 @@
shared_ptr<ndn::util::DummyClientFace> face;
ndn::KeyChain keyChain;
- const Name COMMAND_PREFIX;
- const Name::Component ADD_NEXTHOP_VERB;
- const Name::Component REMOVE_NEXTHOP_VERB;
+ static const uint64_t DEFAULT_INCOMING_FACE_ID;
- const Name REGISTER_COMMAND;
- const Name UNREGISTER_COMMAND;
+ static const Name COMMAND_PREFIX;
+ static const name::Component ADD_NEXTHOP_VERB;
+ static const name::Component REMOVE_NEXTHOP_VERB;
+
+ static const Name REGISTER_COMMAND;
+ static const Name UNREGISTER_COMMAND;
};
+const uint64_t RibManagerFixture::DEFAULT_INCOMING_FACE_ID = 25122;
+const Name RibManagerFixture::COMMAND_PREFIX("/localhost/nfd/rib");
+const name::Component RibManagerFixture::ADD_NEXTHOP_VERB("add-nexthop");
+const name::Component RibManagerFixture::REMOVE_NEXTHOP_VERB("remove-nexthop");
+const Name RibManagerFixture::REGISTER_COMMAND("/localhost/nfd/rib/register");
+const Name RibManagerFixture::UNREGISTER_COMMAND("/localhost/nfd/rib/unregister");
+
class AuthorizedRibManager : public RibManagerFixture
{
public:
@@ -232,6 +239,55 @@
BOOST_CHECK_EQUAL(extractedParameters.getFaceId(), removeParameters.getFaceId());
}
+BOOST_FIXTURE_TEST_CASE(SelfRegister, AuthorizedRibManager)
+{
+ ControlParameters parameters;
+ parameters
+ .setName("/hello");
+
+ receiveCommandInterest(REGISTER_COMMAND, parameters, 10129);
+
+ BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
+
+ Interest& request = face->sentInterests[0];
+
+ ControlParameters extractedParameters;
+ Name::Component verb;
+ extractParameters(request, verb, extractedParameters);
+
+ BOOST_CHECK_EQUAL(verb, ADD_NEXTHOP_VERB);
+ BOOST_CHECK_EQUAL(extractedParameters.getName(), parameters.getName());
+ BOOST_CHECK_EQUAL(extractedParameters.getFaceId(), 10129);
+}
+
+BOOST_FIXTURE_TEST_CASE(SelfUnregister, AuthorizedRibManager)
+{
+ ControlParameters addParameters;
+ addParameters
+ .setName("/hello")
+ .setFaceId(10129);
+
+ receiveCommandInterest(REGISTER_COMMAND, addParameters);
+ face->sentInterests.clear();
+
+ ControlParameters removeParameters;
+ removeParameters
+ .setName("/hello");
+
+ receiveCommandInterest(UNREGISTER_COMMAND, removeParameters, 10129);
+
+ BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
+
+ Interest& request = face->sentInterests[0];
+
+ ControlParameters extractedParameters;
+ Name::Component verb;
+ extractParameters(request, verb, extractedParameters);
+
+ BOOST_CHECK_EQUAL(verb, REMOVE_NEXTHOP_VERB);
+ BOOST_CHECK_EQUAL(extractedParameters.getName(), removeParameters.getName());
+ BOOST_CHECK_EQUAL(extractedParameters.getFaceId(), 10129);
+}
BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedRibManager)
{
@@ -264,7 +320,7 @@
manager->m_managedRib.insert(prefix, route);
face->receive(Interest("/localhost/nfd/rib/list"));
- face->processEvents(time::milliseconds(1));
+ advanceClocks(time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
RibStatusPublisherFixture::decodeRibEntryBlock(face->sentDatas[0], prefix, route);
@@ -298,8 +354,7 @@
addParameters.setExpirationPeriod(ndn::time::milliseconds::max());
receiveCommandInterest(REGISTER_COMMAND, addParameters);
- nfd::tests::LimitedIo limitedIo;
- limitedIo.run(nfd::tests::LimitedIo::UNLIMITED_OPS, time::seconds(1));
+ advanceClocks(time::milliseconds(100), time::seconds(1));
BOOST_REQUIRE_EQUAL(manager->m_managedRib.size(), 1);
}
@@ -338,8 +393,7 @@
manager->removeInvalidFaces(buffer);
// Run scheduler
- nfd::tests::LimitedIo limitedIo;
- limitedIo.run(nfd::tests::LimitedIo::UNLIMITED_OPS, time::seconds(1));
+ advanceClocks(time::milliseconds(100), time::seconds(1));
BOOST_REQUIRE_EQUAL(manager->m_managedRib.size(), 1);
@@ -399,8 +453,7 @@
BOOST_REQUIRE_EQUAL(manager->m_managedRib.size(), 1);
// Route should expire
- nfd::tests::LimitedIo limitedIo;
- limitedIo.run(nfd::tests::LimitedIo::UNLIMITED_OPS, time::seconds(1));
+ advanceClocks(time::milliseconds(100), time::seconds(1));
BOOST_CHECK_EQUAL(manager->m_managedRib.size(), 0);
}