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 | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 11 | #include "management/nfd-face-status.hpp" |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 12 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 13 | #include <boost/test/unit_test.hpp> |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 14 | #include <boost/test/output_test_stream.hpp> |
| 15 | |
| 16 | using namespace std; |
| 17 | |
| 18 | namespace ndn { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 19 | namespace nfd { |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 20 | |
| 21 | BOOST_AUTO_TEST_SUITE(TestNfdControl) |
| 22 | |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 23 | const 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 Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 27 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 28 | const uint8_t TestFibManagementOptions[] = { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 29 | 0x68, 0x49, 0x07, 0x16, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 30 | 0x6f, 0x73, 0x74, 0x08, 0x03, 0x72, 0x65, 0x67, 0x08, 0x04, 0x74, 0x65, |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 31 | 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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 36 | }; |
| 37 | |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 38 | const 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 Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 44 | const uint8_t TestFaceEventNotification[] = { |
Alexander Afanasyev | 2c75331 | 2014-03-20 17:31:01 -0700 | [diff] [blame] | 45 | 0xc0, 0x20, 0xc1, 0x01, 0x01, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 46 | 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, |
Alexander Afanasyev | 2c75331 | 2014-03-20 17:31:01 -0700 | [diff] [blame] | 47 | 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33, 0xc2, 0x01, 0x03 |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
Alexander Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 50 | const 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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 57 | // ControlResponse |
| 58 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 59 | BOOST_AUTO_TEST_CASE(ControlResponseEncode) |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 60 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 61 | ControlResponse controlResponse(404, "Nothing not found"); |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 62 | const Block &wire = controlResponse.wireEncode(); |
| 63 | |
| 64 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse), |
| 65 | wire.begin(), wire.end()); |
| 66 | } |
| 67 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 68 | BOOST_AUTO_TEST_CASE(ControlResponseDecode) |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 69 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 70 | ControlResponse controlResponse; |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 71 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 72 | 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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 78 | // FibManagementOptions |
| 79 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 80 | BOOST_AUTO_TEST_CASE(FibManagementOptionsEncoding) |
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 | Name n("/localhost/reg/test"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 83 | FibManagementOptions opt; |
| 84 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 85 | opt.setName(n); |
| 86 | opt.setFaceId(0); |
| 87 | opt.setCost(1); |
| 88 | opt.setStrategy("/localhost/nfd/strategy/hello-world"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 89 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 90 | const Block& blk = opt.wireEncode(); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 91 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 92 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions, |
| 93 | TestFibManagementOptions + sizeof(TestFibManagementOptions), |
| 94 | blk.begin(), blk.end()); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 97 | BOOST_AUTO_TEST_CASE(FibManagementOptionsFastEncoding) |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 98 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 99 | Name n("/localhost/reg/test"); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 100 | FibManagementOptions opt; |
| 101 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 102 | opt.setName(n); |
| 103 | opt.setFaceId(0); |
| 104 | opt.setCost(1); |
| 105 | opt.setStrategy("/localhost/nfd/strategy/hello-world"); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 106 | |
| 107 | EncodingBuffer blk; |
| 108 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 109 | BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk)); |
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 | blk.begin(), blk.end()); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 114 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 115 | EncodingBuffer blk2(4); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 116 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 117 | BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk2)); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 118 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 119 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions, |
| 120 | TestFibManagementOptions + sizeof(TestFibManagementOptions), |
| 121 | blk2.begin(), blk2.end()); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 124 | BOOST_AUTO_TEST_CASE(FibManagementOptionsDecoding) |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 125 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 126 | Block blk(TestFibManagementOptions, sizeof(TestFibManagementOptions)); |
| 127 | Name n("/localhost/reg/test"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 128 | FibManagementOptions opt; |
| 129 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 130 | 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 Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 136 | } |
| 137 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 138 | BOOST_AUTO_TEST_CASE(FaceManagementOptionsFastEncoding) |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 139 | { |
| 140 | FaceManagementOptions opt; |
| 141 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 142 | opt.setFaceId(10); |
| 143 | opt.setUri("tcp://1.1.1.1/hello/world"); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 144 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 145 | BOOST_REQUIRE_NO_THROW(opt.wireEncode ()); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 146 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 147 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFaceManagementOptions, |
| 148 | TestFaceManagementOptions + sizeof(TestFaceManagementOptions), |
| 149 | opt.wireEncode().begin(), opt.wireEncode().end()); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 152 | BOOST_AUTO_TEST_CASE(FaceManagementOptionsDecoding) |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 153 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 154 | Block blk(TestFaceManagementOptions, sizeof(TestFaceManagementOptions)); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 155 | FaceManagementOptions opt; |
| 156 | |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 157 | BOOST_REQUIRE_NO_THROW(opt.wireDecode(blk)); |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 158 | |
| 159 | BOOST_CHECK_EQUAL(opt.getFaceId(), 10); |
| 160 | BOOST_CHECK_EQUAL(opt.getUri(), "tcp://1.1.1.1/hello/world"); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 161 | } |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 162 | |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 163 | |
| 164 | BOOST_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; |
Alexander Afanasyev | 2c75331 | 2014-03-20 17:31:01 -0700 | [diff] [blame] | 169 | uint64_t expectedFlags = 3; |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 170 | |
| 171 | { |
Alexander Afanasyev | 2c75331 | 2014-03-20 17:31:01 -0700 | [diff] [blame] | 172 | FaceEventNotification faceEvent(expectedKind, expectedFaceId, expectedUri, expectedFlags); |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 173 | BOOST_REQUIRE_NO_THROW(faceEvent.wireEncode()); |
| 174 | |
| 175 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFaceEventNotification, |
| 176 | TestFaceEventNotification + sizeof(TestFaceEventNotification), |
| 177 | faceEvent.wireEncode().begin(), faceEvent.wireEncode().end()); |
| 178 | |
| 179 | std::ostringstream os; |
| 180 | os << faceEvent; |
Alexander Afanasyev | 2c75331 | 2014-03-20 17:31:01 -0700 | [diff] [blame] | 181 | BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification(Kind: created, FaceID: 100, Uri: tcp4://127.0.0.1:6363, Flags: 3)"); |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | { |
| 185 | Block blk(TestFaceEventNotification, sizeof(TestFaceEventNotification)); |
| 186 | FaceEventNotification faceEvent(blk); |
| 187 | |
| 188 | BOOST_CHECK_EQUAL(faceEvent.getEventKind(), expectedKind); |
| 189 | BOOST_CHECK_EQUAL(faceEvent.getFaceId(), expectedFaceId); |
| 190 | BOOST_CHECK_EQUAL(faceEvent.getUri(), expectedUri); |
Alexander Afanasyev | 2c75331 | 2014-03-20 17:31:01 -0700 | [diff] [blame] | 191 | BOOST_CHECK_EQUAL(faceEvent.getFlags(), expectedFlags); |
| 192 | BOOST_CHECK(faceEvent.isLocal()); |
| 193 | BOOST_CHECK(faceEvent.isOnDemand()); |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Alexander Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 197 | BOOST_AUTO_TEST_CASE(FaceStatusEncodingDecoding) |
| 198 | { |
| 199 | { |
| 200 | FaceStatus faceStatus(100, "tcp4://127.0.0.1:6363", 10, 20, 30, 400); |
| 201 | BOOST_REQUIRE_NO_THROW(faceStatus.wireEncode()); |
| 202 | |
| 203 | BOOST_CHECK_EQUAL_COLLECTIONS(TestFaceStatus, |
| 204 | TestFaceStatus + sizeof(TestFaceStatus), |
| 205 | faceStatus.wireEncode().begin(), faceStatus.wireEncode().end()); |
| 206 | |
| 207 | std::ostringstream os; |
| 208 | os << faceStatus; |
| 209 | BOOST_CHECK_EQUAL(os.str(), "FaceStatus(FaceID: 100, Uri: tcp4://127.0.0.1:6363, " |
| 210 | "Counters: 10|20|30|400)"); |
| 211 | } |
| 212 | |
| 213 | { |
| 214 | Block block(TestFaceStatus, sizeof(TestFaceStatus)); |
| 215 | BOOST_REQUIRE_NO_THROW((FaceStatus(block))); |
| 216 | |
| 217 | FaceStatus faceStatus(block); |
| 218 | |
| 219 | BOOST_CHECK_EQUAL(faceStatus.getFaceId(), 100); |
| 220 | BOOST_CHECK_EQUAL(faceStatus.getUri(), "tcp4://127.0.0.1:6363"); |
| 221 | |
| 222 | BOOST_CHECK_EQUAL(faceStatus.getInInterest(), 10); |
| 223 | BOOST_CHECK_EQUAL(faceStatus.getInData(), 20); |
| 224 | BOOST_CHECK_EQUAL(faceStatus.getOutInterest(), 30); |
| 225 | BOOST_CHECK_EQUAL(faceStatus.getOutData(), 400); |
| 226 | } |
| 227 | } |
| 228 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 229 | BOOST_AUTO_TEST_SUITE_END() |
| 230 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 231 | } // namespace nfd |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 232 | } // namespace ndn |