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