mgmt: support LpReliability flag in faces/create and faces/update

refs #4003

Change-Id: Iddf94ea55c630b038187c2503783591b118230ec
diff --git a/daemon/face/ethernet-channel.cpp b/daemon/face/ethernet-channel.cpp
index 44fb03c..bc149d2 100644
--- a/daemon/face/ethernet-channel.cpp
+++ b/daemon/face/ethernet-channel.cpp
@@ -55,12 +55,13 @@
 void
 EthernetChannel::connect(const ethernet::Address& remoteEndpoint,
                          ndn::nfd::FacePersistency persistency,
+                         bool wantLpReliability,
                          const FaceCreatedCallback& onFaceCreated,
                          const FaceCreationFailedCallback& onConnectFailed)
 {
   shared_ptr<Face> face;
   try {
-    face = createFace(remoteEndpoint, persistency).second;
+    face = createFace(remoteEndpoint, persistency, wantLpReliability).second;
   }
   catch (const boost::system::system_error& e) {
     NFD_LOG_CHAN_DEBUG("Face creation for " << remoteEndpoint << " failed: " << e.what());
@@ -165,7 +166,7 @@
   bool isCreated = false;
   shared_ptr<Face> face;
   try {
-    std::tie(isCreated, face) = createFace(sender, ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+    std::tie(isCreated, face) = createFace(sender, ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, false);
   }
   catch (const EthernetTransport::Error& e) {
     NFD_LOG_CHAN_DEBUG("Face creation for " << sender << " failed: " << e.what());
@@ -186,7 +187,8 @@
 
 std::pair<bool, shared_ptr<Face>>
 EthernetChannel::createFace(const ethernet::Address& remoteEndpoint,
-                            ndn::nfd::FacePersistency persistency)
+                            ndn::nfd::FacePersistency persistency,
+                            bool wantLpReliability)
 {
   auto it = m_channelFaces.find(remoteEndpoint);
   if (it != m_channelFaces.end()) {
@@ -196,7 +198,9 @@
   }
 
   // else, create a new face
-  auto linkService = make_unique<GenericLinkService>();
+  GenericLinkService::Options options;
+  options.reliabilityOptions.isEnabled = wantLpReliability;
+  auto linkService = make_unique<GenericLinkService>(options);
   auto transport = make_unique<UnicastEthernetTransport>(*m_localEndpoint, remoteEndpoint,
                                                          persistency, m_idleFaceTimeout);
   auto face = make_shared<Face>(std::move(linkService), std::move(transport));
diff --git a/daemon/face/ethernet-channel.hpp b/daemon/face/ethernet-channel.hpp
index 8ad2432..5847af5 100644
--- a/daemon/face/ethernet-channel.hpp
+++ b/daemon/face/ethernet-channel.hpp
@@ -79,12 +79,14 @@
    *
    * \param remoteEndpoint The remote Ethernet endpoint
    * \param persistency Persistency of the newly created face
+   * \param wantLpReliability whether LpReliability should be enabled
    * \param onFaceCreated Callback to notify successful creation of the face
    * \param onConnectFailed Callback to notify errors
    */
   void
   connect(const ethernet::Address& remoteEndpoint,
           ndn::nfd::FacePersistency persistency,
+          bool wantLpReliability,
           const FaceCreatedCallback& onFaceCreated,
           const FaceCreationFailedCallback& onConnectFailed);
 
@@ -122,7 +124,8 @@
 
   std::pair<bool, shared_ptr<Face>>
   createFace(const ethernet::Address& remoteEndpoint,
-             ndn::nfd::FacePersistency persistency);
+             ndn::nfd::FacePersistency persistency,
+             bool wantLpReliability);
 
   void
   updateFilter();
diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp
index b00fa5f..36f7c45 100644
--- a/daemon/face/ethernet-factory.cpp
+++ b/daemon/face/ethernet-factory.cpp
@@ -193,7 +193,7 @@
     return;
   }
 
-  if (params.wantLocalFieldsEnabled) {
+  if (params.wantLocalFields) {
     // Ethernet faces are never local
     NFD_LOG_TRACE("createFace cannot create non-local face with local fields enabled");
     onFailure(406, "Local fields can only be enabled on faces with local scope");
@@ -202,7 +202,8 @@
 
   for (const auto& i : m_channels) {
     if (i.first == localEndpoint) {
-      i.second->connect(remoteEndpoint, params.persistency, onCreated, onFailure);
+      i.second->connect(remoteEndpoint, params.persistency, params.wantLpReliability,
+                        onCreated, onFailure);
       return;
     }
   }
diff --git a/daemon/face/protocol-factory.hpp b/daemon/face/protocol-factory.hpp
index 0eee552..e0c62a1 100644
--- a/daemon/face/protocol-factory.hpp
+++ b/daemon/face/protocol-factory.hpp
@@ -139,7 +139,8 @@
     FaceUri remoteUri;
     ndn::optional<FaceUri> localUri;
     ndn::nfd::FacePersistency persistency;
-    bool wantLocalFieldsEnabled;
+    bool wantLocalFields;
+    bool wantLpReliability;
   };
 
   /** \brief Try to create face using the supplied parameters
diff --git a/daemon/face/tcp-channel.cpp b/daemon/face/tcp-channel.cpp
index dee9fa6..4c4c290 100644
--- a/daemon/face/tcp-channel.cpp
+++ b/daemon/face/tcp-channel.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
@@ -69,7 +69,8 @@
 void
 TcpChannel::connect(const tcp::Endpoint& remoteEndpoint,
                     ndn::nfd::FacePersistency persistency,
-                    bool wantLocalFieldsEnabled,
+                    bool wantLocalFields,
+                    bool wantLpReliability,
                     const FaceCreatedCallback& onFaceCreated,
                     const FaceCreationFailedCallback& onConnectFailed,
                     time::nanoseconds timeout)
@@ -88,15 +89,18 @@
   NFD_LOG_CHAN_TRACE("Connecting to " << remoteEndpoint);
   clientSocket->async_connect(remoteEndpoint,
                               bind(&TcpChannel::handleConnect, this,
-                                   boost::asio::placeholders::error, remoteEndpoint,
-                                   clientSocket, persistency, wantLocalFieldsEnabled,
+                                   boost::asio::placeholders::error, remoteEndpoint, clientSocket,
+                                   // Creating a parameters struct works around limit on number of
+                                   // parameters to bind
+                                   ConnectParams{persistency, wantLocalFields, wantLpReliability},
                                    timeoutEvent, onFaceCreated, onConnectFailed));
 }
 
 void
 TcpChannel::createFace(ip::tcp::socket&& socket,
                        ndn::nfd::FacePersistency persistency,
-                       bool wantLocalFieldsEnabled,
+                       bool wantLocalFields,
+                       bool wantLpReliability,
                        const FaceCreatedCallback& onFaceCreated)
 {
   shared_ptr<Face> face;
@@ -104,10 +108,10 @@
 
   auto it = m_channelFaces.find(remoteEndpoint);
   if (it == m_channelFaces.end()) {
-    auto linkService = make_unique<GenericLinkService>();
-    auto options = linkService->getOptions();
-    options.allowLocalFields = wantLocalFieldsEnabled;
-    linkService->setOptions(options);
+    GenericLinkService::Options options;
+    options.allowLocalFields = wantLocalFields;
+    options.reliabilityOptions.isEnabled = wantLpReliability;
+    auto linkService = make_unique<GenericLinkService>(options);
 
     auto transport = make_unique<TcpTransport>(std::move(socket), persistency);
     face = make_shared<Face>(std::move(linkService), std::move(transport));
@@ -154,7 +158,7 @@
   }
 
   NFD_LOG_CHAN_TRACE("Incoming connection from " << m_socket.remote_endpoint());
-  createFace(std::move(m_socket), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, false, onFaceCreated);
+  createFace(std::move(m_socket), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, false, false, onFaceCreated);
 
   // prepare accepting the next connection
   accept(onFaceCreated, onAcceptFailed);
@@ -164,8 +168,7 @@
 TcpChannel::handleConnect(const boost::system::error_code& error,
                           const tcp::Endpoint& remoteEndpoint,
                           const shared_ptr<ip::tcp::socket>& socket,
-                          ndn::nfd::FacePersistency persistency,
-                          bool wantLocalFieldsEnabled,
+                          TcpChannel::ConnectParams params,
                           const scheduler::EventId& connectTimeoutEvent,
                           const FaceCreatedCallback& onFaceCreated,
                           const FaceCreationFailedCallback& onConnectFailed)
@@ -190,7 +193,8 @@
   }
 
   NFD_LOG_CHAN_TRACE("Connected to " << socket->remote_endpoint());
-  createFace(std::move(*socket), persistency, wantLocalFieldsEnabled, onFaceCreated);
+  createFace(std::move(*socket), params.persistency, params.wantLocalFields,
+             params.wantLpReliability, onFaceCreated);
 }
 
 void
diff --git a/daemon/face/tcp-channel.hpp b/daemon/face/tcp-channel.hpp
index 129587e..ca4c522 100644
--- a/daemon/face/tcp-channel.hpp
+++ b/daemon/face/tcp-channel.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
@@ -88,16 +88,26 @@
   void
   connect(const tcp::Endpoint& remoteEndpoint,
           ndn::nfd::FacePersistency persistency,
-          bool wantLocalFieldsEnabled,
+          bool wantLocalFields,
+          bool wantLpReliability,
           const FaceCreatedCallback& onFaceCreated,
           const FaceCreationFailedCallback& onConnectFailed,
           time::nanoseconds timeout = time::seconds(4));
 
 private:
+  struct ConnectParams
+  {
+    ndn::nfd::FacePersistency persistency;
+    bool wantLocalFields;
+    bool wantLpReliability;
+  };
+
+private:
   void
   createFace(boost::asio::ip::tcp::socket&& socket,
              ndn::nfd::FacePersistency persistency,
-             bool wantLocalFieldsEnabled,
+             bool wantLocalFields,
+             bool wantLpReliability,
              const FaceCreatedCallback& onFaceCreated);
 
   void
@@ -113,8 +123,7 @@
   handleConnect(const boost::system::error_code& error,
                 const tcp::Endpoint& remoteEndpoint,
                 const shared_ptr<boost::asio::ip::tcp::socket>& socket,
-                ndn::nfd::FacePersistency persistency,
-                bool wantLocalFieldsEnabled,
+                ConnectParams params,
                 const scheduler::EventId& connectTimeoutEvent,
                 const FaceCreatedCallback& onFaceCreated,
                 const FaceCreationFailedCallback& onConnectFailed);
diff --git a/daemon/face/tcp-factory.cpp b/daemon/face/tcp-factory.cpp
index a53721c..8214969 100644
--- a/daemon/face/tcp-factory.cpp
+++ b/daemon/face/tcp-factory.cpp
@@ -149,7 +149,7 @@
   // a canonical tcp4/tcp6 FaceUri cannot have a multicast address
   BOOST_ASSERT(!endpoint.address().is_multicast());
 
-  if (params.wantLocalFieldsEnabled && !endpoint.address().is_loopback()) {
+  if (params.wantLocalFields && !endpoint.address().is_loopback()) {
     NFD_LOG_TRACE("createFace cannot create non-local face with local fields enabled");
     onFailure(406, "Local fields can only be enabled on faces with local scope");
     return;
@@ -159,8 +159,8 @@
   for (const auto& i : m_channels) {
     if ((i.first.address().is_v4() && endpoint.address().is_v4()) ||
         (i.first.address().is_v6() && endpoint.address().is_v6())) {
-      i.second->connect(endpoint, params.persistency, params.wantLocalFieldsEnabled,
-                        onCreated, onFailure);
+      i.second->connect(endpoint, params.persistency, params.wantLocalFields,
+                        params.wantLpReliability, onCreated, onFailure);
       return;
     }
   }
diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp
index 3ab9e1f..6ecaeaf 100644
--- a/daemon/face/udp-channel.cpp
+++ b/daemon/face/udp-channel.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
@@ -48,12 +48,13 @@
 void
 UdpChannel::connect(const udp::Endpoint& remoteEndpoint,
                     ndn::nfd::FacePersistency persistency,
+                    bool wantLpReliability,
                     const FaceCreatedCallback& onFaceCreated,
                     const FaceCreationFailedCallback& onConnectFailed)
 {
   shared_ptr<Face> face;
   try {
-    face = createFace(remoteEndpoint, persistency).second;
+    face = createFace(remoteEndpoint, persistency, wantLpReliability).second;
   }
   catch (const boost::system::system_error& e) {
     NFD_LOG_CHAN_DEBUG("Face creation for " << remoteEndpoint << " failed: " << e.what());
@@ -118,7 +119,8 @@
   bool isCreated = false;
   shared_ptr<Face> face;
   try {
-    std::tie(isCreated, face) = createFace(m_remoteEndpoint, ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+    std::tie(isCreated, face) = createFace(m_remoteEndpoint, ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
+                                           false);
   }
   catch (const boost::system::system_error& e) {
     NFD_LOG_CHAN_DEBUG("Face creation for " << m_remoteEndpoint << " failed: " << e.what());
@@ -141,7 +143,8 @@
 
 std::pair<bool, shared_ptr<Face>>
 UdpChannel::createFace(const udp::Endpoint& remoteEndpoint,
-                       ndn::nfd::FacePersistency persistency)
+                       ndn::nfd::FacePersistency persistency,
+                       bool wantLpReliability)
 {
   auto it = m_channelFaces.find(remoteEndpoint);
   if (it != m_channelFaces.end()) {
@@ -156,7 +159,9 @@
   socket.bind(m_localEndpoint);
   socket.connect(remoteEndpoint);
 
-  auto linkService = make_unique<GenericLinkService>();
+  GenericLinkService::Options options;
+  options.reliabilityOptions.isEnabled = wantLpReliability;
+  auto linkService = make_unique<GenericLinkService>(options);
   auto transport = make_unique<UnicastUdpTransport>(std::move(socket), persistency, m_idleFaceTimeout);
   auto face = make_shared<Face>(std::move(linkService), std::move(transport));
 
diff --git a/daemon/face/udp-channel.hpp b/daemon/face/udp-channel.hpp
index b239157..471a971 100644
--- a/daemon/face/udp-channel.hpp
+++ b/daemon/face/udp-channel.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
@@ -67,12 +67,14 @@
    *
    * \param remoteEndpoint The remote UDP endpoint
    * \param persistency Persistency of the newly created face
+   * \param wantLpReliability whether LpReliability should be enabled
    * \param onFaceCreated Callback to notify successful creation of the face
    * \param onConnectFailed Callback to notify errors
    */
   void
   connect(const udp::Endpoint& remoteEndpoint,
           ndn::nfd::FacePersistency persistency,
+          bool wantLpReliability,
           const FaceCreatedCallback& onFaceCreated,
           const FaceCreationFailedCallback& onConnectFailed);
 
@@ -108,7 +110,8 @@
 
   std::pair<bool, shared_ptr<Face>>
   createFace(const udp::Endpoint& remoteEndpoint,
-             ndn::nfd::FacePersistency persistency);
+             ndn::nfd::FacePersistency persistency,
+             bool wantLpReliability);
 
 private:
   const udp::Endpoint m_localEndpoint;
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index da42416..f44e4e9 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -236,7 +236,7 @@
     return;
   }
 
-  if (params.wantLocalFieldsEnabled) {
+  if (params.wantLocalFields) {
     // UDP faces are never local
     NFD_LOG_TRACE("createFace cannot create non-local face with local fields enabled");
     onFailure(406, "Local fields can only be enabled on faces with local scope");
@@ -247,7 +247,8 @@
   for (const auto& i : m_channels) {
     if ((i.first.address().is_v4() && endpoint.address().is_v4()) ||
         (i.first.address().is_v6() && endpoint.address().is_v6())) {
-      i.second->connect(endpoint, params.persistency, onCreated, onFailure);
+      i.second->connect(endpoint, params.persistency, params.wantLpReliability,
+                        onCreated, onFailure);
       return;
     }
   }
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index 8966d9d..c3cd1bd 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -118,7 +118,9 @@
   try {
     factory->createFace({remoteUri, localUri, parameters.getFacePersistency(),
         parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) &&
-        parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)},
+        parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED),
+        parameters.hasFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED) &&
+        parameters.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)},
       bind(&FaceManager::afterCreateFaceSuccess, this, parameters, _1, done),
       bind(&FaceManager::afterCreateFaceFailure, this, _1, _2, done));
   }
