Steve DiBenedetto | 6214e56 | 2014-03-15 16:27:04 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "fib-enumeration-publisher.hpp" |
| 8 | |
| 9 | #include "common.hpp" |
| 10 | |
| 11 | #include <ndn-cpp-dev/management/nfd-fib-entry.hpp> |
| 12 | |
| 13 | namespace nfd { |
| 14 | |
| 15 | NFD_LOG_INIT("FibEnumerationPublisher"); |
| 16 | |
| 17 | FibEnumerationPublisher::FibEnumerationPublisher(const Fib& fib, |
| 18 | shared_ptr<AppFace> face, |
| 19 | const Name& prefix) |
| 20 | : SegmentPublisher(face, prefix) |
| 21 | , m_fib(fib) |
| 22 | { |
| 23 | |
| 24 | } |
| 25 | |
| 26 | FibEnumerationPublisher::~FibEnumerationPublisher() |
| 27 | { |
| 28 | |
| 29 | } |
| 30 | |
| 31 | size_t |
| 32 | FibEnumerationPublisher::generate(ndn::EncodingBuffer& outBuffer) |
| 33 | { |
Steve DiBenedetto | 6214e56 | 2014-03-15 16:27:04 -0600 | [diff] [blame] | 34 | size_t totalLength = 0; |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame^] | 35 | |
| 36 | /// \todo Enable use of Fib::const_reverse_iterator (when it is available) |
Steve DiBenedetto | 6214e56 | 2014-03-15 16:27:04 -0600 | [diff] [blame] | 37 | for (Fib::const_iterator i = m_fib.begin(); i != m_fib.end(); ++i) |
| 38 | { |
| 39 | const fib::Entry& entry = *i; |
| 40 | const Name& prefix = entry.getPrefix(); |
| 41 | size_t fibEntryLength = 0; |
| 42 | |
| 43 | ndn::nfd::FibEntry tlvEntry; |
| 44 | const fib::NextHopList& nextHops = entry.getNextHops(); |
| 45 | |
| 46 | for (fib::NextHopList::const_iterator j = nextHops.begin(); |
| 47 | j != nextHops.end(); |
| 48 | ++j) |
| 49 | { |
| 50 | const fib::NextHop& next = *j; |
| 51 | ndn::nfd::NextHopRecord nextHopRecord; |
| 52 | nextHopRecord.setFaceId(next.getFace()->getId()); |
| 53 | nextHopRecord.setCost(next.getCost()); |
| 54 | |
| 55 | tlvEntry.addNextHopRecord(nextHopRecord); |
| 56 | } |
| 57 | |
| 58 | tlvEntry.setPrefix(prefix); |
| 59 | fibEntryLength += tlvEntry.wireEncode(outBuffer); |
| 60 | |
| 61 | NFD_LOG_DEBUG("generate: fib entry length = " << fibEntryLength); |
| 62 | |
| 63 | totalLength += fibEntryLength; |
| 64 | } |
| 65 | NFD_LOG_DEBUG("generate: Total length = " << totalLength); |
| 66 | return totalLength; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | } // namespace nfd |