management: nfd::FibEntry encoding corrections
Change-Id: I958c171d7a8f47e8ccfe443d839c211f8af29a98
Refs: #1378
diff --git a/src/management/nfd-fib-entry.hpp b/src/management/nfd-fib-entry.hpp
index ea22856..acd87ea 100644
--- a/src/management/nfd-fib-entry.hpp
+++ b/src/management/nfd-fib-entry.hpp
@@ -25,9 +25,7 @@
class Error : public Tlv::Error
{
public:
- Error(const std::string& what) : Tlv::Error(what)
- {
- }
+ Error(const std::string& what) : Tlv::Error(what) {}
};
NextHopRecord()
@@ -146,7 +144,7 @@
{
std::stringstream error;
error << "Expected Cost, but Block is of a different type: #"
- << error.str();
+ << m_wire.type();
throw Error(error.str());
}
m_cost = readNonNegativeInteger(*val);
@@ -230,8 +228,8 @@
{
size_t totalLength = 0;
- for (std::list<NextHopRecord>::const_iterator i = m_nextHopRecords.begin();
- i != m_nextHopRecords.end();
+ for (std::list<NextHopRecord>::const_reverse_iterator i = m_nextHopRecords.rbegin();
+ i != m_nextHopRecords.rend();
++i)
{
totalLength += i->wireEncode(block);
diff --git a/tests/management/nfd-status.cpp b/tests/management/nfd-status.cpp
deleted file mode 100644
index ef411a4..0000000
--- a/tests/management/nfd-status.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * See COPYING for copyright and distribution information.
- */
-
-#include "management/nfd-status.hpp"
-#include "data.hpp"
-
-#include <boost/test/unit_test.hpp>
-
-namespace ndn {
-namespace nfd {
-
-BOOST_AUTO_TEST_SUITE(NfdStatus)
-
-BOOST_AUTO_TEST_CASE(StatusEncode)
-{
- Status status1;
- status1.setNfdVersion(1014210635);
- status1.setStartTimestamp(time::fromUnixTimestamp(time::seconds(375193249)));
- status1.setCurrentTimestamp(time::fromUnixTimestamp(time::seconds(1886109034)));
- status1.setNNameTreeEntries(1849943160);
- status1.setNFibEntries(621739748);
- status1.setNPitEntries(482129741);
- status1.setNMeasurementsEntries(1771725298);
- status1.setNCsEntries(1264968688);
- status1.setNInInterests(612811615);
- status1.setNOutInterests(952144445);
- status1.setNInDatas(1843576050);
- status1.setNOutDatas(138198826);
-
- EncodingBuffer buffer;
- status1.wireEncode(buffer);
-
- Data data;
- data.setContent(buffer.buf(), buffer.size());
-
- Status status2(data.getContent());
- BOOST_CHECK_EQUAL(status1.getNfdVersion(), status2.getNfdVersion());
- BOOST_CHECK_EQUAL(status1.getStartTimestamp(), status2.getStartTimestamp());
- BOOST_CHECK_EQUAL(status1.getCurrentTimestamp(), status2.getCurrentTimestamp());
- BOOST_CHECK_EQUAL(status1.getNNameTreeEntries(), status2.getNNameTreeEntries());
- BOOST_CHECK_EQUAL(status1.getNFibEntries(), status2.getNFibEntries());
- BOOST_CHECK_EQUAL(status1.getNPitEntries(), status2.getNPitEntries());
- BOOST_CHECK_EQUAL(status1.getNMeasurementsEntries(), status2.getNMeasurementsEntries());
- BOOST_CHECK_EQUAL(status1.getNCsEntries(), status2.getNCsEntries());
- BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests());
- BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests());
- BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas());
- BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas());
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace nfd
-} // namespace ndn
diff --git a/tests/management/test-nfd-control.cpp b/tests/management/test-nfd-control.cpp
index 2b4b3cc..a3ca371 100644
--- a/tests/management/test-nfd-control.cpp
+++ b/tests/management/test-nfd-control.cpp
@@ -9,6 +9,8 @@
#include "management/nfd-face-management-options.hpp"
#include "management/nfd-face-event-notification.hpp"
#include "management/nfd-face-status.hpp"
+#include "management/nfd-status.hpp"
+#include "data.hpp"
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
@@ -226,6 +228,43 @@
}
}
+BOOST_AUTO_TEST_CASE(NfdStatusEncode)
+{
+ Status status1;
+ status1.setNfdVersion(1014210635);
+ status1.setStartTimestamp(time::fromUnixTimestamp(time::seconds(375193249)));
+ status1.setCurrentTimestamp(time::fromUnixTimestamp(time::seconds(1886109034)));
+ status1.setNNameTreeEntries(1849943160);
+ status1.setNFibEntries(621739748);
+ status1.setNPitEntries(482129741);
+ status1.setNMeasurementsEntries(1771725298);
+ status1.setNCsEntries(1264968688);
+ status1.setNInInterests(612811615);
+ status1.setNOutInterests(952144445);
+ status1.setNInDatas(1843576050);
+ status1.setNOutDatas(138198826);
+
+ EncodingBuffer buffer;
+ status1.wireEncode(buffer);
+
+ Data data;
+ data.setContent(buffer.buf(), buffer.size());
+
+ Status status2(data.getContent());
+ BOOST_CHECK_EQUAL(status1.getNfdVersion(), status2.getNfdVersion());
+ BOOST_CHECK_EQUAL(status1.getStartTimestamp(), status2.getStartTimestamp());
+ BOOST_CHECK_EQUAL(status1.getCurrentTimestamp(), status2.getCurrentTimestamp());
+ BOOST_CHECK_EQUAL(status1.getNNameTreeEntries(), status2.getNNameTreeEntries());
+ BOOST_CHECK_EQUAL(status1.getNFibEntries(), status2.getNFibEntries());
+ BOOST_CHECK_EQUAL(status1.getNPitEntries(), status2.getNPitEntries());
+ BOOST_CHECK_EQUAL(status1.getNMeasurementsEntries(), status2.getNMeasurementsEntries());
+ BOOST_CHECK_EQUAL(status1.getNCsEntries(), status2.getNCsEntries());
+ BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests());
+ BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests());
+ BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas());
+ BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas());
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace nfd
diff --git a/tests/management/test-nfd-fib-entry.cpp b/tests/management/test-nfd-fib-entry.cpp
index fb3383c..e92c39f 100644
--- a/tests/management/test-nfd-fib-entry.cpp
+++ b/tests/management/test-nfd-fib-entry.cpp
@@ -28,14 +28,10 @@
const uint8_t TestFibEntry[] =
{
- 0x80, 0x38, 0x07, 0x13, 0x08, 0x04, 0x74, 0x68,
- 0x69, 0x73, 0x08, 0x02, 0x69, 0x73, 0x08, 0x01,
- 0x61, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x81,
- 0x07, 0x69, 0x01, 0x28, 0x6a, 0x02, 0x01, 0xf4,
- 0x81, 0x07, 0x69, 0x01, 0x1e, 0x6a, 0x02, 0x01,
- 0x90, 0x81, 0x07, 0x69, 0x01, 0x14, 0x6a, 0x02,
- 0x01, 0x2c, 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a,
- 0x01, 0xc8
+ 0x80, 0x38, 0x07, 0x13, 0x08, 0x04, 0x74, 0x68, 0x69, 0x73, 0x08, 0x02, 0x69, 0x73, 0x08, 0x01,
+ 0x61, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8, 0x81,
+ 0x07, 0x69, 0x01, 0x14, 0x6a, 0x02, 0x01, 0x2c, 0x81, 0x07, 0x69, 0x01, 0x1e, 0x6a, 0x02, 0x01,
+ 0x90, 0x81, 0x07, 0x69, 0x01, 0x28, 0x6a, 0x02, 0x01, 0xf4
};
BOOST_AUTO_TEST_CASE(TestNextHopRecordEncode)
@@ -106,14 +102,13 @@
entry.addNextHopRecord(oneMore);
const Block& wire = entry.wireEncode();
- BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibEntry,
- TestFibEntry + sizeof(TestFibEntry),
- wire.begin(), wire.end());
+ BOOST_CHECK_EQUAL_COLLECTIONS(TestFibEntry,
+ TestFibEntry + sizeof(TestFibEntry),
+ wire.begin(), wire.end());
// std::ofstream of("out.tmp");
// of.write((const char*)entry.wireEncode().wire(),
// entry.wireEncode().size());
-
}
BOOST_AUTO_TEST_CASE(TestFibEntryDecode)
@@ -124,10 +119,10 @@
std::list<NextHopRecord> records = entry.getNextHopRecords();
- BOOST_REQUIRE_EQUAL(entry.getPrefix(), "/this/is/a/test");
- BOOST_REQUIRE_EQUAL(entry.getNextHopRecords().size(), 4);
+ BOOST_CHECK_EQUAL(entry.getPrefix(), "/this/is/a/test");
+ BOOST_CHECK_EQUAL(entry.getNextHopRecords().size(), 4);
- size_t value = 4;
+ size_t value = 1;
for (std::list<NextHopRecord>::const_iterator i = records.begin();
i != records.end();
@@ -135,7 +130,7 @@
{
BOOST_CHECK_EQUAL(i->getFaceId(), value * 10);
BOOST_CHECK_EQUAL(i->getCost(), (value * 100) + 100);
- --value;
+ ++value;
}
}