@@ -227,7 +229,7 @@
   if (parameters.hasFacePersistency()) {
     face->setPersistency(parameters.getFacePersistency());
   }
-  setLinkServiceOptions(*face, parameters, response);
+  setLinkServiceOptions(*face, parameters);
 
   // Set ControlResponse fields
   response = collectFaceProperties(*face, false);
@@ -250,8 +252,7 @@
 
 void
 FaceManager::setLinkServiceOptions(Face& face,
-                                   const ControlParameters& parameters,
-                                   ControlParameters& response)
+                                   const ControlParameters& parameters)
 {
   auto linkService = dynamic_cast<face::GenericLinkService*>(face.getLinkService());
   BOOST_ASSERT(linkService != nullptr);
@@ -261,10 +262,10 @@
       face.getScope() == ndn::nfd::FACE_SCOPE_LOCAL) {
     options.allowLocalFields = parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED);
   }
+  if (parameters.hasFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
+    options.reliabilityOptions.isEnabled = parameters.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED);
+  }
   linkService->setOptions(options);
-
-  // Set Flags for ControlResponse
-  response.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, options.allowLocalFields, false);
 }
 
 ControlParameters
@@ -277,7 +278,8 @@
   ControlParameters params;
   params.setFaceId(face.getId())
         .setFacePersistency(face.getPersistency())
-        .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, options.allowLocalFields, false);
+        .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, options.allowLocalFields, false)
+        .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, options.reliabilityOptions.isEnabled, false);
   if (wantUris) {
     params.setUri(face.getRemoteUri().toString())
           .setLocalUri(face.getLocalUri().toString());
diff --git a/daemon/mgmt/face-manager.hpp b/daemon/mgmt/face-manager.hpp
index 4e43716..bee95a3 100644
--- a/daemon/mgmt/face-manager.hpp
+++ b/daemon/mgmt/face-manager.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
@@ -79,8 +79,7 @@
 
   static void
   setLinkServiceOptions(Face& face,
-                        const ControlParameters& parameters,
-                        ControlParameters& response);
+                        const ControlParameters& parameters);
 
   static ControlParameters
   collectFaceProperties(const Face& face, bool wantUris);