Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "mgmt/local-control-header-manager.hpp" |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 8 | #include "mgmt/internal-face.hpp" |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 9 | #include "tests/face/dummy-face.hpp" |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 10 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 11 | #include "tests/test-common.hpp" |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 12 | |
| 13 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 14 | namespace tests { |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 15 | |
| 16 | NFD_LOG_INIT("LocalControlHeaderManagerTest"); |
| 17 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 18 | class LocalControlHeaderManagerFixture : protected BaseFixture |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 19 | { |
| 20 | public: |
| 21 | |
| 22 | LocalControlHeaderManagerFixture() |
| 23 | : m_callbackFired(false) |
| 24 | { |
| 25 | |
| 26 | } |
| 27 | |
| 28 | shared_ptr<Face> |
| 29 | getFace(FaceId id) |
| 30 | { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 31 | if (id > 0 && static_cast<size_t>(id) <= m_faces.size()) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 32 | { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 33 | return m_faces[id - 1]; |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 34 | } |
| 35 | NFD_LOG_DEBUG("No face found returning NULL"); |
| 36 | return shared_ptr<DummyFace>(); |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | addFace(shared_ptr<Face> face) |
| 41 | { |
| 42 | m_faces.push_back(face); |
| 43 | } |
| 44 | |
| 45 | void |
| 46 | validateControlResponse(const Data& response, |
| 47 | const Name& expectedName, |
| 48 | uint32_t expectedCode, |
| 49 | const std::string& expectedText) |
| 50 | { |
| 51 | m_callbackFired = true; |
| 52 | |
| 53 | ControlResponse control; |
| 54 | Block controlRaw = response.getContent().blockFromValue(); |
| 55 | |
| 56 | control.wireDecode(controlRaw); |
| 57 | |
| 58 | NFD_LOG_DEBUG("received control response" |
| 59 | << " Name: " << response.getName() |
| 60 | << " code: " << control.getCode() |
| 61 | << " text: " << control.getText()); |
| 62 | |
| 63 | BOOST_CHECK_EQUAL(response.getName(), expectedName); |
| 64 | BOOST_CHECK_EQUAL(control.getCode(), expectedCode); |
| 65 | BOOST_CHECK_EQUAL(control.getText(), expectedText); |
| 66 | |
| 67 | if (!control.getBody().empty()) |
| 68 | { |
| 69 | BOOST_FAIL("found unexpected control response body"); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | bool |
| 74 | didCallbackFire() |
| 75 | { |
| 76 | return m_callbackFired; |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | resetCallbackFired() |
| 81 | { |
| 82 | m_callbackFired = false; |
| 83 | } |
| 84 | |
| 85 | private: |
| 86 | std::vector<shared_ptr<Face> > m_faces; |
| 87 | bool m_callbackFired; |
| 88 | }; |
| 89 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 90 | BOOST_FIXTURE_TEST_SUITE(MgmtLocalControlHeaderManager, LocalControlHeaderManagerFixture) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 91 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 92 | BOOST_AUTO_TEST_CASE(InFaceId) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 93 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 94 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 95 | addFace(dummy); |
| 96 | |
| 97 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 98 | |
| 99 | LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1), |
| 100 | face); |
| 101 | |
| 102 | Name enable("/localhost/nfd/control-header/in-faceid/enable"); |
| 103 | |
| 104 | face->onReceiveData += |
| 105 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 106 | enable, 200, "Success"); |
| 107 | |
| 108 | Interest enableCommand(enable); |
| 109 | enableCommand.setIncomingFaceId(1); |
| 110 | manager.onLocalControlHeaderRequest(enableCommand); |
| 111 | |
| 112 | BOOST_REQUIRE(didCallbackFire()); |
| 113 | BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 114 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 115 | |
| 116 | face->onReceiveData.clear(); |
| 117 | resetCallbackFired(); |
| 118 | |
| 119 | Name disable("/localhost/nfd/control-header/in-faceid/disable"); |
| 120 | |
| 121 | face->onReceiveData += |
| 122 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 123 | disable, 200, "Success"); |
| 124 | |
| 125 | Interest disableCommand(disable); |
| 126 | disableCommand.setIncomingFaceId(1); |
| 127 | manager.onLocalControlHeaderRequest(disableCommand); |
| 128 | |
| 129 | BOOST_REQUIRE(didCallbackFire()); |
| 130 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 131 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 132 | } |
| 133 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 134 | BOOST_AUTO_TEST_CASE(NextHopFaceId) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 135 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 136 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 137 | addFace(dummy); |
| 138 | |
| 139 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 140 | |
| 141 | LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1), |
| 142 | face); |
| 143 | |
| 144 | Name enable("/localhost/nfd/control-header/nexthop-faceid/enable"); |
| 145 | |
| 146 | face->onReceiveData += |
| 147 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 148 | enable, 200, "Success"); |
| 149 | |
| 150 | Interest enableCommand(enable); |
| 151 | enableCommand.setIncomingFaceId(1); |
| 152 | manager.onLocalControlHeaderRequest(enableCommand); |
| 153 | |
| 154 | BOOST_REQUIRE(didCallbackFire()); |
| 155 | BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 156 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 157 | |
| 158 | |
| 159 | face->onReceiveData.clear(); |
| 160 | resetCallbackFired(); |
| 161 | |
| 162 | Name disable("/localhost/nfd/control-header/nexthop-faceid/disable"); |
| 163 | |
| 164 | face->onReceiveData += |
| 165 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 166 | disable, 200, "Success"); |
| 167 | |
| 168 | Interest disableCommand(disable); |
| 169 | disableCommand.setIncomingFaceId(1); |
| 170 | manager.onLocalControlHeaderRequest(disableCommand); |
| 171 | |
| 172 | BOOST_REQUIRE(didCallbackFire()); |
| 173 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 174 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 175 | } |
| 176 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 177 | BOOST_AUTO_TEST_CASE(ShortCommand) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 178 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 179 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 180 | addFace(dummy); |
| 181 | |
| 182 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 183 | |
| 184 | LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1), |
| 185 | face); |
| 186 | |
| 187 | Name commandName("/localhost/nfd/control-header"); |
| 188 | |
| 189 | face->onReceiveData += |
| 190 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 191 | commandName, 400, "Malformed command"); |
| 192 | |
| 193 | Interest command(commandName); |
| 194 | command.setIncomingFaceId(1); |
| 195 | manager.onLocalControlHeaderRequest(command); |
| 196 | |
| 197 | BOOST_REQUIRE(didCallbackFire()); |
| 198 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 199 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 200 | } |
| 201 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 202 | BOOST_AUTO_TEST_CASE(ShortCommandModule) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 203 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 204 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 205 | addFace(dummy); |
| 206 | |
| 207 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 208 | |
| 209 | LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1), |
| 210 | face); |
| 211 | |
| 212 | Name commandName("/localhost/nfd/control-header/in-faceid"); |
| 213 | |
| 214 | face->onReceiveData += |
| 215 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 216 | commandName, 400, "Malformed command"); |
| 217 | |
| 218 | Interest command(commandName); |
| 219 | command.setIncomingFaceId(1); |
| 220 | manager.onLocalControlHeaderRequest(command); |
| 221 | |
| 222 | BOOST_REQUIRE(didCallbackFire()); |
| 223 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 224 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 225 | } |
| 226 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 227 | BOOST_AUTO_TEST_CASE(UnsupportedModule) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 228 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 229 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 230 | addFace(dummy); |
| 231 | |
| 232 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 233 | |
| 234 | LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1), |
| 235 | face); |
| 236 | |
| 237 | Name commandName("/localhost/nfd/control-header/madeup/moremadeup"); |
| 238 | |
| 239 | face->onReceiveData += |
| 240 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 241 | commandName, 501, "Unsupported"); |
| 242 | |
| 243 | Interest command(commandName); |
| 244 | command.setIncomingFaceId(1); |
| 245 | manager.onLocalControlHeaderRequest(command); |
| 246 | |
| 247 | BOOST_REQUIRE(didCallbackFire()); |
| 248 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 249 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 250 | } |
| 251 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 252 | BOOST_AUTO_TEST_CASE(InFaceIdUnsupportedVerb) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 253 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 254 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 255 | addFace(dummy); |
| 256 | |
| 257 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 258 | |
| 259 | LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1), |
| 260 | face); |
| 261 | |
| 262 | Name commandName("/localhost/nfd/control-header/in-faceid/madeup"); |
| 263 | |
| 264 | face->onReceiveData += |
| 265 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 266 | commandName, 501, "Unsupported"); |
| 267 | |
| 268 | Interest command(commandName); |
| 269 | command.setIncomingFaceId(1); |
| 270 | manager.onLocalControlHeaderRequest(command); |
| 271 | |
| 272 | BOOST_REQUIRE(didCallbackFire()); |
| 273 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 274 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 275 | } |
| 276 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 277 | BOOST_AUTO_TEST_CASE(NextHopFaceIdUnsupportedVerb) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 278 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 279 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 280 | addFace(dummy); |
| 281 | |
| 282 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 283 | |
| 284 | LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1), |
| 285 | face); |
| 286 | |
| 287 | Name commandName("/localhost/nfd/control-header/nexthop-faceid/madeup"); |
| 288 | |
| 289 | face->onReceiveData += |
| 290 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 291 | commandName, 501, "Unsupported"); |
| 292 | |
| 293 | Interest command(commandName); |
| 294 | command.setIncomingFaceId(1); |
| 295 | manager.onLocalControlHeaderRequest(command); |
| 296 | |
| 297 | BOOST_REQUIRE(didCallbackFire()); |
| 298 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 299 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 300 | } |
| 301 | |
| 302 | BOOST_AUTO_TEST_SUITE_END() |
| 303 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 304 | } // namespace tests |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 305 | } // namespace nfd |