NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
link-service.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2019, 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 "face.hpp"
28 
29 namespace nfd {
30 namespace face {
31 
33 
35  : m_face(nullptr)
36  , m_transport(nullptr)
37 {
38 }
39 
41 {
42 }
43 
44 void
46 {
47  BOOST_ASSERT(m_face == nullptr);
48  BOOST_ASSERT(m_transport == nullptr);
49 
50  m_face = &face;
51  m_transport = &transport;
52 }
53 
54 void
55 LinkService::sendInterest(const Interest& interest, const EndpointId& endpoint)
56 {
57  BOOST_ASSERT(m_transport != nullptr);
58  NFD_LOG_FACE_TRACE(__func__);
59 
60  ++this->nOutInterests;
61 
62  doSendInterest(interest, endpoint);
63 
64  afterSendInterest(interest);
65 }
66 
67 void
68 LinkService::sendData(const Data& data, const EndpointId& endpoint)
69 {
70  BOOST_ASSERT(m_transport != nullptr);
71  NFD_LOG_FACE_TRACE(__func__);
72 
73  ++this->nOutData;
74 
75  doSendData(data, endpoint);
76 
77  afterSendData(data);
78 }
79 
80 void
81 LinkService::sendNack(const ndn::lp::Nack& nack, const EndpointId& endpoint)
82 {
83  BOOST_ASSERT(m_transport != nullptr);
84  NFD_LOG_FACE_TRACE(__func__);
85 
86  ++this->nOutNacks;
87 
88  doSendNack(nack, endpoint);
89 
90  afterSendNack(nack);
91 }
92 
93 void
94 LinkService::receiveInterest(const Interest& interest, const EndpointId& endpoint)
95 {
96  NFD_LOG_FACE_TRACE(__func__);
97 
98  ++this->nInInterests;
99 
100  afterReceiveInterest(interest, endpoint);
101 }
102 
103 void
104 LinkService::receiveData(const Data& data, const EndpointId& endpoint)
105 {
106  NFD_LOG_FACE_TRACE(__func__);
107 
108  ++this->nInData;
109 
110  afterReceiveData(data, endpoint);
111 }
112 
113 void
114 LinkService::receiveNack(const ndn::lp::Nack& nack, const EndpointId& endpoint)
115 {
116  NFD_LOG_FACE_TRACE(__func__);
117 
118  ++this->nInNacks;
119 
120  afterReceiveNack(nack, endpoint);
121 }
122 
123 void
125 {
126  ++this->nDroppedInterests;
127  onDroppedInterest(interest);
128 }
129 
130 std::ostream&
131 operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh)
132 {
133  const Face* face = flh.obj.getFace();
134  if (face == nullptr) {
135  os << "[id=0,local=unknown,remote=unknown] ";
136  }
137  else {
138  os << "[id=" << face->getId() << ",local=" << face->getLocalUri()
139  << ",remote=" << face->getRemoteUri() << "] ";
140  }
141  return os;
142 }
143 
144 } // namespace face
145 } // namespace nfd
nfd::face::LinkService::~LinkService
virtual ~LinkService()
Definition: link-service.cpp:40
nfd::face::LinkService::LinkService
LinkService()
Definition: link-service.cpp:34
nfd::face::LinkService::receiveData
void receiveData(const Data &data, const EndpointId &endpoint)
delivers received Data to forwarding
Definition: link-service.cpp:104
nfd::face::LinkService::sendInterest
void sendInterest(const Interest &interest, const EndpointId &endpoint)
Send Interest to endpoint.
Definition: link-service.cpp:55
nfd::face::LinkService::setFaceAndTransport
void setFaceAndTransport(Face &face, Transport &transport)
set Face and Transport for LinkService
Definition: link-service.cpp:45
nfd::face::LinkServiceCounters::nDroppedInterests
PacketCounter nDroppedInterests
count of Interests dropped by reliability system for exceeding allowed number of retx
Definition: link-service.hpp:53
nfd::face::LinkService::afterReceiveData
signal::Signal< LinkService, Data, EndpointId > afterReceiveData
signals on Data received
Definition: link-service.hpp:137
nfd::face::LinkService::notifyDroppedInterest
void notifyDroppedInterest(const Interest &packet)
Definition: link-service.cpp:124
nfd::face::LinkServiceCounters::nInNacks
PacketCounter nInNacks
count of incoming Nacks
Definition: link-service.hpp:65
nfd::face::LinkService::receiveInterest
void receiveInterest(const Interest &interest, const EndpointId &endpoint)
delivers received Interest to forwarding
Definition: link-service.cpp:94
nfd::face::LinkServiceCounters::nInInterests
PacketCounter nInInterests
count of incoming Interests
Definition: link-service.hpp:45
nfd::face::Face::getLocalUri
FaceUri getLocalUri() const
Definition: face.hpp:238
nfd::face::LinkService::sendData
void sendData(const Data &data, const EndpointId &endpoint)
Send Data to endpoint.
Definition: link-service.cpp:68
nfd::face::LinkService::afterSendData
signal::Signal< LinkService, Data > afterSendData
signals on Data sent
Definition: link-service.hpp:153
nfd::face::LinkServiceCounters::nOutNacks
PacketCounter nOutNacks
count of outgoing Nacks
Definition: link-service.hpp:69
nfd::face::operator<<
std::ostream & operator<<(std::ostream &os, const Face &face)
Definition: ndn-common.hpp:87
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
nfd::face::LinkService::afterSendInterest
signal::Signal< LinkService, Interest > afterSendInterest
signals on Interest sent
Definition: link-service.hpp:149
nfd::face::LinkService
the upper part of a Face
Definition: link-service.hpp:76
nfd::face::Face::getRemoteUri
FaceUri getRemoteUri() const
Definition: face.hpp:244
nfd::face::Face
generalization of a network interface
Definition: face.hpp:53
nfd::face::LinkService::getFace
const Face * getFace() const
Definition: link-service.hpp:217
NFD_LOG_FACE_TRACE
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
Definition: face-common.hpp:133
nfd::face::LinkService::afterReceiveInterest
signal::Signal< LinkService, Interest, EndpointId > afterReceiveInterest
signals on Interest received
Definition: link-service.hpp:133
nfd::face::LinkService::onDroppedInterest
signal::Signal< LinkService, Interest > onDroppedInterest
signals on Interest dropped by reliability system for exceeding allowed number of retx
Definition: link-service.hpp:145
nfd::face::LinkService::afterReceiveNack
signal::Signal< LinkService, lp::Nack, EndpointId > afterReceiveNack
signals on Nack received
Definition: link-service.hpp:141
ndn::Interest
Represents an Interest packet.
Definition: interest.hpp:44
nfd::face::Face::getId
FaceId getId() const
Definition: face.hpp:214
nfd::face::LinkService::sendNack
void sendNack(const ndn::lp::Nack &nack, const EndpointId &endpoint)
Send Nack to endpoint.
Definition: link-service.cpp:81
nfd::face::LinkService::afterSendNack
signal::Signal< LinkService, lp::Nack > afterSendNack
signals on Nack sent
Definition: link-service.hpp:157
ndn::Data
Represents a Data packet.
Definition: data.hpp:36
nfd::face::LinkServiceCounters::nInData
PacketCounter nInData
count of incoming Data packets
Definition: link-service.hpp:57
nfd::face::LinkServiceCounters::nOutData
PacketCounter nOutData
count of outgoing Data packets
Definition: link-service.hpp:61
face.hpp
ndn::lp::Nack
represents a Network Nack
Definition: nack.hpp:39
nfd::face::EndpointId
uint64_t EndpointId
Identifies a remote endpoint on the link.
Definition: face-common.hpp:65
nfd::face::LinkService::receiveNack
void receiveNack(const lp::Nack &nack, const EndpointId &endpoint)
delivers received Nack to forwarding
Definition: link-service.cpp:114
nfd::face::FaceLogHelper
For internal use by FaceLogging macros.
Definition: face-common.hpp:93
nfd::face::Transport
The lower half of a Face.
Definition: transport.hpp:109
NFD_LOG_INIT
#define NFD_LOG_INIT(name)
Definition: logger.hpp:31
nfd::face::LinkServiceCounters::nOutInterests
PacketCounter nOutInterests
count of outgoing Interests
Definition: link-service.hpp:49
nfd::face::FaceLogHelper::obj
const T & obj
Definition: face-common.hpp:102