mgmt: add support for FIB enumeration protocol

refs: #1192

Change-Id: If9198c7d90d8882e9590ce93165667923df59a03
diff --git a/daemon/mgmt/fib-enumeration-publisher.cpp b/daemon/mgmt/fib-enumeration-publisher.cpp
new file mode 100644
index 0000000..89f0956
--- /dev/null
+++ b/daemon/mgmt/fib-enumeration-publisher.cpp
@@ -0,0 +1,69 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "fib-enumeration-publisher.hpp"
+
+#include "common.hpp"
+
+#include <ndn-cpp-dev/management/nfd-fib-entry.hpp>
+
+namespace nfd {
+
+NFD_LOG_INIT("FibEnumerationPublisher");
+
+FibEnumerationPublisher::FibEnumerationPublisher(const Fib& fib,
+                                                 shared_ptr<AppFace> face,
+                                                 const Name& prefix)
+  : SegmentPublisher(face, prefix)
+  , m_fib(fib)
+{
+
+}
+
+FibEnumerationPublisher::~FibEnumerationPublisher()
+{
+
+}
+
+size_t
+FibEnumerationPublisher::generate(ndn::EncodingBuffer& outBuffer)
+{
+
+  size_t totalLength = 0;
+  for (Fib::const_iterator i = m_fib.begin(); i != m_fib.end(); ++i)
+    {
+      const fib::Entry& entry = *i;
+      const Name& prefix = entry.getPrefix();
+      size_t fibEntryLength = 0;
+
+      ndn::nfd::FibEntry tlvEntry;
+      const fib::NextHopList& nextHops = entry.getNextHops();
+
+      for (fib::NextHopList::const_iterator j = nextHops.begin();
+           j != nextHops.end();
+           ++j)
+        {
+          const fib::NextHop& next = *j;
+          ndn::nfd::NextHopRecord nextHopRecord;
+          nextHopRecord.setFaceId(next.getFace()->getId());
+          nextHopRecord.setCost(next.getCost());
+
+          tlvEntry.addNextHopRecord(nextHopRecord);
+        }
+
+      tlvEntry.setPrefix(prefix);
+      fibEntryLength += tlvEntry.wireEncode(outBuffer);
+
+      NFD_LOG_DEBUG("generate: fib entry length = " << fibEntryLength);
+
+      totalLength += fibEntryLength;
+    }
+  NFD_LOG_DEBUG("generate: Total length = " << totalLength);
+  return totalLength;
+}
+
+
+} // namespace nfd