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