face: Connect faces to the parent (unicast) or associated (multicast) channels

Change-Id: Ie7b2e8fb60050a2bc6e4f5ad053c26e121f3c3d5
Refs: #4973
diff --git a/tests/daemon/face/channel-fixture.hpp b/tests/daemon/face/channel-fixture.hpp
index 2ec7d8a..58b5ee4 100644
--- a/tests/daemon/face/channel-fixture.hpp
+++ b/tests/daemon/face/channel-fixture.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -63,14 +63,14 @@
     return m_nextPort++;
   }
 
-  virtual unique_ptr<ChannelT>
+  virtual shared_ptr<ChannelT>
   makeChannel()
   {
     BOOST_FAIL("Unimplemented");
     return nullptr;
   }
 
-  virtual unique_ptr<ChannelT>
+  virtual shared_ptr<ChannelT>
   makeChannel(const boost::asio::ip::address&, uint16_t port = 0)
   {
     BOOST_FAIL("Unimplemented");
@@ -101,7 +101,7 @@
 protected:
   LimitedIo limitedIo;
   EndpointT listenerEp;
-  unique_ptr<ChannelT> listenerChannel;
+  shared_ptr<ChannelT> listenerChannel;
   std::vector<shared_ptr<Face>> listenerFaces;
 
 private:
diff --git a/tests/daemon/face/ethernet-channel.t.cpp b/tests/daemon/face/ethernet-channel.t.cpp
index 950bdd2..753f36a 100644
--- a/tests/daemon/face/ethernet-channel.t.cpp
+++ b/tests/daemon/face/ethernet-channel.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -36,11 +36,11 @@
 class EthernetChannelFixture : public EthernetFixture
 {
 protected:
-  unique_ptr<EthernetChannel>
+  shared_ptr<EthernetChannel>
   makeChannel()
   {
     BOOST_ASSERT(netifs.size() > 0);
-    return make_unique<EthernetChannel>(netifs.front(), 2_s);
+    return std::make_shared<EthernetChannel>(netifs.front(), 2_s);
   }
 };
 
@@ -89,6 +89,8 @@
   BOOST_CHECK_EQUAL(channel->size(), 1);
   BOOST_REQUIRE(face != nullptr);
 
+  BOOST_CHECK_EQUAL(face->getChannel().lock(), channel);
+
   face->close();
   g_io.poll();
   BOOST_CHECK_EQUAL(channel->size(), 0);
diff --git a/tests/daemon/face/ethernet-factory.t.cpp b/tests/daemon/face/ethernet-factory.t.cpp
index 605d3e2..269c79f 100644
--- a/tests/daemon/face/ethernet-factory.t.cpp
+++ b/tests/daemon/face/ethernet-factory.t.cpp
@@ -151,6 +151,11 @@
   parseConfig(CONFIG, false);
 
   BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), netifs.size());
+  for (const auto& face : this->listEtherMcastFaces()) {
+    BOOST_REQUIRE(face->getChannel().lock());
+    // not universal, but for Ethernet, local URI of a mcast face matches URI of the associated channel
+    BOOST_CHECK_EQUAL(face->getLocalUri(), face->getChannel().lock()->getUri());
+  }
 }
 
 BOOST_AUTO_TEST_CASE(EnableDisableMcast)
diff --git a/tests/daemon/face/tcp-channel-fixture.hpp b/tests/daemon/face/tcp-channel-fixture.hpp
index b872f94..41f17d5 100644
--- a/tests/daemon/face/tcp-channel-fixture.hpp
+++ b/tests/daemon/face/tcp-channel-fixture.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -43,14 +43,14 @@
     local.assign({{"subnet", "127.0.0.0/8"}, {"subnet", "::1/128"}}, {});
   }
 
-  unique_ptr<TcpChannel>
+  shared_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,
-                                   std::bind(&TcpChannelFixture::determineFaceScope, this, _1, _2));
+    return std::make_shared<TcpChannel>(tcp::Endpoint(addr, port), false,
+                                        std::bind(&TcpChannelFixture::determineFaceScope, this, _1, _2));
   }
 
   void
diff --git a/tests/daemon/face/tcp-udp-channel.t.cpp b/tests/daemon/face/tcp-udp-channel.t.cpp
index 5b86e9d..020c954 100644
--- a/tests/daemon/face/tcp-udp-channel.t.cpp
+++ b/tests/daemon/face/tcp-udp-channel.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -137,6 +137,8 @@
   BOOST_CHECK_EQUAL(this->listenerChannel->size(), 1);
   BOOST_CHECK_EQUAL(clientChannel->size(), 1);
 
+  BOOST_CHECK_EQUAL(this->clientFaces.at(0)->getChannel().lock(), clientChannel);
+
   this->clientFaces.at(0)->close();
 
   BOOST_CHECK_EQUAL(this->limitedIo.run(2, 5_s), LimitedIo::EXCEED_OPS);
