face: implement IPv6 UDP multicast transport
Change-Id: Ib6ab956354dbbba00694c7949fa9ee4639579879
Refs: #4222
diff --git a/daemon/face/multicast-udp-transport.cpp b/daemon/face/multicast-udp-transport.cpp
index 86324d3..8912759 100644
--- a/daemon/face/multicast-udp-transport.cpp
+++ b/daemon/face/multicast-udp-transport.cpp
@@ -27,6 +27,8 @@
#include "socket-utils.hpp"
#include "udp-protocol.hpp"
+#include <boost/functional/hash.hpp>
+
#ifdef __linux__
#include <cerrno> // for errno
#include <cstring> // for std::strerror()
@@ -39,8 +41,7 @@
NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(DatagramTransport, MulticastUdpTransport::protocol,
Multicast, "MulticastUdpTransport");
-MulticastUdpTransport::MulticastUdpTransport(const protocol::endpoint& localEndpoint,
- const protocol::endpoint& multicastGroup,
+MulticastUdpTransport::MulticastUdpTransport(const protocol::endpoint& multicastGroup,
protocol::socket&& recvSocket,
protocol::socket&& sendSocket,
ndn::nfd::LinkType linkType)
@@ -48,12 +49,12 @@
, m_multicastGroup(multicastGroup)
, m_sendSocket(std::move(sendSocket))
{
- this->setLocalUri(FaceUri(localEndpoint));
+ this->setLocalUri(FaceUri(m_sendSocket.local_endpoint()));
this->setRemoteUri(FaceUri(multicastGroup));
this->setScope(ndn::nfd::FACE_SCOPE_NON_LOCAL);
this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
this->setLinkType(linkType);
- this->setMtu(udp::computeMtu(localEndpoint));
+ this->setMtu(udp::computeMtu(m_sendSocket.local_endpoint()));
protocol::socket::send_buffer_size sendBufferSizeOption;
boost::system::error_code error;
@@ -117,16 +118,25 @@
sock.open(multicastGroup.protocol());
sock.set_option(protocol::socket::reuse_address(true));
- sock.bind(protocol::endpoint(multicastGroup.protocol(), multicastGroup.port()));
if (multicastGroup.address().is_v4()) {
BOOST_ASSERT(localAddress.is_v4());
+ sock.bind(multicastGroup);
sock.set_option(boost::asio::ip::multicast::join_group(multicastGroup.address().to_v4(),
localAddress.to_v4()));
}
else {
- // IPv6 multicast is not supported
- BOOST_ASSERT(false);
+ BOOST_ASSERT(localAddress.is_v6());
+ sock.set_option(boost::asio::ip::v6_only(true));
+#ifdef WITH_TESTS
+ // To simplify unit tests, we bind to the "any" IPv6 address if the supplied multicast
+ // address lacks a scope id. Calling bind() without a scope id would otherwise fail.
+ if (multicastGroup.address().to_v6().scope_id() == 0)
+ sock.bind(protocol::endpoint(boost::asio::ip::address_v6::any(), multicastGroup.port()));
+ else
+#endif
+ sock.bind(multicastGroup);
+ sock.set_option(boost::asio::ip::multicast::join_group(multicastGroup.address().to_v6()));
}
#ifdef __linux__
@@ -149,6 +159,7 @@
void
MulticastUdpTransport::openTxSocket(protocol::socket& sock,
const protocol::endpoint& localEndpoint,
+ const shared_ptr<const ndn::net::NetworkInterface>& netif,
bool enableLoopback)
{
BOOST_ASSERT(!sock.is_open());
@@ -156,15 +167,17 @@
sock.open(localEndpoint.protocol());
sock.set_option(protocol::socket::reuse_address(true));
sock.set_option(boost::asio::ip::multicast::enable_loopback(enableLoopback));
- sock.bind(localEndpoint);
if (localEndpoint.address().is_v4()) {
+ sock.bind(localEndpoint);
if (!localEndpoint.address().is_unspecified())
sock.set_option(boost::asio::ip::multicast::outbound_interface(localEndpoint.address().to_v4()));
}
else {
- // IPv6 multicast is not supported
- BOOST_ASSERT(false);
+ sock.set_option(boost::asio::ip::v6_only(true));
+ sock.bind(localEndpoint);
+ if (netif)
+ sock.set_option(boost::asio::ip::multicast::outbound_interface(netif->getIndex()));
}
}
@@ -172,11 +185,17 @@
Transport::EndpointId
DatagramTransport<boost::asio::ip::udp, Multicast>::makeEndpointId(const protocol::endpoint& ep)
{
- // IPv6 multicast is not supported
- BOOST_ASSERT(ep.address().is_v4());
-
- return (static_cast<uint64_t>(ep.port()) << 32) |
- static_cast<uint64_t>(ep.address().to_v4().to_ulong());
+ if (ep.address().is_v4()) {
+ return (static_cast<uint64_t>(ep.port()) << 32) |
+ static_cast<uint64_t>(ep.address().to_v4().to_ulong());
+ }
+ else {
+ size_t seed = 0;
+ const auto& addrBytes = ep.address().to_v6().to_bytes();
+ boost::hash_range(seed, addrBytes.begin(), addrBytes.end());
+ boost::hash_combine(seed, ep.port());
+ return seed;
+ }
}
} // namespace face
diff --git a/daemon/face/multicast-udp-transport.hpp b/daemon/face/multicast-udp-transport.hpp
index e655f4a..ba7bcbe 100644
--- a/daemon/face/multicast-udp-transport.hpp
+++ b/daemon/face/multicast-udp-transport.hpp
@@ -59,14 +59,12 @@
/**
* \brief Creates a UDP-based transport for multicast communication
- * \param localEndpoint local endpoint
* \param multicastGroup multicast group
- * \param recvSocket socket used to receive packets
+ * \param recvSocket socket used to receive multicast packets
* \param sendSocket socket used to send to the multicast group
- * \param linkType either LINK_TYPE_MULTI_ACCESS or LINK_TYPE_AD_HOC
+ * \param linkType either `ndn::nfd::LINK_TYPE_MULTI_ACCESS` or `ndn::nfd::LINK_TYPE_AD_HOC`
*/
- MulticastUdpTransport(const protocol::endpoint& localEndpoint,
- const protocol::endpoint& multicastGroup,
+ MulticastUdpTransport(const protocol::endpoint& multicastGroup,
protocol::socket&& recvSocket,
protocol::socket&& sendSocket,
ndn::nfd::LinkType linkType);
@@ -83,6 +81,7 @@
static void
openTxSocket(protocol::socket& sock,
const protocol::endpoint& localEndpoint,
+ const shared_ptr<const ndn::net::NetworkInterface>& netif = nullptr,
bool enableLoopback = false);
private:
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index c9cab22..2024cd6 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -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,
@@ -68,6 +68,8 @@
// mcast yes
// mcast_group 224.0.23.170
// mcast_port 56363
+ // mcast_group_v6 ff02::1234
+ // mcast_port_v6 56363
// mcast_ad_hoc no
// whitelist
// {
@@ -126,6 +128,22 @@
else if (key == "mcast_port") {
mcastConfig.group.port(ConfigFile::parseNumber<uint16_t>(pair, "face_system.udp"));
}
+ else if (key == "mcast_group_v6") {
+ const std::string& valueStr = value.get_value<std::string>();
+ boost::system::error_code ec;
+ mcastConfig.groupV6.address(ndn::ip::addressV6FromString(valueStr, ec));
+ if (ec) {
+ BOOST_THROW_EXCEPTION(ConfigFile::Error("face_system.udp.mcast_group_v6: '" +
+ valueStr + "' cannot be parsed as an IPv6 address"));
+ }
+ else if (!mcastConfig.groupV6.address().is_multicast()) {
+ BOOST_THROW_EXCEPTION(ConfigFile::Error("face_system.udp.mcast_group_v6: '" +
+ valueStr + "' is not a multicast address"));
+ }
+ }
+ else if (key == "mcast_port_v6") {
+ mcastConfig.groupV6.port(ConfigFile::parseNumber<uint16_t>(pair, "face_system.udp"));
+ }
else if (key == "mcast_ad_hoc") {
bool wantAdHoc = ConfigFile::parseYesNo(pair, "face_system.udp");
mcastConfig.linkType = wantAdHoc ? ndn::nfd::LINK_TYPE_AD_HOC : ndn::nfd::LINK_TYPE_MULTI_ACCESS;
@@ -181,6 +199,7 @@
if (m_mcastConfig.isEnabled != mcastConfig.isEnabled) {
if (mcastConfig.isEnabled) {
NFD_LOG_INFO("enabling multicast on " << mcastConfig.group);
+ NFD_LOG_INFO("enabling multicast on " << mcastConfig.groupV6);
}
else {
NFD_LOG_INFO("disabling multicast");
@@ -191,9 +210,13 @@
NFD_LOG_WARN("Cannot change ad hoc setting on existing faces");
}
if (m_mcastConfig.group != mcastConfig.group) {
- NFD_LOG_INFO("changing multicast group from " << m_mcastConfig.group <<
+ NFD_LOG_INFO("changing IPv4 multicast group from " << m_mcastConfig.group <<
" to " << mcastConfig.group);
}
+ if (m_mcastConfig.groupV6 != mcastConfig.groupV6) {
+ NFD_LOG_INFO("changing IPv6 multicast group from " << m_mcastConfig.groupV6 <<
+ " to " << mcastConfig.groupV6);
+ }
if (m_mcastConfig.netifPredicate != mcastConfig.netifPredicate) {
NFD_LOG_INFO("changing whitelist/blacklist");
}
@@ -262,15 +285,11 @@
if (it != m_channels.end())
return it->second;
- if (localEndpoint.address().is_multicast()) {
- BOOST_THROW_EXCEPTION(Error("createChannel is only for unicast channels. The provided endpoint "
- "is multicast. Use createMulticastFace to create a multicast face"));
- }
-
// check if the endpoint is already used by a multicast face
if (m_mcastFaces.find(localEndpoint) != m_mcastFaces.end()) {
- BOOST_THROW_EXCEPTION(Error("Cannot create the requested UDP unicast channel, local "
- "endpoint is already allocated for a UDP multicast face"));
+ BOOST_THROW_EXCEPTION(Error("Cannot create UDP channel on " +
+ boost::lexical_cast<std::string>(localEndpoint) +
+ ", endpoint already allocated for a UDP multicast face"));
}
auto channel = std::make_shared<UdpChannel>(localEndpoint, idleTimeout);
@@ -286,126 +305,148 @@
}
shared_ptr<Face>
-UdpFactory::createMulticastFace(const udp::Endpoint& localEndpoint,
- const udp::Endpoint& multicastEndpoint,
- const shared_ptr<const ndn::net::NetworkInterface>& netif)
+UdpFactory::createMulticastFace(const shared_ptr<const net::NetworkInterface>& netif,
+ const ip::address& localAddress,
+ const udp::Endpoint& multicastEndpoint)
{
BOOST_ASSERT(multicastEndpoint.address().is_multicast());
- BOOST_ASSERT(localEndpoint.port() == multicastEndpoint.port());
- // check if the local and multicast endpoints are already in use for a multicast face
- auto it = m_mcastFaces.find(localEndpoint);
+ udp::Endpoint localEp(localAddress, multicastEndpoint.port());
+ BOOST_ASSERT(localEp.protocol() == multicastEndpoint.protocol());
+
+ auto mcastEp = multicastEndpoint;
+ if (mcastEp.address().is_v6()) {
+ // in IPv6, a scope id on the multicast address is always required
+ auto mcastAddress = mcastEp.address().to_v6();
+ mcastAddress.scope_id(netif->getIndex());
+ mcastEp.address(mcastAddress);
+ }
+
+ // check if the local endpoint is already used by another multicast face
+ auto it = m_mcastFaces.find(localEp);
if (it != m_mcastFaces.end()) {
- if (it->second->getRemoteUri() == FaceUri(multicastEndpoint))
+ if (it->second->getRemoteUri() == FaceUri(mcastEp))
return it->second;
else
- BOOST_THROW_EXCEPTION(Error("Cannot create the requested UDP multicast face, local "
- "endpoint is already allocated for a UDP multicast face "
- "on a different multicast group"));
+ BOOST_THROW_EXCEPTION(Error("Cannot create UDP multicast face on " +
+ boost::lexical_cast<std::string>(localEp) +
+ ", endpoint already allocated for a different UDP multicast face"));
}
// check if the local endpoint is already used by a unicast channel
- if (m_channels.find(localEndpoint) != m_channels.end()) {
- BOOST_THROW_EXCEPTION(Error("Cannot create the requested UDP multicast face, local "
- "endpoint is already allocated for a UDP unicast channel"));
- }
-
- if (localEndpoint.address().is_v6() || multicastEndpoint.address().is_v6()) {
- BOOST_THROW_EXCEPTION(Error("IPv6 multicast is not supported yet. Please provide an IPv4 "
- "address"));
+ if (m_channels.find(localEp) != m_channels.end()) {
+ BOOST_THROW_EXCEPTION(Error("Cannot create UDP multicast face on " +
+ boost::lexical_cast<std::string>(localEp) +
+ ", endpoint already allocated for a UDP channel"));
}
ip::udp::socket rxSock(getGlobalIoService());
- MulticastUdpTransport::openRxSocket(rxSock, multicastEndpoint, localEndpoint.address(), netif);
+ MulticastUdpTransport::openRxSocket(rxSock, mcastEp, localAddress, netif);
ip::udp::socket txSock(getGlobalIoService());
- MulticastUdpTransport::openTxSocket(txSock, localEndpoint);
+ MulticastUdpTransport::openTxSocket(txSock, udp::Endpoint(localAddress, 0), netif);
auto linkService = make_unique<GenericLinkService>();
- auto transport = make_unique<MulticastUdpTransport>(localEndpoint, multicastEndpoint,
- std::move(rxSock), std::move(txSock),
+ auto transport = make_unique<MulticastUdpTransport>(mcastEp, std::move(rxSock), std::move(txSock),
m_mcastConfig.linkType);
auto face = make_shared<Face>(std::move(linkService), std::move(transport));
- m_mcastFaces[localEndpoint] = face;
- connectFaceClosedSignal(*face, [this, localEndpoint] { m_mcastFaces.erase(localEndpoint); });
+ m_mcastFaces[localEp] = face;
+ connectFaceClosedSignal(*face, [this, localEp] { m_mcastFaces.erase(localEp); });
return face;
}
static ndn::optional<ip::address>
-getV4Address(const net::NetworkInterface& netif)
+pickAddress(const net::NetworkInterface& netif, net::AddressFamily af)
{
for (const auto& na : netif.getNetworkAddresses()) {
- if (na.getFamily() == net::AddressFamily::V4 && na.getScope() != net::AddressScope::NOWHERE) {
+ if (na.getFamily() == af &&
+ (na.getScope() == net::AddressScope::LINK || na.getScope() == net::AddressScope::GLOBAL)) {
return na.getIp();
}
}
return ndn::nullopt;
}
-shared_ptr<Face>
+std::vector<shared_ptr<Face>>
UdpFactory::applyMcastConfigToNetif(const shared_ptr<const net::NetworkInterface>& netif)
{
BOOST_ASSERT(netif != nullptr);
if (!m_mcastConfig.isEnabled) {
- return nullptr;
+ return {};
}
if (!netif->isUp()) {
- NFD_LOG_DEBUG("Not creating multicast face on " << netif->getName() << ": netif is down");
- return nullptr;
+ NFD_LOG_DEBUG("Not creating multicast faces on " << netif->getName() << ": netif is down");
+ return {};
+ }
+
+ if (netif->isLoopback()) {
+ NFD_LOG_DEBUG("Not creating multicast faces on " << netif->getName() << ": netif is loopback");
+ return {};
}
if (!netif->canMulticast()) {
- NFD_LOG_DEBUG("Not creating multicast face on " << netif->getName() << ": netif cannot multicast");
- return nullptr;
- }
-
- auto address = getV4Address(*netif);
- if (!address) {
- NFD_LOG_DEBUG("Not creating multicast face on " << netif->getName() << ": no IPv4 address");
- // keep an eye on new addresses
- m_netifConns[netif->getIndex()].addrAddConn =
- netif->onAddressAdded.connectSingleShot(bind(&UdpFactory::applyMcastConfigToNetif, this, netif));
- return nullptr;
+ NFD_LOG_DEBUG("Not creating multicast faces on " << netif->getName() << ": netif cannot multicast");
+ return {};
}
if (!m_mcastConfig.netifPredicate(*netif)) {
- NFD_LOG_DEBUG("Not creating multicast face on " << netif->getName() << ": rejected by whitelist/blacklist");
- return nullptr;
+ NFD_LOG_DEBUG("Not creating multicast faces on " << netif->getName() << ": rejected by whitelist/blacklist");
+ return {};
}
- NFD_LOG_DEBUG("Creating multicast face on " << netif->getName());
-
- udp::Endpoint localEndpoint(*address, m_mcastConfig.group.port());
- auto face = this->createMulticastFace(localEndpoint, m_mcastConfig.group, netif);
- if (face->getId() == INVALID_FACEID) {
- // new face: register with forwarding
- this->addFace(face);
+ std::vector<ip::address> addrs;
+ for (auto af : {net::AddressFamily::V4, net::AddressFamily::V6}) {
+ auto addr = pickAddress(*netif, af);
+ if (addr)
+ addrs.push_back(*addr);
}
- return face;
+ if (addrs.empty()) {
+ NFD_LOG_DEBUG("Not creating multicast faces on " << netif->getName() << ": no viable IP address");
+ // keep an eye on new addresses
+ m_netifConns[netif->getIndex()].addrAddConn =
+ netif->onAddressAdded.connect(bind(&UdpFactory::applyMcastConfigToNetif, this, netif));
+ return {};
+ }
+
+ NFD_LOG_DEBUG("Creating multicast faces on " << netif->getName());
+
+ std::vector<shared_ptr<Face>> faces;
+ for (const auto& addr : addrs) {
+ auto face = this->createMulticastFace(netif, addr,
+ addr.is_v4() ? m_mcastConfig.group : m_mcastConfig.groupV6);
+ if (face->getId() == INVALID_FACEID) {
+ // new face: register with forwarding
+ this->addFace(face);
+ }
+ faces.push_back(std::move(face));
+ }
+
+ return faces;
}
void
UdpFactory::applyMcastConfig(const FaceSystem::ConfigContext& context)
{
// collect old faces
- std::set<shared_ptr<Face>> oldFaces;
- boost::copy(m_mcastFaces | boost::adaptors::map_values, std::inserter(oldFaces, oldFaces.end()));
+ std::set<shared_ptr<Face>> facesToClose;
+ boost::copy(m_mcastFaces | boost::adaptors::map_values,
+ std::inserter(facesToClose, facesToClose.end()));
// create faces if requested by config
for (const auto& netif : netmon->listNetworkInterfaces()) {
- auto face = this->applyMcastConfigToNetif(netif);
- if (face != nullptr) {
+ auto facesToKeep = this->applyMcastConfigToNetif(netif);
+ for (const auto& face : facesToKeep) {
// don't destroy face
- oldFaces.erase(face);
+ facesToClose.erase(face);
}
}
// destroy old faces that are not needed in new configuration
- for (const auto& face : oldFaces) {
+ for (const auto& face : facesToClose) {
face->close();
}
}
diff --git a/daemon/face/udp-factory.hpp b/daemon/face/udp-factory.hpp
index 3f644c4..1153a7a 100644
--- a/daemon/face/udp-factory.hpp
+++ b/daemon/face/udp-factory.hpp
@@ -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,
@@ -99,30 +99,31 @@
*
* The face will join the specified multicast group.
*
- * If this method is called twice with the same pair of endpoints, only one
+ * If this method is called twice with the same set of arguments, only one
* face will be created. The second call will just return the existing face.
*
* If a UDP channel, unicast face, or multicast face already exists on the
- * same local endpoint, the creation fails and an exception is thrown.
+ * same combination of local address and multicast port, the creation fails
+ * and an exception is thrown.
*
- * \param localEndpoint the local endpoint
- * \param multicastEndpoint the multicast endpoint
* \param netif the network interface to which the face will be bound
+ * \param localAddress the local IP address to which the face will be bound
+ * \param multicastEndpoint the multicast endpoint (multicast group and port number)
*
* \return always a valid shared pointer to the created face;
* an exception is thrown if the face cannot be created.
* \throw UdpFactory::Error
*/
shared_ptr<Face>
- createMulticastFace(const udp::Endpoint& localEndpoint,
- const udp::Endpoint& multicastEndpoint,
- const shared_ptr<const ndn::net::NetworkInterface>& netif);
+ createMulticastFace(const shared_ptr<const ndn::net::NetworkInterface>& netif,
+ const boost::asio::ip::address& localAddress,
+ const udp::Endpoint& multicastEndpoint);
private:
- /** \brief Create UDP multicast face on \p netif if needed by \p m_mcastConfig
- * \return new or existing face, or nullptr if no face should be created
+ /** \brief Create UDP multicast faces on \p netif if needed by \p m_mcastConfig
+ * \return list of faces (just created or already existing) on \p netif
*/
- shared_ptr<Face>
+ std::vector<shared_ptr<Face>>
applyMcastConfigToNetif(const shared_ptr<const ndn::net::NetworkInterface>& netif);
/** \brief Create and destroy UDP multicast faces according to \p m_mcastConfig
@@ -137,6 +138,7 @@
{
bool isEnabled = false;
udp::Endpoint group = udp::getDefaultMulticastGroup();
+ udp::Endpoint groupV6 = udp::getDefaultMulticastGroupV6();
ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS;
NetworkInterfacePredicate netifPredicate;
};
diff --git a/daemon/face/udp-protocol.hpp b/daemon/face/udp-protocol.hpp
index f716658..85a6a5f 100644
--- a/daemon/face/udp-protocol.hpp
+++ b/daemon/face/udp-protocol.hpp
@@ -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,
@@ -38,15 +38,22 @@
ssize_t
computeMtu(const Endpoint& localEndpoint);
-/** \return default multicast group: 224.0.23.170:56363
+/** \return default IPv4 multicast group: 224.0.23.170:56363
*/
inline Endpoint
getDefaultMulticastGroup()
{
- // 224.0.23.170:56363
return {boost::asio::ip::address_v4(0xE00017AA), 56363};
}
+/** \return default IPv6 multicast group: [FF02::1234]:56363
+ */
+inline Endpoint
+getDefaultMulticastGroupV6()
+{
+ return {boost::asio::ip::address_v6::from_string("FF02::1234"), 56363};
+}
+
} // namespace udp
} // namespace nfd
diff --git a/nfd.conf.sample.in b/nfd.conf.sample.in
index a960b7d..2ae5f84 100644
--- a/nfd.conf.sample.in
+++ b/nfd.conf.sample.in
@@ -127,8 +127,10 @@
; sudo setcap cap_net_raw=eip /path/to/nfd
;
mcast yes ; set to 'no' to disable UDP multicast, default 'yes'
- mcast_group 224.0.23.170 ; UDP multicast group (IPv4 only)
- mcast_port 56363 ; UDP multicast port number
+ mcast_group 224.0.23.170 ; UDP multicast group (IPv4)
+ mcast_port 56363 ; UDP multicast port number (IPv4)
+ mcast_group_v6 ff02::1234 ; UDP multicast group (IPv6)
+ mcast_port_v6 56363 ; UDP multicast port number (IPv6)
mcast_ad_hoc no ; set to 'yes' to make all UDP multicast faces "ad hoc", default 'no'
; Whitelist and blacklist can contain, in no particular order:
diff --git a/tests/daemon/face/datagram-transport.t.cpp b/tests/daemon/face/datagram-transport.t.cpp
index 8cfb622..d5ce2a8 100644
--- a/tests/daemon/face/datagram-transport.t.cpp
+++ b/tests/daemon/face/datagram-transport.t.cpp
@@ -39,7 +39,9 @@
using DatagramTransportFixtures = boost::mpl::vector<
GENERATE_IP_TRANSPORT_FIXTURE_INSTANTIATIONS(UnicastUdpTransportFixture),
- IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V4, AddressScope::Global, MulticastInterface::Yes>
+ IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V4, AddressScope::Global, MulticastInterface::Yes>,
+ IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::LinkLocal, MulticastInterface::Yes>,
+ IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::Global, MulticastInterface::Yes>
>;
BOOST_FIXTURE_TEST_CASE_TEMPLATE(Send, T, DatagramTransportFixtures, T)
diff --git a/tests/daemon/face/multicast-udp-transport-fixture.hpp b/tests/daemon/face/multicast-udp-transport-fixture.hpp
index 2b86833..5959821 100644
--- a/tests/daemon/face/multicast-udp-transport-fixture.hpp
+++ b/tests/daemon/face/multicast-udp-transport-fixture.hpp
@@ -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,
@@ -45,7 +45,7 @@
protected:
MulticastUdpTransportFixture()
: transport(nullptr)
- , multicastEp(ip::address::from_string("230.15.19.47"), 7070)
+ , txPort(7001)
, receivedPackets(nullptr)
, remoteSockRx(g_io)
, remoteSockTx(g_io)
@@ -55,21 +55,32 @@
void
initialize(ip::address address)
{
- localEp = udp::endpoint(address, 7001);
+ ip::address mcastAddr;
+ if (address.is_v4()) {
+ // the administratively scoped group 224.0.0.254 is reserved for experimentation (RFC 4727)
+ mcastAddr = ip::address_v4(0xE00000FE);
+ }
+ else {
+ // the group FF0X::114 is reserved for experimentation at all scope levels (RFC 4727)
+ auto v6Addr = ip::address_v6::from_string("FF01::114");
+ v6Addr.scope_id(address.to_v6().scope_id());
+ mcastAddr = v6Addr;
+ }
+ mcastEp = udp::endpoint(mcastAddr, 7373);
+ remoteMcastEp = udp::endpoint(mcastAddr, 8383);
- MulticastUdpTransport::openRxSocket(remoteSockRx, multicastEp, ip::address_v4::any());
- MulticastUdpTransport::openTxSocket(remoteSockTx, udp::endpoint(udp::v4(), 0), true);
+ MulticastUdpTransport::openRxSocket(remoteSockRx, mcastEp, address);
+ MulticastUdpTransport::openTxSocket(remoteSockTx, udp::endpoint(address, 0), nullptr, true);
udp::socket sockRx(g_io);
udp::socket sockTx(g_io);
- MulticastUdpTransport::openRxSocket(sockRx, udp::endpoint(multicastEp.address(), localEp.port()),
- ip::address_v4::any());
- MulticastUdpTransport::openTxSocket(sockTx, udp::endpoint(udp::v4(), 0), true);
+ MulticastUdpTransport::openRxSocket(sockRx, remoteMcastEp, address);
+ MulticastUdpTransport::openTxSocket(sockTx, udp::endpoint(address, txPort), nullptr, true);
face = make_unique<Face>(
make_unique<DummyReceiveLinkService>(),
- make_unique<MulticastUdpTransport>(localEp, multicastEp, std::move(sockRx),
- std::move(sockTx), ndn::nfd::LINK_TYPE_MULTI_ACCESS));
+ make_unique<MulticastUdpTransport>(mcastEp, std::move(sockRx), std::move(sockTx),
+ ndn::nfd::LINK_TYPE_MULTI_ACCESS));
transport = static_cast<MulticastUdpTransport*>(face->getTransport());
receivedPackets = &static_cast<DummyReceiveLinkService*>(face->getLinkService())->receivedPackets;
@@ -92,24 +103,31 @@
void
remoteWrite(const std::vector<uint8_t>& buf, bool needToCheck = true)
{
- remoteSockTx.async_send_to(boost::asio::buffer(buf), udp::endpoint(multicastEp.address(), 7001),
+ sendToGroup(remoteSockTx, buf, needToCheck);
+ limitedIo.defer(time::seconds(1));
+ }
+
+ void
+ sendToGroup(udp::socket& sock, const std::vector<uint8_t>& buf, bool needToCheck = true) const
+ {
+ sock.async_send_to(boost::asio::buffer(buf), remoteMcastEp,
[needToCheck] (const boost::system::error_code& error, size_t) {
if (needToCheck) {
BOOST_REQUIRE_EQUAL(error, boost::system::errc::success);
}
});
- limitedIo.defer(time::seconds(1));
}
protected:
LimitedIo limitedIo;
MulticastUdpTransport* transport;
- udp::endpoint localEp;
- udp::endpoint multicastEp;
+ udp::endpoint mcastEp;
+ uint16_t txPort;
std::vector<Transport::Packet>* receivedPackets;
private:
unique_ptr<Face> face;
+ udp::endpoint remoteMcastEp;
udp::socket remoteSockRx;
udp::socket remoteSockTx;
};
diff --git a/tests/daemon/face/multicast-udp-transport.t.cpp b/tests/daemon/face/multicast-udp-transport.t.cpp
index de6d30f..d8e7a60 100644
--- a/tests/daemon/face/multicast-udp-transport.t.cpp
+++ b/tests/daemon/face/multicast-udp-transport.t.cpp
@@ -36,17 +36,15 @@
BOOST_AUTO_TEST_SUITE(Face)
using MulticastUdpTransportFixtureWithAddress =
- // TODO: change to AddressFamily::Any after IPv6 support is implemented
- IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V4,
+ IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::Any,
AddressScope::Global, MulticastInterface::Yes>;
BOOST_FIXTURE_TEST_SUITE(TestMulticastUdpTransport, MulticastUdpTransportFixtureWithAddress)
using MulticastUdpTransportFixtures = boost::mpl::vector<
- IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V4, AddressScope::Global, MulticastInterface::Yes>
- // TODO: IPv6 not supported yet
- //IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::LinkLocal, MulticastInterface::Yes>,
- //IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::Global, MulticastInterface::Yes>
+ IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V4, AddressScope::Global, MulticastInterface::Yes>,
+ IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::LinkLocal, MulticastInterface::Yes>,
+ IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::Global, MulticastInterface::Yes>
>;
BOOST_FIXTURE_TEST_CASE_TEMPLATE(StaticProperties, T, MulticastUdpTransportFixtures, T)
@@ -55,8 +53,8 @@
checkStaticPropertiesInitialized(*this->transport);
- BOOST_CHECK_EQUAL(this->transport->getLocalUri(), FaceUri(udp::endpoint(this->address, this->localEp.port())));
- BOOST_CHECK_EQUAL(this->transport->getRemoteUri(), FaceUri(this->multicastEp));
+ BOOST_CHECK_EQUAL(this->transport->getLocalUri(), FaceUri(udp::endpoint(this->address, this->txPort)));
+ BOOST_CHECK_EQUAL(this->transport->getRemoteUri(), FaceUri(this->mcastEp));
BOOST_CHECK_EQUAL(this->transport->getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
BOOST_CHECK_EQUAL(this->transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
BOOST_CHECK_EQUAL(this->transport->getLinkType(), ndn::nfd::LINK_TYPE_MULTI_ACCESS);
@@ -78,9 +76,9 @@
{
TRANSPORT_TEST_INIT();
- // remoteSockRx2 unnecessary for this test case - only remoteSockTx2 is needed
+ // we need a second remote tx socket for this test case
udp::socket remoteSockTx2(this->g_io);
- MulticastUdpTransport::openTxSocket(remoteSockTx2, udp::endpoint(udp::v4(), 7071), true);
+ MulticastUdpTransport::openTxSocket(remoteSockTx2, udp::endpoint(this->address, 0), nullptr, true);
Block pkt1 = ndn::encoding::makeStringBlock(300, "hello");
ndn::Buffer buf1(pkt1.begin(), pkt1.end());
@@ -98,15 +96,8 @@
BOOST_CHECK_EQUAL(this->receivedPackets->at(0).remoteEndpoint,
this->receivedPackets->at(1).remoteEndpoint);
- udp::endpoint destEp(this->multicastEp.address(), this->localEp.port());
- remoteSockTx2.async_send_to(boost::asio::buffer(buf1), destEp,
- [] (const boost::system::error_code& error, size_t) {
- BOOST_REQUIRE_EQUAL(error, boost::system::errc::success);
- });
- remoteSockTx2.async_send_to(boost::asio::buffer(buf2), destEp,
- [] (const boost::system::error_code& error, size_t) {
- BOOST_REQUIRE_EQUAL(error, boost::system::errc::success);
- });
+ this->sendToGroup(remoteSockTx2, buf1);
+ this->sendToGroup(remoteSockTx2, buf2);
this->limitedIo.defer(time::seconds(1));
BOOST_CHECK_EQUAL(this->transport->getCounters().nInPackets, 4);
diff --git a/tests/daemon/face/udp-factory.t.cpp b/tests/daemon/face/udp-factory.t.cpp
index 5e7e615..01a24a0 100644
--- a/tests/daemon/face/udp-factory.t.cpp
+++ b/tests/daemon/face/udp-factory.t.cpp
@@ -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,
@@ -29,7 +29,6 @@
#include "factory-test-common.hpp"
#include <boost/algorithm/string/replace.hpp>
-#include <boost/range/algorithm/count_if.hpp>
#include <ndn-cxx/net/address-converter.hpp>
namespace nfd {
@@ -53,22 +52,54 @@
UdpFactoryMcastFixture()
{
for (const auto& netif : collectNetworkInterfaces()) {
- if (netif->isUp() && netif->canMulticast() &&
- hasAddressFamily(*netif, ndn::net::AddressFamily::V4)) {
- netifs.push_back(netif);
+ // same filtering logic as UdpFactory::applyMcastConfigToNetif()
+ if (netif->isUp() && !netif->isLoopback() && netif->canMulticast()) {
+ bool hasValidIpAddress = false;
+ if (hasAddressFamily(*netif, ndn::net::AddressFamily::V4)) {
+ hasValidIpAddress = true;
+ netifsV4.push_back(netif);
+ }
+ if (hasAddressFamily(*netif, ndn::net::AddressFamily::V6)) {
+ hasValidIpAddress = true;
+ netifsV6.push_back(netif);
+ }
+ if (hasValidIpAddress) {
+ netifs.push_back(netif);
+ }
}
}
-
this->copyRealNetifsToNetmon();
}
shared_ptr<Face>
createMulticastFace(const std::string& localIp, const std::string& mcastIp, uint16_t mcastPort)
{
- BOOST_ASSERT(!netifs.empty());
- udp::Endpoint localEndpoint(ndn::ip::addressFromString(localIp), mcastPort);
+ auto localAddress = ndn::ip::addressFromString(localIp);
udp::Endpoint mcastEndpoint(ndn::ip::addressFromString(mcastIp), mcastPort);
- return factory.createMulticastFace(localEndpoint, mcastEndpoint, netifs.front());
+
+ if (localAddress.is_v4()) {
+ BOOST_ASSERT(!netifsV4.empty());
+ return factory.createMulticastFace(netifsV4.front(), localAddress, mcastEndpoint);
+ }
+ else {
+ BOOST_ASSERT(!netifsV6.empty());
+ return factory.createMulticastFace(netifsV6.front(), localAddress, mcastEndpoint);
+ }
+ }
+
+ /** \brief returns a non-loopback IP address suitable for the creation of a UDP multicast face
+ */
+ boost::asio::ip::address
+ findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily af) const
+ {
+ const auto& netifList = af == ndn::net::AddressFamily::V4 ? netifsV4 : netifsV6;
+ for (const auto& netif : netifList) {
+ for (const auto& a : netif->getNetworkAddresses()) {
+ if (a.getFamily() == af && !a.getIp().is_loopback())
+ return a.getIp();
+ }
+ }
+ return {};
}
std::vector<const Face*>
@@ -77,7 +108,13 @@
return this->listFacesByScheme("udp4", linkType);
}
- /** \brief determine whether \p netif has at least one address of the given family
+ std::vector<const Face*>
+ listUdp6McastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const
+ {
+ return this->listFacesByScheme("udp6", linkType);
+ }
+
+ /** \brief determine whether \p netif has at least one IP address of the given family
*/
static bool
hasAddressFamily(const NetworkInterface& netif, ndn::net::AddressFamily af)
@@ -89,17 +126,27 @@
/** \brief determine whether a UDP multicast face is created on \p netif
*/
static bool
- isFaceOnNetif(const Face& face, const shared_ptr<const NetworkInterface>& netif)
+ isFaceOnNetif(const Face& face, const NetworkInterface& netif)
{
- auto ip = boost::asio::ip::address_v4::from_string(face.getLocalUri().getHost());
- return std::any_of(netif->getNetworkAddresses().begin(), netif->getNetworkAddresses().end(),
+ auto ip = ndn::ip::addressFromString(face.getLocalUri().getHost());
+ return std::any_of(netif.getNetworkAddresses().begin(), netif.getNetworkAddresses().end(),
[ip] (const NetworkAddress& a) { return a.getIp() == ip; });
}
protected:
- /** \brief MulticastUdpTransport-capable network interfaces
+ /** \brief MulticastUdpTransport-capable network interfaces (IPv4 + IPv6)
+ *
+ * This should be used in test cases that do not depend on a specific address family
*/
std::vector<shared_ptr<const NetworkInterface>> netifs;
+
+ /** \brief MulticastUdpTransport-capable network interfaces (IPv4 only)
+ */
+ std::vector<shared_ptr<const NetworkInterface>> netifsV4;
+
+ /** \brief MulticastUdpTransport-capable network interfaces (IPv6 only)
+ */
+ std::vector<shared_ptr<const NetworkInterface>> netifsV6;
};
#define SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(n) \
@@ -111,6 +158,24 @@
} \
} while (false)
+#define SKIP_IF_UDP_MCAST_V4_NETIF_COUNT_LT(n) \
+ do { \
+ if (this->netifsV4.size() < (n)) { \
+ BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \
+ " or more IPv4 MulticastUdpTransport-capable network interfaces"); \
+ return; \
+ } \
+ } while (false)
+
+#define SKIP_IF_UDP_MCAST_V6_NETIF_COUNT_LT(n) \
+ do { \
+ if (this->netifsV6.size() < (n)) { \
+ BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \
+ " or more IPv6 MulticastUdpTransport-capable network interfaces"); \
+ return; \
+ } \
+ } while (false)
+
BOOST_AUTO_TEST_SUITE(Face)
BOOST_FIXTURE_TEST_SUITE(TestUdpFactory, UdpFactoryFixture)
@@ -184,11 +249,6 @@
BOOST_FIXTURE_TEST_CASE(EnableDisableMcast, UdpFactoryMcastFixture)
{
-#ifdef __linux__
- // need superuser privilege for creating multicast faces on Linux
- SKIP_IF_NOT_SUPERUSER();
-#endif // __linux__
-
const std::string CONFIG_WITH_MCAST = R"CONFIG(
face_system
{
@@ -210,22 +270,28 @@
parseConfig(CONFIG_WITHOUT_MCAST, false);
BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), 0);
+ BOOST_CHECK_EQUAL(this->listUdp6McastFaces().size(), 0);
- SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1);
+#ifdef __linux__
+ // need superuser privileges to create multicast faces on Linux
+ SKIP_IF_NOT_SUPERUSER();
+#endif // __linux__
parseConfig(CONFIG_WITH_MCAST, false);
g_io.poll();
- BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), netifs.size());
+ BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), netifsV4.size());
+ BOOST_CHECK_EQUAL(this->listUdp6McastFaces().size(), netifsV6.size());
parseConfig(CONFIG_WITHOUT_MCAST, false);
g_io.poll();
BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), 0);
+ BOOST_CHECK_EQUAL(this->listUdp6McastFaces().size(), 0);
}
BOOST_FIXTURE_TEST_CASE(McastAdHoc, UdpFactoryMcastFixture)
{
#ifdef __linux__
- // need superuser privilege for creating multicast faces on Linux
+ // need superuser privileges to create multicast faces on Linux
SKIP_IF_NOT_SUPERUSER();
#endif // __linux__
SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1);
@@ -241,16 +307,17 @@
)CONFIG";
parseConfig(CONFIG, false);
- BOOST_CHECK_EQUAL(this->listUdp4McastFaces(ndn::nfd::LINK_TYPE_AD_HOC).size(), netifs.size());
+ BOOST_CHECK_EQUAL(this->listUdp4McastFaces(ndn::nfd::LINK_TYPE_AD_HOC).size(), netifsV4.size());
+ BOOST_CHECK_EQUAL(this->listUdp6McastFaces(ndn::nfd::LINK_TYPE_AD_HOC).size(), netifsV6.size());
}
-BOOST_FIXTURE_TEST_CASE(ChangeMcastEndpoint, UdpFactoryMcastFixture)
+BOOST_FIXTURE_TEST_CASE(ChangeMcastEndpointV4, UdpFactoryMcastFixture)
{
#ifdef __linux__
- // need superuser privilege for creating multicast faces on Linux
+ // need superuser privileges to create multicast faces on Linux
SKIP_IF_NOT_SUPERUSER();
#endif // __linux__
- SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1);
+ SKIP_IF_UDP_MCAST_V4_NETIF_COUNT_LT(1);
const std::string CONFIG1 = R"CONFIG(
face_system
@@ -275,22 +342,65 @@
parseConfig(CONFIG1, false);
auto udpMcastFaces = this->listUdp4McastFaces();
- BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifs.size());
- BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(),
- FaceUri("udp4://239.66.30.1:7011"));
+ BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifsV4.size());
+ BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), FaceUri("udp4://239.66.30.1:7011"));
parseConfig(CONFIG2, false);
g_io.poll();
udpMcastFaces = this->listUdp4McastFaces();
- BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifs.size());
- BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(),
- FaceUri("udp4://239.66.30.2:7012"));
+ BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifsV4.size());
+ BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), FaceUri("udp4://239.66.30.2:7012"));
+}
+
+BOOST_FIXTURE_TEST_CASE(ChangeMcastEndpointV6, UdpFactoryMcastFixture)
+{
+#ifdef __linux__
+ // need superuser privileges to create multicast faces on Linux
+ SKIP_IF_NOT_SUPERUSER();
+#endif // __linux__
+ SKIP_IF_UDP_MCAST_V6_NETIF_COUNT_LT(1);
+
+ const std::string CONFIG1 = R"CONFIG(
+ face_system
+ {
+ udp
+ {
+ mcast_group_v6 ff02::1101
+ mcast_port_v6 7011
+ }
+ }
+ )CONFIG";
+ const std::string CONFIG2 = R"CONFIG(
+ face_system
+ {
+ udp
+ {
+ mcast_group_v6 ff02::1102
+ mcast_port_v6 7012
+ }
+ }
+ )CONFIG";
+
+ parseConfig(CONFIG1, false);
+ auto udpMcastFaces = this->listUdp6McastFaces();
+ BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifsV6.size());
+ auto expectedAddr = boost::asio::ip::address_v6::from_string("ff02::1101");
+ expectedAddr.scope_id(netifsV6.front()->getIndex());
+ BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), FaceUri(udp::Endpoint(expectedAddr, 7011)));
+
+ parseConfig(CONFIG2, false);
+ g_io.poll();
+ udpMcastFaces = this->listUdp6McastFaces();
+ BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifsV6.size());
+ expectedAddr = boost::asio::ip::address_v6::from_string("ff02::1102");
+ expectedAddr.scope_id(netifsV6.front()->getIndex());
+ BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), FaceUri(udp::Endpoint(expectedAddr, 7012)));
}
BOOST_FIXTURE_TEST_CASE(Whitelist, UdpFactoryMcastFixture)
{
#ifdef __linux__
- // need superuser privilege for creating multicast faces on Linux
+ // need superuser privileges to create multicast faces on Linux
SKIP_IF_NOT_SUPERUSER();
#endif // __linux__
SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1);
@@ -310,15 +420,21 @@
boost::replace_first(CONFIG, "%ifname", netifs.front()->getName());
parseConfig(CONFIG, false);
+
auto udpMcastFaces = this->listUdp4McastFaces();
- BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), 1);
- BOOST_CHECK(isFaceOnNetif(*udpMcastFaces.front(), netifs.front()));
+ BOOST_CHECK_LE(udpMcastFaces.size(), 1);
+ auto udpMcastFacesV6 = this->listUdp6McastFaces();
+ BOOST_CHECK_LE(udpMcastFacesV6.size(), 1);
+ udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end());
+ BOOST_CHECK_GE(udpMcastFaces.size(), 1);
+ BOOST_CHECK(std::all_of(udpMcastFaces.begin(), udpMcastFaces.end(),
+ [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.front()); }));
}
BOOST_FIXTURE_TEST_CASE(Blacklist, UdpFactoryMcastFixture)
{
#ifdef __linux__
- // need superuser privilege for creating multicast faces on Linux
+ // need superuser privileges to create multicast faces on Linux
SKIP_IF_NOT_SUPERUSER();
#endif // __linux__
SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1);
@@ -338,17 +454,21 @@
boost::replace_first(CONFIG, "%ifname", netifs.front()->getName());
parseConfig(CONFIG, false);
+
auto udpMcastFaces = this->listUdp4McastFaces();
- BOOST_CHECK_EQUAL(udpMcastFaces.size(), netifs.size() - 1);
- BOOST_CHECK_EQUAL(boost::count_if(udpMcastFaces, [this] (const Face* face) {
- return isFaceOnNetif(*face, netifs.front());
- }), 0);
+ BOOST_CHECK_GE(udpMcastFaces.size(), netifsV4.size() - 1);
+ auto udpMcastFacesV6 = this->listUdp6McastFaces();
+ BOOST_CHECK_GE(udpMcastFacesV6.size(), netifsV6.size() - 1);
+ udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end());
+ BOOST_CHECK_LT(udpMcastFaces.size(), netifsV4.size() + netifsV6.size());
+ BOOST_CHECK(std::none_of(udpMcastFaces.begin(), udpMcastFaces.end(),
+ [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.front()); }));
}
BOOST_FIXTURE_TEST_CASE(ChangePredicate, UdpFactoryMcastFixture)
{
#ifdef __linux__
- // need superuser privilege for creating multicast faces on Linux
+ // need superuser privileges to create multicast faces on Linux
SKIP_IF_NOT_SUPERUSER();
#endif // __linux__
SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(2);
@@ -370,15 +490,23 @@
boost::replace_first(CONFIG2, "%ifname", netifs.back()->getName());
parseConfig(CONFIG1, false);
+
auto udpMcastFaces = this->listUdp4McastFaces();
- BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), 1);
- BOOST_CHECK(isFaceOnNetif(*udpMcastFaces.front(), netifs.front()));
+ auto udpMcastFacesV6 = this->listUdp6McastFaces();
+ udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end());
+ BOOST_CHECK_GE(udpMcastFaces.size(), 1);
+ BOOST_CHECK(std::all_of(udpMcastFaces.begin(), udpMcastFaces.end(),
+ [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.front()); }));
parseConfig(CONFIG2, false);
g_io.poll();
+
udpMcastFaces = this->listUdp4McastFaces();
- BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), 1);
- BOOST_CHECK(isFaceOnNetif(*udpMcastFaces.front(), netifs.back()));
+ udpMcastFacesV6 = this->listUdp6McastFaces();
+ udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end());
+ BOOST_CHECK_GE(udpMcastFaces.size(), 1);
+ BOOST_CHECK(std::all_of(udpMcastFaces.begin(), udpMcastFaces.end(),
+ [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.back()); }));
}
BOOST_AUTO_TEST_CASE(Omitted)
@@ -394,6 +522,7 @@
BOOST_CHECK_EQUAL(factory.getChannels().size(), 0);
BOOST_CHECK_EQUAL(this->listFacesByScheme("udp4", ndn::nfd::LINK_TYPE_MULTI_ACCESS).size(), 0);
+ BOOST_CHECK_EQUAL(this->listFacesByScheme("udp6", ndn::nfd::LINK_TYPE_MULTI_ACCESS).size(), 0);
}
BOOST_AUTO_TEST_CASE(AllDisabled)
@@ -446,7 +575,7 @@
BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
}
-BOOST_AUTO_TEST_CASE(BadMcastGroup)
+BOOST_AUTO_TEST_CASE(BadMcastGroupV4)
{
// not an address
const std::string CONFIG1 = R"CONFIG(
@@ -491,7 +620,52 @@
BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error);
}
-BOOST_AUTO_TEST_CASE(BadMcastPort)
+BOOST_AUTO_TEST_CASE(BadMcastGroupV6)
+{
+ // not an address
+ const std::string CONFIG1 = R"CONFIG(
+ face_system
+ {
+ udp
+ {
+ mcast_group_v6 foo
+ }
+ }
+ )CONFIG";
+
+ BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error);
+ BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error);
+
+ // non-multicast address
+ const std::string CONFIG2 = R"CONFIG(
+ face_system
+ {
+ udp
+ {
+ mcast_group_v6 fe80::1234
+ }
+ }
+ )CONFIG";
+
+ BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error);
+ BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error);
+
+ // wrong address family
+ const std::string CONFIG3 = R"CONFIG(
+ face_system
+ {
+ udp
+ {
+ mcast_group_v6 224.0.23.170
+ }
+ }
+ )CONFIG";
+
+ BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error);
+ BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error);
+}
+
+BOOST_AUTO_TEST_CASE(BadMcastPortV4)
{
const std::string CONFIG1 = R"CONFIG(
face_system
@@ -520,6 +694,35 @@
BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error);
}
+BOOST_AUTO_TEST_CASE(BadMcastPortV6)
+{
+ const std::string CONFIG1 = R"CONFIG(
+ face_system
+ {
+ udp
+ {
+ mcast_port_v6 bar
+ }
+ }
+ )CONFIG";
+
+ BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error);
+ BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error);
+
+ const std::string CONFIG2 = R"CONFIG(
+ face_system
+ {
+ udp
+ {
+ mcast_port_v6 99999
+ }
+ }
+ )CONFIG";
+
+ BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error);
+ BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error);
+}
+
BOOST_AUTO_TEST_CASE(UnknownOption)
{
const std::string CONFIG = R"CONFIG(
@@ -563,67 +766,107 @@
BOOST_CHECK_NE(channel2, channel3);
BOOST_CHECK_EQUAL(channel3->getUri().toString(), "udp6://[::1]:20071");
- // createChannel with multicast address
- BOOST_CHECK_EXCEPTION(createChannel("224.0.0.1", 20070), UdpFactory::Error,
- [] (const UdpFactory::Error& e) {
- return strcmp(e.what(),
- "createChannel is only for unicast channels. The provided endpoint "
- "is multicast. Use createMulticastFace to create a multicast face") == 0;
- });
-
#ifdef __linux__
- // need superuser privilege for creating multicast faces on Linux
+ // need superuser privileges to create multicast faces on Linux
SKIP_IF_NOT_SUPERUSER();
#endif // __linux__
- SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1);
// createChannel with a local endpoint that has already been allocated for a UDP multicast face
- auto multicastFace = createMulticastFace("127.0.0.1", "224.0.0.1", 20072);
- BOOST_CHECK_EXCEPTION(createChannel("127.0.0.1", 20072), UdpFactory::Error,
- [] (const UdpFactory::Error& e) {
- return strcmp(e.what(),
- "Cannot create the requested UDP unicast channel, local "
- "endpoint is already allocated for a UDP multicast face") == 0;
- });
+ if (!netifsV4.empty()) {
+ auto mcastFace = createMulticastFace("127.0.0.1", "224.0.0.254", 20072);
+ BOOST_CHECK_EXCEPTION(createChannel("127.0.0.1", 20072), UdpFactory::Error,
+ [] (const UdpFactory::Error& e) {
+ return strcmp(e.what(),
+ "Cannot create UDP channel on 127.0.0.1:20072, "
+ "endpoint already allocated for a UDP multicast face") == 0;
+ });
+ }
+ if (!netifsV6.empty()) {
+ auto mcastFace = createMulticastFace("::1", "ff02::114", 20072);
+ BOOST_CHECK_EXCEPTION(createChannel("::1", 20072), UdpFactory::Error,
+ [] (const UdpFactory::Error& e) {
+ return strcmp(e.what(),
+ "Cannot create UDP channel on [::1]:20072, "
+ "endpoint already allocated for a UDP multicast face") == 0;
+ });
+ }
}
-BOOST_FIXTURE_TEST_CASE(CreateMulticastFace, UdpFactoryMcastFixture)
+BOOST_FIXTURE_TEST_CASE(CreateMulticastFaceV4, UdpFactoryMcastFixture)
{
#ifdef __linux__
- // need superuser privilege for creating multicast faces on Linux
+ // need superuser privileges to create multicast faces on Linux
SKIP_IF_NOT_SUPERUSER();
#endif // __linux__
- SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1);
+ SKIP_IF_UDP_MCAST_V4_NETIF_COUNT_LT(1);
- auto multicastFace1 = createMulticastFace("127.0.0.1", "224.0.0.1", 20070);
- auto multicastFace1a = createMulticastFace("127.0.0.1", "224.0.0.1", 20070);
+ auto multicastFace1 = createMulticastFace("127.0.0.1", "224.0.0.254", 20070);
+ auto multicastFace1a = createMulticastFace("127.0.0.1", "224.0.0.254", 20070);
+ auto multicastFace2 = createMulticastFace("127.0.0.1", "224.0.0.254", 20030);
BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
+ BOOST_CHECK_NE(multicastFace1, multicastFace2);
- // createMulticastFace with an IPv4 local endpoint already used by a channel
+ auto address = findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily::V4);
+ if (!address.is_unspecified()) {
+ auto multicastFace3 = createMulticastFace(address.to_string(), "224.0.0.254", 20070);
+ BOOST_CHECK_NE(multicastFace1, multicastFace3);
+ BOOST_CHECK_NE(multicastFace2, multicastFace3);
+ }
+
+ // create with a local endpoint already used by a channel
auto channel = createChannel("127.0.0.1", 20071);
- BOOST_CHECK_EXCEPTION(createMulticastFace("127.0.0.1", "224.0.0.1", 20071), UdpFactory::Error,
+ BOOST_CHECK_EXCEPTION(createMulticastFace("127.0.0.1", "224.0.0.254", 20071), UdpFactory::Error,
[] (const UdpFactory::Error& e) {
return strcmp(e.what(),
- "Cannot create the requested UDP multicast face, local "
- "endpoint is already allocated for a UDP unicast channel") == 0;
+ "Cannot create UDP multicast face on 127.0.0.1:20071, "
+ "endpoint already allocated for a UDP channel") == 0;
});
- // createMulticastFace with an IPv4 local endpoint already
- // used by a multicast face on a different multicast group
+ // create with a local endpoint already used by a multicast face on a different multicast group
BOOST_CHECK_EXCEPTION(createMulticastFace("127.0.0.1", "224.0.0.42", 20070), UdpFactory::Error,
[] (const UdpFactory::Error& e) {
return strcmp(e.what(),
- "Cannot create the requested UDP multicast face, local "
- "endpoint is already allocated for a UDP multicast face "
- "on a different multicast group") == 0;
+ "Cannot create UDP multicast face on 127.0.0.1:20070, "
+ "endpoint already allocated for a different UDP multicast face") == 0;
});
+}
- // createMulticastFace with an IPv6 multicast address
- BOOST_CHECK_EXCEPTION(createMulticastFace("::1", "ff01::114", 20073), UdpFactory::Error,
+BOOST_FIXTURE_TEST_CASE(CreateMulticastFaceV6, UdpFactoryMcastFixture)
+{
+#ifdef __linux__
+ // need superuser privileges to create multicast faces on Linux
+ SKIP_IF_NOT_SUPERUSER();
+#endif // __linux__
+ SKIP_IF_UDP_MCAST_V6_NETIF_COUNT_LT(1);
+
+ auto multicastFace1 = createMulticastFace("::1", "ff02::114", 20070);
+ auto multicastFace1a = createMulticastFace("::1", "ff02::114", 20070);
+ auto multicastFace2 = createMulticastFace("::1", "ff02::114", 20030);
+ BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
+ BOOST_CHECK_NE(multicastFace1, multicastFace2);
+
+ auto address = findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily::V6);
+ if (!address.is_unspecified()) {
+ auto multicastFace3 = createMulticastFace(address.to_string(), "ff02::114", 20070);
+ BOOST_CHECK_NE(multicastFace1, multicastFace3);
+ BOOST_CHECK_NE(multicastFace2, multicastFace3);
+ }
+
+ // create with a local endpoint already used by a channel
+ auto channel = createChannel("::1", 20071);
+ BOOST_CHECK_EXCEPTION(createMulticastFace("::1", "ff02::114", 20071), UdpFactory::Error,
[] (const UdpFactory::Error& e) {
return strcmp(e.what(),
- "IPv6 multicast is not supported yet. Please provide an IPv4 "
- "address") == 0;
+ "Cannot create UDP multicast face on [::1]:20071, "
+ "endpoint already allocated for a UDP channel") == 0;
+ });
+
+ // create with a local endpoint already used by a multicast face on a different multicast group
+ BOOST_CHECK_EXCEPTION(createMulticastFace("::1", "ff02::42", 20070), UdpFactory::Error,
+ [] (const UdpFactory::Error& e) {
+ return strcmp(e.what(),
+ "Cannot create UDP multicast face on [::1]:20070, "
+ "endpoint already allocated for a different UDP multicast face") == 0;
});
}