face: Configurable IP subnets for "local" TCP faces

Change-Id: Idaddfe4b2c304b552d2e132235f4c3d3e6c2ebcb
Refs: #4546
This commit is contained in:
Alexander Afanasyev
2018-04-03 19:00:23 -04:00
parent e4d745d41f
commit ded17426c6
13 changed files with 201 additions and 22 deletions
+6 -2
View File
@@ -64,11 +64,15 @@ createFace(ProtocolFactory& factory,
const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
const TestFaceParams& params,
const CreateFaceExpectedResult& expected)
const CreateFaceExpectedResult& expected,
const std::function<void(const Face&)>& extraChecks = nullptr)
{
factory.createFace({remoteUri, localUri, params},
[expected] (const shared_ptr<Face>&) {
[expected, extraChecks] (const shared_ptr<Face>& face) {
BOOST_CHECK_EQUAL(CreateFaceExpectedResult::SUCCESS, expected.result);
if (extraChecks) {
extraChecks(*face);
}
},
[expected] (uint32_t actualStatus, const std::string& actualReason) {
BOOST_CHECK_EQUAL(CreateFaceExpectedResult::FAILURE, expected.result);
+21 -1
View File
@@ -27,6 +27,7 @@
#define NFD_TESTS_DAEMON_FACE_TCP_CHANNEL_FIXTURE_HPP
#include "face/tcp-channel.hpp"
#include "core/network-predicate.hpp"
#include "channel-fixture.hpp"
@@ -37,13 +38,19 @@ namespace tests {
class TcpChannelFixture : public ChannelFixture<TcpChannel, tcp::Endpoint>
{
protected:
TcpChannelFixture()
{
local.assign({{"subnet", "127.0.0.0/8"}, {"subnet", "::1/128"}}, {});
}
unique_ptr<TcpChannel>
makeChannel(const boost::asio::ip::address& addr, uint16_t port = 0) final
{
if (port == 0)
port = getNextPort();
return make_unique<TcpChannel>(tcp::Endpoint(addr, port), false);
return make_unique<TcpChannel>(tcp::Endpoint(addr, port), false,
std::bind(&TcpChannelFixture::determineFaceScope, this, _1, _2));
}
void
@@ -61,8 +68,21 @@ protected:
});
}
ndn::nfd::FaceScope
determineFaceScope(const boost::asio::ip::address& localAddress,
const boost::asio::ip::address& remoteAddress)
{
if (local(localAddress) && local(remoteAddress)) {
return ndn::nfd::FACE_SCOPE_LOCAL;
}
else {
return ndn::nfd::FACE_SCOPE_NON_LOCAL;
}
}
protected:
std::vector<shared_ptr<Face>> clientFaces;
IpAddressPredicate local;
};
} // namespace tests
+90 -1
View File
@@ -45,6 +45,9 @@ protected:
boost::lexical_cast<uint16_t>(localPort));
return factory.createChannel(endpoint);
}
protected:
LimitedIo limitedIo;
};
BOOST_AUTO_TEST_SUITE(Face)
@@ -68,6 +71,11 @@ BOOST_AUTO_TEST_CASE(Defaults)
auto channels = factory.getChannels();
BOOST_CHECK(std::all_of(channels.begin(), channels.end(),
[] (const shared_ptr<const Channel>& ch) { return ch->isListening(); }));
BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.size(), 2);
BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.count("127.0.0.0/8"), 1);
BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.count("::1/128"), 1);
BOOST_CHECK_EQUAL(factory.m_local.m_blacklist.size(), 0);
}
BOOST_AUTO_TEST_CASE(DisableListen)
@@ -132,6 +140,88 @@ BOOST_AUTO_TEST_CASE(DisableV6)
checkChannelListEqual(factory, {"tcp4://0.0.0.0:7001"});
}
BOOST_AUTO_TEST_CASE(ConfigureLocal)
{
const std::string CONFIG = R"CONFIG(
face_system
{
tcp
{
local {
whitelist {
subnet 127.0.0.0/8
}
blacklist {
subnet ::1/128
}
}
}
}
)CONFIG";
parseConfig(CONFIG, true);
parseConfig(CONFIG, false);
BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.size(), 1);
BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.count("127.0.0.0/8"), 1);
BOOST_CHECK_EQUAL(factory.m_local.m_blacklist.size(), 1);
BOOST_CHECK_EQUAL(factory.m_local.m_blacklist.count("::1/128"), 1);
createFace(factory,
FaceUri("tcp4://127.0.0.1:6363"),
{},
{ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, false, false, false},
{CreateFaceExpectedResult::SUCCESS, 0, ""},
[] (const nfd::Face& face) {
BOOST_CHECK_EQUAL(face.getScope(), ndn::nfd::FACE_SCOPE_LOCAL);
});
limitedIo.run(1, 100_ms);
}
BOOST_AUTO_TEST_CASE(ConfigureNonLocal)
{
const std::string CONFIG = R"CONFIG(
face_system
{
tcp
{
local {
whitelist {
*
}
blacklist {
subnet 127.0.0.0/8
subnet ::1/128
}
}
}
}
)CONFIG";
parseConfig(CONFIG, true);
parseConfig(CONFIG, false);
BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.size(), 1);
BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.count("*"), 1);
BOOST_CHECK_EQUAL(factory.m_local.m_blacklist.size(), 2);
BOOST_CHECK_EQUAL(factory.m_local.m_blacklist.count("127.0.0.0/8"), 1);
BOOST_CHECK_EQUAL(factory.m_local.m_blacklist.count("::1/128"), 1);
createFace(factory,
FaceUri("tcp4://127.0.0.1:6363"),
{},
{ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, false, false, false},
{CreateFaceExpectedResult::SUCCESS, 0, ""},
[] (const nfd::Face& face) {
BOOST_CHECK_EQUAL(face.getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
});
limitedIo.run(1, 100_ms);
}
BOOST_AUTO_TEST_CASE(Omitted)
{
const std::string CONFIG = R"CONFIG(
@@ -357,7 +447,6 @@ public:
}
public:
LimitedIo limitedIo;
shared_ptr<nfd::Face> face;
};
+11 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2017, Regents of the University of California,
* Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -88,8 +88,17 @@ protected:
BOOST_REQUIRE_EQUAL(limitedIo.run(2, time::seconds(1)), LimitedIo::EXCEED_OPS);
localEp = sock.local_endpoint();
ndn::nfd::FaceScope scope;
if (sock.local_endpoint().address().is_loopback() && sock.remote_endpoint().address().is_loopback()) {
scope = ndn::nfd::FACE_SCOPE_LOCAL;
}
else {
scope = ndn::nfd::FACE_SCOPE_NON_LOCAL;
}
face = make_unique<Face>(make_unique<DummyReceiveLinkService>(),
make_unique<TcpTransport>(std::move(sock), persistency));
make_unique<TcpTransport>(std::move(sock), persistency, scope));
transport = static_cast<TcpTransport*>(face->getTransport());
receivedPackets = &static_cast<DummyReceiveLinkService*>(face->getLinkService())->receivedPackets;
+1 -1
View File
@@ -119,7 +119,7 @@ class PermanentTcpTransportReconnectObserver : public TcpTransport
{
public:
PermanentTcpTransportReconnectObserver(protocol::socket&& socket, LimitedIo& io)
: TcpTransport(std::move(socket), ndn::nfd::FACE_PERSISTENCY_PERMANENT)
: TcpTransport(std::move(socket), ndn::nfd::FACE_PERSISTENCY_PERMANENT, ndn::nfd::FACE_SCOPE_LOCAL)
, m_io(io)
{
}
+1 -1
View File
@@ -45,7 +45,7 @@ class FaceBenchmark
public:
FaceBenchmark(const char* configFileName)
: m_terminationSignalSet{getGlobalIoService()}
, m_tcpChannel{tcp::Endpoint{boost::asio::ip::tcp::v4(), 6363}, false}
, m_tcpChannel{tcp::Endpoint{boost::asio::ip::tcp::v4(), 6363}, false, bind([] { return ndn::nfd::FACE_SCOPE_NON_LOCAL; })}
, m_udpChannel{udp::Endpoint{boost::asio::ip::udp::v4(), 6363}, time::minutes{10}, false}
{
m_terminationSignalSet.add(SIGINT);