blob: 68df3972f7dc21174d9e333e3c320faa1a747631 [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 Afanasyev44b438a2014-03-19 12:51:49 -070010#include "management/nfd-face-event-notification.hpp"
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -070011#include "management/nfd-face-status.hpp"
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080012
Wentao Shang4d5e1de2014-01-28 21:00:03 -080013#include <boost/test/unit_test.hpp>
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080014#include <boost/test/output_test_stream.hpp>
15
16using namespace std;
17
18namespace ndn {
Alexander Afanasyeve289b532014-02-09 22:14:44 -080019namespace nfd {
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080020
21BOOST_AUTO_TEST_SUITE(TestNfdControl)
22
Alexander Afanasyev4b456282014-02-13 00:34:34 -080023const uint8_t TestControlResponse[] = {0x65, 0x17,
24 0x66, 0x02, 0x01, 0x94, 0x67, 0x11, 0x4e, 0x6f, 0x74,
25 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x6f, 0x74, 0x20,
26 0x66, 0x6f, 0x75, 0x6e, 0x64};
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080027
Wentao Shang4d5e1de2014-01-28 21:00:03 -080028const uint8_t TestFibManagementOptions[] = {
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080029 0x68, 0x49, 0x07, 0x16, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080030 0x6f, 0x73, 0x74, 0x08, 0x03, 0x72, 0x65, 0x67, 0x08, 0x04, 0x74, 0x65,
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080031 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x01, 0x6b, 0x29, 0x07, 0x27,
32 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x08,
33 0x03, 0x6e, 0x66, 0x64, 0x08, 0x08, 0x73, 0x74, 0x72, 0x61, 0x74, 0x65,
34 0x67, 0x79, 0x08, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2d, 0x77, 0x6f,
35 0x72, 0x6c, 0x64
Wentao Shang4d5e1de2014-01-28 21:00:03 -080036};
37
Yingdi Yud3370492014-02-12 17:17:11 -080038const uint8_t TestFaceManagementOptions[] = {
39 0x6c, 0x1e, 0x69, 0x01, 0x0a, 0x72, 0x19, 0x74, 0x63, 0x70, 0x3a, 0x2f,
40 0x2f, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2f, 0x68, 0x65, 0x6c,
41 0x6c, 0x6f, 0x2f, 0x77, 0x6f, 0x72, 0x6c, 0x64
42};
43
Alexander Afanasyev44b438a2014-03-19 12:51:49 -070044const uint8_t TestFaceEventNotification[] = {
45 0xc0, 0x1d, 0xc1, 0x01, 0x01, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63,
46 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30,
47 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33
48};
49
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -070050const uint8_t TestFaceStatus[] = {
51 0x80, 0x27, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a,
52 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x3a,
53 0x36, 0x33, 0x36, 0x33, 0x91, 0x01, 0x0a, 0x90, 0x01, 0x14, 0x92, 0x01,
54 0x1e, 0x93, 0x02, 0x01, 0x90
55};
56
Wentao Shang4d5e1de2014-01-28 21:00:03 -080057// ControlResponse
58
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080059BOOST_AUTO_TEST_CASE(ControlResponseEncode)
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080060{
Alexander Afanasyeve289b532014-02-09 22:14:44 -080061 ControlResponse controlResponse(404, "Nothing not found");
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080062 const Block &wire = controlResponse.wireEncode();
63
64 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse),
65 wire.begin(), wire.end());
66}
67
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080068BOOST_AUTO_TEST_CASE(ControlResponseDecode)
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080069{
Alexander Afanasyeve289b532014-02-09 22:14:44 -080070 ControlResponse controlResponse;
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080071
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -080072 BOOST_REQUIRE_NO_THROW(controlResponse.wireDecode(Block(TestControlResponse, sizeof(TestControlResponse))));
73
74 BOOST_REQUIRE_EQUAL(controlResponse.getCode(), 404);
75 BOOST_REQUIRE_EQUAL(controlResponse.getText(), "Nothing not found");
76}
77
Wentao Shang4d5e1de2014-01-28 21:00:03 -080078// FibManagementOptions
79
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080080BOOST_AUTO_TEST_CASE(FibManagementOptionsEncoding)
Wentao Shang4d5e1de2014-01-28 21:00:03 -080081{
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080082 Name n("/localhost/reg/test");
Wentao Shang4d5e1de2014-01-28 21:00:03 -080083 FibManagementOptions opt;
84
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080085 opt.setName(n);
86 opt.setFaceId(0);
87 opt.setCost(1);
88 opt.setStrategy("/localhost/nfd/strategy/hello-world");
Wentao Shang4d5e1de2014-01-28 21:00:03 -080089
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080090 const Block& blk = opt.wireEncode();
Wentao Shang4d5e1de2014-01-28 21:00:03 -080091
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080092 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions,
93 TestFibManagementOptions + sizeof(TestFibManagementOptions),
94 blk.begin(), blk.end());
Wentao Shang4d5e1de2014-01-28 21:00:03 -080095}
96
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080097BOOST_AUTO_TEST_CASE(FibManagementOptionsFastEncoding)
Wentao Shang77949212014-02-01 23:42:24 -080098{
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -080099 Name n("/localhost/reg/test");
Wentao Shang77949212014-02-01 23:42:24 -0800100 FibManagementOptions opt;
101
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800102 opt.setName(n);
103 opt.setFaceId(0);
104 opt.setCost(1);
105 opt.setStrategy("/localhost/nfd/strategy/hello-world");
Wentao Shang77949212014-02-01 23:42:24 -0800106
107 EncodingBuffer blk;
108
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800109 BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk));
Wentao Shang77949212014-02-01 23:42:24 -0800110
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800111 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions,
112 TestFibManagementOptions + sizeof(TestFibManagementOptions),
113 blk.begin(), blk.end());
Wentao Shang77949212014-02-01 23:42:24 -0800114
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800115 EncodingBuffer blk2(4);
Wentao Shang77949212014-02-01 23:42:24 -0800116
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800117 BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk2));
Wentao Shang77949212014-02-01 23:42:24 -0800118
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800119 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions,
120 TestFibManagementOptions + sizeof(TestFibManagementOptions),
121 blk2.begin(), blk2.end());
Wentao Shang77949212014-02-01 23:42:24 -0800122}
123
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800124BOOST_AUTO_TEST_CASE(FibManagementOptionsDecoding)
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800125{
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800126 Block blk(TestFibManagementOptions, sizeof(TestFibManagementOptions));
127 Name n("/localhost/reg/test");
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800128 FibManagementOptions opt;
129
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800130 BOOST_REQUIRE_NO_THROW(opt.wireDecode(blk));
131
132 BOOST_CHECK_EQUAL(opt.getName(), n);
133 BOOST_CHECK_EQUAL(opt.getFaceId(), 0);
134 BOOST_CHECK_EQUAL(opt.getCost(), 1);
135 BOOST_CHECK_EQUAL(opt.getStrategy().toUri(), "/localhost/nfd/strategy/hello-world");
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800136}
137
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800138BOOST_AUTO_TEST_CASE(FaceManagementOptionsFastEncoding)
Yingdi Yud3370492014-02-12 17:17:11 -0800139{
140 FaceManagementOptions opt;
141
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800142 opt.setFaceId(10);
143 opt.setUri("tcp://1.1.1.1/hello/world");
Yingdi Yud3370492014-02-12 17:17:11 -0800144
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800145 BOOST_REQUIRE_NO_THROW(opt.wireEncode ());
Yingdi Yud3370492014-02-12 17:17:11 -0800146
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800147 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFaceManagementOptions,
148 TestFaceManagementOptions + sizeof(TestFaceManagementOptions),
149 opt.wireEncode().begin(), opt.wireEncode().end());
Yingdi Yud3370492014-02-12 17:17:11 -0800150}
151
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800152BOOST_AUTO_TEST_CASE(FaceManagementOptionsDecoding)
Yingdi Yud3370492014-02-12 17:17:11 -0800153{
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800154 Block blk(TestFaceManagementOptions, sizeof(TestFaceManagementOptions));
Yingdi Yud3370492014-02-12 17:17:11 -0800155 FaceManagementOptions opt;
156
Alexander Afanasyev44b438a2014-03-19 12:51:49 -0700157 BOOST_REQUIRE_NO_THROW(opt.wireDecode(blk));
Alexander Afanasyevc5ad1192014-02-25 14:17:47 -0800158
159 BOOST_CHECK_EQUAL(opt.getFaceId(), 10);
160 BOOST_CHECK_EQUAL(opt.getUri(), "tcp://1.1.1.1/hello/world");
Yingdi Yud3370492014-02-12 17:17:11 -0800161}
Wentao Shang4d5e1de2014-01-28 21:00:03 -0800162
Alexander Afanasyev44b438a2014-03-19 12:51:49 -0700163
164BOOST_AUTO_TEST_CASE(FaceEventNotificationEncodingDecoding)
165{
166 FaceEventKind expectedKind = FACE_EVENT_CREATED;
167 std::string expectedUri("tcp4://127.0.0.1:6363");
168 uint64_t expectedFaceId = 100;
169
170 {
171 FaceEventNotification faceEvent(expectedKind, expectedFaceId, expectedUri);
172 BOOST_REQUIRE_NO_THROW(faceEvent.wireEncode());
173
174 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFaceEventNotification,
175 TestFaceEventNotification + sizeof(TestFaceEventNotification),
176 faceEvent.wireEncode().begin(), faceEvent.wireEncode().end());
177
178 std::ostringstream os;
179 os << faceEvent;
180 BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification(Kind: created, FaceID: 100, Uri: tcp4://127.0.0.1:6363)");
181 }
182
183 {
184 Block blk(TestFaceEventNotification, sizeof(TestFaceEventNotification));
185 FaceEventNotification faceEvent(blk);
186
187 BOOST_CHECK_EQUAL(faceEvent.getEventKind(), expectedKind);
188 BOOST_CHECK_EQUAL(faceEvent.getFaceId(), expectedFaceId);
189 BOOST_CHECK_EQUAL(faceEvent.getUri(), expectedUri);
190 }
191}
192
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -0700193BOOST_AUTO_TEST_CASE(FaceStatusEncodingDecoding)
194{
195 {
196 FaceStatus faceStatus(100, "tcp4://127.0.0.1:6363", 10, 20, 30, 400);
197 BOOST_REQUIRE_NO_THROW(faceStatus.wireEncode());
198
199 BOOST_CHECK_EQUAL_COLLECTIONS(TestFaceStatus,
200 TestFaceStatus + sizeof(TestFaceStatus),
201 faceStatus.wireEncode().begin(), faceStatus.wireEncode().end());
202
203 std::ostringstream os;
204 os << faceStatus;
205 BOOST_CHECK_EQUAL(os.str(), "FaceStatus(FaceID: 100, Uri: tcp4://127.0.0.1:6363, "
206 "Counters: 10|20|30|400)");
207 }
208
209 {
210 Block block(TestFaceStatus, sizeof(TestFaceStatus));
211 BOOST_REQUIRE_NO_THROW((FaceStatus(block)));
212
213 FaceStatus faceStatus(block);
214
215 BOOST_CHECK_EQUAL(faceStatus.getFaceId(), 100);
216 BOOST_CHECK_EQUAL(faceStatus.getUri(), "tcp4://127.0.0.1:6363");
217
218 BOOST_CHECK_EQUAL(faceStatus.getInInterest(), 10);
219 BOOST_CHECK_EQUAL(faceStatus.getInData(), 20);
220 BOOST_CHECK_EQUAL(faceStatus.getOutInterest(), 30);
221 BOOST_CHECK_EQUAL(faceStatus.getOutData(), 400);
222 }
223}
224
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800225BOOST_AUTO_TEST_SUITE_END()
226
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800227} // namespace nfd
Alexander Afanasyeveaf105c2014-01-30 17:40:24 -0800228} // namespace ndn