route: Adjust cost to integer before registering
refs: #1907
Change-Id: I471cd2eafb65a8458b4f527a3c3d7ea6682f5627
diff --git a/src/route/fib-entry.cpp b/src/route/fib-entry.cpp
index a7eb68f..07346f0 100644
--- a/src/route/fib-entry.cpp
+++ b/src/route/fib-entry.cpp
@@ -31,30 +31,6 @@
using namespace std;
-bool
-FibEntry::isEqualNextHops(NexthopList& nhlOther)
-{
- if (m_nexthopList.getSize() != nhlOther.getSize()) {
- return false;
- }
- else {
- uint32_t nhCount = 0;
- std::list<NextHop>::iterator it1, it2;
- for (it1 = m_nexthopList.getNextHops().begin(),
- it2 = nhlOther.getNextHops().begin() ;
- it1 != m_nexthopList.getNextHops().end() ; it1++, it2++) {
- if (it1->getConnectingFaceUri() == it2->getConnectingFaceUri()) {
- it1->setRouteCost(it2->getRouteCost());
- nhCount++;
- }
- else {
- break;
- }
- }
- return nhCount == m_nexthopList.getSize();
- }
-}
-
void
FibEntry::writeLog()
{
diff --git a/src/route/fib-entry.hpp b/src/route/fib-entry.hpp
index 7f39fdd..2c98002 100644
--- a/src/route/fib-entry.hpp
+++ b/src/route/fib-entry.hpp
@@ -102,9 +102,6 @@
return m_seqNo;
}
- bool
- isEqualNextHops(NexthopList& nhlOther);
-
void
writeLog();
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index de9d365..1e8b9ed 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.cpp
@@ -112,7 +112,7 @@
if (isPrefixUpdatable(name)) {
// Add nexthop to NDN-FIB
registerPrefix(name, hopIt->getConnectingFaceUri(),
- std::ceil(hopIt->getRouteCost()),
+ hopIt->getRouteCostAsAdjustedInteger(),
ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
}
diff --git a/src/route/nexthop-list.cpp b/src/route/nexthop-list.cpp
index 0822d38..9ef6fd3 100644
--- a/src/route/nexthop-list.cpp
+++ b/src/route/nexthop-list.cpp
@@ -41,7 +41,7 @@
nexthopRemoveCompare(NextHop& nh1, NextHop& nh2)
{
return (nh1.getConnectingFaceUri() == nh2.getConnectingFaceUri() &&
- nh1.getRouteCost() == nh2.getRouteCost()) ;
+ nh1.getRouteCostAsAdjustedInteger() == nh2.getRouteCostAsAdjustedInteger()) ;
}
static bool
diff --git a/src/route/nexthop.hpp b/src/route/nexthop.hpp
index a354752..a4feec2 100644
--- a/src/route/nexthop.hpp
+++ b/src/route/nexthop.hpp
@@ -56,10 +56,15 @@
}
uint64_t
+ getRouteCostAsAdjustedInteger() const
+ {
+ return static_cast<uint64_t>(m_routeCost*HYPERBOLIC_COST_ADJUSTMENT_FACTOR);
+ }
+
+ double
getRouteCost() const
{
- uint64_t routeCost = static_cast<uint64_t>(ceil(m_routeCost));
- return routeCost;
+ return m_routeCost;
}
void
@@ -71,6 +76,7 @@
private:
std::string m_connectingFaceUri;
double m_routeCost;
+ static const uint64_t HYPERBOLIC_COST_ADJUSTMENT_FACTOR = 100;
};
}//namespace nlsr
diff --git a/tests/test-nexthop-list.cpp b/tests/test-nexthop-list.cpp
index f2bb7fd..eeea461 100644
--- a/tests/test-nexthop-list.cpp
+++ b/tests/test-nexthop-list.cpp
@@ -43,6 +43,26 @@
BOOST_CHECK_EQUAL(nhl1.getSize(), (uint32_t)0);
}
+BOOST_AUTO_TEST_CASE(RemoveNextHop)
+{
+ NextHop hop1;
+ hop1.setRouteCost(12.34);
+
+ NexthopList hopList;
+ hopList.addNextHop(hop1);
+
+ NextHop hop2;
+ hop2.setRouteCost(12.35);
+
+ BOOST_REQUIRE_EQUAL(hopList.getSize(), 1);
+
+ hopList.removeNextHop(hop2);
+ BOOST_CHECK_EQUAL(hopList.getSize(), 1);
+
+ hopList.removeNextHop(hop1);
+ BOOST_CHECK_EQUAL(hopList.getSize(), 0);
+}
+
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
diff --git a/tests/test-nexthop.cpp b/tests/test-nexthop.cpp
index 7c30069..da3a19f 100644
--- a/tests/test-nexthop.cpp
+++ b/tests/test-nexthop.cpp
@@ -31,14 +31,21 @@
BOOST_AUTO_TEST_CASE(NexthopSetAndGet)
{
- NextHop np1;
+ NextHop hop1;
+ hop1.setConnectingFaceUri("udp://test/uri");
+ hop1.setRouteCost(12.34);
- np1.setConnectingFaceUri("udp://test/uri");
+ BOOST_CHECK_EQUAL(hop1.getConnectingFaceUri(), "udp://test/uri");
+ BOOST_CHECK_EQUAL(hop1.getRouteCost(), 12.34);
+ BOOST_CHECK_EQUAL(hop1.getRouteCostAsAdjustedInteger(), 1234);
- np1.setRouteCost(10.1);
+ NextHop hop2;
- BOOST_CHECK_EQUAL(np1.getConnectingFaceUri(), "udp://test/uri");
- BOOST_CHECK_EQUAL(np1.getRouteCost(), 11);
+ hop2.setRouteCost(12.34);
+ BOOST_CHECK_EQUAL(hop1.getRouteCostAsAdjustedInteger(), hop2.getRouteCostAsAdjustedInteger());
+
+ hop2.setRouteCost(12.35);
+ BOOST_CHECK(hop1.getRouteCostAsAdjustedInteger() < hop2.getRouteCostAsAdjustedInteger());
}
BOOST_AUTO_TEST_SUITE_END()