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) |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame^] | 38 | , m_oldCounters(nullptr) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 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; |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame^] | 54 | m_oldCounters = &m_face->getMutableCounters(); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void |
| 58 | LinkService::sendInterest(const Interest& interest) |
| 59 | { |
| 60 | BOOST_ASSERT(m_transport != nullptr); |
| 61 | NFD_LOG_FACE_TRACE(__func__); |
| 62 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame^] | 63 | ++this->nOutInterests; |
| 64 | ++m_oldCounters->getNOutInterests(); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 65 | |
| 66 | doSendInterest(interest); |
| 67 | } |
| 68 | |
| 69 | void |
| 70 | LinkService::sendData(const Data& data) |
| 71 | { |
| 72 | BOOST_ASSERT(m_transport != nullptr); |
| 73 | NFD_LOG_FACE_TRACE(__func__); |
| 74 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame^] | 75 | ++this->nOutData; |
| 76 | ++m_oldCounters->getNOutDatas(); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 77 | |
| 78 | doSendData(data); |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | LinkService::sendNack(const ndn::lp::Nack& nack) |
| 83 | { |
| 84 | BOOST_ASSERT(m_transport != nullptr); |
| 85 | NFD_LOG_FACE_TRACE(__func__); |
| 86 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame^] | 87 | ++this->nOutNacks; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 88 | |
| 89 | doSendNack(nack); |
| 90 | } |
| 91 | |
| 92 | void |
| 93 | LinkService::receiveInterest(const Interest& interest) |
| 94 | { |
| 95 | NFD_LOG_FACE_TRACE(__func__); |
| 96 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame^] | 97 | ++this->nInInterests; |
| 98 | ++m_oldCounters->getNInInterests(); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 99 | |
| 100 | afterReceiveInterest(interest); |
| 101 | } |
| 102 | |
| 103 | void |
| 104 | LinkService::receiveData(const Data& data) |
| 105 | { |
| 106 | NFD_LOG_FACE_TRACE(__func__); |
| 107 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame^] | 108 | ++this->nInData; |
| 109 | ++m_oldCounters->getNInDatas(); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 110 | |
| 111 | afterReceiveData(data); |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | LinkService::receiveNack(const ndn::lp::Nack& nack) |
| 116 | { |
| 117 | NFD_LOG_FACE_TRACE(__func__); |
| 118 | |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame^] | 119 | ++this->nInNacks; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 120 | |
| 121 | afterReceiveNack(nack); |
| 122 | } |
| 123 | |
| 124 | std::ostream& |
| 125 | operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh) |
| 126 | { |
| 127 | const LpFace* face = flh.obj.getFace(); |
| 128 | if (face == nullptr) { |
| 129 | os << "[id=0,local=unknown,remote=unknown] "; |
| 130 | } |
| 131 | else { |
| 132 | os << "[id=" << face->getId() << ",local=" << face->getLocalUri() |
| 133 | << ",remote=" << face->getRemoteUri() << "] "; |
| 134 | } |
| 135 | return os; |
| 136 | } |
| 137 | |
| 138 | } // namespace face |
| 139 | } // namespace nfd |