face: deduplicate multicast UDP socket setup
In preparation for adding IPv6 support.
Change-Id: I5a3be2007f7fecc44915a5d6794093143ce9c0f9
Refs: #4222
diff --git a/tests/daemon/face/multicast-udp-transport-fixture.hpp b/tests/daemon/face/multicast-udp-transport-fixture.hpp
index 7c3ca21..2b86833 100644
--- a/tests/daemon/face/multicast-udp-transport-fixture.hpp
+++ b/tests/daemon/face/multicast-udp-transport-fixture.hpp
@@ -55,12 +55,16 @@
void
initialize(ip::address address)
{
- openMulticastSockets(remoteSockRx, remoteSockTx, multicastEp.port());
+ localEp = udp::endpoint(address, 7001);
+
+ MulticastUdpTransport::openRxSocket(remoteSockRx, multicastEp, ip::address_v4::any());
+ MulticastUdpTransport::openTxSocket(remoteSockTx, udp::endpoint(udp::v4(), 0), true);
udp::socket sockRx(g_io);
udp::socket sockTx(g_io);
- localEp = udp::endpoint(address, 7001);
- openMulticastSockets(sockRx, sockTx, localEp.port());
+ MulticastUdpTransport::openRxSocket(sockRx, udp::endpoint(multicastEp.address(), localEp.port()),
+ ip::address_v4::any());
+ MulticastUdpTransport::openTxSocket(sockTx, udp::endpoint(udp::v4(), 0), true);
face = make_unique<Face>(
make_unique<DummyReceiveLinkService>(),
@@ -73,20 +77,6 @@
}
void
- openMulticastSockets(udp::socket& rx, udp::socket& tx, uint16_t port)
- {
- rx.open(udp::v4());
- rx.set_option(udp::socket::reuse_address(true));
- rx.bind(udp::endpoint(multicastEp.address(), port));
- rx.set_option(ip::multicast::join_group(multicastEp.address()));
-
- tx.open(udp::v4());
- tx.set_option(udp::socket::reuse_address(true));
- tx.set_option(ip::multicast::enable_loopback(true));
- tx.bind(udp::endpoint(ip::address_v4::any(), port));
- }
-
- void
remoteRead(std::vector<uint8_t>& buf, bool needToCheck = true)
{
remoteSockRx.async_receive(boost::asio::buffer(buf),
diff --git a/tests/daemon/face/multicast-udp-transport.t.cpp b/tests/daemon/face/multicast-udp-transport.t.cpp
index 6e4a8cf..51acb08 100644
--- a/tests/daemon/face/multicast-udp-transport.t.cpp
+++ b/tests/daemon/face/multicast-udp-transport.t.cpp
@@ -79,10 +79,7 @@
// remoteSockRx2 unnecessary for this test case - only remoteSockTx2 is needed
udp::socket remoteSockTx2(this->g_io);
- remoteSockTx2.open(udp::v4());
- remoteSockTx2.set_option(udp::socket::reuse_address(true));
- remoteSockTx2.set_option(ip::multicast::enable_loopback(true));
- remoteSockTx2.bind(udp::endpoint(ip::address_v4::any(), 7071));
+ MulticastUdpTransport::openTxSocket(remoteSockTx2, udp::endpoint(udp::v4(), 7071), true);
Block pkt1 = ndn::encoding::makeStringBlock(300, "hello");
ndn::Buffer buf1(pkt1.begin(), pkt1.end());
diff --git a/tests/daemon/face/udp-factory.t.cpp b/tests/daemon/face/udp-factory.t.cpp
index 84d4529..5e7e615 100644
--- a/tests/daemon/face/udp-factory.t.cpp
+++ b/tests/daemon/face/udp-factory.t.cpp
@@ -68,7 +68,7 @@
BOOST_ASSERT(!netifs.empty());
udp::Endpoint localEndpoint(ndn::ip::addressFromString(localIp), mcastPort);
udp::Endpoint mcastEndpoint(ndn::ip::addressFromString(mcastIp), mcastPort);
- return factory.createMulticastFace(localEndpoint, mcastEndpoint, *netifs.front());
+ return factory.createMulticastFace(localEndpoint, mcastEndpoint, netifs.front());
}
std::vector<const Face*>