NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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; -*- */
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.connect(bind(&Forwarder::onInterest, &m_forwarder, ref(*face), _1));
89  face->onReceiveData.connect(bind(&Forwarder::onData, &m_forwarder, ref(*face), _1));
90  face->onFail.connectSingleShot(bind(&FaceTable::remove, this, face, _1));
91 
92  this->onAdd(face);
93 }
94 
95 void
96 FaceTable::remove(shared_ptr<Face> face, const std::string& reason)
97 {
98  this->onRemove(face);
99 
100  FaceId faceId = face->getId();
101  m_faces.erase(faceId);
102  face->setId(INVALID_FACEID);
103 
104  NFD_LOG_INFO("Removed face id=" << faceId <<
105  " remote=" << face->getRemoteUri() <<
106  " local=" << face->getLocalUri() <<
107  " (" << reason << ")");
108 
109  m_forwarder.getFib().removeNextHopFromAllEntries(face);
110 }
111 
113 FaceTable::getForwardRange() const
114 {
115  return m_faces | boost::adaptors::map_values;
116 }
117 
120 {
121  return this->getForwardRange().begin();
122 }
123 
126 {
127  return this->getForwardRange().end();
128 }
129 
130 } // namespace nfd
boost::range_iterator< ForwardRange >::type const_iterator
ForwardIterator for shared_ptr<Face>
Definition: face-table.hpp:67
const FaceId FACEID_RESERVED_MAX
upper bound of reserved FaceIds
Definition: face.hpp:52
const_iterator end() const
Definition: face-table.cpp:125
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
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
void onData(Face &face, const Data &data)
Definition: forwarder.hpp:272
identifies a face
Fib & getFib()
Definition: forwarder.hpp:284
boost::select_second_const_range< FaceMap > ForwardRange
Definition: face-table.hpp:63
void onInterest(Face &face, const Interest &interest)
Definition: forwarder.hpp:266
#define NFD_LOG_INIT(name)
Definition: logger.hpp:33
const FaceId INVALID_FACEID
indicates an invalid FaceId
Definition: face.hpp:43
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:119
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