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 | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 2 | /** |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [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 | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include "management/nfd-control-command.hpp" |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 24 | #include "boost-test.hpp" |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -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 | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 29 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 30 | BOOST_AUTO_TEST_SUITE(ManagementNfdControlCommand) |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 31 | |
| 32 | BOOST_AUTO_TEST_CASE(FaceCreate) |
| 33 | { |
| 34 | FaceCreateCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 35 | |
| 36 | ControlParameters p1; |
| 37 | p1.setUri("tcp4://192.0.2.1") |
| 38 | .setFaceId(4); |
| 39 | BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 40 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 41 | |
| 42 | ControlParameters p2; |
| 43 | p2.setName("ndn:/example"); |
| 44 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 45 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 46 | |
| 47 | ControlParameters p3; |
| 48 | p3.setUri("tcp4://192.0.2.1") |
| 49 | .setFaceId(0); |
| 50 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 51 | |
| 52 | ControlParameters p4; |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 53 | p4.setUri("tcp4://192.0.2.1") |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 54 | .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT) |
| 55 | .setFlags(0x3) |
| 56 | .setMask(0x1); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 57 | BOOST_CHECK_NO_THROW(command.validateRequest(p4)); |
| 58 | |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 59 | ControlParameters p5; |
| 60 | p5.setUri("tcp4://192.0.2.1") |
| 61 | .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT) |
| 62 | .setFlags(0x1); |
| 63 | BOOST_CHECK_THROW(command.validateRequest(p5), ControlCommand::ArgumentError); |
| 64 | |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 65 | p4.unsetFacePersistency(); |
| 66 | BOOST_CHECK_NO_THROW(command.validateRequest(p4)); |
| 67 | command.applyDefaultsToRequest(p4); |
| 68 | BOOST_REQUIRE(p4.hasFacePersistency()); |
| 69 | BOOST_CHECK_EQUAL(p4.getFacePersistency(), ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 70 | |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 71 | ControlParameters p6; |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 72 | p6.setFaceId(4) |
| 73 | .setUri("tcp4://192.0.2.1") |
| 74 | .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 75 | BOOST_CHECK_NO_THROW(command.validateResponse(p6)); |
| 76 | |
| 77 | ControlParameters p7; |
| 78 | p7.setUri("tcp4://192.0.2.1:6363"); |
| 79 | Name n7; |
| 80 | BOOST_CHECK_NO_THROW(n7 = command.getRequestName("/PREFIX", p7)); |
| 81 | BOOST_CHECK(Name("ndn:/PREFIX/faces/create").isPrefixOf(n7)); |
| 82 | |
| 83 | ControlParameters p8; |
| 84 | p8.setFaceId(5) |
| 85 | .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERMANENT) |
| 86 | .setFlags(0x2); |
| 87 | BOOST_CHECK_NO_THROW(command.validateResponse(p8)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 90 | BOOST_AUTO_TEST_CASE(FaceUpdate) |
| 91 | { |
| 92 | FaceUpdateCommand command; |
| 93 | |
| 94 | ControlParameters p1; |
| 95 | p1.setFaceId(0); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 96 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 97 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 98 | |
| 99 | p1.setFaceId(1); |
| 100 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 101 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 102 | |
| 103 | ControlParameters p2; |
| 104 | p2.setFaceId(1) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 105 | .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT) |
| 106 | .setFlags(0x0) |
| 107 | .setMask(0x1); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 108 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 109 | BOOST_CHECK_NO_THROW(command.validateResponse(p2)); |
| 110 | |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 111 | p2.unsetFaceId(); |
| 112 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 113 | |
| 114 | p2.unsetMask(); |
| 115 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 116 | |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 117 | ControlParameters p3; |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 118 | p3.setFaceId(1) |
| 119 | .setName("/ndn/name"); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 120 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 121 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
| 122 | |
| 123 | ControlParameters p4; |
| 124 | p4.setFaceId(1) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 125 | .setUri("tcp4://192.0.2.1"); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 126 | BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError); |
| 127 | BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError); |
| 128 | |
| 129 | ControlParameters p5; |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 130 | BOOST_CHECK_NO_THROW(command.validateResponse(p5)); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 131 | } |
| 132 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 133 | BOOST_AUTO_TEST_CASE(FaceDestroy) |
| 134 | { |
| 135 | FaceDestroyCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 136 | |
| 137 | ControlParameters p1; |
| 138 | p1.setUri("tcp4://192.0.2.1") |
| 139 | .setFaceId(4); |
| 140 | BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError); |
| 141 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 142 | |
| 143 | ControlParameters p2; |
| 144 | p2.setFaceId(0); |
| 145 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 146 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 147 | |
| 148 | ControlParameters p3; |
| 149 | p3.setFaceId(6); |
| 150 | BOOST_CHECK_NO_THROW(command.validateRequest(p3)); |
| 151 | BOOST_CHECK_NO_THROW(command.validateResponse(p3)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 152 | Name n3; |
| 153 | BOOST_CHECK_NO_THROW(n3 = command.getRequestName("/PREFIX", p3)); |
| 154 | BOOST_CHECK(Name("ndn:/PREFIX/faces/destroy").isPrefixOf(n3)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | BOOST_AUTO_TEST_CASE(FaceEnableLocalControl) |
| 158 | { |
| 159 | FaceEnableLocalControlCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 160 | |
| 161 | ControlParameters p1; |
| 162 | p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 163 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 164 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 165 | Name n1; |
| 166 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 167 | BOOST_CHECK(Name("ndn:/PREFIX/faces/enable-local-control").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 168 | |
| 169 | ControlParameters p2; |
| 170 | p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID) |
| 171 | .setFaceId(9); |
| 172 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 173 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 174 | |
| 175 | ControlParameters p3; |
| 176 | p3.setLocalControlFeature(static_cast<LocalControlFeature>(666)); |
| 177 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 178 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | BOOST_AUTO_TEST_CASE(FaceDisableLocalControl) |
| 182 | { |
| 183 | FaceDisableLocalControlCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 184 | |
| 185 | ControlParameters p1; |
| 186 | p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 187 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 188 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 189 | Name n1; |
| 190 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 191 | BOOST_CHECK(Name("ndn:/PREFIX/faces/disable-local-control").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 192 | |
| 193 | ControlParameters p2; |
| 194 | p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID) |
| 195 | .setFaceId(9); |
| 196 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 197 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 198 | |
| 199 | ControlParameters p3; |
| 200 | p3.setLocalControlFeature(static_cast<LocalControlFeature>(666)); |
| 201 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 202 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | BOOST_AUTO_TEST_CASE(FibAddNextHop) |
| 206 | { |
| 207 | FibAddNextHopCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 208 | |
| 209 | ControlParameters p1; |
| 210 | p1.setName("ndn:/") |
| 211 | .setFaceId(22); |
| 212 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 213 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 214 | Name n1; |
| 215 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 216 | BOOST_CHECK(Name("ndn:/PREFIX/fib/add-nexthop").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 217 | |
| 218 | ControlParameters p2; |
| 219 | p2.setName("ndn:/example") |
| 220 | .setFaceId(0) |
| 221 | .setCost(6); |
| 222 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 223 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 224 | |
| 225 | command.applyDefaultsToRequest(p1); |
| 226 | BOOST_REQUIRE(p1.hasCost()); |
| 227 | BOOST_CHECK_EQUAL(p1.getCost(), 0); |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 228 | |
| 229 | p1.unsetFaceId(); |
| 230 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 231 | command.applyDefaultsToRequest(p1); |
| 232 | BOOST_REQUIRE(p1.hasFaceId()); |
| 233 | BOOST_CHECK_EQUAL(p1.getFaceId(), 0); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | BOOST_AUTO_TEST_CASE(FibRemoveNextHop) |
| 237 | { |
| 238 | FibRemoveNextHopCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 239 | |
| 240 | ControlParameters p1; |
| 241 | p1.setName("ndn:/") |
| 242 | .setFaceId(22); |
| 243 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 244 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 245 | Name n1; |
| 246 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 247 | BOOST_CHECK(Name("ndn:/PREFIX/fib/remove-nexthop").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 248 | |
| 249 | ControlParameters p2; |
| 250 | p2.setName("ndn:/example") |
| 251 | .setFaceId(0); |
| 252 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 253 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 254 | |
| 255 | p1.unsetFaceId(); |
| 256 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 257 | command.applyDefaultsToRequest(p1); |
| 258 | BOOST_REQUIRE(p1.hasFaceId()); |
| 259 | BOOST_CHECK_EQUAL(p1.getFaceId(), 0); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | BOOST_AUTO_TEST_CASE(StrategyChoiceSet) |
| 263 | { |
| 264 | StrategyChoiceSetCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 265 | |
| 266 | ControlParameters p1; |
| 267 | p1.setName("ndn:/") |
| 268 | .setStrategy("ndn:/strategy/P"); |
| 269 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 270 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 271 | Name n1; |
| 272 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 273 | BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/set").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 274 | |
| 275 | ControlParameters p2; |
| 276 | p2.setName("ndn:/example"); |
| 277 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 278 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 279 | } |
| 280 | |
| 281 | BOOST_AUTO_TEST_CASE(StrategyChoiceUnset) |
| 282 | { |
| 283 | StrategyChoiceUnsetCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 284 | |
| 285 | ControlParameters p1; |
| 286 | p1.setName("ndn:/example"); |
| 287 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 288 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 289 | Name n1; |
| 290 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 291 | BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/unset").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 292 | |
| 293 | ControlParameters p2; |
| 294 | p2.setName("ndn:/example") |
| 295 | .setStrategy("ndn:/strategy/P"); |
| 296 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 297 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 298 | |
| 299 | ControlParameters p3; |
| 300 | p3.setName("ndn:/"); |
| 301 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 302 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
| 303 | } |
| 304 | |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 305 | BOOST_AUTO_TEST_CASE(RibRegister) |
| 306 | { |
| 307 | RibRegisterCommand command; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 308 | |
| 309 | ControlParameters p1; |
| 310 | p1.setName("ndn:/"); |
| 311 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 312 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 313 | Name n1; |
| 314 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 315 | BOOST_CHECK(Name("ndn:/PREFIX/rib/register").isPrefixOf(n1)); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 316 | |
| 317 | command.applyDefaultsToRequest(p1); |
| 318 | BOOST_REQUIRE(p1.hasOrigin()); |
| 319 | BOOST_CHECK_EQUAL(p1.getOrigin(), static_cast<uint64_t>(ROUTE_ORIGIN_APP)); |
| 320 | BOOST_REQUIRE(p1.hasCost()); |
| 321 | BOOST_CHECK_EQUAL(p1.getCost(), 0); |
| 322 | BOOST_REQUIRE(p1.hasFlags()); |
| 323 | BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT)); |
Alexander Afanasyev | 21f13b0 | 2014-07-17 16:17:34 -0700 | [diff] [blame] | 324 | BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 325 | |
| 326 | ControlParameters p2; |
| 327 | p2.setName("ndn:/example") |
| 328 | .setFaceId(2) |
| 329 | .setCost(6); |
| 330 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 331 | command.applyDefaultsToRequest(p2); |
Alexander Afanasyev | 21f13b0 | 2014-07-17 16:17:34 -0700 | [diff] [blame] | 332 | BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 333 | BOOST_CHECK_NO_THROW(command.validateResponse(p2)); |
| 334 | } |
| 335 | |
| 336 | BOOST_AUTO_TEST_CASE(RibUnregister) |
| 337 | { |
| 338 | RibUnregisterCommand command; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 339 | |
| 340 | ControlParameters p1; |
| 341 | p1.setName("ndn:/") |
| 342 | .setFaceId(22) |
| 343 | .setOrigin(ROUTE_ORIGIN_STATIC); |
| 344 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 345 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 346 | Name n1; |
| 347 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 348 | BOOST_CHECK(Name("ndn:/PREFIX/rib/unregister").isPrefixOf(n1)); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 349 | |
| 350 | ControlParameters p2; |
| 351 | p2.setName("ndn:/example") |
| 352 | .setFaceId(0) |
| 353 | .setOrigin(ROUTE_ORIGIN_APP); |
| 354 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 355 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 356 | |
| 357 | p2.unsetFaceId(); |
| 358 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 359 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 360 | } |
| 361 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 362 | BOOST_AUTO_TEST_SUITE_END() |
| 363 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 364 | } // namespace tests |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 365 | } // namespace nfd |
| 366 | } // namespace ndn |