Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include "management/nfd-control-command.hpp" |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 14 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 15 | #include "boost-test.hpp" |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 16 | |
| 17 | namespace ndn { |
| 18 | namespace nfd { |
| 19 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 20 | BOOST_AUTO_TEST_SUITE(ManagementTestNfdControlCommand) |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 21 | |
| 22 | BOOST_AUTO_TEST_CASE(FaceCreate) |
| 23 | { |
| 24 | FaceCreateCommand command; |
| 25 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/create"); |
| 26 | |
| 27 | ControlParameters p1; |
| 28 | p1.setUri("tcp4://192.0.2.1") |
| 29 | .setFaceId(4); |
| 30 | BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError); |
| 31 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 32 | |
| 33 | ControlParameters p2; |
| 34 | p2.setName("ndn:/example"); |
| 35 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 36 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 37 | |
| 38 | ControlParameters p3; |
| 39 | p3.setUri("tcp4://192.0.2.1") |
| 40 | .setFaceId(0); |
| 41 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
| 42 | } |
| 43 | |
| 44 | BOOST_AUTO_TEST_CASE(FaceDestroy) |
| 45 | { |
| 46 | FaceDestroyCommand command; |
| 47 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/destroy"); |
| 48 | |
| 49 | ControlParameters p1; |
| 50 | p1.setUri("tcp4://192.0.2.1") |
| 51 | .setFaceId(4); |
| 52 | BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError); |
| 53 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 54 | |
| 55 | ControlParameters p2; |
| 56 | p2.setFaceId(0); |
| 57 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 58 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 59 | |
| 60 | ControlParameters p3; |
| 61 | p3.setFaceId(6); |
| 62 | BOOST_CHECK_NO_THROW(command.validateRequest(p3)); |
| 63 | BOOST_CHECK_NO_THROW(command.validateResponse(p3)); |
| 64 | } |
| 65 | |
| 66 | BOOST_AUTO_TEST_CASE(FaceEnableLocalControl) |
| 67 | { |
| 68 | FaceEnableLocalControlCommand command; |
| 69 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/enable-local-control"); |
| 70 | |
| 71 | ControlParameters p1; |
| 72 | p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 73 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 74 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 75 | |
| 76 | ControlParameters p2; |
| 77 | p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID) |
| 78 | .setFaceId(9); |
| 79 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 80 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 81 | |
| 82 | ControlParameters p3; |
| 83 | p3.setLocalControlFeature(static_cast<LocalControlFeature>(666)); |
| 84 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 85 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | BOOST_AUTO_TEST_CASE(FaceDisableLocalControl) |
| 89 | { |
| 90 | FaceDisableLocalControlCommand command; |
| 91 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/disable-local-control"); |
| 92 | |
| 93 | ControlParameters p1; |
| 94 | p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 95 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 96 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 97 | |
| 98 | ControlParameters p2; |
| 99 | p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID) |
| 100 | .setFaceId(9); |
| 101 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 102 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 103 | |
| 104 | ControlParameters p3; |
| 105 | p3.setLocalControlFeature(static_cast<LocalControlFeature>(666)); |
| 106 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 107 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | BOOST_AUTO_TEST_CASE(FibAddNextHop) |
| 111 | { |
| 112 | FibAddNextHopCommand command; |
| 113 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/add-nexthop"); |
| 114 | |
| 115 | ControlParameters p1; |
| 116 | p1.setName("ndn:/") |
| 117 | .setFaceId(22); |
| 118 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 119 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 120 | |
| 121 | ControlParameters p2; |
| 122 | p2.setName("ndn:/example") |
| 123 | .setFaceId(0) |
| 124 | .setCost(6); |
| 125 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 126 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 127 | |
| 128 | command.applyDefaultsToRequest(p1); |
| 129 | BOOST_REQUIRE(p1.hasCost()); |
| 130 | BOOST_CHECK_EQUAL(p1.getCost(), 0); |
| 131 | } |
| 132 | |
| 133 | BOOST_AUTO_TEST_CASE(FibRemoveNextHop) |
| 134 | { |
| 135 | FibRemoveNextHopCommand command; |
| 136 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/remove-nexthop"); |
| 137 | |
| 138 | ControlParameters p1; |
| 139 | p1.setName("ndn:/") |
| 140 | .setFaceId(22); |
| 141 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 142 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 143 | |
| 144 | ControlParameters p2; |
| 145 | p2.setName("ndn:/example") |
| 146 | .setFaceId(0); |
| 147 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 148 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 149 | } |
| 150 | |
| 151 | BOOST_AUTO_TEST_CASE(StrategyChoiceSet) |
| 152 | { |
| 153 | StrategyChoiceSetCommand command; |
| 154 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/set"); |
| 155 | |
| 156 | ControlParameters p1; |
| 157 | p1.setName("ndn:/") |
| 158 | .setStrategy("ndn:/strategy/P"); |
| 159 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 160 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 161 | |
| 162 | ControlParameters p2; |
| 163 | p2.setName("ndn:/example"); |
| 164 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 165 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 166 | } |
| 167 | |
| 168 | BOOST_AUTO_TEST_CASE(StrategyChoiceUnset) |
| 169 | { |
| 170 | StrategyChoiceUnsetCommand command; |
| 171 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/unset"); |
| 172 | |
| 173 | ControlParameters p1; |
| 174 | p1.setName("ndn:/example"); |
| 175 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 176 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 177 | |
| 178 | ControlParameters p2; |
| 179 | p2.setName("ndn:/example") |
| 180 | .setStrategy("ndn:/strategy/P"); |
| 181 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 182 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 183 | |
| 184 | ControlParameters p3; |
| 185 | p3.setName("ndn:/"); |
| 186 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 187 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
| 188 | } |
| 189 | |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 190 | BOOST_AUTO_TEST_CASE(RibRegister) |
| 191 | { |
| 192 | RibRegisterCommand command; |
| 193 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/rib/register"); |
| 194 | |
| 195 | ControlParameters p1; |
| 196 | p1.setName("ndn:/"); |
| 197 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 198 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 199 | |
| 200 | command.applyDefaultsToRequest(p1); |
| 201 | BOOST_REQUIRE(p1.hasOrigin()); |
| 202 | BOOST_CHECK_EQUAL(p1.getOrigin(), static_cast<uint64_t>(ROUTE_ORIGIN_APP)); |
| 203 | BOOST_REQUIRE(p1.hasCost()); |
| 204 | BOOST_CHECK_EQUAL(p1.getCost(), 0); |
| 205 | BOOST_REQUIRE(p1.hasFlags()); |
| 206 | BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT)); |
| 207 | BOOST_REQUIRE(p1.hasExpirationPeriod()); |
| 208 | BOOST_CHECK_GT(p1.getExpirationPeriod(), time::hours(240)); |
| 209 | |
| 210 | ControlParameters p2; |
| 211 | p2.setName("ndn:/example") |
| 212 | .setFaceId(2) |
| 213 | .setCost(6); |
| 214 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 215 | command.applyDefaultsToRequest(p2); |
| 216 | BOOST_CHECK_EQUAL(p2.getExpirationPeriod(), time::hours(1)); |
| 217 | BOOST_CHECK_NO_THROW(command.validateResponse(p2)); |
| 218 | } |
| 219 | |
| 220 | BOOST_AUTO_TEST_CASE(RibUnregister) |
| 221 | { |
| 222 | RibUnregisterCommand command; |
| 223 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/rib/unregister"); |
| 224 | |
| 225 | ControlParameters p1; |
| 226 | p1.setName("ndn:/") |
| 227 | .setFaceId(22) |
| 228 | .setOrigin(ROUTE_ORIGIN_STATIC); |
| 229 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 230 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 231 | |
| 232 | ControlParameters p2; |
| 233 | p2.setName("ndn:/example") |
| 234 | .setFaceId(0) |
| 235 | .setOrigin(ROUTE_ORIGIN_APP); |
| 236 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 237 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 238 | |
| 239 | p2.unsetFaceId(); |
| 240 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 241 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 242 | } |
| 243 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 244 | BOOST_AUTO_TEST_SUITE_END() |
| 245 | |
| 246 | } // namespace nfd |
| 247 | } // namespace ndn |