NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
rib-status-publisher.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
27 #include "rib/rib.hpp"
28 #include "core/logger.hpp"
29 
30 #include <ndn-cxx/management/nfd-rib-entry.hpp>
31 #include <ndn-cxx/face.hpp>
32 
33 namespace nfd {
34 namespace rib {
35 
36 NFD_LOG_INIT("RibStatusPublisher");
37 
39  ndn::Face& face,
40  const Name& prefix,
41  ndn::KeyChain& keyChain)
42  : SegmentPublisher<ndn::Face>(face, prefix, keyChain)
43  , m_rib(rib)
44 {
45 }
46 
48 {
49 }
50 
51 size_t
53 {
54  size_t totalLength = 0;
55 
56  for (Rib::const_iterator ribIt = m_rib.begin(); ribIt != m_rib.end(); ++ribIt)
57  {
58  RibEntry& entry = *ribIt->second;
59 
60  const Name& prefix = entry.getName();
61  size_t ribEntryLength = 0;
62 
63  ndn::nfd::RibEntry tlvEntry;
64 
65  for (const Route& route : entry)
66  {
67  ndn::nfd::Route routeEle;
68  routeEle.setFaceId(route.faceId)
69  .setOrigin(route.origin)
70  .setCost(route.cost)
71  .setFlags(route.flags);
72 
73  if (route.expires < time::steady_clock::TimePoint::max()) {
74  routeEle.setExpirationPeriod(time::duration_cast<time::milliseconds>(
75  route.expires - time::steady_clock::now()));
76  }
77 
78  tlvEntry.addRoute(routeEle);
79  }
80 
81  tlvEntry.setName(prefix);
82  ribEntryLength += tlvEntry.wireEncode(outBuffer);
83 
84  NFD_LOG_DEBUG("generate: rib entry length = " << ribEntryLength);
85 
86  totalLength += ribEntryLength;
87  }
88  NFD_LOG_DEBUG("generate: Total length = " << totalLength);
89  return totalLength;
90 }
91 
92 
93 } // namespace rib
94 } // namespace nfd
provides a publisher of Status Dataset or other segmented octet stream
Copyright (c) 2011-2015 Regents of the University of California.
represents the RIB
Definition: rib.hpp:45
#define NFD_LOG_DEBUG(expression)
Definition: logger.hpp:36
static time_point now() noexcept
Definition: time.cpp:79
RibEntry & setName(const Name &prefix)
virtual size_t generate(ndn::EncodingBuffer &outBuffer)
In a derived class, write the octets into outBuffer.
Data abstraction for Route.
Route & setFaceId(uint64_t faceId)
Route & setExpirationPeriod(const time::milliseconds &expirationPeriod)
represents a face
Definition: face.hpp:57
Route & setFlags(uint64_t flags)
set route inheritance flags
EncodingImpl< EncoderTag > EncodingBuffer
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
size_t wireEncode(EncodingImpl< TAG > &block) const
represents a RIB entry, which contains one or more Routes with the same prefix
Definition: rib-entry.hpp:36
represents a route for a name prefix
Definition: route.hpp:37
Abstraction to communicate with local or remote NDN forwarder.
Definition: face.hpp:100
RibStatusPublisher(const Rib &rib, ndn::Face &face, const Name &prefix, ndn::KeyChain &keyChain)
Name abstraction to represent an absolute name.
Definition: name.hpp:46
RibTable::const_iterator const_iterator
Definition: rib.hpp:50
const Name & getName() const
Definition: rib-entry.hpp:202
RibEntry & addRoute(const Route &route)
const_iterator end() const
Definition: rib.hpp:243
#define NFD_LOG_INIT(name)
Definition: logger.hpp:33
Route & setCost(uint64_t cost)
const_iterator begin() const
Definition: rib.hpp:237
Route & setOrigin(uint64_t origin)
set Origin
Data abstraction for RIB entry.