Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 4460e82 | 2017-08-07 22:02:45 +0000 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * 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 Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 22 | #include "face.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 23 | #include "detail/face-impl.hpp" |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 24 | |
Junxiao Shi | 468abc3 | 2014-11-04 09:12:47 -0700 | [diff] [blame] | 25 | #include "encoding/tlv.hpp" |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 26 | #include "net/face-uri.hpp" |
Junxiao Shi | c6acc7a | 2015-06-23 10:03:56 -0700 | [diff] [blame] | 27 | #include "security/signing-helpers.hpp" |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 28 | #include "util/random.hpp" |
Junxiao Shi | 4460e82 | 2017-08-07 22:02:45 +0000 | [diff] [blame] | 29 | #include "util/time.hpp" |
| 30 | |
Spyridon Mastorakis | b42184a | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 31 | #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 Shi | 4460e82 | 2017-08-07 22:02:45 +0000 | [diff] [blame] | 36 | // NDN_LOG_INIT(ndn.Face) is declared in face-impl.hpp |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 37 | |
Spyridon Mastorakis | b42184a | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 38 | // 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 Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 42 | #define IO_CAPTURE_WEAK_IMPL(OP) \ |
| 43 | { \ |
| 44 | weak_ptr<Impl> implWeak(m_impl); \ |
Spyridon Mastorakis | b42184a | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 45 | m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { \ |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 46 | auto impl = implWeak.lock(); \ |
| 47 | if (impl != nullptr) { |
| 48 | #define IO_CAPTURE_WEAK_IMPL_END \ |
| 49 | } \ |
| 50 | }); \ |
| 51 | } |
| 52 | |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 53 | namespace ndn { |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 54 | |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 55 | Face::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 | |
Alexander Afanasyev | c37bf16 | 2018-05-08 19:54:16 -0400 | [diff] [blame^] | 65 | Face::Face(DummyIoService& ioService) |
| 66 | : m_impl(new Impl(*this)) |
| 67 | { |
| 68 | construct(nullptr, ns3::ndn::StackHelper::getKeyChain()); |
| 69 | } |
| 70 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 71 | Face::Face(shared_ptr<Transport> transport) |
Spyridon Mastorakis | b42184a | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 72 | : m_impl(new Impl(*this)) |
Jeff Thompson | fb29cda | 2013-08-24 10:26:54 -0700 | [diff] [blame] | 73 | { |
Spyridon Mastorakis | b42184a | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 74 | construct(transport, ns3::ndn::StackHelper::getKeyChain()); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 77 | Face::Face(shared_ptr<Transport> transport, KeyChain& keyChain) |
Spyridon Mastorakis | b42184a | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 78 | : m_impl(new Impl(*this)) |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 79 | { |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 80 | construct(std::move(transport), keyChain); |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 83 | shared_ptr<Transport> |
| 84 | Face::makeDefaultTransport() |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 85 | { |
Spyridon Mastorakis | b42184a | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 86 | ns3::Ptr<ns3::Node> node = ns3::NodeList::GetNode(ns3::Simulator::GetContext()); |
| 87 | NS_ASSERT_MSG(node->GetObject<ns3::ndn::L3Protocol>() != 0, |
| 88 | "NDN stack should be installed on the node " << node); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 89 | |
Spyridon Mastorakis | b42184a | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 90 | auto uri = ::nfd::FaceUri("ndnFace://" + boost::lexical_cast<std::string>(node->GetId())); |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 91 | |
Spyridon Mastorakis | b42184a | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 92 | ::nfd::face::GenericLinkService::Options serviceOpts; |
| 93 | serviceOpts.allowLocalFields = true; |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 94 | |
Spyridon Mastorakis | b42184a | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 95 | auto nfdFace = make_shared<::nfd::Face>(make_unique<::nfd::face::GenericLinkService>(serviceOpts), |
| 96 | make_unique<::nfd::face::InternalForwarderTransport>(uri, uri)); |
| 97 | auto forwarderTransport = static_cast<::nfd::face::InternalForwarderTransport*>(nfdFace->getTransport()); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 98 | |
Spyridon Mastorakis | b42184a | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 99 | auto clientTransport = make_shared<::nfd::face::InternalClientTransport>(); |
| 100 | clientTransport->connectToForwarder(forwarderTransport); |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 101 | |
Spyridon Mastorakis | b42184a | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 102 | node->GetObject<ns3::ndn::L3Protocol>()->addFace(nfdFace);; |
| 103 | |
| 104 | return clientTransport; |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void |
Joao Pereira | 68c0d88 | 2015-05-19 14:27:55 -0400 | [diff] [blame] | 108 | Face::construct(shared_ptr<Transport> transport, KeyChain& keyChain) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 109 | { |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 110 | if (transport == nullptr) { |
| 111 | transport = makeDefaultTransport(); |
| 112 | } |
| 113 | BOOST_ASSERT(transport != nullptr); |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 114 | m_transport = std::move(transport); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 115 | |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 116 | m_nfdController = make_unique<nfd::Controller>(*this, keyChain); |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 117 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 118 | IO_CAPTURE_WEAK_IMPL(post) { |
| 119 | impl->ensureConnected(false); |
| 120 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Joao Pereira | 68c0d88 | 2015-05-19 14:27:55 -0400 | [diff] [blame] | 123 | Face::~Face() = default; |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 124 | |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 125 | shared_ptr<Transport> |
| 126 | Face::getTransport() |
| 127 | { |
| 128 | return m_transport; |
| 129 | } |
| 130 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 131 | const PendingInterestId* |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 132 | Face::expressInterest(const Interest& interest, |
| 133 | const DataCallback& afterSatisfied, |
| 134 | const NackCallback& afterNacked, |
| 135 | const TimeoutCallback& afterTimeout) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 136 | { |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 137 | shared_ptr<Interest> interest2 = make_shared<Interest>(interest); |
| 138 | interest2->getNonce(); |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 139 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 140 | IO_CAPTURE_WEAK_IMPL(dispatch) { |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 141 | impl->asyncExpressInterest(interest2, afterSatisfied, afterNacked, afterTimeout); |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 142 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 143 | |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 144 | return reinterpret_cast<const PendingInterestId*>(interest2.get()); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 147 | void |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 148 | Face::removePendingInterest(const PendingInterestId* pendingInterestId) |
| 149 | { |
| 150 | IO_CAPTURE_WEAK_IMPL(post) { |
| 151 | impl->asyncRemovePendingInterest(pendingInterestId); |
| 152 | } IO_CAPTURE_WEAK_IMPL_END |
| 153 | } |
| 154 | |
| 155 | void |
| 156 | Face::removeAllPendingInterests() |
| 157 | { |
| 158 | IO_CAPTURE_WEAK_IMPL(post) { |
| 159 | impl->asyncRemoveAllPendingInterests(); |
| 160 | } IO_CAPTURE_WEAK_IMPL_END |
| 161 | } |
| 162 | |
| 163 | size_t |
| 164 | Face::getNPendingInterests() const |
| 165 | { |
| 166 | return m_impl->m_pendingInterestTable.size(); |
| 167 | } |
| 168 | |
| 169 | void |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 170 | Face::put(Data data) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 171 | { |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 172 | IO_CAPTURE_WEAK_IMPL(dispatch) { |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 173 | impl->asyncPutData(data); |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 174 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 177 | void |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 178 | Face::put(lp::Nack nack) |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 179 | { |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 180 | IO_CAPTURE_WEAK_IMPL(dispatch) { |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 181 | impl->asyncPutNack(nack); |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 182 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 6fcdde2 | 2014-08-22 19:03:36 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 185 | const RegisteredPrefixId* |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 186 | Face::setInterestFilter(const InterestFilter& interestFilter, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 187 | const InterestCallback& onInterest, |
| 188 | const RegisterPrefixFailureCallback& onFailure, |
| 189 | const security::SigningInfo& signingInfo, |
| 190 | uint64_t flags) |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 191 | { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 192 | return setInterestFilter(interestFilter, onInterest, nullptr, onFailure, signingInfo, flags); |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | const RegisteredPrefixId* |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 196 | Face::setInterestFilter(const InterestFilter& interestFilter, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 197 | const InterestCallback& onInterest, |
| 198 | const RegisterPrefixSuccessCallback& onSuccess, |
| 199 | const RegisterPrefixFailureCallback& onFailure, |
| 200 | const security::SigningInfo& signingInfo, |
| 201 | uint64_t flags) |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 202 | { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 203 | auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 204 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 205 | nfd::CommandOptions options; |
| 206 | options.setSigningInfo(signingInfo); |
Junxiao Shi | 388ec25 | 2014-11-02 15:19:57 -0700 | [diff] [blame] | 207 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 208 | return m_impl->registerPrefix(interestFilter.getPrefix(), filter, |
| 209 | onSuccess, onFailure, flags, options); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 212 | const InterestFilterId* |
| 213 | Face::setInterestFilter(const InterestFilter& interestFilter, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 214 | const InterestCallback& onInterest) |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 215 | { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 216 | auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 217 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 218 | IO_CAPTURE_WEAK_IMPL(post) { |
| 219 | impl->asyncSetInterestFilter(filter); |
| 220 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 221 | |
| 222 | return reinterpret_cast<const InterestFilterId*>(filter.get()); |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 225 | const RegisteredPrefixId* |
| 226 | Face::registerPrefix(const Name& prefix, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 227 | const RegisterPrefixSuccessCallback& onSuccess, |
| 228 | const RegisterPrefixFailureCallback& onFailure, |
| 229 | const security::SigningInfo& signingInfo, |
| 230 | uint64_t flags) |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 231 | { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 232 | nfd::CommandOptions options; |
| 233 | options.setSigningInfo(signingInfo); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 234 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 235 | return m_impl->registerPrefix(prefix, nullptr, onSuccess, onFailure, flags, options); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 236 | } |
| 237 | |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 238 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 239 | Face::unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 240 | { |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 241 | IO_CAPTURE_WEAK_IMPL(post) { |
| 242 | impl->asyncUnregisterPrefix(registeredPrefixId, nullptr, nullptr); |
| 243 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 246 | void |
| 247 | Face::unsetInterestFilter(const InterestFilterId* interestFilterId) |
| 248 | { |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 249 | IO_CAPTURE_WEAK_IMPL(post) { |
| 250 | impl->asyncUnsetInterestFilter(interestFilterId); |
| 251 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 252 | } |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 253 | |
| 254 | void |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 255 | Face::unregisterPrefix(const RegisteredPrefixId* registeredPrefixId, |
| 256 | const UnregisterPrefixSuccessCallback& onSuccess, |
| 257 | const UnregisterPrefixFailureCallback& onFailure) |
| 258 | { |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 259 | IO_CAPTURE_WEAK_IMPL(post) { |
| 260 | impl->asyncUnregisterPrefix(registeredPrefixId, onSuccess, onFailure); |
| 261 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 264 | void |
Junxiao Shi | 2ed9e07 | 2017-08-13 16:45:48 +0000 | [diff] [blame] | 265 | Face::doProcessEvents(time::milliseconds timeout, bool keepThread) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 266 | { |
Jeff Thompson | fb29cda | 2013-08-24 10:26:54 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 269 | void |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 270 | Face::shutdown() |
Jeff Thompson | 517ffa8 | 2013-08-05 16:04:34 -0700 | [diff] [blame] | 271 | { |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 272 | IO_CAPTURE_WEAK_IMPL(post) { |
| 273 | this->asyncShutdown(); |
| 274 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 7dced46 | 2014-03-19 15:12:32 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | void |
| 278 | Face::asyncShutdown() |
| 279 | { |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 280 | m_impl->m_pendingInterestTable.clear(); |
| 281 | m_impl->m_registeredPrefixTable.clear(); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 282 | |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 283 | if (m_transport->isConnected()) |
| 284 | m_transport->close(); |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 287 | /** |
| 288 | * @brief extract local fields from NDNLPv2 packet and tag onto a network layer packet |
| 289 | */ |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 290 | template<typename NetPkt> |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 291 | static void |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 292 | extractLpLocalFields(NetPkt& netPacket, const lp::Packet& lpPacket) |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 293 | { |
Junxiao Shi | b38e6d4 | 2017-08-16 16:15:28 +0000 | [diff] [blame] | 294 | addTagFromField<lp::IncomingFaceIdTag, lp::IncomingFaceIdField>(netPacket, lpPacket); |
| 295 | addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(netPacket, lpPacket); |
Spyridon Mastorakis | d31b8ef | 2016-12-06 15:21:44 -0800 | [diff] [blame] | 296 | |
| 297 | if (lpPacket.has<lp::HopCountTagField>()) { |
| 298 | netPacket.setTag(make_shared<lp::HopCountTag>(lpPacket.get<lp::HopCountTagField>() + 1)); |
| 299 | } |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 302 | void |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 303 | Face::onReceiveElement(const Block& blockFromDaemon) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 304 | { |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 305 | lp::Packet lpPacket(blockFromDaemon); // bare Interest/Data is a valid lp::Packet, |
| 306 | // no need to distinguish |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 307 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 308 | Buffer::const_iterator begin, end; |
| 309 | std::tie(begin, end) = lpPacket.get<lp::FragmentField>(); |
| 310 | Block netPacket(&*begin, std::distance(begin, end)); |
| 311 | switch (netPacket.type()) { |
| 312 | case tlv::Interest: { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 313 | auto interest = make_shared<Interest>(netPacket); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 314 | if (lpPacket.has<lp::NackField>()) { |
| 315 | auto nack = make_shared<lp::Nack>(std::move(*interest)); |
| 316 | nack->setHeader(lpPacket.get<lp::NackField>()); |
| 317 | extractLpLocalFields(*nack, lpPacket); |
Junxiao Shi | 4460e82 | 2017-08-07 22:02:45 +0000 | [diff] [blame] | 318 | NDN_LOG_DEBUG(">N " << nack->getInterest() << '~' << nack->getHeader().getReason()); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 319 | m_impl->nackPendingInterests(*nack); |
| 320 | } |
| 321 | else { |
| 322 | extractLpLocalFields(*interest, lpPacket); |
Junxiao Shi | 4460e82 | 2017-08-07 22:02:45 +0000 | [diff] [blame] | 323 | NDN_LOG_DEBUG(">I " << *interest); |
Junxiao Shi | 1ad0b4b | 2017-08-18 14:19:14 +0000 | [diff] [blame] | 324 | m_impl->processIncomingInterest(std::move(interest)); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 325 | } |
| 326 | break; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 327 | } |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 328 | case tlv::Data: { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 329 | auto data = make_shared<Data>(netPacket); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 330 | extractLpLocalFields(*data, lpPacket); |
Junxiao Shi | 4460e82 | 2017-08-07 22:02:45 +0000 | [diff] [blame] | 331 | NDN_LOG_DEBUG(">D " << data->getName()); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 332 | m_impl->satisfyPendingInterests(*data); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 333 | break; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 334 | } |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 335 | } |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 338 | } // namespace ndn |