nrd: basic implementation of rib
Change-Id: I0d6acf8188d39068081babd8c23f6ea6eb3c9406
diff --git a/src/common.hpp b/src/common.hpp
new file mode 100644
index 0000000..e19ead0
--- /dev/null
+++ b/src/common.hpp
@@ -0,0 +1,15 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NRD_COMMON_HPP
+#define NRD_COMMON_HPP
+
+#include <iostream>
+#include <list>
+
+#include <ndn-cpp-dev/management/nrd-prefix-reg-options.hpp>
+
+#endif // NRD_COMMON_HPP
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..0ec8e7a
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,11 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+int
+main(int argc, char** argv)
+{
+ return 0;
+}
diff --git a/src/rib.cpp b/src/rib.cpp
new file mode 100644
index 0000000..0e0cbfe
--- /dev/null
+++ b/src/rib.cpp
@@ -0,0 +1,66 @@
+/* -*- 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 "rib.hpp"
+
+namespace ndn {
+namespace nrd {
+
+Rib::Rib()
+{
+}
+
+//
+Rib::~Rib()
+{
+}
+
+static inline bool
+ribEntryNameCompare(const PrefixRegOptions& opt1, const PrefixRegOptions& opt2)
+{
+ return opt1.getName() == opt2.getName();
+}
+
+//
+Rib::const_iterator
+Rib::find(const PrefixRegOptions& options) const
+{
+ RibTable::const_iterator it = std::find_if(m_rib.begin(), m_rib.end(),
+ bind(&ribEntryNameCompare, _1, options));
+ if (it == m_rib.end())
+ {
+ return end();
+ }
+ else
+ return it;
+}
+
+//
+void
+Rib::insert(const PrefixRegOptions& options)
+{
+ RibTable::const_iterator it = std::find_if(m_rib.begin(), m_rib.end(),
+ bind(&ribEntryNameCompare, _1, options));
+ if (it == m_rib.end())
+ {
+ m_rib.push_front(options);
+ }
+}
+
+//
+void
+Rib::erase(const PrefixRegOptions& options)
+{
+ RibTable::iterator it = std::find_if(m_rib.begin(), m_rib.end(),
+ bind(&ribEntryNameCompare, _1, options));
+ if (it != m_rib.end())
+ {
+ m_rib.erase(it);
+ }
+}
+
+} // namespace nrd
+} // namespace ndn
diff --git a/src/rib.hpp b/src/rib.hpp
new file mode 100644
index 0000000..f3a713a
--- /dev/null
+++ b/src/rib.hpp
@@ -0,0 +1,81 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NRD_RIB_HPP
+#define NRD_RIB_HPP
+
+#include "common.hpp"
+
+namespace ndn {
+namespace nrd {
+
+/** \brief represents the RIB
+ */
+class Rib
+{
+public:
+ typedef std::list<PrefixRegOptions> RibTable;
+ typedef RibTable::const_iterator const_iterator;
+
+ Rib();
+
+ ~Rib();
+
+ const_iterator
+ find(const PrefixRegOptions& options) const;
+
+ void
+ insert(const PrefixRegOptions& options);
+
+ void
+ erase(const PrefixRegOptions& options);
+
+ const_iterator
+ begin() const;
+
+ const_iterator
+ end() const;
+
+ size_t
+ size() const;
+
+ size_t
+ empty() const;
+
+private:
+ // Note: Taking a list right now. A Trie will be used later to store
+ // prefixes
+ RibTable m_rib;
+};
+
+inline Rib::const_iterator
+Rib::begin() const
+{
+ return m_rib.begin();
+}
+
+inline Rib::const_iterator
+Rib::end() const
+{
+ return m_rib.end();
+}
+
+inline size_t
+Rib::size() const
+{
+ return m_rib.size();
+}
+
+inline size_t
+Rib::empty() const
+{
+ return m_rib.empty();
+}
+
+} // namespace nrd
+} // namespace ndn
+
+#endif // NRD_RIB_HPP