Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "management/nfd-control-command.hpp" |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 8 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 9 | #include "boost-test.hpp" |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 10 | |
| 11 | namespace ndn { |
| 12 | namespace nfd { |
| 13 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame^] | 14 | BOOST_AUTO_TEST_SUITE(ManagementTestNfdControlCommand) |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 15 | |
| 16 | BOOST_AUTO_TEST_CASE(FaceCreate) |
| 17 | { |
| 18 | FaceCreateCommand command; |
| 19 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/create"); |
| 20 | |
| 21 | ControlParameters p1; |
| 22 | p1.setUri("tcp4://192.0.2.1") |
| 23 | .setFaceId(4); |
| 24 | BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError); |
| 25 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 26 | |
| 27 | ControlParameters p2; |
| 28 | p2.setName("ndn:/example"); |
| 29 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 30 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 31 | |
| 32 | ControlParameters p3; |
| 33 | p3.setUri("tcp4://192.0.2.1") |
| 34 | .setFaceId(0); |
| 35 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
| 36 | } |
| 37 | |
| 38 | BOOST_AUTO_TEST_CASE(FaceDestroy) |
| 39 | { |
| 40 | FaceDestroyCommand command; |
| 41 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/destroy"); |
| 42 | |
| 43 | ControlParameters p1; |
| 44 | p1.setUri("tcp4://192.0.2.1") |
| 45 | .setFaceId(4); |
| 46 | BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError); |
| 47 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 48 | |
| 49 | ControlParameters p2; |
| 50 | p2.setFaceId(0); |
| 51 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 52 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 53 | |
| 54 | ControlParameters p3; |
| 55 | p3.setFaceId(6); |
| 56 | BOOST_CHECK_NO_THROW(command.validateRequest(p3)); |
| 57 | BOOST_CHECK_NO_THROW(command.validateResponse(p3)); |
| 58 | } |
| 59 | |
| 60 | BOOST_AUTO_TEST_CASE(FaceEnableLocalControl) |
| 61 | { |
| 62 | FaceEnableLocalControlCommand command; |
| 63 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/enable-local-control"); |
| 64 | |
| 65 | ControlParameters p1; |
| 66 | p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 67 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 68 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 69 | |
| 70 | ControlParameters p2; |
| 71 | p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID) |
| 72 | .setFaceId(9); |
| 73 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 74 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 75 | |
| 76 | ControlParameters p3; |
| 77 | p3.setLocalControlFeature(static_cast<LocalControlFeature>(666)); |
| 78 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 79 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | BOOST_AUTO_TEST_CASE(FaceDisableLocalControl) |
| 83 | { |
| 84 | FaceDisableLocalControlCommand command; |
| 85 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/disable-local-control"); |
| 86 | |
| 87 | ControlParameters p1; |
| 88 | p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 89 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 90 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 91 | |
| 92 | ControlParameters p2; |
| 93 | p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID) |
| 94 | .setFaceId(9); |
| 95 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 96 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 97 | |
| 98 | ControlParameters p3; |
| 99 | p3.setLocalControlFeature(static_cast<LocalControlFeature>(666)); |
| 100 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 101 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | BOOST_AUTO_TEST_CASE(FibAddNextHop) |
| 105 | { |
| 106 | FibAddNextHopCommand command; |
| 107 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/add-nexthop"); |
| 108 | |
| 109 | ControlParameters p1; |
| 110 | p1.setName("ndn:/") |
| 111 | .setFaceId(22); |
| 112 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 113 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 114 | |
| 115 | ControlParameters p2; |
| 116 | p2.setName("ndn:/example") |
| 117 | .setFaceId(0) |
| 118 | .setCost(6); |
| 119 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 120 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 121 | |
| 122 | command.applyDefaultsToRequest(p1); |
| 123 | BOOST_REQUIRE(p1.hasCost()); |
| 124 | BOOST_CHECK_EQUAL(p1.getCost(), 0); |
| 125 | } |
| 126 | |
| 127 | BOOST_AUTO_TEST_CASE(FibRemoveNextHop) |
| 128 | { |
| 129 | FibRemoveNextHopCommand command; |
| 130 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/remove-nexthop"); |
| 131 | |
| 132 | ControlParameters p1; |
| 133 | p1.setName("ndn:/") |
| 134 | .setFaceId(22); |
| 135 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 136 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 137 | |
| 138 | ControlParameters p2; |
| 139 | p2.setName("ndn:/example") |
| 140 | .setFaceId(0); |
| 141 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 142 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 143 | } |
| 144 | |
| 145 | BOOST_AUTO_TEST_CASE(StrategyChoiceSet) |
| 146 | { |
| 147 | StrategyChoiceSetCommand command; |
| 148 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/set"); |
| 149 | |
| 150 | ControlParameters p1; |
| 151 | p1.setName("ndn:/") |
| 152 | .setStrategy("ndn:/strategy/P"); |
| 153 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 154 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 155 | |
| 156 | ControlParameters p2; |
| 157 | p2.setName("ndn:/example"); |
| 158 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 159 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 160 | } |
| 161 | |
| 162 | BOOST_AUTO_TEST_CASE(StrategyChoiceUnset) |
| 163 | { |
| 164 | StrategyChoiceUnsetCommand command; |
| 165 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/unset"); |
| 166 | |
| 167 | ControlParameters p1; |
| 168 | p1.setName("ndn:/example"); |
| 169 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 170 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 171 | |
| 172 | ControlParameters p2; |
| 173 | p2.setName("ndn:/example") |
| 174 | .setStrategy("ndn:/strategy/P"); |
| 175 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 176 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 177 | |
| 178 | ControlParameters p3; |
| 179 | p3.setName("ndn:/"); |
| 180 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 181 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
| 182 | } |
| 183 | |
| 184 | BOOST_AUTO_TEST_SUITE_END() |
| 185 | |
| 186 | } // namespace nfd |
| 187 | } // namespace ndn |