blob: 3b0727486cd911049e6cb129b9b3b90b6456be1f [file] [log] [blame]
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology
9 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070024
25#include "mgmt/face-manager.hpp"
26#include "mgmt/internal-face.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060027#include "mgmt/face-status-publisher.hpp"
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060028
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070029#include "face/face.hpp"
30#include "../face/dummy-face.hpp"
31#include "fw/face-table.hpp"
32#include "fw/forwarder.hpp"
33
34#include "common.hpp"
35#include "tests/test-common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070036#include "validation-common.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060037#include "face-status-publisher-common.hpp"
38
39#include <ndn-cpp-dev/encoding/tlv.hpp>
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060040#include <ndn-cpp-dev/management/nfd-face-event-notification.hpp>
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070041
42namespace nfd {
43namespace tests {
44
45NFD_LOG_INIT("FaceManagerTest");
46
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060047class FaceManagerTestFace : public DummyFace
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070048{
49public:
50
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060051 FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070052 : m_closeFired(false)
53 {
54
55 }
56
57 virtual
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060058 ~FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070059 {
60
61 }
62
63 virtual void
64 close()
65 {
66 m_closeFired = true;
67 }
68
69 bool
70 didCloseFire() const
71 {
72 return m_closeFired;
73 }
74
75private:
76 bool m_closeFired;
77};
78
79class TestFaceTable : public FaceTable
80{
81public:
82 TestFaceTable(Forwarder& forwarder)
83 : FaceTable(forwarder),
84 m_addFired(false),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070085 m_getFired(false),
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060086 m_dummy(make_shared<FaceManagerTestFace>())
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070087 {
88
89 }
90
91 virtual
92 ~TestFaceTable()
93 {
94
95 }
96
97 virtual void
98 add(shared_ptr<Face> face)
99 {
100 m_addFired = true;
101 }
102
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700103 virtual shared_ptr<Face>
104 get(FaceId id) const
105 {
106 m_getFired = true;
107 return m_dummy;
108 }
109
110 bool
111 didAddFire() const
112 {
113 return m_addFired;
114 }
115
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700116 bool
117 didGetFire() const
118 {
119 return m_getFired;
120 }
121
122 void
123 reset()
124 {
125 m_addFired = false;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700126 m_getFired = false;
127 }
128
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600129 shared_ptr<FaceManagerTestFace>&
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700130 getDummyFace()
131 {
132 return m_dummy;
133 }
134
135private:
136 bool m_addFired;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700137 mutable bool m_getFired;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600138 shared_ptr<FaceManagerTestFace> m_dummy;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700139};
140
141
142class TestFaceTableFixture : public BaseFixture
143{
144public:
145 TestFaceTableFixture()
146 : m_faceTable(m_forwarder)
147 {
148
149 }
150
151 virtual
152 ~TestFaceTableFixture()
153 {
154
155 }
156
157protected:
158 Forwarder m_forwarder;
159 TestFaceTable m_faceTable;
160};
161
162class TestFaceManagerCommon
163{
164public:
165 TestFaceManagerCommon()
166 : m_face(make_shared<InternalFace>()),
167 m_callbackFired(false)
168 {
169
170 }
171
172 virtual
173 ~TestFaceManagerCommon()
174 {
175
176 }
177
178 shared_ptr<InternalFace>&
179 getFace()
180 {
181 return m_face;
182 }
183
184 void
185 validateControlResponseCommon(const Data& response,
186 const Name& expectedName,
187 uint32_t expectedCode,
188 const std::string& expectedText,
189 ControlResponse& control)
190 {
191 m_callbackFired = true;
192 Block controlRaw = response.getContent().blockFromValue();
193
194 control.wireDecode(controlRaw);
195
196 // NFD_LOG_DEBUG("received control response"
197 // << " Name: " << response.getName()
198 // << " code: " << control.getCode()
199 // << " text: " << control.getText());
200
201 BOOST_CHECK_EQUAL(response.getName(), expectedName);
202 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
203 BOOST_CHECK_EQUAL(control.getText(), expectedText);
204 }
205
206 void
207 validateControlResponse(const Data& response,
208 const Name& expectedName,
209 uint32_t expectedCode,
210 const std::string& expectedText)
211 {
212 ControlResponse control;
213 validateControlResponseCommon(response, expectedName,
214 expectedCode, expectedText, control);
215
216 if (!control.getBody().empty())
217 {
218 BOOST_FAIL("found unexpected control response body");
219 }
220 }
221
222 void
223 validateControlResponse(const Data& response,
224 const Name& expectedName,
225 uint32_t expectedCode,
226 const std::string& expectedText,
227 const Block& expectedBody)
228 {
229 ControlResponse control;
230 validateControlResponseCommon(response, expectedName,
231 expectedCode, expectedText, control);
232
233 BOOST_REQUIRE(!control.getBody().empty());
234 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
235
236 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
237 expectedBody.value_size()) == 0);
238
239 }
240
241 bool
242 didCallbackFire() const
243 {
244 return m_callbackFired;
245 }
246
247 void
248 resetCallbackFired()
249 {
250 m_callbackFired = false;
251 }
252
253protected:
254 shared_ptr<InternalFace> m_face;
255
256private:
257 bool m_callbackFired;
258};
259
260class FaceManagerFixture : public TestFaceTableFixture, public TestFaceManagerCommon
261{
262public:
263 FaceManagerFixture()
264 : m_manager(m_faceTable, m_face)
265 {
266 m_manager.setConfigFile(m_config);
267 }
268
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700269 virtual
270 ~FaceManagerFixture()
271 {
272
273 }
274
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600275 void
276 parseConfig(const std::string configuration, bool isDryRun)
277 {
278 m_config.parse(configuration, isDryRun, "dummy-config");
279 }
280
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700281 FaceManager&
282 getManager()
283 {
284 return m_manager;
285 }
286
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700287 void
288 addInterestRule(const std::string& regex,
289 ndn::IdentityCertificate& certificate)
290 {
291 m_manager.addInterestRule(regex, certificate);
292 }
293
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700294 bool
295 didFaceTableAddFire() const
296 {
297 return m_faceTable.didAddFire();
298 }
299
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700300 bool
301 didFaceTableGetFire() const
302 {
303 return m_faceTable.didGetFire();
304 }
305
306 void
307 resetFaceTable()
308 {
309 m_faceTable.reset();
310 }
311
312private:
313 FaceManager m_manager;
314 ConfigFile m_config;
315};
316
317BOOST_FIXTURE_TEST_SUITE(MgmtFaceManager, FaceManagerFixture)
318
319bool
320isExpectedException(const ConfigFile::Error& error, const std::string& expectedMessage)
321{
322 if (error.what() != expectedMessage)
323 {
324 NFD_LOG_ERROR("expected: " << expectedMessage << "\tgot: " << error.what());
325 }
326 return error.what() == expectedMessage;
327}
328
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600329#ifdef HAVE_UNIX_SOCKETS
330
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700331BOOST_AUTO_TEST_CASE(TestProcessSectionUnix)
332{
333 const std::string CONFIG =
334 "face_system\n"
335 "{\n"
336 " unix\n"
337 " {\n"
338 " listen yes\n"
339 " path /tmp/nfd.sock\n"
340 " }\n"
341 "}\n";
342 BOOST_TEST_CHECKPOINT("Calling parse");
343 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
344}
345
346BOOST_AUTO_TEST_CASE(TestProcessSectionUnixDryRun)
347{
348 const std::string CONFIG =
349 "face_system\n"
350 "{\n"
351 " unix\n"
352 " {\n"
353 " listen yes\n"
354 " path /var/run/nfd.sock\n"
355 " }\n"
356 "}\n";
357
358 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
359}
360
361BOOST_AUTO_TEST_CASE(TestProcessSectionUnixBadListen)
362{
363 const std::string CONFIG =
364 "face_system\n"
365 "{\n"
366 " unix\n"
367 " {\n"
368 " listen hello\n"
369 " }\n"
370 "}\n";
371 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
372 bind(&isExpectedException, _1,
373 "Invalid value for option \"listen\" in \"unix\" section"));
374}
375
376BOOST_AUTO_TEST_CASE(TestProcessSectionUnixUnknownOption)
377{
378 const std::string CONFIG =
379 "face_system\n"
380 "{\n"
381 " unix\n"
382 " {\n"
383 " hello\n"
384 " }\n"
385 "}\n";
386 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
387 bind(&isExpectedException, _1,
388 "Unrecognized option \"hello\" in \"unix\" section"));
389}
390
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600391#endif // HAVE_UNIX_SOCKETS
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700392
393
394BOOST_AUTO_TEST_CASE(TestProcessSectionTcp)
395{
396 const std::string CONFIG =
397 "face_system\n"
398 "{\n"
399 " tcp\n"
400 " {\n"
401 " listen yes\n"
402 " port 6363\n"
403 " }\n"
404 "}\n";
405 try
406 {
407 parseConfig(CONFIG, false);
408 }
409 catch (const std::runtime_error& e)
410 {
411 const std::string reason = e.what();
412 if (reason.find("Address in use") != std::string::npos)
413 {
414 BOOST_FAIL(reason);
415 }
416 }
417}
418
419BOOST_AUTO_TEST_CASE(TestProcessSectionTcpDryRun)
420{
421 const std::string CONFIG =
422 "face_system\n"
423 "{\n"
424 " tcp\n"
425 " {\n"
426 " listen yes\n"
427 " port 6363\n"
428 " }\n"
429 "}\n";
430 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
431}
432
433BOOST_AUTO_TEST_CASE(TestProcessSectionTcpBadListen)
434{
435 const std::string CONFIG =
436 "face_system\n"
437 "{\n"
438 " tcp\n"
439 " {\n"
440 " listen hello\n"
441 " }\n"
442 "}\n";
443 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
444 bind(&isExpectedException, _1,
445 "Invalid value for option \"listen\" in \"tcp\" section"));
446}
447
448BOOST_AUTO_TEST_CASE(TestProcessSectionTcpUnknownOption)
449{
450 const std::string CONFIG =
451 "face_system\n"
452 "{\n"
453 " tcp\n"
454 " {\n"
455 " hello\n"
456 " }\n"
457 "}\n";
458 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
459 bind(&isExpectedException, _1,
460 "Unrecognized option \"hello\" in \"tcp\" section"));
461}
462
463BOOST_AUTO_TEST_CASE(TestProcessSectionUdp)
464{
465 const std::string CONFIG =
466 "face_system\n"
467 "{\n"
468 " udp\n"
469 " {\n"
470 " port 6363\n"
471 " idle_timeout 30\n"
472 " keep_alive_interval 25\n"
473 " mcast yes\n"
474 " mcast_port 56363\n"
475 " mcast_group 224.0.23.170\n"
476 " }\n"
477 "}\n";
478 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
479}
480
481BOOST_AUTO_TEST_CASE(TestProcessSectionUdpDryRun)
482{
483 const std::string CONFIG =
484 "face_system\n"
485 "{\n"
486 " udp\n"
487 " {\n"
488 " port 6363\n"
489 " idle_timeout 30\n"
490 " keep_alive_interval 25\n"
491 " mcast yes\n"
492 " mcast_port 56363\n"
493 " mcast_group 224.0.23.170\n"
494 " }\n"
495 "}\n";
496 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
497}
498
499BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadIdleTimeout)
500{
501 const std::string CONFIG =
502 "face_system\n"
503 "{\n"
504 " udp\n"
505 " {\n"
506 " idle_timeout hello\n"
507 " }\n"
508 "}\n";
509
510 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
511 bind(&isExpectedException, _1,
512 "Invalid value for option \"idle_timeout\" in \"udp\" section"));
513}
514
515BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcast)
516{
517 const std::string CONFIG =
518 "face_system\n"
519 "{\n"
520 " udp\n"
521 " {\n"
522 " mcast hello\n"
523 " }\n"
524 "}\n";
525
526 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
527 bind(&isExpectedException, _1,
528 "Invalid value for option \"mcast\" in \"udp\" section"));
529}
530
531BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroup)
532{
533 const std::string CONFIG =
534 "face_system\n"
535 "{\n"
536 " udp\n"
537 " {\n"
538 " mcast no\n"
539 " mcast_port 50\n"
540 " mcast_group hello\n"
541 " }\n"
542 "}\n";
543
544 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
545 bind(&isExpectedException, _1,
546 "Invalid value for option \"mcast_group\" in \"udp\" section"));
547}
548
549BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroupV6)
550{
551 const std::string CONFIG =
552 "face_system\n"
553 "{\n"
554 " udp\n"
555 " {\n"
556 " mcast no\n"
557 " mcast_port 50\n"
558 " mcast_group ::1\n"
559 " }\n"
560 "}\n";
561
562 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
563 bind(&isExpectedException, _1,
564 "Invalid value for option \"mcast_group\" in \"udp\" section"));
565}
566
567BOOST_AUTO_TEST_CASE(TestProcessSectionUdpUnknownOption)
568{
569 const std::string CONFIG =
570 "face_system\n"
571 "{\n"
572 " udp\n"
573 " {\n"
574 " hello\n"
575 " }\n"
576 "}\n";
577 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
578 bind(&isExpectedException, _1,
579 "Unrecognized option \"hello\" in \"udp\" section"));
580}
581
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600582#ifdef HAVE_PCAP
583
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700584BOOST_AUTO_TEST_CASE(TestProcessSectionEther)
585{
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600586
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700587 const std::string CONFIG =
588 "face_system\n"
589 "{\n"
590 " ether\n"
591 " {\n"
592 " mcast yes\n"
593 " mcast_group 01:00:5E:00:17:AA\n"
594 " }\n"
595 "}\n";
596
597 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
598}
599
600BOOST_AUTO_TEST_CASE(TestProcessSectionEtherDryRun)
601{
602 const std::string CONFIG =
603 "face_system\n"
604 "{\n"
605 " ether\n"
606 " {\n"
607 " mcast yes\n"
608 " mcast_group 01:00:5E:00:17:AA\n"
609 " }\n"
610 "}\n";
611
612 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
613}
614
615BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcast)
616{
617 const std::string CONFIG =
618 "face_system\n"
619 "{\n"
620 " ether\n"
621 " {\n"
622 " mcast hello\n"
623 " }\n"
624 "}\n";
625
626 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
627 bind(&isExpectedException, _1,
628 "Invalid value for option \"mcast\" in \"ether\" section"));
629}
630
631BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcastGroup)
632{
633 const std::string CONFIG =
634 "face_system\n"
635 "{\n"
636 " ether\n"
637 " {\n"
638 " mcast yes\n"
639 " mcast_group\n"
640 " }\n"
641 "}\n";
642
643 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
644 bind(&isExpectedException, _1,
645 "Invalid value for option \"mcast_group\" in \"ether\" section"));
646}
647
648BOOST_AUTO_TEST_CASE(TestProcessSectionEtherUnknownOption)
649{
650 const std::string CONFIG =
651 "face_system\n"
652 "{\n"
653 " ether\n"
654 " {\n"
655 " hello\n"
656 " }\n"
657 "}\n";
658 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
659 bind(&isExpectedException, _1,
660 "Unrecognized option \"hello\" in \"ether\" section"));
661}
662
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600663#endif
664
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700665BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
666{
667 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
668
669 getFace()->onReceiveData +=
670 bind(&FaceManagerFixture::validateControlResponse, this, _1,
671 command->getName(), 400, "Malformed command");
672
673 getFace()->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700674 g_io.run_one();
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700675
676 BOOST_REQUIRE(didCallbackFire());
677}
678
679BOOST_AUTO_TEST_CASE(MalformedCommmand)
680{
681 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
682
683 getFace()->onReceiveData +=
684 bind(&FaceManagerFixture::validateControlResponse, this, _1,
685 command->getName(), 400, "Malformed command");
686
687 getManager().onFaceRequest(*command);
688
689 BOOST_REQUIRE(didCallbackFire());
690}
691
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700692BOOST_AUTO_TEST_CASE(UnsignedCommand)
693{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600694 ControlParameters parameters;
695 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700696
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600697 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700698
699 Name commandName("/localhost/nfd/faces");
700 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600701 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700702
703 shared_ptr<Interest> command(make_shared<Interest>(commandName));
704
705 getFace()->onReceiveData +=
706 bind(&FaceManagerFixture::validateControlResponse, this, _1,
707 command->getName(), 401, "Signature required");
708
709 getManager().onFaceRequest(*command);
710
711 BOOST_REQUIRE(didCallbackFire());
712}
713
714BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>)
715{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600716 ControlParameters parameters;
717 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700718
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600719 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700720
721 Name commandName("/localhost/nfd/faces");
722 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600723 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700724
725 shared_ptr<Interest> command(make_shared<Interest>(commandName));
726 generateCommand(*command);
727
728 getFace()->onReceiveData +=
729 bind(&FaceManagerFixture::validateControlResponse, this, _1,
730 command->getName(), 403, "Unauthorized command");
731
732 getManager().onFaceRequest(*command);
733
734 BOOST_REQUIRE(didCallbackFire());
735}
736
737template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
738{
739public:
740 AuthorizedCommandFixture()
741 {
742 const std::string regex = "^<localhost><nfd><faces>";
743 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
744 }
745
746 virtual
747 ~AuthorizedCommandFixture()
748 {
749
750 }
751};
752
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700753BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700754{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600755 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700756
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600757 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700758
759 Name commandName("/localhost/nfd/faces");
760 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600761 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700762
763 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700764 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700765
766 getFace()->onReceiveData +=
767 bind(&FaceManagerFixture::validateControlResponse, this, _1,
768 command->getName(), 501, "Unsupported command");
769
770 getManager().onFaceRequest(*command);
771
772 BOOST_REQUIRE(didCallbackFire());
773}
774
775class ValidatedFaceRequestFixture : public TestFaceTableFixture,
776 public TestFaceManagerCommon,
777 public FaceManager
778{
779public:
780
781 ValidatedFaceRequestFixture()
782 : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face),
783 m_createFaceFired(false),
784 m_destroyFaceFired(false)
785 {
786
787 }
788
789 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600790 createFace(const Interest& request,
791 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700792 {
793 m_createFaceFired = true;
794 }
795
796 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600797 destroyFace(const Interest& request,
798 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700799 {
800 m_destroyFaceFired = true;
801 }
802
803 virtual
804 ~ValidatedFaceRequestFixture()
805 {
806
807 }
808
809 bool
810 didCreateFaceFire() const
811 {
812 return m_createFaceFired;
813 }
814
815 bool
816 didDestroyFaceFire() const
817 {
818 return m_destroyFaceFired;
819 }
820
821private:
822 bool m_createFaceFired;
823 bool m_destroyFaceFired;
824};
825
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700826BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse,
827 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700828{
829 Name commandName("/localhost/nfd/faces");
830 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600831 commandName.append("NotReallyParameters");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700832
833 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700834 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700835
836 getFace()->onReceiveData +=
837 bind(&ValidatedFaceRequestFixture::validateControlResponse, this, _1,
838 command->getName(), 400, "Malformed command");
839
840 onValidatedFaceRequest(command);
841
842 BOOST_REQUIRE(didCallbackFire());
843}
844
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700845BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace,
846 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700847{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600848 ControlParameters parameters;
849 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700850
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600851 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700852
853 Name commandName("/localhost/nfd/faces");
854 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600855 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700856
857 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700858 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700859
860 onValidatedFaceRequest(command);
861 BOOST_CHECK(didCreateFaceFire());
862}
863
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700864BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace,
865 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700866{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600867 ControlParameters parameters;
868 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700869
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600870 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700871
872 Name commandName("/localhost/nfd/faces");
873 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600874 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700875
876 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700877 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700878
879 onValidatedFaceRequest(command);
880 BOOST_CHECK(didDestroyFaceFire());
881}
882
Steve DiBenedettofbb40a82014-03-11 19:40:15 -0600883class FaceTableFixture
884{
885public:
886 FaceTableFixture()
887 : m_faceTable(m_forwarder)
888 {
889 }
890
891 virtual
892 ~FaceTableFixture()
893 {
894 }
895
896protected:
897 Forwarder m_forwarder;
898 FaceTable m_faceTable;
899};
900
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600901class LocalControlFixture : public FaceTableFixture,
902 public TestFaceManagerCommon,
903 public FaceManager
904{
905public:
906 LocalControlFixture()
907 : FaceManager(FaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face)
908 {
909 }
910};
911
912BOOST_FIXTURE_TEST_CASE(LocalControlInFaceId,
913 AuthorizedCommandFixture<LocalControlFixture>)
914{
915 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
916 BOOST_REQUIRE(dummy->isLocal());
917 FaceTableFixture::m_faceTable.add(dummy);
918
919 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600920 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
921
922 Block encodedParameters(parameters.wireEncode());
923
924 Name enable("/localhost/nfd/faces/enable-local-control");
925 enable.append(encodedParameters);
926
927 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
928 enableCommand->setIncomingFaceId(dummy->getId());
929
930 generateCommand(*enableCommand);
931
932 TestFaceManagerCommon::m_face->onReceiveData +=
933 bind(&LocalControlFixture::validateControlResponse, this, _1,
934 enableCommand->getName(), 200, "Success", encodedParameters);
935
936 onValidatedFaceRequest(enableCommand);
937
938 BOOST_REQUIRE(didCallbackFire());
939 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
940 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
941
942 TestFaceManagerCommon::m_face->onReceiveData.clear();
943 resetCallbackFired();
944
945 Name disable("/localhost/nfd/faces/disable-local-control");
946 disable.append(encodedParameters);
947
948 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
949 disableCommand->setIncomingFaceId(dummy->getId());
950
951 generateCommand(*disableCommand);
952
953 TestFaceManagerCommon::m_face->onReceiveData +=
954 bind(&LocalControlFixture::validateControlResponse, this, _1,
955 disableCommand->getName(), 200, "Success", encodedParameters);
956
957 onValidatedFaceRequest(disableCommand);
958
959 BOOST_REQUIRE(didCallbackFire());
960 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
961 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
962}
963
964BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound,
965 AuthorizedCommandFixture<LocalControlFixture>)
966{
967 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
968 BOOST_REQUIRE(dummy->isLocal());
969 FaceTableFixture::m_faceTable.add(dummy);
970
971 ControlParameters parameters;
972 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
973
974 Block encodedParameters(parameters.wireEncode());
975
976 Name enable("/localhost/nfd/faces/enable-local-control");
977 enable.append(encodedParameters);
978
979 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
980 enableCommand->setIncomingFaceId(dummy->getId() + 100);
981
982 generateCommand(*enableCommand);
983
984 TestFaceManagerCommon::m_face->onReceiveData +=
985 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600986 enableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600987
988 onValidatedFaceRequest(enableCommand);
989
990 BOOST_REQUIRE(didCallbackFire());
991 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
992 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
993
994 TestFaceManagerCommon::m_face->onReceiveData.clear();
995 resetCallbackFired();
996
997 Name disable("/localhost/nfd/faces/disable-local-control");
998 disable.append(encodedParameters);
999
1000 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1001 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1002
1003 generateCommand(*disableCommand);
1004
1005 TestFaceManagerCommon::m_face->onReceiveData +=
1006 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001007 disableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001008
1009 onValidatedFaceRequest(disableCommand);
1010
1011 BOOST_REQUIRE(didCallbackFire());
1012 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1013 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1014}
1015
1016BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature,
1017 AuthorizedCommandFixture<LocalControlFixture>)
1018{
1019 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1020 BOOST_REQUIRE(dummy->isLocal());
1021 FaceTableFixture::m_faceTable.add(dummy);
1022
1023 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001024
1025 Block encodedParameters(parameters.wireEncode());
1026
1027 Name enable("/localhost/nfd/faces/enable-local-control");
1028 enable.append(encodedParameters);
1029
1030 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1031 enableCommand->setIncomingFaceId(dummy->getId());
1032
1033 generateCommand(*enableCommand);
1034
1035 TestFaceManagerCommon::m_face->onReceiveData +=
1036 bind(&LocalControlFixture::validateControlResponse, this, _1,
1037 enableCommand->getName(), 400, "Malformed command");
1038
1039 onValidatedFaceRequest(enableCommand);
1040
1041 BOOST_REQUIRE(didCallbackFire());
1042 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1043 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1044
1045 TestFaceManagerCommon::m_face->onReceiveData.clear();
1046 resetCallbackFired();
1047
1048 Name disable("/localhost/nfd/faces/disable-local-control");
1049 disable.append(encodedParameters);
1050
1051 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1052 disableCommand->setIncomingFaceId(dummy->getId());
1053
1054 generateCommand(*disableCommand);
1055
1056 TestFaceManagerCommon::m_face->onReceiveData +=
1057 bind(&LocalControlFixture::validateControlResponse, this, _1,
1058 disableCommand->getName(), 400, "Malformed command");
1059
1060 onValidatedFaceRequest(disableCommand);
1061
1062 BOOST_REQUIRE(didCallbackFire());
1063 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1064 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1065}
1066
1067BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal,
1068 AuthorizedCommandFixture<LocalControlFixture>)
1069{
1070 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1071 BOOST_REQUIRE(!dummy->isLocal());
1072 FaceTableFixture::m_faceTable.add(dummy);
1073
1074 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001075 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1076
1077 Block encodedParameters(parameters.wireEncode());
1078
1079 Name enable("/localhost/nfd/faces/enable-local-control");
1080 enable.append(encodedParameters);
1081
1082 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1083 enableCommand->setIncomingFaceId(dummy->getId());
1084
1085 generateCommand(*enableCommand);
1086
1087 TestFaceManagerCommon::m_face->onReceiveData +=
1088 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001089 enableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001090
1091 onValidatedFaceRequest(enableCommand);
1092
1093 BOOST_REQUIRE(didCallbackFire());
1094
1095 TestFaceManagerCommon::m_face->onReceiveData.clear();
1096 resetCallbackFired();
1097
1098 Name disable("/localhost/nfd/faces/disable-local-control");
1099 enable.append(encodedParameters);
1100
1101 shared_ptr<Interest> disableCommand(make_shared<Interest>(enable));
1102 disableCommand->setIncomingFaceId(dummy->getId());
1103
1104 generateCommand(*disableCommand);
1105
1106 TestFaceManagerCommon::m_face->onReceiveData +=
1107 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001108 disableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001109
1110 onValidatedFaceRequest(disableCommand);
1111
1112 BOOST_REQUIRE(didCallbackFire());
1113}
1114
1115BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId,
1116 AuthorizedCommandFixture<LocalControlFixture>)
1117{
1118 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1119 BOOST_REQUIRE(dummy->isLocal());
1120 FaceTableFixture::m_faceTable.add(dummy);
1121
1122 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001123 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1124
1125 Block encodedParameters(parameters.wireEncode());
1126
1127 Name enable("/localhost/nfd/faces/enable-local-control");
1128 enable.append(encodedParameters);
1129
1130 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1131 enableCommand->setIncomingFaceId(dummy->getId());
1132
1133 generateCommand(*enableCommand);
1134
1135 TestFaceManagerCommon::m_face->onReceiveData +=
1136 bind(&LocalControlFixture::validateControlResponse, this, _1,
1137 enableCommand->getName(), 200, "Success", encodedParameters);
1138
1139 onValidatedFaceRequest(enableCommand);
1140
1141 BOOST_REQUIRE(didCallbackFire());
1142 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1143 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1144
1145
1146 TestFaceManagerCommon::m_face->onReceiveData.clear();
1147 resetCallbackFired();
1148
1149 Name disable("/localhost/nfd/faces/disable-local-control");
1150 disable.append(encodedParameters);
1151
1152 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1153 disableCommand->setIncomingFaceId(dummy->getId());
1154
1155 generateCommand(*disableCommand);
1156
1157 TestFaceManagerCommon::m_face->onReceiveData +=
1158 bind(&LocalControlFixture::validateControlResponse, this, _1,
1159 disableCommand->getName(), 200, "Success", encodedParameters);
1160
1161 onValidatedFaceRequest(disableCommand);
1162
1163 BOOST_REQUIRE(didCallbackFire());
1164 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1165 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1166}
1167
1168BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound,
1169 AuthorizedCommandFixture<LocalControlFixture>)
1170{
1171 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1172 BOOST_REQUIRE(dummy->isLocal());
1173 FaceTableFixture::m_faceTable.add(dummy);
1174
1175 ControlParameters parameters;
1176 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1177
1178 Block encodedParameters(parameters.wireEncode());
1179
1180 Name enable("/localhost/nfd/faces/enable-local-control");
1181 enable.append(encodedParameters);
1182
1183 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1184 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1185
1186 generateCommand(*enableCommand);
1187
1188 TestFaceManagerCommon::m_face->onReceiveData +=
1189 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001190 enableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001191
1192 onValidatedFaceRequest(enableCommand);
1193
1194 BOOST_REQUIRE(didCallbackFire());
1195 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1196 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1197
1198
1199 TestFaceManagerCommon::m_face->onReceiveData.clear();
1200 resetCallbackFired();
1201
1202 Name disable("/localhost/nfd/faces/disable-local-control");
1203 disable.append(encodedParameters);
1204
1205 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1206 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1207
1208 generateCommand(*disableCommand);
1209
1210 TestFaceManagerCommon::m_face->onReceiveData +=
1211 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001212 disableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001213
1214 onValidatedFaceRequest(disableCommand);
1215
1216 BOOST_REQUIRE(didCallbackFire());
1217 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1218 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1219}
1220
1221BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal,
1222 AuthorizedCommandFixture<LocalControlFixture>)
1223{
1224 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1225 BOOST_REQUIRE(!dummy->isLocal());
1226 FaceTableFixture::m_faceTable.add(dummy);
1227
1228 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001229 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1230
1231 Block encodedParameters(parameters.wireEncode());
1232
1233 Name enable("/localhost/nfd/faces/enable-local-control");
1234 enable.append(encodedParameters);
1235
1236 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1237 enableCommand->setIncomingFaceId(dummy->getId());
1238
1239 generateCommand(*enableCommand);
1240
1241 TestFaceManagerCommon::m_face->onReceiveData +=
1242 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001243 enableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001244
1245 onValidatedFaceRequest(enableCommand);
1246
1247 BOOST_REQUIRE(didCallbackFire());
1248
1249 TestFaceManagerCommon::m_face->onReceiveData.clear();
1250 resetCallbackFired();
1251
1252 Name disable("/localhost/nfd/faces/disable-local-control");
1253 disable.append(encodedParameters);
1254
1255 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1256 disableCommand->setIncomingFaceId(dummy->getId());
1257
1258 generateCommand(*disableCommand);
1259
1260 TestFaceManagerCommon::m_face->onReceiveData +=
1261 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001262 disableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001263
1264 onValidatedFaceRequest(disableCommand);
1265
1266 BOOST_REQUIRE(didCallbackFire());
1267}
1268
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001269class FaceFixture : public FaceTableFixture,
1270 public TestFaceManagerCommon,
1271 public FaceManager
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001272{
1273public:
1274 FaceFixture()
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001275 : FaceManager(FaceTableFixture::m_faceTable,
1276 TestFaceManagerCommon::m_face)
1277 , m_receivedNotification(false)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001278 {
1279
1280 }
1281
1282 virtual
1283 ~FaceFixture()
1284 {
1285
1286 }
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001287
1288 void
1289 callbackDispatch(const Data& response,
1290 const Name& expectedName,
1291 uint32_t expectedCode,
1292 const std::string& expectedText,
1293 const Block& expectedBody,
1294 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1295 {
1296 Block payload = response.getContent().blockFromValue();
1297 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1298 {
1299 validateControlResponse(response, expectedName, expectedCode,
1300 expectedText, expectedBody);
1301 }
1302 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1303 {
1304 validateFaceEvent(payload, expectedFaceEvent);
1305 }
1306 else
1307 {
1308 BOOST_FAIL("Received unknown message type: #" << payload.type());
1309 }
1310 }
1311
1312 void
1313 callbackDispatch(const Data& response,
1314 const Name& expectedName,
1315 uint32_t expectedCode,
1316 const std::string& expectedText,
1317 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1318 {
1319 Block payload = response.getContent().blockFromValue();
1320 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1321 {
1322 validateControlResponse(response, expectedName,
1323 expectedCode, expectedText);
1324 }
1325 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1326 {
1327 validateFaceEvent(payload, expectedFaceEvent);
1328 }
1329 else
1330 {
1331 BOOST_FAIL("Received unknown message type: #" << payload.type());
1332 }
1333 }
1334
1335 void
1336 validateFaceEvent(const Block& wire,
1337 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1338 {
1339
1340 m_receivedNotification = true;
1341
1342 ndn::nfd::FaceEventNotification notification(wire);
1343
Junxiao Shi6e694322014-04-03 10:27:13 -07001344 BOOST_CHECK_EQUAL(notification.getKind(), expectedFaceEvent.getKind());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001345 BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId());
Junxiao Shi6e694322014-04-03 10:27:13 -07001346 BOOST_CHECK_EQUAL(notification.getRemoteUri(), expectedFaceEvent.getRemoteUri());
1347 BOOST_CHECK_EQUAL(notification.getLocalUri(), expectedFaceEvent.getLocalUri());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001348 }
1349
1350 bool
1351 didReceiveNotication() const
1352 {
1353 return m_receivedNotification;
1354 }
1355
1356protected:
1357 bool m_receivedNotification;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001358};
1359
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001360BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001361{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001362 ControlParameters parameters;
1363 parameters.setUri("tcp:/127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001364
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001365 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001366
1367 Name commandName("/localhost/nfd/faces");
1368 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001369 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001370
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001371 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1372 generateCommand(*command);
1373
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001374 getFace()->onReceiveData +=
1375 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001376 command->getName(), 400, "Malformed command");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001377
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001378 createFace(*command, parameters);
1379
1380 BOOST_REQUIRE(didCallbackFire());
1381}
1382
1383BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>)
1384{
1385 ControlParameters parameters;
1386
1387 Block encodedParameters(parameters.wireEncode());
1388
1389 Name commandName("/localhost/nfd/faces");
1390 commandName.append("create");
1391 commandName.append(encodedParameters);
1392
1393 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1394 generateCommand(*command);
1395
1396 getFace()->onReceiveData +=
1397 bind(&FaceFixture::validateControlResponse, this, _1,
1398 command->getName(), 400, "Malformed command");
1399
1400 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001401
1402 BOOST_REQUIRE(didCallbackFire());
1403}
1404
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001405BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001406{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001407 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001408 // this will be an unsupported protocol because no factories have been
1409 // added to the face manager
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001410 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001411
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001412 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001413
1414 Name commandName("/localhost/nfd/faces");
1415 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001416 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001417
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001418 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1419 generateCommand(*command);
1420
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001421 getFace()->onReceiveData +=
1422 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001423 command->getName(), 501, "Unsupported protocol");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001424
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001425 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001426
1427 BOOST_REQUIRE(didCallbackFire());
1428}
1429
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001430BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001431{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001432 ControlParameters parameters;
1433 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001434
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001435 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001436
1437 Name commandName("/localhost/nfd/faces");
1438 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001439 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001440
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001441 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1442 generateCommand(*command);
1443
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001444 ControlParameters resultParameters;
1445 resultParameters.setUri("tcp://127.0.0.1");
1446 resultParameters.setFaceId(1);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001447
1448 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1449
Junxiao Shi6e694322014-04-03 10:27:13 -07001450 ndn::nfd::FaceEventNotification expectedFaceEvent;
1451 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED)
1452 .setFaceId(1)
1453 .setRemoteUri(dummy->getRemoteUri().toString())
1454 .setLocalUri(dummy->getLocalUri().toString())
1455 .setFlags(0);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001456
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001457 Block encodedResultParameters(resultParameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001458
1459 getFace()->onReceiveData +=
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001460 bind(&FaceFixture::callbackDispatch, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001461 command->getName(), 200, "Success",
1462 encodedResultParameters, expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001463
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001464 onCreated(command->getName(), parameters, dummy);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001465
1466 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001467 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001468}
1469
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001470BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001471{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001472 ControlParameters parameters;
1473 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001474
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001475 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001476
1477 Name commandName("/localhost/nfd/faces");
1478 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001479 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001480
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001481 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1482 generateCommand(*command);
1483
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001484 getFace()->onReceiveData +=
1485 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedettoca53ac62014-03-27 19:58:40 -06001486 command->getName(), 408, "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001487
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001488 onConnectFailed(command->getName(), "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001489
1490 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001491 BOOST_CHECK_EQUAL(didReceiveNotication(), false);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001492}
1493
1494
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001495BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001496{
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001497 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1498 FaceTableFixture::m_faceTable.add(dummy);
1499
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001500 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001501 parameters.setFaceId(dummy->getId());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001502
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001503 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001504
1505 Name commandName("/localhost/nfd/faces");
1506 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001507 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001508
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001509 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1510 generateCommand(*command);
1511
Junxiao Shi6e694322014-04-03 10:27:13 -07001512 ndn::nfd::FaceEventNotification expectedFaceEvent;
1513 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
1514 .setFaceId(dummy->getId())
1515 .setRemoteUri(dummy->getRemoteUri().toString())
1516 .setLocalUri(dummy->getLocalUri().toString())
1517 .setFlags(0);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001518
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001519 getFace()->onReceiveData +=
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001520 bind(&FaceFixture::callbackDispatch, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001521 command->getName(), 200, "Success", boost::ref(encodedParameters), expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001522
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001523 destroyFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001524
1525 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001526 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001527}
1528
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001529class FaceListFixture : public FaceStatusPublisherFixture
1530{
1531public:
1532 FaceListFixture()
1533 : m_manager(m_table, m_face)
1534 {
1535
1536 }
1537
1538 virtual
1539 ~FaceListFixture()
1540 {
1541
1542 }
1543
1544protected:
1545 FaceManager m_manager;
1546};
1547
1548BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture)
1549
1550{
1551 Name commandName("/localhost/nfd/faces/list");
1552 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1553
1554 // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 55
1555 // 55 divides 4400 (== 80), so only use 79 FaceStatuses and then two smaller ones
1556 // to force a FaceStatus to span Data packets
1557 for (int i = 0; i < 79; i++)
1558 {
1559 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1560
1561 uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
1562 dummy->setCounters(filler, filler, filler, filler);
1563
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001564 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001565
1566 add(dummy);
1567 }
1568
1569 for (int i = 0; i < 2; i++)
1570 {
1571 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1572 uint64_t filler = std::numeric_limits<uint32_t>::max() - 1;
1573 dummy->setCounters(filler, filler, filler, filler);
1574
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001575 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001576
1577 add(dummy);
1578 }
1579
1580 ndn::EncodingBuffer buffer;
1581
1582 m_face->onReceiveData +=
1583 bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, this, _1);
1584
1585 m_manager.listFaces(*command);
1586 BOOST_REQUIRE(m_finished);
1587}
1588
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001589BOOST_AUTO_TEST_SUITE_END()
1590
1591} // namespace tests
1592} // namespace nfd