NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
face-table.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "face-table.hpp"
27 #include "forwarder.hpp"
28 #include "core/logger.hpp"
29 
30 namespace nfd {
31 
32 NFD_LOG_INIT("FaceTable");
33 
35  : m_forwarder(forwarder)
36  , m_lastFaceId(FACEID_RESERVED_MAX)
37 {
38 }
39 
41 {
42 
43 }
44 
45 shared_ptr<Face>
47 {
48  std::map<FaceId, shared_ptr<Face> >::const_iterator i = m_faces.find(id);
49  return (i == m_faces.end()) ? (shared_ptr<Face>()) : (i->second);
50 }
51 
52 size_t
54 {
55  return m_faces.size();
56 }
57 
58 void
59 FaceTable::add(shared_ptr<Face> face)
60 {
61  if (face->getId() != INVALID_FACEID && m_faces.count(face->getId()) > 0) {
62  NFD_LOG_WARN("Trying to add existing face id=" << face->getId() << " to the face table");
63  return;
64  }
65 
66  FaceId faceId = ++m_lastFaceId;
67  BOOST_ASSERT(faceId > FACEID_RESERVED_MAX);
68  this->addImpl(face, faceId);
69 }
70 
71 void
72 FaceTable::addReserved(shared_ptr<Face> face, FaceId faceId)
73 {
74  BOOST_ASSERT(face->getId() == INVALID_FACEID);
75  BOOST_ASSERT(m_faces.count(face->getId()) == 0);
76  BOOST_ASSERT(faceId <= FACEID_RESERVED_MAX);
77  this->addImpl(face, faceId);
78 }
79 
80 void
81 FaceTable::addImpl(shared_ptr<Face> face, FaceId faceId)
82 {
83  face->setId(faceId);
84  m_faces[faceId] = face;
85  NFD_LOG_INFO("Added face id=" << faceId << " remote=" << face->getRemoteUri()
86  << " local=" << face->getLocalUri());
87 
88  face->onReceiveInterest += bind(&Forwarder::onInterest,
89  &m_forwarder, ref(*face), _1);
90  face->onReceiveData += bind(&Forwarder::onData,
91  &m_forwarder, ref(*face), _1);
92  face->onFail += bind(&FaceTable::remove,
93  this, face);
94 
95  this->onAdd(face);
96 }
97 
98 void
99 FaceTable::remove(shared_ptr<Face> face)
100 {
101  this->onRemove(face);
102 
103  FaceId faceId = face->getId();
104  m_faces.erase(faceId);
105  face->setId(INVALID_FACEID);
106  NFD_LOG_INFO("Removed face id=" << faceId << " remote=" << face->getRemoteUri() <<
107  " local=" << face->getLocalUri());
108 
109  // XXX This clears all subscriptions, because EventEmitter
110  // does not support only removing Forwarder's subscription
111  face->onReceiveInterest.clear();
112  face->onReceiveData .clear();
113  face->onSendInterest .clear();
114  face->onSendData .clear();
115  // don't clear onFail because other functions may need to execute
116 
117  m_forwarder.getFib().removeNextHopFromAllEntries(face);
118 }
119 
121 FaceTable::getForwardRange() const
122 {
123  return m_faces | boost::adaptors::map_values;
124 }
125 
128 {
129  return this->getForwardRange().begin();
130 }
131 
134 {
135  return this->getForwardRange().end();
136 }
137 
138 } // namespace nfd
boost::range_iterator< ForwardRange >::type const_iterator
ForwardIterator for shared_ptr
Definition: face-table.hpp:67
const FaceId FACEID_RESERVED_MAX
upper bound of reserved FaceIds
Definition: face.hpp:53
const_iterator end() const
Definition: face-table.cpp:133
void add(shared_ptr< Face > face)
Definition: face-table.cpp:59
main class of NFD
Definition: forwarder.hpp:54
size_t size() const
Definition: face-table.cpp:53
signal::Signal< FaceTable, shared_ptr< Face > > onRemove
fires before a Face is removed
Definition: face-table.hpp:84
#define NFD_LOG_WARN(expression)
Definition: logger.hpp:39
void removeNextHopFromAllEntries(shared_ptr< Face > face)
removes the NextHop record for face in all entrites
Definition: fib.cpp:159
#define NFD_LOG_INFO(expression)
Definition: logger.hpp:37
void onData(Face &face, const Data &data)
Definition: forwarder.hpp:261
identifies a face
Fib & getFib()
Definition: forwarder.hpp:273
boost::select_second_const_range< FaceMap > ForwardRange
Definition: face-table.hpp:63
void onInterest(Face &face, const Interest &interest)
Definition: forwarder.hpp:255
#define NFD_LOG_INIT(name)
Definition: logger.hpp:33
const FaceId INVALID_FACEID
indicates an invalid FaceId
Definition: face.hpp:44
FaceTable(Forwarder &forwarder)
Definition: face-table.cpp:34
void addReserved(shared_ptr< Face > face, FaceId faceId)
add a special Face with a reserved FaceId
Definition: face-table.cpp:72
const_iterator begin() const
Definition: face-table.cpp:127
signal::Signal< FaceTable, shared_ptr< Face > > onAdd
fires after a Face is added
Definition: face-table.hpp:78
shared_ptr< Face > get(FaceId id) const
Definition: face-table.cpp:46