blob: 76a164c8e4227acff16ea1b9c158ea4e13787414 [file] [log] [blame]
Vince Lehmancd16c832014-07-23 15:14:55 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, 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 "rib/rib-status-publisher.hpp"
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
33namespace nfd {
34namespace rib {
35
36NFD_LOG_INIT("RibStatusPublisher");
37
38RibStatusPublisher::RibStatusPublisher(const Rib& rib,
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
47RibStatusPublisher::~RibStatusPublisher()
48{
49}
50
51size_t
52RibStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
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 const RibEntry::FaceList& faces = entry.getFaces();
65
66 for (RibEntry::FaceList::const_iterator faceIt = faces.begin();
67 faceIt != faces.end(); ++faceIt)
68 {
69 const FaceEntry& face = *faceIt;
70
71 ndn::nfd::Route route;
72 route
73 .setFaceId(face.faceId)
74 .setOrigin(face.origin)
75 .setCost(face.cost)
76 .setFlags(face.flags);
77 if (face.expires < time::steady_clock::TimePoint::max()) {
78 route.setExpirationPeriod(time::duration_cast<time::milliseconds>
79 (face.expires - time::steady_clock::now()));
80 }
81 tlvEntry.addRoute(route);
82 }
83
84 tlvEntry.setName(prefix);
85 ribEntryLength += tlvEntry.wireEncode(outBuffer);
86
87 NFD_LOG_DEBUG("generate: rib entry length = " << ribEntryLength);
88
89 totalLength += ribEntryLength;
90 }
91 NFD_LOG_DEBUG("generate: Total length = " << totalLength);
92 return totalLength;
93}
94
95
96} // namespace rib
97} // namespace nfd