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