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 | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 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"); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 38 | parameters.setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 39 | parameters.setFlags(1); |
| 40 | parameters.setMask(1); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 41 | Block wire = parameters.wireEncode(); |
| 42 | |
| 43 | ControlParameters decoded(wire); |
| 44 | BOOST_CHECK_EQUAL(decoded.getUri(), "tcp4://192.0.2.1:6363"); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 45 | BOOST_CHECK_EQUAL(decoded.getFacePersistency(), ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 46 | BOOST_CHECK_EQUAL(decoded.getFlags(), 1); |
| 47 | BOOST_CHECK_EQUAL(decoded.getMask(), 1); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 48 | |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 49 | BOOST_CHECK_EQUAL(decoded.hasName(), false); |
| 50 | BOOST_CHECK_EQUAL(decoded.hasFaceId(), false); |
| 51 | BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 52 | BOOST_CHECK_EQUAL(decoded.hasOrigin(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 53 | BOOST_CHECK_EQUAL(decoded.hasCost(), false); |
| 54 | BOOST_CHECK_EQUAL(decoded.hasStrategy(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 55 | BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | BOOST_AUTO_TEST_CASE(FaceLocalControlOptions) |
| 59 | { |
| 60 | ControlParameters parameters; |
| 61 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 62 | |
| 63 | Block wire = parameters.wireEncode(); |
| 64 | |
| 65 | ControlParameters decoded(wire); |
| 66 | BOOST_CHECK_EQUAL(decoded.getLocalControlFeature(), LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 67 | |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 68 | BOOST_CHECK_EQUAL(decoded.hasName(), false); |
| 69 | BOOST_CHECK_EQUAL(decoded.hasFaceId(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 70 | BOOST_CHECK_EQUAL(decoded.hasUri(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 71 | BOOST_CHECK_EQUAL(decoded.hasOrigin(), false); |
| 72 | BOOST_CHECK_EQUAL(decoded.hasCost(), false); |
| 73 | BOOST_CHECK_EQUAL(decoded.hasFlags(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 74 | BOOST_CHECK_EQUAL(decoded.hasStrategy(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 75 | BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 76 | BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | BOOST_AUTO_TEST_CASE(FibOptions) |
| 80 | { |
| 81 | ControlParameters parameters; |
| 82 | parameters.setName("ndn:/example") |
| 83 | .setFaceId(4) |
| 84 | .setCost(555); |
| 85 | |
| 86 | Block wire = parameters.wireEncode(); |
| 87 | |
| 88 | ControlParameters decoded(wire); |
| 89 | BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/example")); |
| 90 | BOOST_CHECK_EQUAL(decoded.getFaceId(), 4); |
| 91 | BOOST_CHECK_EQUAL(decoded.getCost(), 555); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 92 | |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 93 | BOOST_CHECK_EQUAL(decoded.hasUri(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 94 | BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false); |
| 95 | BOOST_CHECK_EQUAL(decoded.hasOrigin(), false); |
| 96 | BOOST_CHECK_EQUAL(decoded.hasFlags(), false); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 97 | BOOST_CHECK_EQUAL(decoded.hasMask(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 98 | BOOST_CHECK_EQUAL(decoded.hasStrategy(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 99 | BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 100 | BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | BOOST_AUTO_TEST_CASE(StrategyChoiceOptions) |
| 104 | { |
| 105 | ControlParameters parameters; |
| 106 | parameters.setName("ndn:/") |
| 107 | .setStrategy("ndn:/strategy/A"); |
| 108 | |
| 109 | Block wire = parameters.wireEncode(); |
| 110 | |
| 111 | ControlParameters decoded(wire); |
| 112 | BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/")); |
| 113 | BOOST_CHECK_EQUAL(decoded.getStrategy(), Name("ndn:/strategy/A")); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 114 | |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 115 | BOOST_CHECK_EQUAL(decoded.hasFaceId(), false); |
| 116 | BOOST_CHECK_EQUAL(decoded.hasUri(), false); |
| 117 | BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 118 | BOOST_CHECK_EQUAL(decoded.hasOrigin(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 119 | BOOST_CHECK_EQUAL(decoded.hasCost(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 120 | BOOST_CHECK_EQUAL(decoded.hasFlags(), false); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 121 | BOOST_CHECK_EQUAL(decoded.hasMask(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 122 | BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 123 | BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | BOOST_AUTO_TEST_CASE(RibOptions) |
| 127 | { |
| 128 | ControlParameters parameters; |
| 129 | parameters.setName("ndn:/example") |
| 130 | .setFaceId(4) |
| 131 | .setOrigin(128) |
| 132 | .setCost(6) |
| 133 | .setFlags(0x01) |
| 134 | .setExpirationPeriod(time::milliseconds(1800000)); |
| 135 | |
| 136 | Block wire = parameters.wireEncode(); |
| 137 | |
| 138 | ControlParameters decoded(wire); |
| 139 | BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/example")); |
| 140 | BOOST_CHECK_EQUAL(decoded.getFaceId(), 4); |
| 141 | BOOST_CHECK_EQUAL(decoded.getOrigin(), 128); |
| 142 | BOOST_CHECK_EQUAL(decoded.getCost(), 6); |
| 143 | BOOST_CHECK_EQUAL(decoded.getFlags(), 0x01); |
| 144 | BOOST_CHECK_EQUAL(decoded.getExpirationPeriod(), time::milliseconds(1800000)); |
| 145 | |
| 146 | BOOST_CHECK_EQUAL(decoded.hasUri(), false); |
| 147 | BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 148 | BOOST_CHECK_EQUAL(decoded.hasMask(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 149 | BOOST_CHECK_EQUAL(decoded.hasStrategy(), false); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 150 | BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false); |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 153 | BOOST_AUTO_TEST_CASE(FlagsAndMask) |
| 154 | { |
| 155 | ControlParameters p; |
| 156 | |
| 157 | BOOST_CHECK(!p.hasFlags()); |
| 158 | BOOST_CHECK(!p.hasMask()); |
| 159 | BOOST_CHECK(!p.hasFlagBit(0)); |
| 160 | BOOST_CHECK(!p.getFlagBit(0)); |
| 161 | |
| 162 | // Set bit 2 to true (change Mask) |
| 163 | p.setFlagBit(2, true); |
| 164 | // 2^2 = 4 |
| 165 | BOOST_CHECK_EQUAL(p.getFlags(), 4); |
| 166 | BOOST_CHECK_EQUAL(p.getMask(), 4); |
| 167 | BOOST_CHECK(p.hasFlagBit(2)); |
| 168 | BOOST_CHECK(p.getFlagBit(2)); |
| 169 | BOOST_CHECK(!p.hasFlagBit(1)); |
| 170 | BOOST_CHECK(!p.getFlagBit(1)); |
| 171 | |
| 172 | // Set bit 3 to true (no change to Mask) |
| 173 | p.setFlagBit(3, true, false); |
| 174 | // 2^3 + 2^2 = 12 |
| 175 | BOOST_CHECK_EQUAL(p.getFlags(), 12); |
| 176 | // 2^2 = 4 |
| 177 | BOOST_CHECK_EQUAL(p.getMask(), 4); |
| 178 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 179 | BOOST_CHECK(p.getFlagBit(3)); |
| 180 | BOOST_CHECK(p.hasFlagBit(2)); |
| 181 | BOOST_CHECK(p.getFlagBit(2)); |
| 182 | |
| 183 | // Set bit 1 to false (change Mask) |
| 184 | p.setFlagBit(1, false); |
| 185 | // 2^3 + 2^2 = 12 |
| 186 | BOOST_CHECK_EQUAL(p.getFlags(), 12); |
| 187 | // 2^2 + 2^1 = 6 |
| 188 | BOOST_CHECK_EQUAL(p.getMask(), 6); |
| 189 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 190 | BOOST_CHECK(p.getFlagBit(3)); |
| 191 | BOOST_CHECK(p.hasFlagBit(2)); |
| 192 | BOOST_CHECK(p.getFlagBit(2)); |
| 193 | BOOST_CHECK(p.hasFlagBit(1)); |
| 194 | BOOST_CHECK(!p.getFlagBit(1)); |
| 195 | |
| 196 | // Set bit 2 to false (change Mask) |
| 197 | p.setFlagBit(2, false); |
| 198 | // 2^3 = 8 |
| 199 | BOOST_CHECK_EQUAL(p.getFlags(), 8); |
| 200 | // 2^2 + 2^1 = 6 |
| 201 | BOOST_CHECK_EQUAL(p.getMask(), 6); |
| 202 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 203 | BOOST_CHECK(p.getFlagBit(3)); |
| 204 | BOOST_CHECK(p.hasFlagBit(2)); |
| 205 | BOOST_CHECK(!p.getFlagBit(2)); |
| 206 | BOOST_CHECK(p.hasFlagBit(1)); |
| 207 | BOOST_CHECK(!p.getFlagBit(1)); |
| 208 | |
| 209 | // Set bit 0 to true (change Mask) |
| 210 | p.setFlagBit(0, true); |
| 211 | // 2^3 + 2^0 = 9 |
| 212 | BOOST_CHECK_EQUAL(p.getFlags(), 9); |
| 213 | // 2^2 + 2^1 + 2^0 = 7 |
| 214 | BOOST_CHECK_EQUAL(p.getMask(), 7); |
| 215 | BOOST_CHECK(p.hasFlagBit(0)); |
| 216 | BOOST_CHECK(p.getFlagBit(0)); |
| 217 | |
| 218 | // Unset bit 0 |
| 219 | p.unsetFlagBit(0); |
| 220 | BOOST_REQUIRE(p.hasFlags()); |
| 221 | BOOST_REQUIRE(p.hasMask()); |
| 222 | // 2^3 + 2^0 = 9 |
| 223 | BOOST_CHECK_EQUAL(p.getFlags(), 9); |
| 224 | // 2^2 + 2^1 = 6 |
| 225 | BOOST_CHECK_EQUAL(p.getMask(), 6); |
| 226 | BOOST_CHECK(p.hasFlagBit(1)); |
| 227 | BOOST_CHECK(!p.hasFlagBit(0)); |
| 228 | BOOST_CHECK(p.getFlagBit(0)); |
| 229 | |
| 230 | // Unset bit 3 (already unset in Mask, so no change) |
| 231 | p.unsetFlagBit(3); |
| 232 | BOOST_REQUIRE(p.hasFlags()); |
| 233 | BOOST_REQUIRE(p.hasMask()); |
| 234 | // 2^3 + 2^0 = 9 |
| 235 | BOOST_CHECK_EQUAL(p.getFlags(), 9); |
| 236 | // 2^2 + 2^1 = 6 |
| 237 | BOOST_CHECK_EQUAL(p.getMask(), 6); |
| 238 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 239 | BOOST_CHECK(p.getFlagBit(3)); |
| 240 | |
| 241 | // Unset bit 2 |
| 242 | p.unsetFlagBit(2); |
| 243 | BOOST_REQUIRE(p.hasFlags()); |
| 244 | BOOST_REQUIRE(p.hasMask()); |
| 245 | // 2^3 + 2^0 = 9 |
| 246 | BOOST_CHECK_EQUAL(p.getFlags(), 9); |
| 247 | // 2^1 = 2 |
| 248 | BOOST_CHECK_EQUAL(p.getMask(), 2); |
| 249 | BOOST_CHECK(!p.hasFlagBit(2)); |
| 250 | BOOST_CHECK(!p.getFlagBit(2)); |
| 251 | |
| 252 | // Unset bit 1 |
| 253 | // Flags and Mask fields will be deleted as Mask is now 0 |
| 254 | p.unsetFlagBit(1); |
| 255 | BOOST_CHECK(!p.hasFlags()); |
| 256 | BOOST_CHECK(!p.hasMask()); |
| 257 | BOOST_CHECK(!p.hasFlagBit(3)); |
| 258 | BOOST_CHECK(!p.getFlagBit(3)); |
| 259 | BOOST_CHECK(!p.hasFlagBit(2)); |
| 260 | BOOST_CHECK(!p.getFlagBit(2)); |
| 261 | BOOST_CHECK(!p.hasFlagBit(1)); |
| 262 | BOOST_CHECK(!p.getFlagBit(1)); |
| 263 | BOOST_CHECK(!p.hasFlagBit(0)); |
| 264 | BOOST_CHECK(!p.getFlagBit(0)); |
| 265 | |
| 266 | BOOST_CHECK_THROW(p.setFlagBit(64, true), std::out_of_range); |
| 267 | BOOST_CHECK_THROW(p.unsetFlagBit(64), std::out_of_range); |
| 268 | } |
| 269 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 270 | BOOST_AUTO_TEST_SUITE_END() // TestControlParameters |
| 271 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 272 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 273 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 274 | } // namespace tests |
Junxiao Shi | bc19b37 | 2014-03-23 16:59:25 -0700 | [diff] [blame] | 275 | } // namespace nfd |
| 276 | } // namespace ndn |