blob: 4e477a62376de17966253ca1b41f34854e7167fa [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi4460e822017-08-07 22:02:45 +00002/*
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -08003 * Copyright (c) 2013-2017 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070020 */
21
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080022#include "face.hpp"
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070023#include "detail/face-impl.hpp"
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070024
Junxiao Shi468abc32014-11-04 09:12:47 -070025#include "encoding/tlv.hpp"
Junxiao Shi25467942017-06-30 02:53:14 +000026#include "net/face-uri.hpp"
Junxiao Shic6acc7a2015-06-23 10:03:56 -070027#include "security/signing-helpers.hpp"
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080028#include "util/random.hpp"
Junxiao Shi4460e822017-08-07 22:02:45 +000029#include "util/time.hpp"
30
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -080031#include "ns3/node-list.h"
32#include "ns3/ndnSIM/helper/ndn-stack-helper.hpp"
33#include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp"
34#include "ns3/ndnSIM/NFD/daemon/face/internal-transport.hpp"
35
Junxiao Shi4460e822017-08-07 22:02:45 +000036// NDN_LOG_INIT(ndn.Face) is declared in face-impl.hpp
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070037
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -080038// A callback scheduled through io.post and io.dispatch may be invoked after the face
39// is destructed. To prevent this situation, these macros captures Face::m_impl as weak_ptr,
40// and skips callback execution if the face has been destructed.
41
Junxiao Shiae0b4182016-08-08 22:53:17 +000042#define IO_CAPTURE_WEAK_IMPL(OP) \
43 { \
44 weak_ptr<Impl> implWeak(m_impl); \
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -080045 m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { \
Junxiao Shiae0b4182016-08-08 22:53:17 +000046 auto impl = implWeak.lock(); \
47 if (impl != nullptr) {
48#define IO_CAPTURE_WEAK_IMPL_END \
49 } \
50 }); \
51 }
52
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070053namespace ndn {
Alexander Afanasyevb790d952014-01-24 12:07:53 -080054
Junxiao Shib6e276f2017-08-14 20:10:04 +000055Face::OversizedPacketError::OversizedPacketError(char pktType, const Name& name, size_t wireSize)
56 : Error((pktType == 'I' ? "Interest " : pktType == 'D' ? "Data " : "Nack ") +
57 name.toUri() + " encodes into " + to_string(wireSize) + " octets, "
58 "exceeding the implementation limit of " + to_string(MAX_NDN_PACKET_SIZE) + " octets")
59 , pktType(pktType)
60 , name(name)
61 , wireSize(wireSize)
62{
63}
64
Junxiao Shi103d8ed2016-08-07 20:34:10 +000065Face::Face(shared_ptr<Transport> transport)
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -080066 : m_impl(new Impl(*this))
Jeff Thompsonfb29cda2013-08-24 10:26:54 -070067{
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -080068 construct(transport, ns3::ndn::StackHelper::getKeyChain());
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080069}
70
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -070071Face::Face(boost::asio::io_service& ioService)
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -080072 : m_impl(new Impl(*this))
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -070073{
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -080074 construct(nullptr, ns3::ndn::StackHelper::getKeyChain());
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080075}
76
Alexander Afanasyev8cf1c562016-06-23 16:01:55 -070077Face::Face(shared_ptr<Transport> transport, KeyChain& keyChain)
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -080078 : m_impl(new Impl(*this))
Alexander Afanasyev8cf1c562016-06-23 16:01:55 -070079{
Junxiao Shib6e276f2017-08-14 20:10:04 +000080 construct(std::move(transport), keyChain);
Alexander Afanasyev8cf1c562016-06-23 16:01:55 -070081}
82
83Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService)
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -080084 : m_impl(new Impl(*this))
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080085{
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -080086 construct(transport, ns3::ndn::StackHelper::getKeyChain());
Junxiao Shiedd834e2014-10-28 20:28:58 -070087}
88
Alexander Afanasyev8cf1c562016-06-23 16:01:55 -070089Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, KeyChain& keyChain)
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -080090 : m_impl(new Impl(*this))
Junxiao Shiedd834e2014-10-28 20:28:58 -070091{
Junxiao Shib6e276f2017-08-14 20:10:04 +000092 construct(std::move(transport), keyChain);
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080093}
94
Alexander Afanasyevbb64c172015-12-29 20:32:45 -080095shared_ptr<Transport>
96Face::makeDefaultTransport()
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070097{
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -080098 ns3::Ptr<ns3::Node> node = ns3::NodeList::GetNode(ns3::Simulator::GetContext());
99 NS_ASSERT_MSG(node->GetObject<ns3::ndn::L3Protocol>() != 0,
100 "NDN stack should be installed on the node " << node);
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -0700101
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -0800102 auto uri = ::nfd::FaceUri("ndnFace://" + boost::lexical_cast<std::string>(node->GetId()));
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700103
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -0800104 ::nfd::face::GenericLinkService::Options serviceOpts;
105 serviceOpts.allowLocalFields = true;
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700106
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -0800107 auto nfdFace = make_shared<::nfd::Face>(make_unique<::nfd::face::GenericLinkService>(serviceOpts),
108 make_unique<::nfd::face::InternalForwarderTransport>(uri, uri));
109 auto forwarderTransport = static_cast<::nfd::face::InternalForwarderTransport*>(nfdFace->getTransport());
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -0700110
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -0800111 auto clientTransport = make_shared<::nfd::face::InternalClientTransport>();
112 clientTransport->connectToForwarder(forwarderTransport);
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700113
Spyridon Mastorakisbf266ab2016-11-28 18:03:05 -0800114 node->GetObject<ns3::ndn::L3Protocol>()->addFace(nfdFace);;
115
116 return clientTransport;
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -0700117}
118
119void
Joao Pereira68c0d882015-05-19 14:27:55 -0400120Face::construct(shared_ptr<Transport> transport, KeyChain& keyChain)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800121{
Alexander Afanasyevbb64c172015-12-29 20:32:45 -0800122 if (transport == nullptr) {
123 transport = makeDefaultTransport();
124 }
125 BOOST_ASSERT(transport != nullptr);
Junxiao Shib6e276f2017-08-14 20:10:04 +0000126 m_transport = std::move(transport);
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800127
Junxiao Shib6e276f2017-08-14 20:10:04 +0000128 m_nfdController = make_unique<nfd::Controller>(*this, keyChain);
Alexander Afanasyevbb64c172015-12-29 20:32:45 -0800129
Junxiao Shiae0b4182016-08-08 22:53:17 +0000130 IO_CAPTURE_WEAK_IMPL(post) {
131 impl->ensureConnected(false);
132 } IO_CAPTURE_WEAK_IMPL_END
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800133}
134
Joao Pereira68c0d882015-05-19 14:27:55 -0400135Face::~Face() = default;
Junxiao Shiedd834e2014-10-28 20:28:58 -0700136
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800137shared_ptr<Transport>
138Face::getTransport()
139{
140 return m_transport;
141}
142
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800143const PendingInterestId*
Eric Newberry83872fd2015-08-06 17:01:24 -0700144Face::expressInterest(const Interest& interest,
145 const DataCallback& afterSatisfied,
146 const NackCallback& afterNacked,
147 const TimeoutCallback& afterTimeout)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800148{
Junxiao Shib6e276f2017-08-14 20:10:04 +0000149 shared_ptr<Interest> interest2 = make_shared<Interest>(interest);
150 interest2->getNonce();
151 NDN_LOG_DEBUG("<I " << *interest2);
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800152
Junxiao Shiae0b4182016-08-08 22:53:17 +0000153 IO_CAPTURE_WEAK_IMPL(dispatch) {
Junxiao Shib6e276f2017-08-14 20:10:04 +0000154 impl->asyncExpressInterest(interest2, afterSatisfied, afterNacked, afterTimeout);
Junxiao Shiae0b4182016-08-08 22:53:17 +0000155 } IO_CAPTURE_WEAK_IMPL_END
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800156
Junxiao Shib6e276f2017-08-14 20:10:04 +0000157 return reinterpret_cast<const PendingInterestId*>(interest2.get());
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800158}
159
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800160void
Junxiao Shiae0b4182016-08-08 22:53:17 +0000161Face::removePendingInterest(const PendingInterestId* pendingInterestId)
162{
163 IO_CAPTURE_WEAK_IMPL(post) {
164 impl->asyncRemovePendingInterest(pendingInterestId);
165 } IO_CAPTURE_WEAK_IMPL_END
166}
167
168void
169Face::removeAllPendingInterests()
170{
171 IO_CAPTURE_WEAK_IMPL(post) {
172 impl->asyncRemoveAllPendingInterests();
173 } IO_CAPTURE_WEAK_IMPL_END
174}
175
176size_t
177Face::getNPendingInterests() const
178{
179 return m_impl->m_pendingInterestTable.size();
180}
181
182void
Junxiao Shib6e276f2017-08-14 20:10:04 +0000183Face::put(Data data)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800184{
Junxiao Shi4460e822017-08-07 22:02:45 +0000185 NDN_LOG_DEBUG("<D " << data.getName());
Junxiao Shiae0b4182016-08-08 22:53:17 +0000186 IO_CAPTURE_WEAK_IMPL(dispatch) {
Junxiao Shib6e276f2017-08-14 20:10:04 +0000187 impl->asyncPutData(data);
Junxiao Shiae0b4182016-08-08 22:53:17 +0000188 } IO_CAPTURE_WEAK_IMPL_END
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800189}
190
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800191void
Junxiao Shib6e276f2017-08-14 20:10:04 +0000192Face::put(lp::Nack nack)
Eric Newberry83872fd2015-08-06 17:01:24 -0700193{
Junxiao Shi4460e822017-08-07 22:02:45 +0000194 NDN_LOG_DEBUG("<N " << nack.getInterest() << '~' << nack.getHeader().getReason());
Junxiao Shiae0b4182016-08-08 22:53:17 +0000195 IO_CAPTURE_WEAK_IMPL(dispatch) {
Junxiao Shib6e276f2017-08-14 20:10:04 +0000196 impl->asyncPutNack(nack);
Junxiao Shiae0b4182016-08-08 22:53:17 +0000197 } IO_CAPTURE_WEAK_IMPL_END
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -0700198}
199
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800200const RegisteredPrefixId*
Alexander Afanasyev90164962014-03-06 08:29:59 +0000201Face::setInterestFilter(const InterestFilter& interestFilter,
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000202 const InterestCallback& onInterest,
203 const RegisterPrefixFailureCallback& onFailure,
204 const security::SigningInfo& signingInfo,
205 uint64_t flags)
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700206{
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000207 return setInterestFilter(interestFilter, onInterest, nullptr, onFailure, signingInfo, flags);
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700208}
209
210const RegisteredPrefixId*
Alexander Afanasyev90164962014-03-06 08:29:59 +0000211Face::setInterestFilter(const InterestFilter& interestFilter,
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000212 const InterestCallback& onInterest,
213 const RegisterPrefixSuccessCallback& onSuccess,
214 const RegisterPrefixFailureCallback& onFailure,
215 const security::SigningInfo& signingInfo,
216 uint64_t flags)
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700217{
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000218 auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700219
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000220 nfd::CommandOptions options;
221 options.setSigningInfo(signingInfo);
Junxiao Shi388ec252014-11-02 15:19:57 -0700222
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000223 return m_impl->registerPrefix(interestFilter.getPrefix(), filter,
224 onSuccess, onFailure, flags, options);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700225}
226
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700227const InterestFilterId*
228Face::setInterestFilter(const InterestFilter& interestFilter,
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000229 const InterestCallback& onInterest)
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700230{
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000231 auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700232
Junxiao Shiae0b4182016-08-08 22:53:17 +0000233 IO_CAPTURE_WEAK_IMPL(post) {
234 impl->asyncSetInterestFilter(filter);
235 } IO_CAPTURE_WEAK_IMPL_END
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700236
237 return reinterpret_cast<const InterestFilterId*>(filter.get());
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700238}
239
Joao Pereira0b3cac52015-07-02 14:49:49 -0400240const RegisteredPrefixId*
241Face::registerPrefix(const Name& prefix,
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000242 const RegisterPrefixSuccessCallback& onSuccess,
243 const RegisterPrefixFailureCallback& onFailure,
244 const security::SigningInfo& signingInfo,
245 uint64_t flags)
Joao Pereira0b3cac52015-07-02 14:49:49 -0400246{
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000247 nfd::CommandOptions options;
248 options.setSigningInfo(signingInfo);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400249
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000250 return m_impl->registerPrefix(prefix, nullptr, onSuccess, onFailure, flags, options);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400251}
252
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700253void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800254Face::unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800255{
Junxiao Shiae0b4182016-08-08 22:53:17 +0000256 IO_CAPTURE_WEAK_IMPL(post) {
257 impl->asyncUnregisterPrefix(registeredPrefixId, nullptr, nullptr);
258 } IO_CAPTURE_WEAK_IMPL_END
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800259}
260
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -0700261void
262Face::unsetInterestFilter(const InterestFilterId* interestFilterId)
263{
Junxiao Shiae0b4182016-08-08 22:53:17 +0000264 IO_CAPTURE_WEAK_IMPL(post) {
265 impl->asyncUnsetInterestFilter(interestFilterId);
266 } IO_CAPTURE_WEAK_IMPL_END
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -0700267}
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700268
269void
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700270Face::unregisterPrefix(const RegisteredPrefixId* registeredPrefixId,
271 const UnregisterPrefixSuccessCallback& onSuccess,
272 const UnregisterPrefixFailureCallback& onFailure)
273{
Junxiao Shiae0b4182016-08-08 22:53:17 +0000274 IO_CAPTURE_WEAK_IMPL(post) {
275 impl->asyncUnregisterPrefix(registeredPrefixId, onSuccess, onFailure);
276 } IO_CAPTURE_WEAK_IMPL_END
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700277}
278
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800279void
Junxiao Shi2ed9e072017-08-13 16:45:48 +0000280Face::doProcessEvents(time::milliseconds timeout, bool keepThread)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800281{
Jeff Thompsonfb29cda2013-08-24 10:26:54 -0700282}
283
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800284void
Jeff Thompson0050abe2013-09-17 12:50:25 -0700285Face::shutdown()
Jeff Thompson517ffa82013-08-05 16:04:34 -0700286{
Junxiao Shiae0b4182016-08-08 22:53:17 +0000287 IO_CAPTURE_WEAK_IMPL(post) {
288 this->asyncShutdown();
289 } IO_CAPTURE_WEAK_IMPL_END
Alexander Afanasyev7dced462014-03-19 15:12:32 -0700290}
291
292void
293Face::asyncShutdown()
294{
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -0700295 m_impl->m_pendingInterestTable.clear();
296 m_impl->m_registeredPrefixTable.clear();
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800297
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700298 if (m_transport->isConnected())
299 m_transport->close();
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700300}
301
Eric Newberry83872fd2015-08-06 17:01:24 -0700302/**
303 * @brief extract local fields from NDNLPv2 packet and tag onto a network layer packet
304 */
Eric Newberry4d261b62016-11-10 13:40:09 -0700305template<typename NetPkt>
Eric Newberry83872fd2015-08-06 17:01:24 -0700306static void
Eric Newberry4d261b62016-11-10 13:40:09 -0700307extractLpLocalFields(NetPkt& netPacket, const lp::Packet& lpPacket)
Eric Newberry83872fd2015-08-06 17:01:24 -0700308{
Junxiao Shib38e6d42017-08-16 16:15:28 +0000309 addTagFromField<lp::IncomingFaceIdTag, lp::IncomingFaceIdField>(netPacket, lpPacket);
310 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(netPacket, lpPacket);
Spyridon Mastorakis9a738052016-12-06 15:21:44 -0800311
312 if (lpPacket.has<lp::HopCountTagField>()) {
313 netPacket.setTag(make_shared<lp::HopCountTag>(lpPacket.get<lp::HopCountTagField>() + 1));
314 }
Eric Newberry83872fd2015-08-06 17:01:24 -0700315}
316
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800317void
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800318Face::onReceiveElement(const Block& blockFromDaemon)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800319{
Eric Newberry83872fd2015-08-06 17:01:24 -0700320 lp::Packet lpPacket(blockFromDaemon); // bare Interest/Data is a valid lp::Packet,
321 // no need to distinguish
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800322
Eric Newberry83872fd2015-08-06 17:01:24 -0700323 Buffer::const_iterator begin, end;
324 std::tie(begin, end) = lpPacket.get<lp::FragmentField>();
325 Block netPacket(&*begin, std::distance(begin, end));
326 switch (netPacket.type()) {
327 case tlv::Interest: {
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000328 auto interest = make_shared<Interest>(netPacket);
Eric Newberry83872fd2015-08-06 17:01:24 -0700329 if (lpPacket.has<lp::NackField>()) {
330 auto nack = make_shared<lp::Nack>(std::move(*interest));
331 nack->setHeader(lpPacket.get<lp::NackField>());
332 extractLpLocalFields(*nack, lpPacket);
Junxiao Shi4460e822017-08-07 22:02:45 +0000333 NDN_LOG_DEBUG(">N " << nack->getInterest() << '~' << nack->getHeader().getReason());
Eric Newberry83872fd2015-08-06 17:01:24 -0700334 m_impl->nackPendingInterests(*nack);
335 }
336 else {
337 extractLpLocalFields(*interest, lpPacket);
Junxiao Shi4460e822017-08-07 22:02:45 +0000338 NDN_LOG_DEBUG(">I " << *interest);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000339 m_impl->processIncomingInterest(std::move(interest));
Eric Newberry83872fd2015-08-06 17:01:24 -0700340 }
341 break;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800342 }
Eric Newberry83872fd2015-08-06 17:01:24 -0700343 case tlv::Data: {
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000344 auto data = make_shared<Data>(netPacket);
Eric Newberry83872fd2015-08-06 17:01:24 -0700345 extractLpLocalFields(*data, lpPacket);
Junxiao Shi4460e822017-08-07 22:02:45 +0000346 NDN_LOG_DEBUG(">D " << data->getName());
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -0700347 m_impl->satisfyPendingInterests(*data);
Eric Newberry83872fd2015-08-06 17:01:24 -0700348 break;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800349 }
Eric Newberry83872fd2015-08-06 17:01:24 -0700350 }
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800351}
352
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800353} // namespace ndn