blob: 2e5351235f1f402354e452545ba62cc3d7f712e4 [file] [log] [blame]
Wentao Shang77949212014-02-01 23:42:24 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -08002/**
3 * Copyright (C) 2013 Regents of the University of California.
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -08004 * See COPYING for copyright and distribution information.
5 */
6
Alexander Afanasyeve289b532014-02-09 22:14:44 -08007#include "management/nfd-control-response.hpp"
8#include "management/nfd-fib-management-options.hpp"
Yingdi Yud3370492014-02-12 17:17:11 -08009#include "management/nfd-face-management-options.hpp"
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080010
Wentao Shang4d5e1de2014-01-28 21:00:03 -080011#include <boost/test/unit_test.hpp>
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080012#include <boost/test/output_test_stream.hpp>
13
14using namespace std;
15
16namespace ndn {
Alexander Afanasyeve289b532014-02-09 22:14:44 -080017namespace nfd {
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080018
19BOOST_AUTO_TEST_SUITE(TestNfdControl)
20
Alexander Afanasyev4b456282014-02-13 00:34:34 -080021const uint8_t TestControlResponse[] = {0x65, 0x17,
22 0x66, 0x02, 0x01, 0x94, 0x67, 0x11, 0x4e, 0x6f, 0x74,
23 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x6f, 0x74, 0x20,
24 0x66, 0x6f, 0x75, 0x6e, 0x64};
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080025
Wentao Shang4d5e1de2014-01-28 21:00:03 -080026const uint8_t TestFibManagementOptions[] = {
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080027 0x68, 0x49, 0x07, 0x16, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080028 0x6f, 0x73, 0x74, 0x08, 0x03, 0x72, 0x65, 0x67, 0x08, 0x04, 0x74, 0x65,
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080029 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x01, 0x6b, 0x29, 0x07, 0x27,
30 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x08,
31 0x03, 0x6e, 0x66, 0x64, 0x08, 0x08, 0x73, 0x74, 0x72, 0x61, 0x74, 0x65,
32 0x67, 0x79, 0x08, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2d, 0x77, 0x6f,
33 0x72, 0x6c, 0x64
Wentao Shang4d5e1de2014-01-28 21:00:03 -080034};
35
Yingdi Yud3370492014-02-12 17:17:11 -080036const uint8_t TestFaceManagementOptions[] = {
37 0x6c, 0x1e, 0x69, 0x01, 0x0a, 0x72, 0x19, 0x74, 0x63, 0x70, 0x3a, 0x2f,
38 0x2f, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2f, 0x68, 0x65, 0x6c,
39 0x6c, 0x6f, 0x2f, 0x77, 0x6f, 0x72, 0x6c, 0x64
40};
41
Wentao Shang4d5e1de2014-01-28 21:00:03 -080042// ControlResponse
43
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080044BOOST_AUTO_TEST_CASE(ControlResponseEncode)
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080045{
Alexander Afanasyeve289b532014-02-09 22:14:44 -080046 ControlResponse controlResponse(404, "Nothing not found");
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080047 const Block &wire = controlResponse.wireEncode();
48
49 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse),
50 wire.begin(), wire.end());
51}
52
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080053BOOST_AUTO_TEST_CASE(ControlResponseDecode)
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080054{
Alexander Afanasyeve289b532014-02-09 22:14:44 -080055 ControlResponse controlResponse;
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080056
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080057 BOOST_REQUIRE_NO_THROW(controlResponse.wireDecode(Block(TestControlResponse, sizeof(TestControlResponse))));
58
59 BOOST_REQUIRE_EQUAL(controlResponse.getCode(), 404);
60 BOOST_REQUIRE_EQUAL(controlResponse.getText(), "Nothing not found");
61}
62
Wentao Shang4d5e1de2014-01-28 21:00:03 -080063// FibManagementOptions
64
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080065BOOST_AUTO_TEST_CASE(FibManagementOptionsEncoding)
Wentao Shang4d5e1de2014-01-28 21:00:03 -080066{
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080067 Name n("/localhost/reg/test");
Wentao Shang4d5e1de2014-01-28 21:00:03 -080068 FibManagementOptions opt;
69
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080070 opt.setName(n);
71 opt.setFaceId(0);
72 opt.setCost(1);
73 opt.setStrategy("/localhost/nfd/strategy/hello-world");
Wentao Shang4d5e1de2014-01-28 21:00:03 -080074
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080075 const Block& blk = opt.wireEncode();
Wentao Shang4d5e1de2014-01-28 21:00:03 -080076
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080077 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions,
78 TestFibManagementOptions + sizeof(TestFibManagementOptions),
79 blk.begin(), blk.end());
Wentao Shang4d5e1de2014-01-28 21:00:03 -080080}
81
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080082BOOST_AUTO_TEST_CASE(FibManagementOptionsFastEncoding)
Wentao Shang77949212014-02-01 23:42:24 -080083{
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080084 Name n("/localhost/reg/test");
Wentao Shang77949212014-02-01 23:42:24 -080085 FibManagementOptions opt;
86
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080087 opt.setName(n);
88 opt.setFaceId(0);
89 opt.setCost(1);
90 opt.setStrategy("/localhost/nfd/strategy/hello-world");
Wentao Shang77949212014-02-01 23:42:24 -080091
92 EncodingBuffer blk;
93
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080094 BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk));
Wentao Shang77949212014-02-01 23:42:24 -080095
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080096 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions,
97 TestFibManagementOptions + sizeof(TestFibManagementOptions),
98 blk.begin(), blk.end());
Wentao Shang77949212014-02-01 23:42:24 -080099
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800100 EncodingBuffer blk2(4);
Wentao Shang77949212014-02-01 23:42:24 -0800101
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800102 BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk2));
Wentao Shang77949212014-02-01 23:42:24 -0800103
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800104 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions,
105 TestFibManagementOptions + sizeof(TestFibManagementOptions),
106 blk2.begin(), blk2.end());
Wentao Shang77949212014-02-01 23:42:24 -0800107}
108
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800109BOOST_AUTO_TEST_CASE(FibManagementOptionsDecoding)
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800110{
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800111 Block blk(TestFibManagementOptions, sizeof(TestFibManagementOptions));
112 Name n("/localhost/reg/test");
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800113 FibManagementOptions opt;
114
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800115 BOOST_REQUIRE_NO_THROW(opt.wireDecode(blk));
116
117 BOOST_CHECK_EQUAL(opt.getName(), n);
118 BOOST_CHECK_EQUAL(opt.getFaceId(), 0);
119 BOOST_CHECK_EQUAL(opt.getCost(), 1);
120 BOOST_CHECK_EQUAL(opt.getStrategy().toUri(), "/localhost/nfd/strategy/hello-world");
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800121}
122
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800123BOOST_AUTO_TEST_CASE(FaceManagementOptionsFastEncoding)
Yingdi Yud3370492014-02-12 17:17:11 -0800124{
125 FaceManagementOptions opt;
126
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800127 opt.setFaceId(10);
128 opt.setUri("tcp://1.1.1.1/hello/world");
Yingdi Yud3370492014-02-12 17:17:11 -0800129
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800130 BOOST_REQUIRE_NO_THROW(opt.wireEncode ());
Yingdi Yud3370492014-02-12 17:17:11 -0800131
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800132 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFaceManagementOptions,
133 TestFaceManagementOptions + sizeof(TestFaceManagementOptions),
134 opt.wireEncode().begin(), opt.wireEncode().end());
Yingdi Yud3370492014-02-12 17:17:11 -0800135}
136
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800137BOOST_AUTO_TEST_CASE(FaceManagementOptionsDecoding)
Yingdi Yud3370492014-02-12 17:17:11 -0800138{
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800139 Block blk(TestFaceManagementOptions, sizeof(TestFaceManagementOptions));
Yingdi Yud3370492014-02-12 17:17:11 -0800140 FaceManagementOptions opt;
141
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800142 BOOST_REQUIRE_NO_THROW(opt.wireDecode (blk));
143
144 BOOST_CHECK_EQUAL(opt.getFaceId(), 10);
145 BOOST_CHECK_EQUAL(opt.getUri(), "tcp://1.1.1.1/hello/world");
Yingdi Yud3370492014-02-12 17:17:11 -0800146}
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800147
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800148BOOST_AUTO_TEST_SUITE_END()
149
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800150} // namespace nfd
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800151} // namespace ndn