Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 7 | #include "management/nfd-control-response.hpp" |
| 8 | #include "management/nfd-fib-management-options.hpp" |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 9 | #include "management/nfd-face-management-options.hpp" |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame^] | 10 | #include "management/nfd-face-event-notification.hpp" |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 11 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 12 | #include <boost/test/unit_test.hpp> |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 13 | #include <boost/test/output_test_stream.hpp> |
| 14 | |
| 15 | using namespace std; |
| 16 | |
| 17 | namespace ndn { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 18 | namespace nfd { |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 19 | |
| 20 | BOOST_AUTO_TEST_SUITE(TestNfdControl) |
| 21 | |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 22 | const uint8_t TestControlResponse[] = {0x65, 0x17, |
| 23 | 0x66, 0x02, 0x01, 0x94, 0x67, 0x11, 0x4e, 0x6f, 0x74, |
| 24 | 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x6f, 0x74, 0x20, |
| 25 | 0x66, 0x6f, 0x75, 0x6e, 0x64}; |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 26 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 27 | const uint8_t TestFibManagementOptions[] = { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 28 | 0x68, 0x49, 0x07, 0x16, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 29 | 0x6f, 0x73, 0x74, 0x08, 0x03, 0x72, 0x65, 0x67, 0x08, 0x04, 0x74, 0x65, |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 30 | 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x01, 0x6b, 0x29, 0x07, 0x27, |
| 31 | 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x08, |
| 32 | 0x03, 0x6e, 0x66, 0x64, 0x08, 0x08, 0x73, 0x74, 0x72, 0x61, 0x74, 0x65, |
| 33 | 0x67, 0x79, 0x08, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2d, 0x77, 0x6f, |
| 34 | 0x72, 0x6c, 0x64 |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 35 | }; |
| 36 | |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 37 | const uint8_t TestFaceManagementOptions[] = { |
| 38 | 0x6c, 0x1e, 0x69, 0x01, 0x0a, 0x72, 0x19, 0x74, 0x63, 0x70, 0x3a, 0x2f, |
| 39 | 0x2f, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2f, 0x68, 0x65, 0x6c, |
| 40 | 0x6c, 0x6f, 0x2f, 0x77, 0x6f, 0x72, 0x6c, 0x64 |
| 41 | }; |
| 42 | |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame^] | 43 | const uint8_t TestFaceEventNotification[] = { |
| 44 | 0xc0, 0x1d, 0xc1, 0x01, 0x01, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, |
| 45 | 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, |
| 46 | 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33 |
| 47 | }; |
| 48 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 49 | // ControlResponse |
| 50 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 51 | BOOST_AUTO_TEST_CASE(ControlResponseEncode) |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 52 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 53 | ControlResponse controlResponse(404, "Nothing not found"); |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 54 | const Block &wire = controlResponse.wireEncode(); |
| 55 | |
| 56 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse), |
| 57 | wire.begin(), wire.end()); |
| 58 | } |
| 59 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 60 | BOOST_AUTO_TEST_CASE(ControlResponseDecode) |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 61 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 62 | ControlResponse controlResponse; |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 63 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 64 | BOOST_REQUIRE_NO_THROW(controlResponse.wireDecode(Block(TestControlResponse, sizeof(TestControlResponse)))); |
| 65 | |
| 66 | BOOST_REQUIRE_EQUAL(controlResponse.getCode(), 404); |
| 67 | BOOST_REQUIRE_EQUAL(controlResponse.getText(), "Nothing not found"); |
| 68 | } |
| 69 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 70 | // FibManagementOptions |
| 71 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 72 | BOOST_AUTO_TEST_CASE(FibManagementOptionsEncoding) |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 73 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 74 | Name n("/localhost/reg/test"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 75 | FibManagementOptions opt; |
| 76 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 77 | opt.setName(n); |
| 78 | opt.setFaceId(0); |
| 79 | opt.setCost(1); |
| 80 | opt.setStrategy("/localhost/nfd/strategy/hello-world"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 81 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 82 | const Block& blk = opt.wireEncode(); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 83 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 84 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions, |
| 85 | TestFibManagementOptions + sizeof(TestFibManagementOptions), |
| 86 | blk.begin(), blk.end()); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 89 | BOOST_AUTO_TEST_CASE(FibManagementOptionsFastEncoding) |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 90 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 91 | Name n("/localhost/reg/test"); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 92 | FibManagementOptions opt; |
| 93 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 94 | opt.setName(n); |
| 95 | opt.setFaceId(0); |
| 96 | opt.setCost(1); |
| 97 | opt.setStrategy("/localhost/nfd/strategy/hello-world"); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 98 | |
| 99 | EncodingBuffer blk; |
| 100 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 101 | BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk)); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 102 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 103 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions, |
| 104 | TestFibManagementOptions + sizeof(TestFibManagementOptions), |
| 105 | blk.begin(), blk.end()); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 106 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 107 | EncodingBuffer blk2(4); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 108 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 109 | BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk2)); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 110 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 111 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions, |
| 112 | TestFibManagementOptions + sizeof(TestFibManagementOptions), |
| 113 | blk2.begin(), blk2.end()); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 116 | BOOST_AUTO_TEST_CASE(FibManagementOptionsDecoding) |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 117 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 118 | Block blk(TestFibManagementOptions, sizeof(TestFibManagementOptions)); |
| 119 | Name n("/localhost/reg/test"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 120 | FibManagementOptions opt; |
| 121 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 122 | BOOST_REQUIRE_NO_THROW(opt.wireDecode(blk)); |
| 123 | |
| 124 | BOOST_CHECK_EQUAL(opt.getName(), n); |
| 125 | BOOST_CHECK_EQUAL(opt.getFaceId(), 0); |
| 126 | BOOST_CHECK_EQUAL(opt.getCost(), 1); |
| 127 | BOOST_CHECK_EQUAL(opt.getStrategy().toUri(), "/localhost/nfd/strategy/hello-world"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 130 | BOOST_AUTO_TEST_CASE(FaceManagementOptionsFastEncoding) |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 131 | { |
| 132 | FaceManagementOptions opt; |
| 133 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 134 | opt.setFaceId(10); |
| 135 | opt.setUri("tcp://1.1.1.1/hello/world"); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 136 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 137 | BOOST_REQUIRE_NO_THROW(opt.wireEncode ()); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 138 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 139 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFaceManagementOptions, |
| 140 | TestFaceManagementOptions + sizeof(TestFaceManagementOptions), |
| 141 | opt.wireEncode().begin(), opt.wireEncode().end()); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 144 | BOOST_AUTO_TEST_CASE(FaceManagementOptionsDecoding) |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 145 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 146 | Block blk(TestFaceManagementOptions, sizeof(TestFaceManagementOptions)); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 147 | FaceManagementOptions opt; |
| 148 | |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame^] | 149 | BOOST_REQUIRE_NO_THROW(opt.wireDecode(blk)); |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 150 | |
| 151 | BOOST_CHECK_EQUAL(opt.getFaceId(), 10); |
| 152 | BOOST_CHECK_EQUAL(opt.getUri(), "tcp://1.1.1.1/hello/world"); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 153 | } |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 154 | |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame^] | 155 | |
| 156 | BOOST_AUTO_TEST_CASE(FaceEventNotificationEncodingDecoding) |
| 157 | { |
| 158 | FaceEventKind expectedKind = FACE_EVENT_CREATED; |
| 159 | std::string expectedUri("tcp4://127.0.0.1:6363"); |
| 160 | uint64_t expectedFaceId = 100; |
| 161 | |
| 162 | { |
| 163 | FaceEventNotification faceEvent(expectedKind, expectedFaceId, expectedUri); |
| 164 | BOOST_REQUIRE_NO_THROW(faceEvent.wireEncode()); |
| 165 | |
| 166 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFaceEventNotification, |
| 167 | TestFaceEventNotification + sizeof(TestFaceEventNotification), |
| 168 | faceEvent.wireEncode().begin(), faceEvent.wireEncode().end()); |
| 169 | |
| 170 | std::ostringstream os; |
| 171 | os << faceEvent; |
| 172 | BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification(Kind: created, FaceID: 100, Uri: tcp4://127.0.0.1:6363)"); |
| 173 | } |
| 174 | |
| 175 | { |
| 176 | Block blk(TestFaceEventNotification, sizeof(TestFaceEventNotification)); |
| 177 | FaceEventNotification faceEvent(blk); |
| 178 | |
| 179 | BOOST_CHECK_EQUAL(faceEvent.getEventKind(), expectedKind); |
| 180 | BOOST_CHECK_EQUAL(faceEvent.getFaceId(), expectedFaceId); |
| 181 | BOOST_CHECK_EQUAL(faceEvent.getUri(), expectedUri); |
| 182 | } |
| 183 | } |
| 184 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 185 | BOOST_AUTO_TEST_SUITE_END() |
| 186 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 187 | } // namespace nfd |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 188 | } // namespace ndn |