NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
face-table.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 "
face-table.hpp
"
27
#include "
common/global.hpp
"
28
#include "
common/logger.hpp
"
29
#include "
face/channel.hpp
"
30
31
#include <
ndn-cxx/util/concepts.hpp
>
32
33
namespace
nfd
{
34
35
NDN_CXX_ASSERT_FORWARD_ITERATOR
(
FaceTable::const_iterator
);
36
37
NFD_LOG_INIT
(
FaceTable
);
38
39
FaceTable::FaceTable
()
40
: m_lastFaceId(face::
FACEID_RESERVED_MAX
)
41
{
42
}
43
44
Face
*
45
FaceTable::get
(
FaceId
id
)
const
46
{
47
auto
i = m_faces.find(
id
);
48
return
i == m_faces.end() ? nullptr : i->second.get();
49
}
50
51
size_t
52
FaceTable::size
()
const
53
{
54
return
m_faces.size();
55
}
56
57
void
58
FaceTable::add
(shared_ptr<Face> face)
59
{
60
if
(face->getId() !=
face::INVALID_FACEID
&& m_faces.count(face->getId()) > 0) {
61
NFD_LOG_WARN
(
"Trying to add existing face id="
<< face->getId() <<
" to the face table"
);
62
return
;
63
}
64
65
FaceId
faceId = ++m_lastFaceId;
66
BOOST_ASSERT(faceId >
face::FACEID_RESERVED_MAX
);
67
this->addImpl(
std::move
(face), faceId);
68
}
69
70
void
71
FaceTable::addReserved
(shared_ptr<Face> face,
FaceId
faceId)
72
{
73
BOOST_ASSERT(face->getId() ==
face::INVALID_FACEID
);
74
BOOST_ASSERT(faceId <=
face::FACEID_RESERVED_MAX
);
75
this->addImpl(
std::move
(face), faceId);
76
}
77
78
void
79
FaceTable::addImpl(shared_ptr<Face> face,
FaceId
faceId)
80
{
81
face->setId(faceId);
82
auto
ret = m_faces.emplace(faceId, face);
83
BOOST_VERIFY(ret.second);
84
85
NFD_LOG_INFO
(
"Added face id="
<< faceId <<
86
" remote="
<< face->getRemoteUri() <<
87
" local="
<< face->getLocalUri());
88
89
connectFaceClosedSignal
(*face, [=] { remove(faceId); });
90
91
this->
afterAdd
(*face);
92
}
93
94
void
95
FaceTable::remove(
FaceId
faceId)
96
{
97
auto
i = m_faces.find(faceId);
98
BOOST_ASSERT(i != m_faces.end());
99
shared_ptr<Face> face = i->second;
100
101
this->
beforeRemove
(*face);
102
103
m_faces.erase(i);
104
face->setId(
face::INVALID_FACEID
);
105
106
NFD_LOG_INFO
(
"Removed face id="
<< faceId <<
107
" remote="
<< face->getRemoteUri() <<
108
" local="
<< face->getLocalUri());
109
110
// defer Face deallocation, so that Transport isn't deallocated during afterStateChange signal
111
getGlobalIoService
().
post
([face] {});
112
}
113
114
FaceTable::ForwardRange
115
FaceTable::getForwardRange()
const
116
{
117
return
m_faces | boost::adaptors::map_values | boost::adaptors::indirected;
118
}
119
120
FaceTable::const_iterator
121
FaceTable::begin
()
const
122
{
123
return
this->getForwardRange().begin();
124
}
125
126
FaceTable::const_iterator
127
FaceTable::end
()
const
128
{
129
return
this->getForwardRange().end();
130
}
131
132
}
// namespace nfd
nfd::FaceTable::const_iterator
boost::range_iterator< ForwardRange >::type const_iterator
ForwardIterator for Face&.
Definition:
face-table.hpp:74
NFD_LOG_INFO
#define NFD_LOG_INFO
Definition:
logger.hpp:39
global.hpp
nfd::detail::SimulatorIo::post
void post(const std::function< void()> &callback)
Definition:
global.cpp:35
nonstd::optional_lite::std11::move
T & move(T &t)
Definition:
optional.hpp:421
nfd::FaceTable::end
const_iterator end() const
Definition:
face-table.cpp:127
nfd::FaceTable::addReserved
void addReserved(shared_ptr< Face > face, FaceId faceId)
add a special face with a reserved FaceId
Definition:
face-table.cpp:71
nfd::FaceTable::FaceTable
FaceTable()
Definition:
face-table.cpp:39
face-table.hpp
concepts.hpp
nfd::FaceTable::afterAdd
signal::Signal< FaceTable, Face > afterAdd
Fires immediately after a face is added.
Definition:
face-table.hpp:85
nfd::getGlobalIoService
detail::SimulatorIo & getGlobalIoService()
Returns the global io_service instance for the calling thread.
Definition:
global.cpp:49
NFD_LOG_WARN
#define NFD_LOG_WARN
Definition:
logger.hpp:40
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-common.hpp:40
nfd::face::INVALID_FACEID
const FaceId INVALID_FACEID
indicates an invalid FaceId
Definition:
face-common.hpp:47
nfd::face::FaceId
uint64_t FaceId
Identifies a face.
Definition:
face-common.hpp:44
nfd::face::Face
generalization of a network interface
Definition:
face.hpp:53
nfd::FaceTable
container of all faces
Definition:
face-table.hpp:39
nfd::NDN_CXX_ASSERT_FORWARD_ITERATOR
NDN_CXX_ASSERT_FORWARD_ITERATOR(FaceTable::const_iterator)
nfd::face::connectFaceClosedSignal
void connectFaceClosedSignal(Face &face, std::function< void()> f)
Invokes a callback when a face is closed.
Definition:
channel.cpp:41
nfd::FaceTable::get
Face * get(FaceId id) const
get face by FaceId
Definition:
face-table.cpp:45
nfd::FaceTable::begin
const_iterator begin() const
Definition:
face-table.cpp:121
nfd::FaceTable::add
void add(shared_ptr< Face > face)
add a face
Definition:
face-table.cpp:58
nfd::face::FACEID_RESERVED_MAX
const FaceId FACEID_RESERVED_MAX
upper bound of reserved FaceIds
Definition:
face-common.hpp:55
nfd::FaceTable::size
size_t size() const
Definition:
face-table.cpp:52
nfd::FaceTable::ForwardRange
boost::indirected_range< const boost::select_second_const_range< FaceMap > > ForwardRange
Definition:
face-table.hpp:70
nfd::FaceTable::beforeRemove
signal::Signal< FaceTable, Face > beforeRemove
Fires immediately before a face is removed.
Definition:
face-table.hpp:91
NFD_LOG_INIT
#define NFD_LOG_INIT(name)
Definition:
logger.hpp:31
channel.hpp
logger.hpp
ndnSIM
NFD
daemon
fw
face-table.cpp
Generated on Mon Jun 1 2020 22:32:16 for ndnSIM by
1.8.18