diff --git a/tests/daemon/face/udp-channel-fixture.hpp b/tests/daemon/face/udp-channel-fixture.hpp
index 5192a97..93c5a86 100644
--- a/tests/daemon/face/udp-channel-fixture.hpp
+++ b/tests/daemon/face/udp-channel-fixture.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -38,13 +38,13 @@
 class UdpChannelFixture : public ChannelFixture<UdpChannel, udp::Endpoint>
 {
 protected:
-  unique_ptr<UdpChannel>
+  shared_ptr<UdpChannel>
   makeChannel(const boost::asio::ip::address& addr, uint16_t port = 0) final
   {
     if (port == 0)
       port = getNextPort();
 
-    return make_unique<UdpChannel>(udp::Endpoint(addr, port), 2_s, false);
+    return std::make_shared<UdpChannel>(udp::Endpoint(addr, port), 2_s, false);
   }
 
   void
diff --git a/tests/daemon/face/udp-factory.t.cpp b/tests/daemon/face/udp-factory.t.cpp
index c09fe62..0bf7e03 100644
--- a/tests/daemon/face/udp-factory.t.cpp
+++ b/tests/daemon/face/udp-factory.t.cpp
@@ -300,6 +300,17 @@
   BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), netifsV4.size());
   BOOST_CHECK_EQUAL(this->listUdp6McastFaces().size(), netifsV6.size());
 
+  BOOST_REQUIRE_EQUAL(factory.getChannels().size(), 2);
+  for (const auto& face : this->listUdp4McastFaces()) {
+    BOOST_REQUIRE(face->getChannel().lock());
+    BOOST_CHECK_EQUAL(face->getChannel().lock()->getUri().getScheme(), "udp4");
+  }
+
+  for (const auto& face : this->listUdp6McastFaces()) {
+    BOOST_REQUIRE(face->getChannel().lock());
+    BOOST_CHECK_EQUAL(face->getChannel().lock()->getUri().getScheme(), "udp6");
+  }
+
   parseConfig(CONFIG_WITHOUT_MCAST, false);
   g_io.poll();
   BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), 0);
diff --git a/tests/daemon/face/unix-stream-channel.t.cpp b/tests/daemon/face/unix-stream-channel.t.cpp
index fe9d4be..fa9e480 100644
--- a/tests/daemon/face/unix-stream-channel.t.cpp
+++ b/tests/daemon/face/unix-stream-channel.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -45,10 +45,10 @@
     listenerEp = unix_stream::Endpoint("nfd-test-unix-stream-channel.sock");
   }
 
-  unique_ptr<UnixStreamChannel>
+  shared_ptr<UnixStreamChannel>
   makeChannel() final
   {
-    return make_unique<UnixStreamChannel>(listenerEp, false);
+    return std::make_shared<UnixStreamChannel>(listenerEp, false);
   }
 
   void
@@ -120,9 +120,10 @@
   BOOST_CHECK_EQUAL(listenerChannel->size(), 3);
   BOOST_CHECK_EQUAL(listenerFaces.size(), 3);
 
-  // check face persistency
+  // check face persistency and channel association
   for (const auto& face : listenerFaces) {
     BOOST_CHECK_EQUAL(face->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+    BOOST_CHECK_EQUAL(face->getChannel().lock(), listenerChannel);
   }
 }
 
diff --git a/tests/daemon/face/websocket-channel-fixture.hpp b/tests/daemon/face/websocket-channel-fixture.hpp
index 5500281..f28459f 100644
--- a/tests/daemon/face/websocket-channel-fixture.hpp
+++ b/tests/daemon/face/websocket-channel-fixture.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -37,13 +37,13 @@
 class WebSocketChannelFixture : public ChannelFixture<WebSocketChannel, websocket::Endpoint>
 {
 protected:
-  unique_ptr<WebSocketChannel>
+  shared_ptr<WebSocketChannel>
   makeChannel(const boost::asio::ip::address& addr, uint16_t port = 0) final
   {
     if (port == 0)
       port = getNextPort();
 
-    return make_unique<WebSocketChannel>(websocket::Endpoint(addr, port));
+    return std::make_shared<WebSocketChannel>(websocket::Endpoint(addr, port));
   }
 
   void
diff --git a/tests/daemon/face/websocket-channel.t.cpp b/tests/daemon/face/websocket-channel.t.cpp
index 0631efa..d9fe929 100644
--- a/tests/daemon/face/websocket-channel.t.cpp
+++ b/tests/daemon/face/websocket-channel.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -88,9 +88,10 @@
                                   2_s), LimitedIo::EXCEED_OPS);
   BOOST_CHECK_EQUAL(listenerChannel->size(), 3);
 
-  // check face persistency
+  // check face persistency and channel association
   for (const auto& face : listenerFaces) {
     BOOST_CHECK_EQUAL(face->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+    BOOST_CHECK_EQUAL(face->getChannel().lock(), listenerChannel);
   }
 }
 
@@ -152,6 +153,8 @@
   SKIP_IF_IP_UNAVAILABLE(address);
   this->initialize(address);
 
+  BOOST_CHECK_EQUAL(listenerFaces.at(0)->getChannel().lock(), listenerChannel);
+
   listenerFaces.at(0)->close();
   BOOST_CHECK_EQUAL(listenerChannel->size(), 0);
 }