management: Implementing encoding/decoding Strategy in nfd::FibManagementOptions
Change-Id: I865d8d6fc44f7a8232a0260719f697ec6cb6857f
Refs: #1292
diff --git a/src/management/nfd-fib-management-options.hpp b/src/management/nfd-fib-management-options.hpp
index 16d688e..b2f8485 100644
--- a/src/management/nfd-fib-management-options.hpp
+++ b/src/management/nfd-fib-management-options.hpp
@@ -32,13 +32,13 @@
{
wireDecode(block);
}
-
- const Name&
+
+ const Name&
getName () const
{
return m_name;
}
-
+
FibManagementOptions&
setName (const Name &name)
{
@@ -46,8 +46,8 @@
m_wire.reset ();
return *this;
}
-
- uint64_t
+
+ uint64_t
getFaceId () const
{
return m_faceId;
@@ -61,7 +61,7 @@
return *this;
}
- uint64_t
+ uint64_t
getCost () const
{
return m_cost;
@@ -75,7 +75,7 @@
return *this;
}
- const Name&
+ const Name&
getStrategy () const
{
return m_strategy;
@@ -88,17 +88,17 @@
m_wire.reset ();
return *this;
}
-
+
template<bool T>
size_t
wireEncode(EncodingImpl<T> &block) const;
-
+
const Block&
wireEncode () const;
-
- void
+
+ void
wireDecode (const Block &wire);
-
+
private:
Name m_name;
uint64_t m_faceId;
@@ -114,11 +114,11 @@
{
size_t total_len = 0;
- // if (!m_strategy.empty())
- // {
- // total_len += prependNestedBlock(blk, tlv::nfd::Strategy, m_strategy);
- // }
-
+ if (!m_strategy.empty())
+ {
+ total_len += prependNestedBlock(blk, tlv::nfd::Strategy, m_strategy);
+ }
+
if (m_cost != 0)
{
total_len += prependNonNegativeIntegerBlock(blk, tlv::nfd::Cost, m_cost);
@@ -144,15 +144,15 @@
EncodingEstimator estimator;
size_t estimatedSize = wireEncode(estimator);
-
+
EncodingBuffer buffer(estimatedSize, 0);
wireEncode(buffer);
m_wire = buffer.block();
return m_wire;
}
-
-inline void
+
+inline void
FibManagementOptions::wireDecode (const Block &wire)
{
m_name.clear();
@@ -164,7 +164,7 @@
if (m_wire.type() != tlv::nfd::FibManagementOptions)
throw Error("Requested decoding of FibManagementOptions, but Block is of different type");
-
+
m_wire.parse ();
// Name
@@ -202,7 +202,7 @@
operator << (std::ostream &os, const FibManagementOptions &option)
{
os << "ForwardingEntry(";
-
+
// Name
os << "Prefix: " << option.getName() << ", ";
@@ -214,7 +214,7 @@
// Strategy
os << "Strategy: " << option.getStrategy() << ", ";
-
+
os << ")";
return os;
}
diff --git a/tests/management/test-nfd-control.cpp b/tests/management/test-nfd-control.cpp
index 79b4d39..2e53512 100644
--- a/tests/management/test-nfd-control.cpp
+++ b/tests/management/test-nfd-control.cpp
@@ -24,9 +24,13 @@
0x66, 0x6f, 0x75, 0x6e, 0x64};
const uint8_t TestFibManagementOptions[] = {
- 0x68, 0x1e, 0x07, 0x16, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
+ 0x68, 0x49, 0x07, 0x16, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
0x6f, 0x73, 0x74, 0x08, 0x03, 0x72, 0x65, 0x67, 0x08, 0x04, 0x74, 0x65,
- 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x01
+ 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x01, 0x6b, 0x29, 0x07, 0x27,
+ 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x08,
+ 0x03, 0x6e, 0x66, 0x64, 0x08, 0x08, 0x73, 0x74, 0x72, 0x61, 0x74, 0x65,
+ 0x67, 0x79, 0x08, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2d, 0x77, 0x6f,
+ 0x72, 0x6c, 0x64
};
const uint8_t TestFaceManagementOptions[] = {
@@ -37,7 +41,7 @@
// ControlResponse
-BOOST_AUTO_TEST_CASE (ControlResponseEncode)
+BOOST_AUTO_TEST_CASE(ControlResponseEncode)
{
ControlResponse controlResponse(404, "Nothing not found");
const Block &wire = controlResponse.wireEncode();
@@ -46,10 +50,10 @@
wire.begin(), wire.end());
}
-BOOST_AUTO_TEST_CASE (ControlResponseDecode)
+BOOST_AUTO_TEST_CASE(ControlResponseDecode)
{
ControlResponse controlResponse;
-
+
BOOST_REQUIRE_NO_THROW(controlResponse.wireDecode(Block(TestControlResponse, sizeof(TestControlResponse))));
BOOST_REQUIRE_EQUAL(controlResponse.getCode(), 404);
@@ -58,84 +62,87 @@
// FibManagementOptions
-BOOST_AUTO_TEST_CASE (FibManagementOptionsEncoding)
+BOOST_AUTO_TEST_CASE(FibManagementOptionsEncoding)
{
- Name n ("/localhost/reg/test");
+ Name n("/localhost/reg/test");
FibManagementOptions opt;
- opt.setName (n);
- opt.setFaceId (0);
- opt.setCost (1);
+ opt.setName(n);
+ opt.setFaceId(0);
+ opt.setCost(1);
+ opt.setStrategy("/localhost/nfd/strategy/hello-world");
- const Block& blk = opt.wireEncode ();
+ const Block& blk = opt.wireEncode();
- BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions,
- TestFibManagementOptions + sizeof (TestFibManagementOptions),
- blk.begin (), blk.end ());
+ BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions,
+ TestFibManagementOptions + sizeof(TestFibManagementOptions),
+ blk.begin(), blk.end());
}
-BOOST_AUTO_TEST_CASE (FibManagementOptionsFastEncoding)
+BOOST_AUTO_TEST_CASE(FibManagementOptionsFastEncoding)
{
- Name n ("/localhost/reg/test");
+ Name n("/localhost/reg/test");
FibManagementOptions opt;
- opt.setName (n);
- opt.setFaceId (0);
- opt.setCost (1);
+ opt.setName(n);
+ opt.setFaceId(0);
+ opt.setCost(1);
+ opt.setStrategy("/localhost/nfd/strategy/hello-world");
EncodingBuffer blk;
- BOOST_REQUIRE_NO_THROW (opt.wireEncode (blk));
+ BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk));
- BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions,
- TestFibManagementOptions + sizeof (TestFibManagementOptions),
- blk.begin (), blk.end ());
+ BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions,
+ TestFibManagementOptions + sizeof(TestFibManagementOptions),
+ blk.begin(), blk.end());
- EncodingBuffer blk2 (4);
+ EncodingBuffer blk2(4);
- BOOST_REQUIRE_NO_THROW (opt.wireEncode (blk2));
+ BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk2));
- BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFibManagementOptions,
- TestFibManagementOptions + sizeof (TestFibManagementOptions),
- blk2.begin (), blk2.end ());
+ BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions,
+ TestFibManagementOptions + sizeof(TestFibManagementOptions),
+ blk2.begin(), blk2.end());
}
-BOOST_AUTO_TEST_CASE (FibManagementOptionsDecoding)
+BOOST_AUTO_TEST_CASE(FibManagementOptionsDecoding)
{
- Block blk (TestFibManagementOptions, sizeof (TestFibManagementOptions));
- Name n ("/localhost/reg/test");
+ Block blk(TestFibManagementOptions, sizeof(TestFibManagementOptions));
+ Name n("/localhost/reg/test");
FibManagementOptions opt;
- BOOST_REQUIRE_NO_THROW (opt.wireDecode (blk));
-
- BOOST_CHECK_EQUAL (opt.getName (), n);
- BOOST_CHECK_EQUAL (opt.getFaceId (), 0);
- BOOST_CHECK_EQUAL (opt.getCost (), 1);
+ BOOST_REQUIRE_NO_THROW(opt.wireDecode(blk));
+
+ BOOST_CHECK_EQUAL(opt.getName(), n);
+ BOOST_CHECK_EQUAL(opt.getFaceId(), 0);
+ BOOST_CHECK_EQUAL(opt.getCost(), 1);
+ BOOST_CHECK_EQUAL(opt.getStrategy().toUri(), "/localhost/nfd/strategy/hello-world");
}
-BOOST_AUTO_TEST_CASE (FaceManagementOptionsFastEncoding)
+BOOST_AUTO_TEST_CASE(FaceManagementOptionsFastEncoding)
{
FaceManagementOptions opt;
- opt.setFaceId (10);
- opt.setUri ("tcp://1.1.1.1/hello/world");
+ opt.setFaceId(10);
+ opt.setUri("tcp://1.1.1.1/hello/world");
- BOOST_REQUIRE_NO_THROW (opt.wireEncode ());
+ BOOST_REQUIRE_NO_THROW(opt.wireEncode ());
- BOOST_REQUIRE_EQUAL_COLLECTIONS (TestFaceManagementOptions,
- TestFaceManagementOptions + sizeof (TestFibManagementOptions),
- opt.wireEncode ().begin (), opt.wireEncode ().end ());
+ BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFaceManagementOptions,
+ TestFaceManagementOptions + sizeof(TestFaceManagementOptions),
+ opt.wireEncode().begin(), opt.wireEncode().end());
}
-BOOST_AUTO_TEST_CASE (FaceManagementOptionsDecoding)
+BOOST_AUTO_TEST_CASE(FaceManagementOptionsDecoding)
{
- Block blk (TestFaceManagementOptions, sizeof (TestFaceManagementOptions));
+ Block blk(TestFaceManagementOptions, sizeof(TestFaceManagementOptions));
FaceManagementOptions opt;
- BOOST_REQUIRE_NO_THROW (opt.wireDecode (blk));
-
- BOOST_CHECK_EQUAL (opt.getFaceId(), 10);
- BOOST_CHECK_EQUAL (opt.getUri(), "tcp://1.1.1.1/hello/world");
+ BOOST_REQUIRE_NO_THROW(opt.wireDecode (blk));
+
+ BOOST_CHECK_EQUAL(opt.getFaceId(), 10);
+ BOOST_CHECK_EQUAL(opt.getUri(), "tcp://1.1.1.1/hello/world");
}
BOOST_AUTO_TEST_SUITE_END()