rib: Updated logic for inserting and comparing rib entries.
refs #1473
Change-Id: Ie4b34d0e4a72191a96f93f8833e7119c007804a7
diff --git a/src/rib.cpp b/src/rib.cpp
index ce8d7a2..4f1387b 100644
--- a/src/rib.cpp
+++ b/src/rib.cpp
@@ -19,9 +19,11 @@
}
static inline bool
-ribEntryNameCompare(const PrefixRegOptions& opt1, const PrefixRegOptions& opt2)
+compareNameFaceProtocol(const PrefixRegOptions& opt1, const PrefixRegOptions& opt2)
{
- return opt1.getName() == opt2.getName();
+ return (opt1.getName() == opt2.getName() &&
+ opt1.getFaceId() == opt2.getFaceId() &&
+ opt1.getProtocol() == opt2.getProtocol());
}
@@ -29,7 +31,7 @@
Rib::find(const PrefixRegOptions& options) const
{
RibTable::const_iterator it = std::find_if(m_rib.begin(), m_rib.end(),
- bind(&ribEntryNameCompare, _1, options));
+ bind(&compareNameFaceProtocol, _1, options));
if (it == m_rib.end())
{
return end();
@@ -42,12 +44,20 @@
void
Rib::insert(const PrefixRegOptions& options)
{
- RibTable::const_iterator it = std::find_if(m_rib.begin(), m_rib.end(),
- bind(&ribEntryNameCompare, _1, options));
+ RibTable::iterator it = std::find_if(m_rib.begin(), m_rib.end(),
+ bind(&compareNameFaceProtocol, _1, options));
if (it == m_rib.end())
{
m_rib.push_front(options);
}
+ else
+ {
+ //entry exist, update other fields
+ it->setFlags(options.getFlags());
+ it->setCost(options.getCost());
+ it->setExpirationPeriod(options.getExpirationPeriod());
+ it->setProtocol(options.getProtocol());
+ }
}
@@ -55,7 +65,7 @@
Rib::erase(const PrefixRegOptions& options)
{
RibTable::iterator it = std::find_if(m_rib.begin(), m_rib.end(),
- bind(&ribEntryNameCompare, _1, options));
+ bind(&compareNameFaceProtocol, _1, options));
if (it != m_rib.end())
{
m_rib.erase(it);
diff --git a/tests/test-rib.cpp b/tests/test-rib.cpp
index 4360175..920c606 100644
--- a/tests/test-rib.cpp
+++ b/tests/test-rib.cpp
@@ -23,22 +23,33 @@
options1.setFlags(tlv::nrd::NDN_FORW_CHILD_INHERIT | tlv::nrd::NDN_FORW_CAPTURE);
options1.setCost(10);
options1.setExpirationPeriod(time::milliseconds(1500));
+ options1.setFaceId(1);
+
+ rib.insert(options1);
+ BOOST_CHECK_EQUAL(rib.size(), 1);
PrefixRegOptions options2;
options2.setName("/hello/world");
options2.setFlags(tlv::nrd::NDN_FORW_CHILD_INHERIT);
options2.setExpirationPeriod(time::seconds(0));
+ options2.setFaceId(1);
+ options2.setCost(100);
- rib.insert(options1);
- BOOST_CHECK_EQUAL(rib.size(), 1);
-
rib.insert(options2);
BOOST_CHECK_EQUAL(rib.size(), 1);
- options2.setName("/foo/bar");
+ options2.setFaceId(2);
rib.insert(options2);
BOOST_CHECK_EQUAL(rib.size(), 2);
+ options2.setName("/foo/bar");
+ rib.insert(options2);
+ BOOST_CHECK_EQUAL(rib.size(), 3);
+
+ rib.erase(options2);
+ BOOST_CHECK_EQUAL(rib.size(), 2);
+
+ options2.setName("/hello/world");
rib.erase(options2);
BOOST_CHECK_EQUAL(rib.size(), 1);