blob: cdf5cff693c8faba4e2c2794d507b4fb7012e888 [file] [log] [blame]
Vince Lehmancd16c832014-07-23 15:14:55 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev7c10b3b2015-01-20 12:24:27 -08003 * Copyright (c) 2014-2015, 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.
Vince Lehmancd16c832014-07-23 15:14:55 -070010 *
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;
Vince Lehmancd16c832014-07-23 15:14:55 -070064
Vince Lehman218be0a2015-01-15 17:25:20 -060065 for (const Route& route : entry)
Vince Lehmancd16c832014-07-23 15:14:55 -070066 {
Vince Lehman218be0a2015-01-15 17:25:20 -060067 ndn::nfd::Route routeEle;
68 routeEle.setFaceId(route.faceId)
69 .setOrigin(route.origin)
70 .setCost(route.cost)
71 .setFlags(route.flags);
Vince Lehmancd16c832014-07-23 15:14:55 -070072
Vince Lehman218be0a2015-01-15 17:25:20 -060073 if (route.expires < time::steady_clock::TimePoint::max()) {
74 routeEle.setExpirationPeriod(time::duration_cast<time::milliseconds>(
75 route.expires - time::steady_clock::now()));
Vince Lehmancd16c832014-07-23 15:14:55 -070076 }
Vince Lehman218be0a2015-01-15 17:25:20 -060077
78 tlvEntry.addRoute(routeEle);
Vince Lehmancd16c832014-07-23 15:14:55 -070079 }
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