Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "generic-link-service.hpp" |
| 27 | |
| 28 | namespace nfd { |
| 29 | namespace face { |
| 30 | |
| 31 | NFD_LOG_INIT("GenericLinkService"); |
| 32 | |
| 33 | void |
| 34 | GenericLinkService::doSendInterest(const Interest& interest) |
| 35 | { |
| 36 | lp::Packet lpPacket(interest.wireEncode()); |
| 37 | Transport::Packet packet; |
| 38 | packet.packet = lpPacket.wireEncode(); |
| 39 | sendPacket(std::move(packet)); |
| 40 | } |
| 41 | |
| 42 | void |
| 43 | GenericLinkService::doSendData(const Data& data) |
| 44 | { |
| 45 | lp::Packet lpPacket(data.wireEncode()); |
| 46 | Transport::Packet packet; |
| 47 | packet.packet = lpPacket.wireEncode(); |
| 48 | sendPacket(std::move(packet)); |
| 49 | } |
| 50 | |
| 51 | void |
| 52 | GenericLinkService::doSendNack(const lp::Nack& nack) |
| 53 | { |
| 54 | lp::Packet lpPacket(nack.getInterest().wireEncode()); |
| 55 | lpPacket.add<lp::NackField>(nack.getHeader()); |
| 56 | Transport::Packet packet; |
| 57 | packet.packet = lpPacket.wireEncode(); |
| 58 | sendPacket(std::move(packet)); |
| 59 | } |
| 60 | |
| 61 | void |
| 62 | GenericLinkService::doReceivePacket(Transport::Packet&& packet) |
| 63 | { |
| 64 | lp::Packet lpPacket(packet.packet); |
| 65 | ndn::Buffer::const_iterator fragBegin, fragEnd; |
| 66 | std::tie(fragBegin, fragEnd) = lpPacket.get<lp::FragmentField>(); |
| 67 | Block netPacket(&*fragBegin, std::distance(fragBegin, fragEnd)); |
| 68 | |
| 69 | // Forwarding expects Interest and Data to be created with make_shared, |
| 70 | // but has no such requirement on Nack. |
| 71 | switch (netPacket.type()) { |
| 72 | case tlv::Interest: { |
| 73 | auto interest = make_shared<Interest>(netPacket); |
| 74 | if (lpPacket.has<lp::NackField>()) { |
| 75 | lp::Nack nack(std::move(*interest)); |
| 76 | nack.setHeader(lpPacket.get<lp::NackField>()); |
| 77 | receiveNack(nack); |
| 78 | } |
| 79 | else { |
| 80 | receiveInterest(*interest); |
| 81 | } |
| 82 | break; |
| 83 | } |
| 84 | case tlv::Data: { |
| 85 | auto data = make_shared<Data>(netPacket); |
| 86 | receiveData(*data); |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | } // namespace face |
| 93 | } // namespace nfd |