rib: Generate FIB updates using route flags

refs: #1325

Change-Id: I5c567da1c06819caeba5cc5b024914666ba70ab6
diff --git a/rib/rib-entry.cpp b/rib/rib-entry.cpp
index db72d37..98c3b90 100644
--- a/rib/rib-entry.cpp
+++ b/rib/rib-entry.cpp
@@ -43,6 +43,11 @@
 
   if (it == end())
     {
+      if (entry.flags & ndn::nfd::ROUTE_FLAG_CAPTURE)
+        {
+          m_nFacesWithCaptureSet++;
+        }
+
       m_faces.push_back(entry);
       return true;
     }
@@ -56,8 +61,14 @@
 RibEntry::eraseFace(const FaceEntry& face)
 {
   RibEntry::iterator it = std::find_if(begin(), end(), bind(&compareFaceIdAndOrigin, _1, face));
+
   if (it != m_faces.end())
     {
+      if (it->flags & ndn::nfd::ROUTE_FLAG_CAPTURE)
+        {
+          m_nFacesWithCaptureSet--;
+        }
+
       m_faces.erase(it);
       return true;
     }
@@ -68,11 +79,20 @@
 }
 
 bool
+RibEntry::hasFace(const FaceEntry& face)
+{
+  RibEntry::const_iterator it = std::find_if(cbegin(), cend(),
+                                             bind(&compareFaceIdAndOrigin, _1, face));
+
+  return it != cend();
+}
+
+bool
 RibEntry::hasFaceId(const uint64_t faceId) const
 {
   RibEntry::const_iterator it = std::find_if(cbegin(), cend(), bind(&compareFaceId, _1, faceId));
 
-  return (it != cend());
+  return it != cend();
 }
 
 void
@@ -94,7 +114,115 @@
 RibEntry::FaceList::iterator
 RibEntry::eraseFace(FaceList::iterator face)
 {
-  return m_faces.erase(face);
+  if (face != m_faces.end())
+    {
+      if (face->flags & ndn::nfd::ROUTE_FLAG_CAPTURE)
+        {
+          m_nFacesWithCaptureSet--;
+        }
+
+      return m_faces.erase(face);
+    }
+
+  return m_faces.end();
+}
+
+void
+RibEntry::addInheritedFace(const FaceEntry& face)
+{
+  m_inheritedFaces.push_back(face);
+}
+
+void
+RibEntry::removeInheritedFace(const FaceEntry& face)
+{
+  FaceList::iterator it = findInheritedFace(face);
+  m_inheritedFaces.erase(it);
+}
+
+RibEntry::FaceList::iterator
+RibEntry::findInheritedFace(const FaceEntry& face)
+{
+  return std::find_if(m_inheritedFaces.begin(), m_inheritedFaces.end(),
+                      bind(&compareFaceId, _1, face.faceId));
+}
+
+bool
+RibEntry::hasInheritedFace(const FaceEntry& face)
+{
+  FaceList::const_iterator it = findInheritedFace(face);
+
+  return (it != m_inheritedFaces.end());
+}
+
+bool
+RibEntry::hasCapture() const
+{
+  return m_nFacesWithCaptureSet > 0;
+}
+
+bool
+RibEntry::hasChildInheritOnFaceId(uint64_t faceId) const
+{
+  for (RibEntry::const_iterator it = m_faces.begin(); it != m_faces.end(); ++it)
+    {
+      if (it->faceId == faceId && (it->flags & ndn::nfd::ROUTE_FLAG_CHILD_INHERIT))
+        {
+          return true;
+        }
+    }
+
+  return false;
+}
+
+shared_ptr<FaceEntry>
+RibEntry::getFaceWithLowestCostByFaceId(uint64_t faceId)
+{
+  shared_ptr<FaceEntry> face;
+
+  for (FaceList::iterator it = begin(); it != end(); ++it)
+    {
+      // Correct face ID
+      if (it->faceId == faceId)
+        {
+          // If this is the first face with this ID found
+          if (!static_cast<bool>(face))
+            {
+              face = make_shared<FaceEntry>(*it);
+            }
+          else if (it->cost < face->cost) // Found a face with a lower cost
+            {
+              face = make_shared<FaceEntry>(*it);
+            }
+        }
+    }
+
+    return face;
+}
+
+shared_ptr<FaceEntry>
+RibEntry::getFaceWithLowestCostAndChildInheritByFaceId(uint64_t faceId)
+{
+  shared_ptr<FaceEntry> face;
+
+  for (FaceList::iterator it = begin(); it != end(); ++it)
+    {
+      // Correct face ID and Child Inherit flag set
+      if (it->faceId == faceId && it->flags & ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)
+        {
+          // If this is the first face with this ID found
+          if (!static_cast<bool>(face))
+            {
+              face = make_shared<FaceEntry>(*it);
+            }
+          else if (it->cost < face->cost) // Found a face with a lower cost
+            {
+              face = make_shared<FaceEntry>(*it);
+            }
+        }
+    }
+
+    return face;
 }
 
 std::ostream&