blob: 70d8d83b48e88c4841b9721dfcbb19dda44120ce [file] [log] [blame]
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Steve DiBenedettoef04f272014-06-04 14:28:31 -06003 * 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 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Steve DiBenedettoef04f272014-06-04 14:28:31 -060024 */
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070025
26#include "mgmt/face-manager.hpp"
27#include "mgmt/internal-face.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060028#include "mgmt/face-status-publisher.hpp"
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060029
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070030#include "face/face.hpp"
31#include "../face/dummy-face.hpp"
32#include "fw/face-table.hpp"
33#include "fw/forwarder.hpp"
Alexander Afanasyev5959b012014-06-02 19:18:12 +030034#include "face/udp-factory.hpp"
Alexander Afanasyeve9186212014-08-23 20:15:48 -070035
36#ifdef HAVE_LIBPCAP
Alexander Afanasyev5959b012014-06-02 19:18:12 +030037#include "face/ethernet-factory.hpp"
Alexander Afanasyeve9186212014-08-23 20:15:48 -070038#endif // HAVE_LIBPCAP
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070039
40#include "common.hpp"
41#include "tests/test-common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070042#include "validation-common.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060043#include "face-status-publisher-common.hpp"
Chengyu Fan320d2332014-10-29 16:40:33 -060044#include "face-query-status-publisher-common.hpp"
Steve DiBenedettoef04f272014-06-04 14:28:31 -060045#include "channel-status-common.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060046
Alexander Afanasyev4a771362014-04-24 21:29:33 -070047#include <ndn-cxx/encoding/tlv.hpp>
48#include <ndn-cxx/management/nfd-face-event-notification.hpp>
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070049
50namespace nfd {
51namespace tests {
52
53NFD_LOG_INIT("FaceManagerTest");
54
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060055class FaceManagerTestFace : public DummyFace
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070056{
57public:
58
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060059 FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070060 : m_closeFired(false)
61 {
62
63 }
64
65 virtual
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060066 ~FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070067 {
68
69 }
70
71 virtual void
72 close()
73 {
74 m_closeFired = true;
75 }
76
77 bool
78 didCloseFire() const
79 {
80 return m_closeFired;
81 }
82
83private:
84 bool m_closeFired;
85};
86
87class TestFaceTable : public FaceTable
88{
89public:
90 TestFaceTable(Forwarder& forwarder)
91 : FaceTable(forwarder),
92 m_addFired(false),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070093 m_getFired(false),
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060094 m_dummy(make_shared<FaceManagerTestFace>())
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070095 {
96
97 }
98
99 virtual
100 ~TestFaceTable()
101 {
102
103 }
104
105 virtual void
106 add(shared_ptr<Face> face)
107 {
108 m_addFired = true;
109 }
110
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700111 virtual shared_ptr<Face>
112 get(FaceId id) const
113 {
114 m_getFired = true;
115 return m_dummy;
116 }
117
118 bool
119 didAddFire() const
120 {
121 return m_addFired;
122 }
123
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700124 bool
125 didGetFire() const
126 {
127 return m_getFired;
128 }
129
130 void
131 reset()
132 {
133 m_addFired = false;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700134 m_getFired = false;
135 }
136
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600137 shared_ptr<FaceManagerTestFace>&
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700138 getDummyFace()
139 {
140 return m_dummy;
141 }
142
143private:
144 bool m_addFired;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700145 mutable bool m_getFired;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600146 shared_ptr<FaceManagerTestFace> m_dummy;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700147};
148
149
150class TestFaceTableFixture : public BaseFixture
151{
152public:
153 TestFaceTableFixture()
154 : m_faceTable(m_forwarder)
155 {
156
157 }
158
159 virtual
160 ~TestFaceTableFixture()
161 {
162
163 }
164
165protected:
166 Forwarder m_forwarder;
167 TestFaceTable m_faceTable;
168};
169
170class TestFaceManagerCommon
171{
172public:
173 TestFaceManagerCommon()
174 : m_face(make_shared<InternalFace>()),
175 m_callbackFired(false)
176 {
177
178 }
179
180 virtual
181 ~TestFaceManagerCommon()
182 {
183
184 }
185
186 shared_ptr<InternalFace>&
187 getFace()
188 {
189 return m_face;
190 }
191
192 void
193 validateControlResponseCommon(const Data& response,
194 const Name& expectedName,
195 uint32_t expectedCode,
196 const std::string& expectedText,
197 ControlResponse& control)
198 {
199 m_callbackFired = true;
200 Block controlRaw = response.getContent().blockFromValue();
201
202 control.wireDecode(controlRaw);
203
204 // NFD_LOG_DEBUG("received control response"
205 // << " Name: " << response.getName()
206 // << " code: " << control.getCode()
207 // << " text: " << control.getText());
208
209 BOOST_CHECK_EQUAL(response.getName(), expectedName);
210 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
211 BOOST_CHECK_EQUAL(control.getText(), expectedText);
212 }
213
214 void
215 validateControlResponse(const Data& response,
216 const Name& expectedName,
217 uint32_t expectedCode,
218 const std::string& expectedText)
219 {
220 ControlResponse control;
221 validateControlResponseCommon(response, expectedName,
222 expectedCode, expectedText, control);
223
224 if (!control.getBody().empty())
225 {
226 BOOST_FAIL("found unexpected control response body");
227 }
228 }
229
230 void
231 validateControlResponse(const Data& response,
232 const Name& expectedName,
233 uint32_t expectedCode,
234 const std::string& expectedText,
235 const Block& expectedBody)
236 {
237 ControlResponse control;
238 validateControlResponseCommon(response, expectedName,
239 expectedCode, expectedText, control);
240
241 BOOST_REQUIRE(!control.getBody().empty());
242 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
243
244 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
245 expectedBody.value_size()) == 0);
246
247 }
248
249 bool
250 didCallbackFire() const
251 {
252 return m_callbackFired;
253 }
254
255 void
256 resetCallbackFired()
257 {
258 m_callbackFired = false;
259 }
260
261protected:
262 shared_ptr<InternalFace> m_face;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700263 bool m_callbackFired;
Vince Lehman5144f822014-07-23 15:12:56 -0700264 ndn::KeyChain m_testKeyChain;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700265};
266
267class FaceManagerFixture : public TestFaceTableFixture, public TestFaceManagerCommon
268{
269public:
270 FaceManagerFixture()
Vince Lehman5144f822014-07-23 15:12:56 -0700271 : m_manager(m_faceTable, m_face, m_testKeyChain)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700272 {
273 m_manager.setConfigFile(m_config);
274 }
275
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700276 virtual
277 ~FaceManagerFixture()
278 {
279
280 }
281
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600282 void
283 parseConfig(const std::string configuration, bool isDryRun)
284 {
285 m_config.parse(configuration, isDryRun, "dummy-config");
286 }
287
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700288 FaceManager&
289 getManager()
290 {
291 return m_manager;
292 }
293
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700294 void
295 addInterestRule(const std::string& regex,
296 ndn::IdentityCertificate& certificate)
297 {
298 m_manager.addInterestRule(regex, certificate);
299 }
300
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700301 bool
302 didFaceTableAddFire() const
303 {
304 return m_faceTable.didAddFire();
305 }
306
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700307 bool
308 didFaceTableGetFire() const
309 {
310 return m_faceTable.didGetFire();
311 }
312
313 void
314 resetFaceTable()
315 {
316 m_faceTable.reset();
317 }
318
Steve DiBenedettoef04f272014-06-04 14:28:31 -0600319protected:
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700320 FaceManager m_manager;
321 ConfigFile m_config;
322};
323
324BOOST_FIXTURE_TEST_SUITE(MgmtFaceManager, FaceManagerFixture)
325
326bool
327isExpectedException(const ConfigFile::Error& error, const std::string& expectedMessage)
328{
329 if (error.what() != expectedMessage)
330 {
331 NFD_LOG_ERROR("expected: " << expectedMessage << "\tgot: " << error.what());
332 }
333 return error.what() == expectedMessage;
334}
335
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600336#ifdef HAVE_UNIX_SOCKETS
337
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700338BOOST_AUTO_TEST_CASE(TestProcessSectionUnix)
339{
340 const std::string CONFIG =
341 "face_system\n"
342 "{\n"
343 " unix\n"
344 " {\n"
345 " listen yes\n"
346 " path /tmp/nfd.sock\n"
347 " }\n"
348 "}\n";
349 BOOST_TEST_CHECKPOINT("Calling parse");
350 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
351}
352
353BOOST_AUTO_TEST_CASE(TestProcessSectionUnixDryRun)
354{
355 const std::string CONFIG =
356 "face_system\n"
357 "{\n"
358 " unix\n"
359 " {\n"
360 " listen yes\n"
361 " path /var/run/nfd.sock\n"
362 " }\n"
363 "}\n";
364
365 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
366}
367
368BOOST_AUTO_TEST_CASE(TestProcessSectionUnixBadListen)
369{
370 const std::string CONFIG =
371 "face_system\n"
372 "{\n"
373 " unix\n"
374 " {\n"
375 " listen hello\n"
376 " }\n"
377 "}\n";
378 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
379 bind(&isExpectedException, _1,
380 "Invalid value for option \"listen\" in \"unix\" section"));
381}
382
383BOOST_AUTO_TEST_CASE(TestProcessSectionUnixUnknownOption)
384{
385 const std::string CONFIG =
386 "face_system\n"
387 "{\n"
388 " unix\n"
389 " {\n"
390 " hello\n"
391 " }\n"
392 "}\n";
393 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
394 bind(&isExpectedException, _1,
395 "Unrecognized option \"hello\" in \"unix\" section"));
396}
397
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600398#endif // HAVE_UNIX_SOCKETS
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700399
400
401BOOST_AUTO_TEST_CASE(TestProcessSectionTcp)
402{
403 const std::string CONFIG =
404 "face_system\n"
405 "{\n"
406 " tcp\n"
407 " {\n"
408 " listen yes\n"
409 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600410 " enable_v4 yes\n"
411 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700412 " }\n"
413 "}\n";
414 try
415 {
416 parseConfig(CONFIG, false);
417 }
418 catch (const std::runtime_error& e)
419 {
420 const std::string reason = e.what();
421 if (reason.find("Address in use") != std::string::npos)
422 {
423 BOOST_FAIL(reason);
424 }
425 }
426}
427
428BOOST_AUTO_TEST_CASE(TestProcessSectionTcpDryRun)
429{
430 const std::string CONFIG =
431 "face_system\n"
432 "{\n"
433 " tcp\n"
434 " {\n"
435 " listen yes\n"
436 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600437 " enable_v4 yes\n"
438 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700439 " }\n"
440 "}\n";
441 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
442}
443
444BOOST_AUTO_TEST_CASE(TestProcessSectionTcpBadListen)
445{
446 const std::string CONFIG =
447 "face_system\n"
448 "{\n"
449 " tcp\n"
450 " {\n"
451 " listen hello\n"
452 " }\n"
453 "}\n";
454 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
455 bind(&isExpectedException, _1,
456 "Invalid value for option \"listen\" in \"tcp\" section"));
457}
458
Steve DiBenedetto95152872014-04-11 12:40:59 -0600459BOOST_AUTO_TEST_CASE(TestProcessSectionTcpChannelsDisabled)
460{
461 const std::string CONFIG =
462 "face_system\n"
463 "{\n"
464 " tcp\n"
465 " {\n"
466 " port 6363\n"
467 " enable_v4 no\n"
468 " enable_v6 no\n"
469 " }\n"
470 "}\n";
471 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
472 bind(&isExpectedException, _1,
473 "IPv4 and IPv6 channels have been disabled."
474 " Remove \"tcp\" section to disable TCP channels or"
475 " re-enable at least one channel type."));
476}
477
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700478BOOST_AUTO_TEST_CASE(TestProcessSectionTcpUnknownOption)
479{
480 const std::string CONFIG =
481 "face_system\n"
482 "{\n"
483 " tcp\n"
484 " {\n"
485 " hello\n"
486 " }\n"
487 "}\n";
488 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
489 bind(&isExpectedException, _1,
490 "Unrecognized option \"hello\" in \"tcp\" section"));
491}
492
493BOOST_AUTO_TEST_CASE(TestProcessSectionUdp)
494{
495 const std::string CONFIG =
496 "face_system\n"
497 "{\n"
498 " udp\n"
499 " {\n"
500 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600501 " enable_v4 yes\n"
502 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700503 " idle_timeout 30\n"
504 " keep_alive_interval 25\n"
505 " mcast yes\n"
506 " mcast_port 56363\n"
507 " mcast_group 224.0.23.170\n"
508 " }\n"
509 "}\n";
510 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
511}
512
513BOOST_AUTO_TEST_CASE(TestProcessSectionUdpDryRun)
514{
515 const std::string CONFIG =
516 "face_system\n"
517 "{\n"
518 " udp\n"
519 " {\n"
520 " port 6363\n"
521 " idle_timeout 30\n"
522 " keep_alive_interval 25\n"
523 " mcast yes\n"
524 " mcast_port 56363\n"
525 " mcast_group 224.0.23.170\n"
526 " }\n"
527 "}\n";
528 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
529}
530
531BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadIdleTimeout)
532{
533 const std::string CONFIG =
534 "face_system\n"
535 "{\n"
536 " udp\n"
537 " {\n"
538 " idle_timeout hello\n"
539 " }\n"
540 "}\n";
541
542 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
543 bind(&isExpectedException, _1,
544 "Invalid value for option \"idle_timeout\" in \"udp\" section"));
545}
546
547BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcast)
548{
549 const std::string CONFIG =
550 "face_system\n"
551 "{\n"
552 " udp\n"
553 " {\n"
554 " mcast hello\n"
555 " }\n"
556 "}\n";
557
558 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
559 bind(&isExpectedException, _1,
560 "Invalid value for option \"mcast\" in \"udp\" section"));
561}
562
563BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroup)
564{
565 const std::string CONFIG =
566 "face_system\n"
567 "{\n"
568 " udp\n"
569 " {\n"
570 " mcast no\n"
571 " mcast_port 50\n"
572 " mcast_group hello\n"
573 " }\n"
574 "}\n";
575
576 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
577 bind(&isExpectedException, _1,
578 "Invalid value for option \"mcast_group\" in \"udp\" section"));
579}
580
581BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroupV6)
582{
583 const std::string CONFIG =
584 "face_system\n"
585 "{\n"
586 " udp\n"
587 " {\n"
588 " mcast no\n"
589 " mcast_port 50\n"
590 " mcast_group ::1\n"
591 " }\n"
592 "}\n";
593
594 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
595 bind(&isExpectedException, _1,
596 "Invalid value for option \"mcast_group\" in \"udp\" section"));
597}
598
Steve DiBenedetto95152872014-04-11 12:40:59 -0600599BOOST_AUTO_TEST_CASE(TestProcessSectionUdpChannelsDisabled)
600{
601 const std::string CONFIG =
602 "face_system\n"
603 "{\n"
604 " udp\n"
605 " {\n"
606 " port 6363\n"
607 " enable_v4 no\n"
608 " enable_v6 no\n"
609 " idle_timeout 30\n"
610 " keep_alive_interval 25\n"
611 " mcast yes\n"
612 " mcast_port 56363\n"
613 " mcast_group 224.0.23.170\n"
614 " }\n"
615 "}\n";
616 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
617 bind(&isExpectedException, _1,
618 "IPv4 and IPv6 channels have been disabled."
619 " Remove \"udp\" section to disable UDP channels or"
620 " re-enable at least one channel type."));
621}
622
623BOOST_AUTO_TEST_CASE(TestProcessSectionUdpConflictingMcast)
624{
625 const std::string CONFIG =
626 "face_system\n"
627 "{\n"
628 " udp\n"
629 " {\n"
630 " port 6363\n"
631 " enable_v4 no\n"
632 " enable_v6 yes\n"
633 " idle_timeout 30\n"
634 " keep_alive_interval 25\n"
635 " mcast yes\n"
636 " mcast_port 56363\n"
637 " mcast_group 224.0.23.170\n"
638 " }\n"
639 "}\n";
640 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
641 bind(&isExpectedException, _1,
642 "IPv4 multicast requested, but IPv4 channels"
643 " have been disabled (conflicting configuration options set)"));
644}
645
646
647
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700648BOOST_AUTO_TEST_CASE(TestProcessSectionUdpUnknownOption)
649{
650 const std::string CONFIG =
651 "face_system\n"
652 "{\n"
653 " udp\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 \"udp\" section"));
661}
662
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300663
664BOOST_AUTO_TEST_CASE(TestProcessSectionUdpMulticastReinit)
665{
666 const std::string CONFIG_WITH_MCAST =
667 "face_system\n"
668 "{\n"
669 " udp\n"
670 " {\n"
671 " mcast yes\n"
672 " }\n"
673 "}\n";
674 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
675
676 shared_ptr<UdpFactory> factory = static_pointer_cast<UdpFactory>(getManager().findFactory("udp"));
677 BOOST_REQUIRE(static_cast<bool>(factory));
678
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300679 if (factory->getMulticastFaces().size() == 0) {
680 BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
681 "no UDP multicast faces are available");
682 }
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300683
684 const std::string CONFIG_WITHOUT_MCAST =
685 "face_system\n"
686 "{\n"
687 " udp\n"
688 " {\n"
689 " mcast no\n"
690 " }\n"
691 "}\n";
692 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
693 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
694}
695
696
Alexander Afanasyev885a85b2014-04-12 21:01:13 -0700697#ifdef HAVE_LIBPCAP
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600698
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700699BOOST_AUTO_TEST_CASE(TestProcessSectionEther)
700{
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600701
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700702 const std::string CONFIG =
703 "face_system\n"
704 "{\n"
705 " ether\n"
706 " {\n"
707 " mcast yes\n"
708 " mcast_group 01:00:5E:00:17:AA\n"
709 " }\n"
710 "}\n";
711
712 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
713}
714
715BOOST_AUTO_TEST_CASE(TestProcessSectionEtherDryRun)
716{
717 const std::string CONFIG =
718 "face_system\n"
719 "{\n"
720 " ether\n"
721 " {\n"
722 " mcast yes\n"
723 " mcast_group 01:00:5E:00:17:AA\n"
724 " }\n"
725 "}\n";
726
727 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
728}
729
730BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcast)
731{
732 const std::string CONFIG =
733 "face_system\n"
734 "{\n"
735 " ether\n"
736 " {\n"
737 " mcast hello\n"
738 " }\n"
739 "}\n";
740
741 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
742 bind(&isExpectedException, _1,
743 "Invalid value for option \"mcast\" in \"ether\" section"));
744}
745
746BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcastGroup)
747{
748 const std::string CONFIG =
749 "face_system\n"
750 "{\n"
751 " ether\n"
752 " {\n"
753 " mcast yes\n"
754 " mcast_group\n"
755 " }\n"
756 "}\n";
757
758 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
759 bind(&isExpectedException, _1,
760 "Invalid value for option \"mcast_group\" in \"ether\" section"));
761}
762
763BOOST_AUTO_TEST_CASE(TestProcessSectionEtherUnknownOption)
764{
765 const std::string CONFIG =
766 "face_system\n"
767 "{\n"
768 " ether\n"
769 " {\n"
770 " hello\n"
771 " }\n"
772 "}\n";
773 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
774 bind(&isExpectedException, _1,
775 "Unrecognized option \"hello\" in \"ether\" section"));
776}
777
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300778BOOST_AUTO_TEST_CASE(TestProcessSectionEtherMulticastReinit)
779{
780 const std::string CONFIG_WITH_MCAST =
781 "face_system\n"
782 "{\n"
783 " ether\n"
784 " {\n"
785 " mcast yes\n"
786 " }\n"
787 "}\n";
788 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
789
790 shared_ptr<EthernetFactory> factory =
791 static_pointer_cast<EthernetFactory>(getManager().findFactory("ether"));
792 BOOST_REQUIRE(static_cast<bool>(factory));
793
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300794 if (factory->getMulticastFaces().size() == 0) {
795 BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
796 "no Ethernet multicast faces are available");
797 }
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300798
799 const std::string CONFIG_WITHOUT_MCAST =
800 "face_system\n"
801 "{\n"
802 " ether\n"
803 " {\n"
804 " mcast no\n"
805 " }\n"
806 "}\n";
807 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
808 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
809}
810
Alexander Afanasyeve9186212014-08-23 20:15:48 -0700811#endif // HAVE_LIBPCAP
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600812
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700813BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
814{
815 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
816
Junxiao Shicd55cde2014-11-13 16:03:24 -0700817 getFace()->onReceiveData += [this, command] (const Data& response) {
818 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
819 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700820
821 getFace()->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700822 g_io.run_one();
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700823
824 BOOST_REQUIRE(didCallbackFire());
825}
826
827BOOST_AUTO_TEST_CASE(MalformedCommmand)
828{
829 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
830
Junxiao Shicd55cde2014-11-13 16:03:24 -0700831 getFace()->onReceiveData += [this, command] (const Data& response) {
832 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
833 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700834
835 getManager().onFaceRequest(*command);
836
837 BOOST_REQUIRE(didCallbackFire());
838}
839
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700840BOOST_AUTO_TEST_CASE(UnsignedCommand)
841{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600842 ControlParameters parameters;
843 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700844
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600845 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700846
847 Name commandName("/localhost/nfd/faces");
848 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600849 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700850
851 shared_ptr<Interest> command(make_shared<Interest>(commandName));
852
Junxiao Shicd55cde2014-11-13 16:03:24 -0700853 getFace()->onReceiveData += [this, command] (const Data& response) {
854 this->validateControlResponse(response, command->getName(), 401, "Signature required");
855 };
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700856
857 getManager().onFaceRequest(*command);
858
859 BOOST_REQUIRE(didCallbackFire());
860}
861
862BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>)
863{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600864 ControlParameters parameters;
865 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700866
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600867 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700868
869 Name commandName("/localhost/nfd/faces");
870 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600871 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700872
873 shared_ptr<Interest> command(make_shared<Interest>(commandName));
874 generateCommand(*command);
875
Junxiao Shicd55cde2014-11-13 16:03:24 -0700876 getFace()->onReceiveData += [this, command] (const Data& response) {
877 this->validateControlResponse(response, command->getName(), 403, "Unauthorized command");
878 };
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700879
880 getManager().onFaceRequest(*command);
881
882 BOOST_REQUIRE(didCallbackFire());
883}
884
885template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
886{
887public:
888 AuthorizedCommandFixture()
889 {
890 const std::string regex = "^<localhost><nfd><faces>";
891 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
892 }
893
894 virtual
895 ~AuthorizedCommandFixture()
896 {
897
898 }
899};
900
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700901BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700902{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600903 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700904
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600905 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700906
907 Name commandName("/localhost/nfd/faces");
908 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600909 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700910
911 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700912 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700913
Junxiao Shicd55cde2014-11-13 16:03:24 -0700914 getFace()->onReceiveData += [this, command] (const Data& response) {
915 this->validateControlResponse(response, command->getName(), 501, "Unsupported command");
916 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700917
918 getManager().onFaceRequest(*command);
919
920 BOOST_REQUIRE(didCallbackFire());
921}
922
923class ValidatedFaceRequestFixture : public TestFaceTableFixture,
924 public TestFaceManagerCommon,
925 public FaceManager
926{
927public:
928
929 ValidatedFaceRequestFixture()
Vince Lehman5144f822014-07-23 15:12:56 -0700930 : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face, m_testKeyChain),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700931 m_createFaceFired(false),
932 m_destroyFaceFired(false)
933 {
934
935 }
936
937 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600938 createFace(const Interest& request,
939 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700940 {
941 m_createFaceFired = true;
942 }
943
944 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600945 destroyFace(const Interest& request,
946 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700947 {
948 m_destroyFaceFired = true;
949 }
950
951 virtual
952 ~ValidatedFaceRequestFixture()
953 {
954
955 }
956
957 bool
958 didCreateFaceFire() const
959 {
960 return m_createFaceFired;
961 }
962
963 bool
964 didDestroyFaceFire() const
965 {
966 return m_destroyFaceFired;
967 }
968
969private:
970 bool m_createFaceFired;
971 bool m_destroyFaceFired;
972};
973
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700974BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse,
975 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700976{
977 Name commandName("/localhost/nfd/faces");
978 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600979 commandName.append("NotReallyParameters");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700980
981 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700982 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700983
Junxiao Shicd55cde2014-11-13 16:03:24 -0700984 getFace()->onReceiveData += [this, command] (const Data& response) {
985 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
986 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700987
988 onValidatedFaceRequest(command);
989
990 BOOST_REQUIRE(didCallbackFire());
991}
992
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700993BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace,
994 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700995{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600996 ControlParameters parameters;
997 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700998
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600999 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001000
1001 Name commandName("/localhost/nfd/faces");
1002 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001003 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001004
1005 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001006 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001007
1008 onValidatedFaceRequest(command);
1009 BOOST_CHECK(didCreateFaceFire());
1010}
1011
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001012BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace,
1013 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001014{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001015 ControlParameters parameters;
1016 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001017
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001018 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001019
1020 Name commandName("/localhost/nfd/faces");
1021 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001022 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001023
1024 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001025 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001026
1027 onValidatedFaceRequest(command);
1028 BOOST_CHECK(didDestroyFaceFire());
1029}
1030
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001031class FaceTableFixture
1032{
1033public:
1034 FaceTableFixture()
1035 : m_faceTable(m_forwarder)
1036 {
1037 }
1038
1039 virtual
1040 ~FaceTableFixture()
1041 {
1042 }
1043
1044protected:
1045 Forwarder m_forwarder;
1046 FaceTable m_faceTable;
1047};
1048
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001049class LocalControlFixture : public FaceTableFixture,
1050 public TestFaceManagerCommon,
1051 public FaceManager
1052{
1053public:
1054 LocalControlFixture()
Vince Lehman5144f822014-07-23 15:12:56 -07001055 : FaceManager(FaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face, m_testKeyChain)
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001056 {
1057 }
1058};
1059
1060BOOST_FIXTURE_TEST_CASE(LocalControlInFaceId,
1061 AuthorizedCommandFixture<LocalControlFixture>)
1062{
1063 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1064 BOOST_REQUIRE(dummy->isLocal());
1065 FaceTableFixture::m_faceTable.add(dummy);
1066
1067 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001068 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1069
1070 Block encodedParameters(parameters.wireEncode());
1071
1072 Name enable("/localhost/nfd/faces/enable-local-control");
1073 enable.append(encodedParameters);
1074
1075 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1076 enableCommand->setIncomingFaceId(dummy->getId());
1077
1078 generateCommand(*enableCommand);
1079
1080 TestFaceManagerCommon::m_face->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001081 [this, enableCommand, encodedParameters] (const Data& response) {
1082 this->validateControlResponse(response, enableCommand->getName(),
1083 200, "Success", encodedParameters);
1084 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001085
1086 onValidatedFaceRequest(enableCommand);
1087
1088 BOOST_REQUIRE(didCallbackFire());
1089 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1090 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1091
1092 TestFaceManagerCommon::m_face->onReceiveData.clear();
1093 resetCallbackFired();
1094
1095 Name disable("/localhost/nfd/faces/disable-local-control");
1096 disable.append(encodedParameters);
1097
1098 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1099 disableCommand->setIncomingFaceId(dummy->getId());
1100
1101 generateCommand(*disableCommand);
1102
1103 TestFaceManagerCommon::m_face->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001104 [this, disableCommand, encodedParameters] (const Data& response) {
1105 this->validateControlResponse(response, disableCommand->getName(),
1106 200, "Success", encodedParameters);
1107 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001108
1109 onValidatedFaceRequest(disableCommand);
1110
1111 BOOST_REQUIRE(didCallbackFire());
1112 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1113 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1114}
1115
1116BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound,
1117 AuthorizedCommandFixture<LocalControlFixture>)
1118{
1119 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1120 BOOST_REQUIRE(dummy->isLocal());
1121 FaceTableFixture::m_faceTable.add(dummy);
1122
1123 ControlParameters parameters;
1124 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1125
1126 Block encodedParameters(parameters.wireEncode());
1127
1128 Name enable("/localhost/nfd/faces/enable-local-control");
1129 enable.append(encodedParameters);
1130
1131 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1132 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1133
1134 generateCommand(*enableCommand);
1135
Junxiao Shicd55cde2014-11-13 16:03:24 -07001136 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1137 this->validateControlResponse(response, enableCommand->getName(), 410, "Face not found");
1138 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001139
1140 onValidatedFaceRequest(enableCommand);
1141
1142 BOOST_REQUIRE(didCallbackFire());
1143 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1144 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
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() + 100);
1154
1155 generateCommand(*disableCommand);
1156
Junxiao Shicd55cde2014-11-13 16:03:24 -07001157 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1158 this->validateControlResponse(response, disableCommand->getName(), 410, "Face not found");
1159 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001160
1161 onValidatedFaceRequest(disableCommand);
1162
1163 BOOST_REQUIRE(didCallbackFire());
1164 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1165 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1166}
1167
1168BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature,
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;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001176
1177 Block encodedParameters(parameters.wireEncode());
1178
1179 Name enable("/localhost/nfd/faces/enable-local-control");
1180 enable.append(encodedParameters);
1181
1182 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1183 enableCommand->setIncomingFaceId(dummy->getId());
1184
1185 generateCommand(*enableCommand);
1186
Junxiao Shicd55cde2014-11-13 16:03:24 -07001187 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1188 this->validateControlResponse(response, enableCommand->getName(), 400, "Malformed command");
1189 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001190
1191 onValidatedFaceRequest(enableCommand);
1192
1193 BOOST_REQUIRE(didCallbackFire());
1194 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1195 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1196
1197 TestFaceManagerCommon::m_face->onReceiveData.clear();
1198 resetCallbackFired();
1199
1200 Name disable("/localhost/nfd/faces/disable-local-control");
1201 disable.append(encodedParameters);
1202
1203 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1204 disableCommand->setIncomingFaceId(dummy->getId());
1205
1206 generateCommand(*disableCommand);
1207
Junxiao Shicd55cde2014-11-13 16:03:24 -07001208 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1209 this->validateControlResponse(response, disableCommand->getName(), 400, "Malformed command");
1210 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001211
1212 onValidatedFaceRequest(disableCommand);
1213
1214 BOOST_REQUIRE(didCallbackFire());
1215 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1216 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1217}
1218
1219BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal,
1220 AuthorizedCommandFixture<LocalControlFixture>)
1221{
1222 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1223 BOOST_REQUIRE(!dummy->isLocal());
1224 FaceTableFixture::m_faceTable.add(dummy);
1225
1226 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001227 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1228
1229 Block encodedParameters(parameters.wireEncode());
1230
1231 Name enable("/localhost/nfd/faces/enable-local-control");
1232 enable.append(encodedParameters);
1233
1234 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1235 enableCommand->setIncomingFaceId(dummy->getId());
1236
1237 generateCommand(*enableCommand);
1238
Junxiao Shicd55cde2014-11-13 16:03:24 -07001239 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1240 this->validateControlResponse(response, enableCommand->getName(), 412, "Face is non-local");
1241 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001242
1243 onValidatedFaceRequest(enableCommand);
1244
1245 BOOST_REQUIRE(didCallbackFire());
1246
1247 TestFaceManagerCommon::m_face->onReceiveData.clear();
1248 resetCallbackFired();
1249
1250 Name disable("/localhost/nfd/faces/disable-local-control");
1251 enable.append(encodedParameters);
1252
1253 shared_ptr<Interest> disableCommand(make_shared<Interest>(enable));
1254 disableCommand->setIncomingFaceId(dummy->getId());
1255
1256 generateCommand(*disableCommand);
1257
Junxiao Shicd55cde2014-11-13 16:03:24 -07001258 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1259 this->validateControlResponse(response, disableCommand->getName(), 412, "Face is non-local");
1260 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001261
1262 onValidatedFaceRequest(disableCommand);
1263
1264 BOOST_REQUIRE(didCallbackFire());
1265}
1266
1267BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId,
1268 AuthorizedCommandFixture<LocalControlFixture>)
1269{
1270 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1271 BOOST_REQUIRE(dummy->isLocal());
1272 FaceTableFixture::m_faceTable.add(dummy);
1273
1274 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001275 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1276
1277 Block encodedParameters(parameters.wireEncode());
1278
1279 Name enable("/localhost/nfd/faces/enable-local-control");
1280 enable.append(encodedParameters);
1281
1282 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1283 enableCommand->setIncomingFaceId(dummy->getId());
1284
1285 generateCommand(*enableCommand);
1286
1287 TestFaceManagerCommon::m_face->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001288 [this, enableCommand, encodedParameters] (const Data& response) {
1289 this->validateControlResponse(response, enableCommand->getName(),
1290 200, "Success", encodedParameters);
1291 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001292
1293 onValidatedFaceRequest(enableCommand);
1294
1295 BOOST_REQUIRE(didCallbackFire());
1296 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1297 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1298
1299
1300 TestFaceManagerCommon::m_face->onReceiveData.clear();
1301 resetCallbackFired();
1302
1303 Name disable("/localhost/nfd/faces/disable-local-control");
1304 disable.append(encodedParameters);
1305
1306 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1307 disableCommand->setIncomingFaceId(dummy->getId());
1308
1309 generateCommand(*disableCommand);
1310
1311 TestFaceManagerCommon::m_face->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001312 [this, disableCommand, encodedParameters] (const Data& response) {
1313 this->validateControlResponse(response, disableCommand->getName(),
1314 200, "Success", encodedParameters);
1315 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001316
1317 onValidatedFaceRequest(disableCommand);
1318
1319 BOOST_REQUIRE(didCallbackFire());
1320 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1321 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1322}
1323
1324BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound,
1325 AuthorizedCommandFixture<LocalControlFixture>)
1326{
1327 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1328 BOOST_REQUIRE(dummy->isLocal());
1329 FaceTableFixture::m_faceTable.add(dummy);
1330
1331 ControlParameters parameters;
1332 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1333
1334 Block encodedParameters(parameters.wireEncode());
1335
1336 Name enable("/localhost/nfd/faces/enable-local-control");
1337 enable.append(encodedParameters);
1338
1339 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1340 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1341
1342 generateCommand(*enableCommand);
1343
Junxiao Shicd55cde2014-11-13 16:03:24 -07001344 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1345 this->validateControlResponse(response, enableCommand->getName(), 410, "Face not found");
1346 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001347
1348 onValidatedFaceRequest(enableCommand);
1349
1350 BOOST_REQUIRE(didCallbackFire());
1351 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1352 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1353
1354
1355 TestFaceManagerCommon::m_face->onReceiveData.clear();
1356 resetCallbackFired();
1357
1358 Name disable("/localhost/nfd/faces/disable-local-control");
1359 disable.append(encodedParameters);
1360
1361 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1362 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1363
1364 generateCommand(*disableCommand);
1365
Junxiao Shicd55cde2014-11-13 16:03:24 -07001366 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1367 this->validateControlResponse(response, disableCommand->getName(), 410, "Face not found");
1368 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001369
1370 onValidatedFaceRequest(disableCommand);
1371
1372 BOOST_REQUIRE(didCallbackFire());
1373 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1374 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1375}
1376
1377BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal,
1378 AuthorizedCommandFixture<LocalControlFixture>)
1379{
1380 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1381 BOOST_REQUIRE(!dummy->isLocal());
1382 FaceTableFixture::m_faceTable.add(dummy);
1383
1384 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001385 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1386
1387 Block encodedParameters(parameters.wireEncode());
1388
1389 Name enable("/localhost/nfd/faces/enable-local-control");
1390 enable.append(encodedParameters);
1391
1392 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1393 enableCommand->setIncomingFaceId(dummy->getId());
1394
1395 generateCommand(*enableCommand);
1396
Junxiao Shicd55cde2014-11-13 16:03:24 -07001397 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1398 this->validateControlResponse(response, enableCommand->getName(), 412, "Face is non-local");
1399 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001400
1401 onValidatedFaceRequest(enableCommand);
1402
1403 BOOST_REQUIRE(didCallbackFire());
1404
1405 TestFaceManagerCommon::m_face->onReceiveData.clear();
1406 resetCallbackFired();
1407
1408 Name disable("/localhost/nfd/faces/disable-local-control");
1409 disable.append(encodedParameters);
1410
1411 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1412 disableCommand->setIncomingFaceId(dummy->getId());
1413
1414 generateCommand(*disableCommand);
1415
Junxiao Shicd55cde2014-11-13 16:03:24 -07001416 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1417 this->validateControlResponse(response, disableCommand->getName(), 412, "Face is non-local");
1418 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001419
1420 onValidatedFaceRequest(disableCommand);
1421
1422 BOOST_REQUIRE(didCallbackFire());
1423}
1424
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001425class FaceFixture : public FaceTableFixture,
1426 public TestFaceManagerCommon,
1427 public FaceManager
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001428{
1429public:
1430 FaceFixture()
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001431 : FaceManager(FaceTableFixture::m_faceTable,
Vince Lehman5144f822014-07-23 15:12:56 -07001432 TestFaceManagerCommon::m_face,
1433 m_testKeyChain)
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001434 , m_receivedNotification(false)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001435 {
1436
1437 }
1438
1439 virtual
1440 ~FaceFixture()
1441 {
1442
1443 }
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001444
1445 void
1446 callbackDispatch(const Data& response,
1447 const Name& expectedName,
1448 uint32_t expectedCode,
1449 const std::string& expectedText,
1450 const Block& expectedBody,
1451 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1452 {
1453 Block payload = response.getContent().blockFromValue();
1454 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1455 {
1456 validateControlResponse(response, expectedName, expectedCode,
1457 expectedText, expectedBody);
1458 }
1459 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1460 {
1461 validateFaceEvent(payload, expectedFaceEvent);
1462 }
1463 else
1464 {
1465 BOOST_FAIL("Received unknown message type: #" << payload.type());
1466 }
1467 }
1468
1469 void
1470 callbackDispatch(const Data& response,
1471 const Name& expectedName,
1472 uint32_t expectedCode,
1473 const std::string& expectedText,
1474 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1475 {
1476 Block payload = response.getContent().blockFromValue();
1477 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1478 {
1479 validateControlResponse(response, expectedName,
1480 expectedCode, expectedText);
1481 }
1482 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1483 {
1484 validateFaceEvent(payload, expectedFaceEvent);
1485 }
1486 else
1487 {
1488 BOOST_FAIL("Received unknown message type: #" << payload.type());
1489 }
1490 }
1491
1492 void
1493 validateFaceEvent(const Block& wire,
1494 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1495 {
1496
1497 m_receivedNotification = true;
1498
1499 ndn::nfd::FaceEventNotification notification(wire);
1500
Junxiao Shi6e694322014-04-03 10:27:13 -07001501 BOOST_CHECK_EQUAL(notification.getKind(), expectedFaceEvent.getKind());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001502 BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId());
Junxiao Shi6e694322014-04-03 10:27:13 -07001503 BOOST_CHECK_EQUAL(notification.getRemoteUri(), expectedFaceEvent.getRemoteUri());
1504 BOOST_CHECK_EQUAL(notification.getLocalUri(), expectedFaceEvent.getLocalUri());
Chengyu Fanf9c2bb12014-10-06 11:52:44 -06001505 BOOST_CHECK_EQUAL(notification.getFaceScope(), expectedFaceEvent.getFaceScope());
1506 BOOST_CHECK_EQUAL(notification.getFacePersistency(), expectedFaceEvent.getFacePersistency());
1507 BOOST_CHECK_EQUAL(notification.getLinkType(), expectedFaceEvent.getLinkType());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001508 }
1509
1510 bool
1511 didReceiveNotication() const
1512 {
1513 return m_receivedNotification;
1514 }
1515
1516protected:
1517 bool m_receivedNotification;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001518};
1519
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001520BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001521{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001522 ControlParameters parameters;
1523 parameters.setUri("tcp:/127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001524
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001525 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001526
1527 Name commandName("/localhost/nfd/faces");
1528 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001529 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001530
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001531 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1532 generateCommand(*command);
1533
Junxiao Shicd55cde2014-11-13 16:03:24 -07001534 getFace()->onReceiveData += [this, command] (const Data& response) {
1535 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
1536 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001537
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001538 createFace(*command, parameters);
1539
1540 BOOST_REQUIRE(didCallbackFire());
1541}
1542
1543BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>)
1544{
1545 ControlParameters parameters;
1546
1547 Block encodedParameters(parameters.wireEncode());
1548
1549 Name commandName("/localhost/nfd/faces");
1550 commandName.append("create");
1551 commandName.append(encodedParameters);
1552
1553 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1554 generateCommand(*command);
1555
Junxiao Shicd55cde2014-11-13 16:03:24 -07001556 getFace()->onReceiveData += [this, command] (const Data& response) {
1557 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
1558 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001559
1560 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001561
1562 BOOST_REQUIRE(didCallbackFire());
1563}
1564
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001565BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001566{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001567 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001568 // this will be an unsupported protocol because no factories have been
1569 // added to the face manager
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001570 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001571
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001572 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001573
1574 Name commandName("/localhost/nfd/faces");
1575 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001576 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001577
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001578 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1579 generateCommand(*command);
1580
Junxiao Shicd55cde2014-11-13 16:03:24 -07001581 getFace()->onReceiveData += [this, command] (const Data& response) {
1582 this->validateControlResponse(response, command->getName(), 501, "Unsupported protocol");
1583 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001584
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001585 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001586
1587 BOOST_REQUIRE(didCallbackFire());
1588}
1589
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001590BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001591{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001592 ControlParameters parameters;
1593 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001594
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001595 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001596
1597 Name commandName("/localhost/nfd/faces");
1598 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001599 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001600
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001601 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1602 generateCommand(*command);
1603
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001604 ControlParameters resultParameters;
Steve DiBenedetto25999282014-05-22 15:25:12 -06001605 resultParameters.setUri("dummy://");
Junxiao Shi7b984c62014-07-17 22:18:34 -07001606 resultParameters.setFaceId(FACEID_RESERVED_MAX + 1);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001607
1608 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1609
Junxiao Shi6e694322014-04-03 10:27:13 -07001610 ndn::nfd::FaceEventNotification expectedFaceEvent;
1611 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED)
Junxiao Shi7b984c62014-07-17 22:18:34 -07001612 .setFaceId(FACEID_RESERVED_MAX + 1)
Junxiao Shi6e694322014-04-03 10:27:13 -07001613 .setRemoteUri(dummy->getRemoteUri().toString())
1614 .setLocalUri(dummy->getLocalUri().toString())
Chengyu Fan9942cea2014-10-13 14:47:13 -06001615 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
1616 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001617
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001618 Block encodedResultParameters(resultParameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001619
1620 getFace()->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001621 [this, command, encodedResultParameters, expectedFaceEvent] (const Data& response) {
1622 this->callbackDispatch(response,command->getName(), 200, "Success",
1623 encodedResultParameters, expectedFaceEvent);
1624 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001625
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001626 onCreated(command->getName(), parameters, dummy);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001627
1628 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001629 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001630}
1631
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001632BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001633{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001634 ControlParameters parameters;
1635 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001636
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001637 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001638
1639 Name commandName("/localhost/nfd/faces");
1640 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001641 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001642
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001643 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1644 generateCommand(*command);
1645
Junxiao Shicd55cde2014-11-13 16:03:24 -07001646 getFace()->onReceiveData += [this, command] (const Data& response) {
1647 this->validateControlResponse(response, command->getName(), 408, "unit-test-reason");
1648 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001649
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001650 onConnectFailed(command->getName(), "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001651
1652 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001653 BOOST_CHECK_EQUAL(didReceiveNotication(), false);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001654}
1655
1656
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001657BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001658{
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001659 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1660 FaceTableFixture::m_faceTable.add(dummy);
1661
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001662 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001663 parameters.setFaceId(dummy->getId());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001664
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001665 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001666
1667 Name commandName("/localhost/nfd/faces");
1668 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001669 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001670
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001671 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1672 generateCommand(*command);
1673
Junxiao Shi6e694322014-04-03 10:27:13 -07001674 ndn::nfd::FaceEventNotification expectedFaceEvent;
1675 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
1676 .setFaceId(dummy->getId())
1677 .setRemoteUri(dummy->getRemoteUri().toString())
1678 .setLocalUri(dummy->getLocalUri().toString())
Chengyu Fan9942cea2014-10-13 14:47:13 -06001679 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
1680 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001681
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001682 getFace()->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001683 [this, command, encodedParameters, expectedFaceEvent] (const Data& response) {
1684 this->callbackDispatch(response,command->getName(), 200, "Success",
1685 encodedParameters, expectedFaceEvent);
1686 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001687
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001688 destroyFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001689
1690 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001691 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001692}
1693
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001694class FaceListFixture : public FaceStatusPublisherFixture
1695{
1696public:
1697 FaceListFixture()
Vince Lehman5144f822014-07-23 15:12:56 -07001698 : m_manager(m_table, m_face, m_testKeyChain)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001699 {
1700
1701 }
1702
1703 virtual
1704 ~FaceListFixture()
1705 {
1706
1707 }
1708
1709protected:
1710 FaceManager m_manager;
Vince Lehman5144f822014-07-23 15:12:56 -07001711 ndn::KeyChain m_testKeyChain;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001712};
1713
1714BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001715{
1716 Name commandName("/localhost/nfd/faces/list");
1717 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1718
Junxiao Shi632a6202014-07-20 01:14:30 -07001719 // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 75
1720 // use 59 FaceStatuses to force a FaceStatus to span Data packets
1721 for (int i = 0; i < 59; i++)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001722 {
1723 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1724
1725 uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
Junxiao Shi632a6202014-07-20 01:14:30 -07001726 dummy->setCounters(filler, filler, filler, filler, filler, filler);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001727
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001728 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001729
1730 add(dummy);
1731 }
1732
1733 ndn::EncodingBuffer buffer;
1734
1735 m_face->onReceiveData +=
1736 bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, this, _1);
1737
1738 m_manager.listFaces(*command);
1739 BOOST_REQUIRE(m_finished);
1740}
1741
Steve DiBenedettoef04f272014-06-04 14:28:31 -06001742class ChannelStatusFixture : public FaceManagerFixture
1743{
1744public:
1745 void
1746 validatePublish(const Data& data, const ndn::nfd::ChannelStatus& expectedEntry)
1747 {
1748 m_callbackFired = true;
1749 Block b = data.getContent().blockFromValue();
1750 ndn::nfd::ChannelStatus entry(b);
1751 BOOST_CHECK_EQUAL(entry.getLocalUri(), expectedEntry.getLocalUri());
1752 }
1753
1754 virtual shared_ptr<DummyProtocolFactory>
1755 addProtocolFactory(const std::string& protocol)
1756 {
1757 shared_ptr<DummyProtocolFactory> factory(make_shared<DummyProtocolFactory>());
1758 m_manager.m_factories[protocol] = factory;
1759
1760 return factory;
1761 }
1762};
1763
1764BOOST_FIXTURE_TEST_CASE(TestChannelStatus, ChannelStatusFixture)
1765{
1766 shared_ptr<DummyProtocolFactory> factory(addProtocolFactory("dummy"));
1767 factory->addChannel("dummy://");
1768
1769 Name requestName("/localhost/nfd/faces/channels");
1770 shared_ptr<Interest> request(make_shared<Interest>(requestName));
1771
1772 ndn::nfd::ChannelStatus expectedEntry;
1773 expectedEntry.setLocalUri(DummyChannel("dummy://").getUri().toString());
1774
1775 m_face->onReceiveData +=
1776 bind(&ChannelStatusFixture::validatePublish, this, _1, expectedEntry);
1777
1778 m_manager.listChannels(*request);
1779 BOOST_REQUIRE(m_callbackFired);
1780}
1781
Chengyu Fan320d2332014-10-29 16:40:33 -06001782class FaceQueryListFixture : public FaceQueryStatusPublisherFixture
1783{
1784public:
1785 FaceQueryListFixture()
1786 : m_manager(m_table, m_face, m_testKeyChain)
1787 {
1788
1789 }
1790
1791 virtual
1792 ~FaceQueryListFixture()
1793 {
1794
1795 }
1796
1797protected:
1798 FaceManager m_manager;
1799 ndn::KeyChain m_testKeyChain;
1800};
1801
1802BOOST_FIXTURE_TEST_CASE(TestValidQueryFilter, FaceQueryListFixture)
1803{
1804 Name queryName("/localhost/nfd/faces/query");
1805 ndn::nfd::FaceQueryFilter queryFilter;
1806 queryFilter.setUriScheme("dummy");
1807 queryName.append(queryFilter.wireEncode());
1808
1809 shared_ptr<Interest> query(make_shared<Interest>(queryName));
1810
1811 // add expected faces
1812 shared_ptr<DummyLocalFace> expectedFace1(make_shared<DummyLocalFace>());
1813 m_referenceFaces.push_back(expectedFace1);
1814 add(expectedFace1);
1815
1816 shared_ptr<DummyFace> expectedFace2(make_shared<DummyFace>());
1817 m_referenceFaces.push_back(expectedFace2);
1818 add(expectedFace2);
1819
1820 // add other faces
1821 shared_ptr<DummyFace> face1(make_shared<DummyFace>("udp://", "udp://"));
1822 add(face1);
1823 shared_ptr<DummyLocalFace> face2(make_shared<DummyLocalFace>("tcp://", "tcp://"));
1824 add(face2);
1825
1826 m_face->onReceiveData +=
1827 bind(&FaceQueryStatusPublisherFixture::decodeFaceStatusBlock, this, _1);
1828
1829 m_manager.listQueriedFaces(*query);
1830 BOOST_REQUIRE(m_finished);
1831}
1832
1833//BOOST_FIXTURE_TEST_CASE(TestInvalidQueryFilter, FaceQueryListFixture)
1834//{
1835// Name queryName("/localhost/nfd/faces/query");
1836// ndn::nfd::FaceStatus queryFilter;
1837// queryName.append(queryFilter.wireEncode());
1838//
1839// shared_ptr<Interest> query(make_shared<Interest>(queryName));
1840//
1841// shared_ptr<DummyLocalFace> face(make_shared<DummyLocalFace>());
1842// add(face);
1843//
1844// m_face->onReceiveData +=
1845// bind(&FaceQueryStatusPublisherFixture::decodeNackBlock, this, _1);
1846//
1847// m_manager.listQueriedFaces(*query);
1848// BOOST_REQUIRE(m_finished);
1849//}
1850
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001851BOOST_AUTO_TEST_SUITE_END()
1852
1853} // namespace tests
1854} // namespace nfd