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 | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 10 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 11 | #include "boost-test.hpp" |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 12 | |
| 13 | namespace ndn { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 14 | namespace nfd { |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 15 | |
| 16 | BOOST_AUTO_TEST_SUITE(TestNfdControl) |
| 17 | |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 18 | const uint8_t TestControlResponse[] = {0x65, 0x17, |
| 19 | 0x66, 0x02, 0x01, 0x94, 0x67, 0x11, 0x4e, 0x6f, 0x74, |
| 20 | 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x6f, 0x74, 0x20, |
| 21 | 0x66, 0x6f, 0x75, 0x6e, 0x64}; |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 22 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 23 | const uint8_t TestFibManagementOptions[] = { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 24 | 0x68, 0x49, 0x07, 0x16, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 25 | 0x6f, 0x73, 0x74, 0x08, 0x03, 0x72, 0x65, 0x67, 0x08, 0x04, 0x74, 0x65, |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 26 | 0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x01, 0x6b, 0x29, 0x07, 0x27, |
| 27 | 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x08, |
| 28 | 0x03, 0x6e, 0x66, 0x64, 0x08, 0x08, 0x73, 0x74, 0x72, 0x61, 0x74, 0x65, |
| 29 | 0x67, 0x79, 0x08, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2d, 0x77, 0x6f, |
| 30 | 0x72, 0x6c, 0x64 |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 31 | }; |
| 32 | |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 33 | const uint8_t TestFaceManagementOptions[] = { |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 34 | 0x68, 0x1e, 0x69, 0x01, 0x0a, 0x72, 0x19, 0x74, 0x63, 0x70, 0x3a, 0x2f, |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 35 | 0x2f, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2e, 0x31, 0x2f, 0x68, 0x65, 0x6c, |
| 36 | 0x6c, 0x6f, 0x2f, 0x77, 0x6f, 0x72, 0x6c, 0x64 |
| 37 | }; |
| 38 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 39 | // ControlResponse |
| 40 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 41 | BOOST_AUTO_TEST_CASE(ControlResponseEncode) |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 42 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 43 | ControlResponse controlResponse(404, "Nothing not found"); |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 44 | const Block &wire = controlResponse.wireEncode(); |
| 45 | |
| 46 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestControlResponse, TestControlResponse+sizeof(TestControlResponse), |
| 47 | wire.begin(), wire.end()); |
| 48 | } |
| 49 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 50 | BOOST_AUTO_TEST_CASE(ControlResponseDecode) |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 51 | { |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 52 | ControlResponse controlResponse; |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 53 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 54 | BOOST_REQUIRE_NO_THROW(controlResponse.wireDecode(Block(TestControlResponse, sizeof(TestControlResponse)))); |
| 55 | |
| 56 | BOOST_REQUIRE_EQUAL(controlResponse.getCode(), 404); |
| 57 | BOOST_REQUIRE_EQUAL(controlResponse.getText(), "Nothing not found"); |
| 58 | } |
| 59 | |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 60 | // FibManagementOptions |
| 61 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 62 | BOOST_AUTO_TEST_CASE(FibManagementOptionsEncoding) |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 63 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 64 | Name n("/localhost/reg/test"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 65 | FibManagementOptions opt; |
| 66 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 67 | opt.setName(n); |
| 68 | opt.setFaceId(0); |
| 69 | opt.setCost(1); |
| 70 | opt.setStrategy("/localhost/nfd/strategy/hello-world"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 71 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 72 | const Block& blk = opt.wireEncode(); |
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 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions, |
| 75 | TestFibManagementOptions + sizeof(TestFibManagementOptions), |
| 76 | blk.begin(), blk.end()); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 79 | BOOST_AUTO_TEST_CASE(FibManagementOptionsFastEncoding) |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 80 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 81 | Name n("/localhost/reg/test"); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 82 | FibManagementOptions opt; |
| 83 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 84 | opt.setName(n); |
| 85 | opt.setFaceId(0); |
| 86 | opt.setCost(1); |
| 87 | opt.setStrategy("/localhost/nfd/strategy/hello-world"); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 88 | |
| 89 | EncodingBuffer blk; |
| 90 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 91 | BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk)); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 92 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 93 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions, |
| 94 | TestFibManagementOptions + sizeof(TestFibManagementOptions), |
| 95 | blk.begin(), blk.end()); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 96 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 97 | EncodingBuffer blk2(4); |
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 | BOOST_REQUIRE_NO_THROW(opt.wireEncode(blk2)); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 100 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 101 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibManagementOptions, |
| 102 | TestFibManagementOptions + sizeof(TestFibManagementOptions), |
| 103 | blk2.begin(), blk2.end()); |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 106 | BOOST_AUTO_TEST_CASE(FibManagementOptionsDecoding) |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 107 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 108 | Block blk(TestFibManagementOptions, sizeof(TestFibManagementOptions)); |
| 109 | Name n("/localhost/reg/test"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 110 | FibManagementOptions opt; |
| 111 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 112 | BOOST_REQUIRE_NO_THROW(opt.wireDecode(blk)); |
| 113 | |
| 114 | BOOST_CHECK_EQUAL(opt.getName(), n); |
| 115 | BOOST_CHECK_EQUAL(opt.getFaceId(), 0); |
| 116 | BOOST_CHECK_EQUAL(opt.getCost(), 1); |
| 117 | BOOST_CHECK_EQUAL(opt.getStrategy().toUri(), "/localhost/nfd/strategy/hello-world"); |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 120 | BOOST_AUTO_TEST_CASE(FaceManagementOptionsFastEncoding) |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 121 | { |
| 122 | FaceManagementOptions opt; |
| 123 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 124 | opt.setFaceId(10); |
| 125 | opt.setUri("tcp://1.1.1.1/hello/world"); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 126 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 127 | BOOST_REQUIRE_NO_THROW(opt.wireEncode ()); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 128 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 129 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFaceManagementOptions, |
| 130 | TestFaceManagementOptions + sizeof(TestFaceManagementOptions), |
| 131 | opt.wireEncode().begin(), opt.wireEncode().end()); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 134 | BOOST_AUTO_TEST_CASE(FaceManagementOptionsDecoding) |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 135 | { |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 136 | Block blk(TestFaceManagementOptions, sizeof(TestFaceManagementOptions)); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 137 | FaceManagementOptions opt; |
| 138 | |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 139 | BOOST_REQUIRE_NO_THROW(opt.wireDecode(blk)); |
Alexander Afanasyev | c5ad119 | 2014-02-25 14:17:47 -0800 | [diff] [blame] | 140 | |
| 141 | BOOST_CHECK_EQUAL(opt.getFaceId(), 10); |
| 142 | BOOST_CHECK_EQUAL(opt.getUri(), "tcp://1.1.1.1/hello/world"); |
Yingdi Yu | d337049 | 2014-02-12 17:17:11 -0800 | [diff] [blame] | 143 | } |
Wentao Shang | 4d5e1de | 2014-01-28 21:00:03 -0800 | [diff] [blame] | 144 | |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 145 | |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 146 | BOOST_AUTO_TEST_SUITE_END() |
| 147 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 148 | } // namespace nfd |
Alexander Afanasyev | eaf105c | 2014-01-30 17:40:24 -0800 | [diff] [blame] | 149 | } // namespace ndn |