table: Mock implementation of FIB

refs #1127

Change-Id: Ie0bc1fc2ddcc61dd1f1cf10fb1935edde4aff6c5
diff --git a/daemon/table/fib-entry.cpp b/daemon/table/fib-entry.cpp
new file mode 100644
index 0000000..a00a582
--- /dev/null
+++ b/daemon/table/fib-entry.cpp
@@ -0,0 +1,67 @@
+/* -*- 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-entry.hpp"
+#include <algorithm>
+
+namespace ndn {
+namespace fib {
+
+Entry::Entry(const Name& prefix)
+  : m_prefix(prefix)
+{
+}
+
+static inline bool
+predicate_NextHop_eq_Face(const NextHop& nexthop, shared_ptr<Face> face)
+{
+  return nexthop.getFace() == face;
+}
+
+void
+Entry::addNextHop(shared_ptr<Face> face, int32_t cost)
+{
+  NextHopList::iterator it = std::find_if(m_nextHops.begin(), m_nextHops.end(),
+    bind(&predicate_NextHop_eq_Face, _1, face));
+  if (it == m_nextHops.end()) {
+    m_nextHops.push_back(fib::NextHop(face));
+    it = m_nextHops.end() - 1;
+  }
+  // now it refers to the NextHop for face
+  
+  it->setCost(cost);
+  
+  this->sortNextHops();
+
+}
+
+void
+Entry::removeNextHop(shared_ptr<Face> face)
+{
+  NextHopList::iterator it = std::find_if(m_nextHops.begin(), m_nextHops.end(),
+    bind(&predicate_NextHop_eq_Face, _1, face));
+  if (it == m_nextHops.end()) {
+    return;
+  }
+  
+  m_nextHops.erase(it);
+}
+
+static inline bool
+compare_NextHop_cost(const NextHop& a, const NextHop& b)
+{
+  return a.getCost() < b.getCost();
+}
+
+void
+Entry::sortNextHops()
+{
+  std::sort(m_nextHops.begin(), m_nextHops.end(), &compare_NextHop_cost);
+}
+
+
+} // namespace fib
+} // namespace ndn