Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 33 | namespace nfd { |
| 34 | namespace rib { |
| 35 | |
| 36 | NFD_LOG_INIT("RibStatusPublisher"); |
| 37 | |
| 38 | RibStatusPublisher::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 | |
| 47 | RibStatusPublisher::~RibStatusPublisher() |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | size_t |
| 52 | RibStatusPublisher::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 Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 64 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame^] | 65 | for (const Route& route : entry) |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 66 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame^] | 67 | ndn::nfd::Route routeEle; |
| 68 | routeEle.setFaceId(route.faceId) |
| 69 | .setOrigin(route.origin) |
| 70 | .setCost(route.cost) |
| 71 | .setFlags(route.flags); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 72 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame^] | 73 | if (route.expires < time::steady_clock::TimePoint::max()) { |
| 74 | routeEle.setExpirationPeriod(time::duration_cast<time::milliseconds>( |
| 75 | route.expires - time::steady_clock::now())); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 76 | } |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame^] | 77 | |
| 78 | tlvEntry.addRoute(routeEle); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 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 |