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 "link-service.hpp" |
| 27 | #include "lp-face.hpp" |
| 28 | #include "transport.hpp" |
| 29 | |
| 30 | namespace nfd { |
| 31 | namespace face { |
| 32 | |
| 33 | NFD_LOG_INIT("LinkService"); |
| 34 | |
| 35 | LinkService::LinkService() |
| 36 | : m_face(nullptr) |
| 37 | , m_transport(nullptr) |
| 38 | , m_counters(nullptr) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | LinkService::~LinkService() |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | void |
| 47 | LinkService::setFaceAndTransport(LpFace& face, Transport& transport) |
| 48 | { |
| 49 | BOOST_ASSERT(m_face == nullptr); |
| 50 | BOOST_ASSERT(m_transport == nullptr); |
| 51 | |
| 52 | m_face = &face; |
| 53 | m_transport = &transport; |
| 54 | m_counters = &m_face->getMutableCounters(); |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | LinkService::sendInterest(const Interest& interest) |
| 59 | { |
| 60 | BOOST_ASSERT(m_transport != nullptr); |
| 61 | NFD_LOG_FACE_TRACE(__func__); |
| 62 | |
| 63 | ++m_counters->getNOutInterests(); |
| 64 | |
| 65 | doSendInterest(interest); |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | LinkService::sendData(const Data& data) |
| 70 | { |
| 71 | BOOST_ASSERT(m_transport != nullptr); |
| 72 | NFD_LOG_FACE_TRACE(__func__); |
| 73 | |
| 74 | ++m_counters->getNOutDatas(); |
| 75 | |
| 76 | doSendData(data); |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | LinkService::sendNack(const ndn::lp::Nack& nack) |
| 81 | { |
| 82 | BOOST_ASSERT(m_transport != nullptr); |
| 83 | NFD_LOG_FACE_TRACE(__func__); |
| 84 | |
| 85 | // TODO#3177 increment counter |
| 86 | |
| 87 | doSendNack(nack); |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | LinkService::receiveInterest(const Interest& interest) |
| 92 | { |
| 93 | NFD_LOG_FACE_TRACE(__func__); |
| 94 | |
| 95 | ++m_counters->getNInInterests(); |
| 96 | |
| 97 | afterReceiveInterest(interest); |
| 98 | } |
| 99 | |
| 100 | void |
| 101 | LinkService::receiveData(const Data& data) |
| 102 | { |
| 103 | NFD_LOG_FACE_TRACE(__func__); |
| 104 | |
| 105 | ++m_counters->getNInDatas(); |
| 106 | |
| 107 | afterReceiveData(data); |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | LinkService::receiveNack(const ndn::lp::Nack& nack) |
| 112 | { |
| 113 | NFD_LOG_FACE_TRACE(__func__); |
| 114 | |
| 115 | // TODO#3177 increment counter |
| 116 | |
| 117 | afterReceiveNack(nack); |
| 118 | } |
| 119 | |
| 120 | std::ostream& |
| 121 | operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh) |
| 122 | { |
| 123 | const LpFace* face = flh.obj.getFace(); |
| 124 | if (face == nullptr) { |
| 125 | os << "[id=0,local=unknown,remote=unknown] "; |
| 126 | } |
| 127 | else { |
| 128 | os << "[id=" << face->getId() << ",local=" << face->getLocalUri() |
| 129 | << ",remote=" << face->getRemoteUri() << "] "; |
| 130 | } |
| 131 | return os; |
| 132 | } |
| 133 | |
| 134 | } // namespace face |
| 135 | } // namespace nfd |