blob: 89f0956797c80cd0eccecab7d1134a54a972e987 [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
9#include "common.hpp"
10
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{
34
35 size_t totalLength = 0;
36 for (Fib::const_iterator i = m_fib.begin(); i != m_fib.end(); ++i)
37 {
38 const fib::Entry& entry = *i;
39 const Name& prefix = entry.getPrefix();
40 size_t fibEntryLength = 0;
41
42 ndn::nfd::FibEntry tlvEntry;
43 const fib::NextHopList& nextHops = entry.getNextHops();
44
45 for (fib::NextHopList::const_iterator j = nextHops.begin();
46 j != nextHops.end();
47 ++j)
48 {
49 const fib::NextHop& next = *j;
50 ndn::nfd::NextHopRecord nextHopRecord;
51 nextHopRecord.setFaceId(next.getFace()->getId());
52 nextHopRecord.setCost(next.getCost());
53
54 tlvEntry.addNextHopRecord(nextHopRecord);
55 }
56
57 tlvEntry.setPrefix(prefix);
58 fibEntryLength += tlvEntry.wireEncode(outBuffer);
59
60 NFD_LOG_DEBUG("generate: fib entry length = " << fibEntryLength);
61
62 totalLength += fibEntryLength;
63 }
64 NFD_LOG_DEBUG("generate: Total length = " << totalLength);
65 return totalLength;
66}
67
68
69} // namespace nfd