blob: b672e7ef457281c09b64ff624dbdb887576684aa [file] [log] [blame]
Steve DiBenedetto6214e562014-03-15 16:27:04 -06001/* -*- 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
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -06009#include "core/logger.hpp"
Steve DiBenedetto6214e562014-03-15 16:27:04 -060010
11#include <ndn-cpp-dev/management/nfd-fib-entry.hpp>
12
13namespace nfd {
14
15NFD_LOG_INIT("FibEnumerationPublisher");
16
17FibEnumerationPublisher::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
26FibEnumerationPublisher::~FibEnumerationPublisher()
27{
28
29}
30
31size_t
32FibEnumerationPublisher::generate(ndn::EncodingBuffer& outBuffer)
33{
Steve DiBenedetto6214e562014-03-15 16:27:04 -060034 size_t totalLength = 0;
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070035
36 /// \todo Enable use of Fib::const_reverse_iterator (when it is available)
Steve DiBenedetto6214e562014-03-15 16:27:04 -060037 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