Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 2 | /** |
Eric Newberry | d7f5b28 | 2017-03-28 19:55:20 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 22 | #include "mgmt/nfd/control-parameters.hpp" |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 24 | #include "boost-test.hpp" |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace nfd { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 28 | namespace tests { |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 29 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 30 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 31 | BOOST_AUTO_TEST_SUITE(Nfd) |
| 32 | BOOST_AUTO_TEST_SUITE(TestControlParameters) |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 33 | |
| 34 | BOOST_AUTO_TEST_CASE(FaceOptions) |
| 35 | { |
| 36 | ControlParameters parameters; |
| 37 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Eric Newberry | d7f5b28 | 2017-03-28 19:55:20 -0700 | [diff] [blame] | 38 | parameters.setLocalUri("dev://eth0"); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 39 | parameters.setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 40 | parameters.setFlags(1); |
| 41 | parameters.setMask(1); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 42 | Block wire = parameters.wireEncode(); |
| 43 | |
| 44 | ControlParameters decoded(wire); |
| 45 | BOOST_CHECK_EQUAL(decoded.getUri(), "tcp4://192.0.2.1:6363"); |
Eric Newberry | d7f5b28 | 2017-03-28 19:55:20 -0700 | [diff] [blame] | 46 | BOOST_CHECK_EQUAL(decoded.getLocalUri(), "dev://eth0"); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 47 | BOOST_CHECK_EQUAL(decoded.getFacePersistency(), ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 48 | BOOST_CHECK_EQUAL(decoded.getFlags(), 1); |
| 49 | BOOST_CHECK_EQUAL(decoded.getMask(), 1); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 50 | |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 51 | BOOST_CHECK_EQUAL(decoded.hasName(), false); |
| 52 | BOOST_CHECK_EQUAL(decoded.hasFaceId(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 53 | BOOST_CHECK_EQUAL(decoded.hasOrigin(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 54 | BOOST_CHECK_EQUAL(decoded.hasCost(), false); |
| 55 | BOOST_CHECK_EQUAL(decoded.hasStrategy(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 56 | BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 59 | BOOST_AUTO_TEST_CASE(FibOptions) |
| 60 | { |
| 61 | ControlParameters parameters; |
| 62 | parameters.setName("ndn:/example") |
| 63 | .setFaceId(4) |
| 64 | .setCost(555); |
| 65 | |
| 66 | Block wire = parameters.wireEncode(); |
| 67 | |
| 68 | ControlParameters decoded(wire); |
| 69 | BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/example")); |
| 70 | BOOST_CHECK_EQUAL(decoded.getFaceId(), 4); |
| 71 | BOOST_CHECK_EQUAL(decoded.getCost(), 555); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 72 | |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 73 | BOOST_CHECK_EQUAL(decoded.hasUri(), false); |
Eric Newberry | d7f5b28 | 2017-03-28 19:55:20 -0700 | [diff] [blame] | 74 | BOOST_CHECK_EQUAL(decoded.hasLocalUri(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 75 | BOOST_CHECK_EQUAL(decoded.hasOrigin(), false); |
| 76 | BOOST_CHECK_EQUAL(decoded.hasFlags(), false); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 77 | BOOST_CHECK_EQUAL(decoded.hasMask(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 78 | BOOST_CHECK_EQUAL(decoded.hasStrategy(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 79 | BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 80 | BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | BOOST_AUTO_TEST_CASE(StrategyChoiceOptions) |
| 84 | { |
| 85 | ControlParameters parameters; |
| 86 | parameters.setName("ndn:/") |
| 87 | .setStrategy("ndn:/strategy/A"); |
| 88 | |
| 89 | Block wire = parameters.wireEncode(); |
| 90 | |
| 91 | ControlParameters decoded(wire); |
| 92 | BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/")); |
| 93 | BOOST_CHECK_EQUAL(decoded.getStrategy(), Name("ndn:/strategy/A")); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 94 | |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 95 | BOOST_CHECK_EQUAL(decoded.hasFaceId(), false); |
| 96 | BOOST_CHECK_EQUAL(decoded.hasUri(), false); |
Eric Newberry | d7f5b28 | 2017-03-28 19:55:20 -0700 | [diff] [blame] | 97 | BOOST_CHECK_EQUAL(decoded.hasLocalUri(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 98 | BOOST_CHECK_EQUAL(decoded.hasOrigin(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 99 | BOOST_CHECK_EQUAL(decoded.hasCost(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 100 | BOOST_CHECK_EQUAL(decoded.hasFlags(), false); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 101 | BOOST_CHECK_EQUAL(decoded.hasMask(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 102 | BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 103 | BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | BOOST_AUTO_TEST_CASE(RibOptions) |
| 107 | { |
| 108 | ControlParameters parameters; |
| 109 | parameters.setName("ndn:/example") |
| 110 | .setFaceId(4) |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 111 | .setOrigin(ROUTE_ORIGIN_NLSR) |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 112 | .setCost(6) |
| 113 | .setFlags(0x01) |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 114 | .setExpirationPeriod(time::minutes(30)); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 115 | |
| 116 | Block wire = parameters.wireEncode(); |
| 117 | |
| 118 | ControlParameters decoded(wire); |
| 119 | BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/example")); |
| 120 | BOOST_CHECK_EQUAL(decoded.getFaceId(), 4); |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 121 | BOOST_CHECK_EQUAL(decoded.getOrigin(), ROUTE_ORIGIN_NLSR); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 122 | BOOST_CHECK_EQUAL(decoded.getCost(), 6); |
| 123 | BOOST_CHECK_EQUAL(decoded.getFlags(), 0x01); |
| 124 | BOOST_CHECK_EQUAL(decoded.getExpirationPeriod(), time::milliseconds(1800000)); |
| 125 | |
| 126 | BOOST_CHECK_EQUAL(decoded.hasUri(), false); |
Eric Newberry | d7f5b28 | 2017-03-28 19:55:20 -0700 | [diff] [blame] | 127 | BOOST_CHECK_EQUAL(decoded.hasLocalUri(), false); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 128 | BOOST_CHECK_EQUAL(decoded.hasMask(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 129 | BOOST_CHECK_EQUAL(decoded.hasStrategy(), false); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 130 | BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 133 | BOOST_AUTO_TEST_CASE(FlagsAndMask) |
| 134 | { |
| 135 | ControlParameters p; |
| 136 | |
| 137 | BOOST_CHECK(!p.hasFlags()); |
| 138 | BOOST_CHECK(!p.hasMask()); |
| 139 | BOOST_CHECK(!p.hasFlagBit(0)); |
| 140 | BOOST_CHECK(!p.getFlagBit(0)); |
| 141 | |
| 142 | // Set bit 2 to true (change Mask) |
| 143 | p.setFlagBit(2, true); |
| 144 | // 2^2 = 4 |
| 145 | BOOST_CHECK_EQUAL(p.getFlags(), 4); |
| 146 | BOOST_CHECK_EQUAL(p.getMask(), 4); |
| 147 | BOOST_CHECK(p.hasFlagBit(2)); |
| 148 | BOOST_CHECK(p.getFlagBit(2)); |
| 149 | BOOST_CHECK(!p.hasFlagBit(1)); |
| 150 | BOOST_CHECK(!p.getFlagBit(1)); |
| 151 | |
| 152 | // Set bit 3 to true (no change to Mask) |
| 153 | p.setFlagBit(3, true, false); |
| 154 | // 2^3 + 2^2 = 12 |
| 155 | BOOST_CHECK_EQUAL(p.getFlags(), 12); |
| 156 | // 2^2 = 4 |
| 157 | BOOST_CHECK_EQUAL(p.getMask(), 4); |
| 158 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 159 | BOOST_CHECK(p.getFlagBit(3)); |
| 160 | BOOST_CHECK(p.hasFlagBit(2)); |
| 161 | BOOST_CHECK(p.getFlagBit(2)); |
| 162 | |
| 163 | // Set bit 1 to false (change Mask) |
| 164 | p.setFlagBit(1, false); |
| 165 | // 2^3 + 2^2 = 12 |
| 166 | BOOST_CHECK_EQUAL(p.getFlags(), 12); |
| 167 | // 2^2 + 2^1 = 6 |
| 168 | BOOST_CHECK_EQUAL(p.getMask(), 6); |
| 169 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 170 | BOOST_CHECK(p.getFlagBit(3)); |
| 171 | BOOST_CHECK(p.hasFlagBit(2)); |
| 172 | BOOST_CHECK(p.getFlagBit(2)); |
| 173 | BOOST_CHECK(p.hasFlagBit(1)); |
| 174 | BOOST_CHECK(!p.getFlagBit(1)); |
| 175 | |
| 176 | // Set bit 2 to false (change Mask) |
| 177 | p.setFlagBit(2, false); |
| 178 | // 2^3 = 8 |
| 179 | BOOST_CHECK_EQUAL(p.getFlags(), 8); |
| 180 | // 2^2 + 2^1 = 6 |
| 181 | BOOST_CHECK_EQUAL(p.getMask(), 6); |
| 182 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 183 | BOOST_CHECK(p.getFlagBit(3)); |
| 184 | BOOST_CHECK(p.hasFlagBit(2)); |
| 185 | BOOST_CHECK(!p.getFlagBit(2)); |
| 186 | BOOST_CHECK(p.hasFlagBit(1)); |
| 187 | BOOST_CHECK(!p.getFlagBit(1)); |
| 188 | |
| 189 | // Set bit 0 to true (change Mask) |
| 190 | p.setFlagBit(0, true); |
| 191 | // 2^3 + 2^0 = 9 |
| 192 | BOOST_CHECK_EQUAL(p.getFlags(), 9); |
| 193 | // 2^2 + 2^1 + 2^0 = 7 |
| 194 | BOOST_CHECK_EQUAL(p.getMask(), 7); |
| 195 | BOOST_CHECK(p.hasFlagBit(0)); |
| 196 | BOOST_CHECK(p.getFlagBit(0)); |
| 197 | |
| 198 | // Unset bit 0 |
| 199 | p.unsetFlagBit(0); |
| 200 | BOOST_REQUIRE(p.hasFlags()); |
| 201 | BOOST_REQUIRE(p.hasMask()); |
| 202 | // 2^3 + 2^0 = 9 |
| 203 | BOOST_CHECK_EQUAL(p.getFlags(), 9); |
| 204 | // 2^2 + 2^1 = 6 |
| 205 | BOOST_CHECK_EQUAL(p.getMask(), 6); |
| 206 | BOOST_CHECK(p.hasFlagBit(1)); |
| 207 | BOOST_CHECK(!p.hasFlagBit(0)); |
| 208 | BOOST_CHECK(p.getFlagBit(0)); |
| 209 | |
| 210 | // Unset bit 3 (already unset in Mask, so no change) |
| 211 | p.unsetFlagBit(3); |
| 212 | BOOST_REQUIRE(p.hasFlags()); |
| 213 | BOOST_REQUIRE(p.hasMask()); |
| 214 | // 2^3 + 2^0 = 9 |
| 215 | BOOST_CHECK_EQUAL(p.getFlags(), 9); |
| 216 | // 2^2 + 2^1 = 6 |
| 217 | BOOST_CHECK_EQUAL(p.getMask(), 6); |
| 218 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 219 | BOOST_CHECK(p.getFlagBit(3)); |
| 220 | |
| 221 | // Unset bit 2 |
| 222 | p.unsetFlagBit(2); |
| 223 | BOOST_REQUIRE(p.hasFlags()); |
| 224 | BOOST_REQUIRE(p.hasMask()); |
| 225 | // 2^3 + 2^0 = 9 |
| 226 | BOOST_CHECK_EQUAL(p.getFlags(), 9); |
| 227 | // 2^1 = 2 |
| 228 | BOOST_CHECK_EQUAL(p.getMask(), 2); |
| 229 | BOOST_CHECK(!p.hasFlagBit(2)); |
| 230 | BOOST_CHECK(!p.getFlagBit(2)); |
| 231 | |
| 232 | // Unset bit 1 |
| 233 | // Flags and Mask fields will be deleted as Mask is now 0 |
| 234 | p.unsetFlagBit(1); |
| 235 | BOOST_CHECK(!p.hasFlags()); |
| 236 | BOOST_CHECK(!p.hasMask()); |
| 237 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 238 | BOOST_CHECK(!p.getFlagBit(3)); |
| 239 | BOOST_CHECK(!p.hasFlagBit(2)); |
| 240 | BOOST_CHECK(!p.getFlagBit(2)); |
| 241 | BOOST_CHECK(!p.hasFlagBit(1)); |
| 242 | BOOST_CHECK(!p.getFlagBit(1)); |
| 243 | BOOST_CHECK(!p.hasFlagBit(0)); |
| 244 | BOOST_CHECK(!p.getFlagBit(0)); |
| 245 | |
| 246 | BOOST_CHECK_THROW(p.setFlagBit(64, true), std::out_of_range); |
| 247 | BOOST_CHECK_THROW(p.unsetFlagBit(64), std::out_of_range); |
| 248 | } |
| 249 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 250 | BOOST_AUTO_TEST_SUITE_END() // TestControlParameters |
| 251 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 252 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 253 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 254 | } // namespace tests |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 255 | } // namespace nfd |
| 256 | } // namespace ndn |