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