blob: 855c7bd11a310c3e8f19bb2b2832f2991e6a73ea [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"
Steve DiBenedettoef04f272014-06-04 14:28:31 -060044#include "channel-status-common.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060045
Alexander Afanasyev4a771362014-04-24 21:29:33 -070046#include <ndn-cxx/encoding/tlv.hpp>
47#include <ndn-cxx/management/nfd-face-event-notification.hpp>
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070048
49namespace nfd {
50namespace tests {
51
52NFD_LOG_INIT("FaceManagerTest");
53
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060054class FaceManagerTestFace : public DummyFace
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070055{
56public:
57
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060058 FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070059 : m_closeFired(false)
60 {
61
62 }
63
64 virtual
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060065 ~FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070066 {
67
68 }
69
70 virtual void
71 close()
72 {
73 m_closeFired = true;
74 }
75
76 bool
77 didCloseFire() const
78 {
79 return m_closeFired;
80 }
81
82private:
83 bool m_closeFired;
84};
85
86class TestFaceTable : public FaceTable
87{
88public:
89 TestFaceTable(Forwarder& forwarder)
90 : FaceTable(forwarder),
91 m_addFired(false),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070092 m_getFired(false),
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060093 m_dummy(make_shared<FaceManagerTestFace>())
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070094 {
95
96 }
97
98 virtual
99 ~TestFaceTable()
100 {
101
102 }
103
104 virtual void
105 add(shared_ptr<Face> face)
106 {
107 m_addFired = true;
108 }
109
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700110 virtual shared_ptr<Face>
111 get(FaceId id) const
112 {
113 m_getFired = true;
114 return m_dummy;
115 }
116
117 bool
118 didAddFire() const
119 {
120 return m_addFired;
121 }
122
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700123 bool
124 didGetFire() const
125 {
126 return m_getFired;
127 }
128
129 void
130 reset()
131 {
132 m_addFired = false;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700133 m_getFired = false;
134 }
135
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600136 shared_ptr<FaceManagerTestFace>&
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700137 getDummyFace()
138 {
139 return m_dummy;
140 }
141
142private:
143 bool m_addFired;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700144 mutable bool m_getFired;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600145 shared_ptr<FaceManagerTestFace> m_dummy;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700146};
147
148
149class TestFaceTableFixture : public BaseFixture
150{
151public:
152 TestFaceTableFixture()
153 : m_faceTable(m_forwarder)
154 {
155
156 }
157
158 virtual
159 ~TestFaceTableFixture()
160 {
161
162 }
163
164protected:
165 Forwarder m_forwarder;
166 TestFaceTable m_faceTable;
167};
168
169class TestFaceManagerCommon
170{
171public:
172 TestFaceManagerCommon()
173 : m_face(make_shared<InternalFace>()),
174 m_callbackFired(false)
175 {
176
177 }
178
179 virtual
180 ~TestFaceManagerCommon()
181 {
182
183 }
184
185 shared_ptr<InternalFace>&
186 getFace()
187 {
188 return m_face;
189 }
190
191 void
192 validateControlResponseCommon(const Data& response,
193 const Name& expectedName,
194 uint32_t expectedCode,
195 const std::string& expectedText,
196 ControlResponse& control)
197 {
198 m_callbackFired = true;
199 Block controlRaw = response.getContent().blockFromValue();
200
201 control.wireDecode(controlRaw);
202
203 // NFD_LOG_DEBUG("received control response"
204 // << " Name: " << response.getName()
205 // << " code: " << control.getCode()
206 // << " text: " << control.getText());
207
208 BOOST_CHECK_EQUAL(response.getName(), expectedName);
209 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
210 BOOST_CHECK_EQUAL(control.getText(), expectedText);
211 }
212
213 void
214 validateControlResponse(const Data& response,
215 const Name& expectedName,
216 uint32_t expectedCode,
217 const std::string& expectedText)
218 {
219 ControlResponse control;
220 validateControlResponseCommon(response, expectedName,
221 expectedCode, expectedText, control);
222
223 if (!control.getBody().empty())
224 {
225 BOOST_FAIL("found unexpected control response body");
226 }
227 }
228
229 void
230 validateControlResponse(const Data& response,
231 const Name& expectedName,
232 uint32_t expectedCode,
233 const std::string& expectedText,
234 const Block& expectedBody)
235 {
236 ControlResponse control;
237 validateControlResponseCommon(response, expectedName,
238 expectedCode, expectedText, control);
239
240 BOOST_REQUIRE(!control.getBody().empty());
241 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
242
243 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
244 expectedBody.value_size()) == 0);
245
246 }
247
248 bool
249 didCallbackFire() const
250 {
251 return m_callbackFired;
252 }
253
254 void
255 resetCallbackFired()
256 {
257 m_callbackFired = false;
258 }
259
260protected:
261 shared_ptr<InternalFace> m_face;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700262 bool m_callbackFired;
Vince Lehman5144f822014-07-23 15:12:56 -0700263 ndn::KeyChain m_testKeyChain;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700264};
265
266class FaceManagerFixture : public TestFaceTableFixture, public TestFaceManagerCommon
267{
268public:
269 FaceManagerFixture()
Vince Lehman5144f822014-07-23 15:12:56 -0700270 : m_manager(m_faceTable, m_face, m_testKeyChain)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700271 {
272 m_manager.setConfigFile(m_config);
273 }
274
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700275 virtual
276 ~FaceManagerFixture()
277 {
278
279 }
280
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600281 void
282 parseConfig(const std::string configuration, bool isDryRun)
283 {
284 m_config.parse(configuration, isDryRun, "dummy-config");
285 }
286
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700287 FaceManager&
288 getManager()
289 {
290 return m_manager;
291 }
292
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700293 void
294 addInterestRule(const std::string& regex,
295 ndn::IdentityCertificate& certificate)
296 {
297 m_manager.addInterestRule(regex, certificate);
298 }
299
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700300 bool
301 didFaceTableAddFire() const
302 {
303 return m_faceTable.didAddFire();
304 }
305
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700306 bool
307 didFaceTableGetFire() const
308 {
309 return m_faceTable.didGetFire();
310 }
311
312 void
313 resetFaceTable()
314 {
315 m_faceTable.reset();
316 }
317
Steve DiBenedettoef04f272014-06-04 14:28:31 -0600318protected:
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700319 FaceManager m_manager;
320 ConfigFile m_config;
321};
322
323BOOST_FIXTURE_TEST_SUITE(MgmtFaceManager, FaceManagerFixture)
324
325bool
326isExpectedException(const ConfigFile::Error& error, const std::string& expectedMessage)
327{
328 if (error.what() != expectedMessage)
329 {
330 NFD_LOG_ERROR("expected: " << expectedMessage << "\tgot: " << error.what());
331 }
332 return error.what() == expectedMessage;
333}
334
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600335#ifdef HAVE_UNIX_SOCKETS
336
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700337BOOST_AUTO_TEST_CASE(TestProcessSectionUnix)
338{
339 const std::string CONFIG =
340 "face_system\n"
341 "{\n"
342 " unix\n"
343 " {\n"
344 " listen yes\n"
345 " path /tmp/nfd.sock\n"
346 " }\n"
347 "}\n";
348 BOOST_TEST_CHECKPOINT("Calling parse");
349 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
350}
351
352BOOST_AUTO_TEST_CASE(TestProcessSectionUnixDryRun)
353{
354 const std::string CONFIG =
355 "face_system\n"
356 "{\n"
357 " unix\n"
358 " {\n"
359 " listen yes\n"
360 " path /var/run/nfd.sock\n"
361 " }\n"
362 "}\n";
363
364 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
365}
366
367BOOST_AUTO_TEST_CASE(TestProcessSectionUnixBadListen)
368{
369 const std::string CONFIG =
370 "face_system\n"
371 "{\n"
372 " unix\n"
373 " {\n"
374 " listen hello\n"
375 " }\n"
376 "}\n";
377 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
378 bind(&isExpectedException, _1,
379 "Invalid value for option \"listen\" in \"unix\" section"));
380}
381
382BOOST_AUTO_TEST_CASE(TestProcessSectionUnixUnknownOption)
383{
384 const std::string CONFIG =
385 "face_system\n"
386 "{\n"
387 " unix\n"
388 " {\n"
389 " hello\n"
390 " }\n"
391 "}\n";
392 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
393 bind(&isExpectedException, _1,
394 "Unrecognized option \"hello\" in \"unix\" section"));
395}
396
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600397#endif // HAVE_UNIX_SOCKETS
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700398
399
400BOOST_AUTO_TEST_CASE(TestProcessSectionTcp)
401{
402 const std::string CONFIG =
403 "face_system\n"
404 "{\n"
405 " tcp\n"
406 " {\n"
407 " listen yes\n"
408 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600409 " enable_v4 yes\n"
410 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700411 " }\n"
412 "}\n";
413 try
414 {
415 parseConfig(CONFIG, false);
416 }
417 catch (const std::runtime_error& e)
418 {
419 const std::string reason = e.what();
420 if (reason.find("Address in use") != std::string::npos)
421 {
422 BOOST_FAIL(reason);
423 }
424 }
425}
426
427BOOST_AUTO_TEST_CASE(TestProcessSectionTcpDryRun)
428{
429 const std::string CONFIG =
430 "face_system\n"
431 "{\n"
432 " tcp\n"
433 " {\n"
434 " listen yes\n"
435 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600436 " enable_v4 yes\n"
437 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700438 " }\n"
439 "}\n";
440 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
441}
442
443BOOST_AUTO_TEST_CASE(TestProcessSectionTcpBadListen)
444{
445 const std::string CONFIG =
446 "face_system\n"
447 "{\n"
448 " tcp\n"
449 " {\n"
450 " listen hello\n"
451 " }\n"
452 "}\n";
453 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
454 bind(&isExpectedException, _1,
455 "Invalid value for option \"listen\" in \"tcp\" section"));
456}
457
Steve DiBenedetto95152872014-04-11 12:40:59 -0600458BOOST_AUTO_TEST_CASE(TestProcessSectionTcpChannelsDisabled)
459{
460 const std::string CONFIG =
461 "face_system\n"
462 "{\n"
463 " tcp\n"
464 " {\n"
465 " port 6363\n"
466 " enable_v4 no\n"
467 " enable_v6 no\n"
468 " }\n"
469 "}\n";
470 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
471 bind(&isExpectedException, _1,
472 "IPv4 and IPv6 channels have been disabled."
473 " Remove \"tcp\" section to disable TCP channels or"
474 " re-enable at least one channel type."));
475}
476
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700477BOOST_AUTO_TEST_CASE(TestProcessSectionTcpUnknownOption)
478{
479 const std::string CONFIG =
480 "face_system\n"
481 "{\n"
482 " tcp\n"
483 " {\n"
484 " hello\n"
485 " }\n"
486 "}\n";
487 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
488 bind(&isExpectedException, _1,
489 "Unrecognized option \"hello\" in \"tcp\" section"));
490}
491
492BOOST_AUTO_TEST_CASE(TestProcessSectionUdp)
493{
494 const std::string CONFIG =
495 "face_system\n"
496 "{\n"
497 " udp\n"
498 " {\n"
499 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600500 " enable_v4 yes\n"
501 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700502 " idle_timeout 30\n"
503 " keep_alive_interval 25\n"
504 " mcast yes\n"
505 " mcast_port 56363\n"
506 " mcast_group 224.0.23.170\n"
507 " }\n"
508 "}\n";
509 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
510}
511
512BOOST_AUTO_TEST_CASE(TestProcessSectionUdpDryRun)
513{
514 const std::string CONFIG =
515 "face_system\n"
516 "{\n"
517 " udp\n"
518 " {\n"
519 " port 6363\n"
520 " idle_timeout 30\n"
521 " keep_alive_interval 25\n"
522 " mcast yes\n"
523 " mcast_port 56363\n"
524 " mcast_group 224.0.23.170\n"
525 " }\n"
526 "}\n";
527 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
528}
529
530BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadIdleTimeout)
531{
532 const std::string CONFIG =
533 "face_system\n"
534 "{\n"
535 " udp\n"
536 " {\n"
537 " idle_timeout hello\n"
538 " }\n"
539 "}\n";
540
541 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
542 bind(&isExpectedException, _1,
543 "Invalid value for option \"idle_timeout\" in \"udp\" section"));
544}
545
546BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcast)
547{
548 const std::string CONFIG =
549 "face_system\n"
550 "{\n"
551 " udp\n"
552 " {\n"
553 " mcast hello\n"
554 " }\n"
555 "}\n";
556
557 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
558 bind(&isExpectedException, _1,
559 "Invalid value for option \"mcast\" in \"udp\" section"));
560}
561
562BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroup)
563{
564 const std::string CONFIG =
565 "face_system\n"
566 "{\n"
567 " udp\n"
568 " {\n"
569 " mcast no\n"
570 " mcast_port 50\n"
571 " mcast_group hello\n"
572 " }\n"
573 "}\n";
574
575 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
576 bind(&isExpectedException, _1,
577 "Invalid value for option \"mcast_group\" in \"udp\" section"));
578}
579
580BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroupV6)
581{
582 const std::string CONFIG =
583 "face_system\n"
584 "{\n"
585 " udp\n"
586 " {\n"
587 " mcast no\n"
588 " mcast_port 50\n"
589 " mcast_group ::1\n"
590 " }\n"
591 "}\n";
592
593 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
594 bind(&isExpectedException, _1,
595 "Invalid value for option \"mcast_group\" in \"udp\" section"));
596}
597
Steve DiBenedetto95152872014-04-11 12:40:59 -0600598BOOST_AUTO_TEST_CASE(TestProcessSectionUdpChannelsDisabled)
599{
600 const std::string CONFIG =
601 "face_system\n"
602 "{\n"
603 " udp\n"
604 " {\n"
605 " port 6363\n"
606 " enable_v4 no\n"
607 " enable_v6 no\n"
608 " idle_timeout 30\n"
609 " keep_alive_interval 25\n"
610 " mcast yes\n"
611 " mcast_port 56363\n"
612 " mcast_group 224.0.23.170\n"
613 " }\n"
614 "}\n";
615 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
616 bind(&isExpectedException, _1,
617 "IPv4 and IPv6 channels have been disabled."
618 " Remove \"udp\" section to disable UDP channels or"
619 " re-enable at least one channel type."));
620}
621
622BOOST_AUTO_TEST_CASE(TestProcessSectionUdpConflictingMcast)
623{
624 const std::string CONFIG =
625 "face_system\n"
626 "{\n"
627 " udp\n"
628 " {\n"
629 " port 6363\n"
630 " enable_v4 no\n"
631 " enable_v6 yes\n"
632 " idle_timeout 30\n"
633 " keep_alive_interval 25\n"
634 " mcast yes\n"
635 " mcast_port 56363\n"
636 " mcast_group 224.0.23.170\n"
637 " }\n"
638 "}\n";
639 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
640 bind(&isExpectedException, _1,
641 "IPv4 multicast requested, but IPv4 channels"
642 " have been disabled (conflicting configuration options set)"));
643}
644
645
646
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700647BOOST_AUTO_TEST_CASE(TestProcessSectionUdpUnknownOption)
648{
649 const std::string CONFIG =
650 "face_system\n"
651 "{\n"
652 " udp\n"
653 " {\n"
654 " hello\n"
655 " }\n"
656 "}\n";
657 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
658 bind(&isExpectedException, _1,
659 "Unrecognized option \"hello\" in \"udp\" section"));
660}
661
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300662
663BOOST_AUTO_TEST_CASE(TestProcessSectionUdpMulticastReinit)
664{
665 const std::string CONFIG_WITH_MCAST =
666 "face_system\n"
667 "{\n"
668 " udp\n"
669 " {\n"
670 " mcast yes\n"
671 " }\n"
672 "}\n";
673 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
674
675 shared_ptr<UdpFactory> factory = static_pointer_cast<UdpFactory>(getManager().findFactory("udp"));
676 BOOST_REQUIRE(static_cast<bool>(factory));
677
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300678 if (factory->getMulticastFaces().size() == 0) {
679 BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
680 "no UDP multicast faces are available");
681 }
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300682
683 const std::string CONFIG_WITHOUT_MCAST =
684 "face_system\n"
685 "{\n"
686 " udp\n"
687 " {\n"
688 " mcast no\n"
689 " }\n"
690 "}\n";
691 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
692 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
693}
694
695
Alexander Afanasyev885a85b2014-04-12 21:01:13 -0700696#ifdef HAVE_LIBPCAP
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600697
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700698BOOST_AUTO_TEST_CASE(TestProcessSectionEther)
699{
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600700
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700701 const std::string CONFIG =
702 "face_system\n"
703 "{\n"
704 " ether\n"
705 " {\n"
706 " mcast yes\n"
707 " mcast_group 01:00:5E:00:17:AA\n"
708 " }\n"
709 "}\n";
710
711 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
712}
713
714BOOST_AUTO_TEST_CASE(TestProcessSectionEtherDryRun)
715{
716 const std::string CONFIG =
717 "face_system\n"
718 "{\n"
719 " ether\n"
720 " {\n"
721 " mcast yes\n"
722 " mcast_group 01:00:5E:00:17:AA\n"
723 " }\n"
724 "}\n";
725
726 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
727}
728
729BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcast)
730{
731 const std::string CONFIG =
732 "face_system\n"
733 "{\n"
734 " ether\n"
735 " {\n"
736 " mcast hello\n"
737 " }\n"
738 "}\n";
739
740 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
741 bind(&isExpectedException, _1,
742 "Invalid value for option \"mcast\" in \"ether\" section"));
743}
744
745BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcastGroup)
746{
747 const std::string CONFIG =
748 "face_system\n"
749 "{\n"
750 " ether\n"
751 " {\n"
752 " mcast yes\n"
753 " mcast_group\n"
754 " }\n"
755 "}\n";
756
757 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
758 bind(&isExpectedException, _1,
759 "Invalid value for option \"mcast_group\" in \"ether\" section"));
760}
761
762BOOST_AUTO_TEST_CASE(TestProcessSectionEtherUnknownOption)
763{
764 const std::string CONFIG =
765 "face_system\n"
766 "{\n"
767 " ether\n"
768 " {\n"
769 " hello\n"
770 " }\n"
771 "}\n";
772 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
773 bind(&isExpectedException, _1,
774 "Unrecognized option \"hello\" in \"ether\" section"));
775}
776
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300777BOOST_AUTO_TEST_CASE(TestProcessSectionEtherMulticastReinit)
778{
779 const std::string CONFIG_WITH_MCAST =
780 "face_system\n"
781 "{\n"
782 " ether\n"
783 " {\n"
784 " mcast yes\n"
785 " }\n"
786 "}\n";
787 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
788
789 shared_ptr<EthernetFactory> factory =
790 static_pointer_cast<EthernetFactory>(getManager().findFactory("ether"));
791 BOOST_REQUIRE(static_cast<bool>(factory));
792
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300793 if (factory->getMulticastFaces().size() == 0) {
794 BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
795 "no Ethernet multicast faces are available");
796 }
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300797
798 const std::string CONFIG_WITHOUT_MCAST =
799 "face_system\n"
800 "{\n"
801 " ether\n"
802 " {\n"
803 " mcast no\n"
804 " }\n"
805 "}\n";
806 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
807 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
808}
809
Alexander Afanasyeve9186212014-08-23 20:15:48 -0700810#endif // HAVE_LIBPCAP
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600811
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700812BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
813{
814 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
815
816 getFace()->onReceiveData +=
817 bind(&FaceManagerFixture::validateControlResponse, this, _1,
818 command->getName(), 400, "Malformed command");
819
820 getFace()->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700821 g_io.run_one();
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700822
823 BOOST_REQUIRE(didCallbackFire());
824}
825
826BOOST_AUTO_TEST_CASE(MalformedCommmand)
827{
828 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
829
830 getFace()->onReceiveData +=
831 bind(&FaceManagerFixture::validateControlResponse, this, _1,
832 command->getName(), 400, "Malformed command");
833
834 getManager().onFaceRequest(*command);
835
836 BOOST_REQUIRE(didCallbackFire());
837}
838
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700839BOOST_AUTO_TEST_CASE(UnsignedCommand)
840{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600841 ControlParameters parameters;
842 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700843
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600844 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700845
846 Name commandName("/localhost/nfd/faces");
847 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600848 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700849
850 shared_ptr<Interest> command(make_shared<Interest>(commandName));
851
852 getFace()->onReceiveData +=
853 bind(&FaceManagerFixture::validateControlResponse, this, _1,
854 command->getName(), 401, "Signature required");
855
856 getManager().onFaceRequest(*command);
857
858 BOOST_REQUIRE(didCallbackFire());
859}
860
861BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>)
862{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600863 ControlParameters parameters;
864 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700865
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600866 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700867
868 Name commandName("/localhost/nfd/faces");
869 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600870 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700871
872 shared_ptr<Interest> command(make_shared<Interest>(commandName));
873 generateCommand(*command);
874
875 getFace()->onReceiveData +=
876 bind(&FaceManagerFixture::validateControlResponse, this, _1,
877 command->getName(), 403, "Unauthorized command");
878
879 getManager().onFaceRequest(*command);
880
881 BOOST_REQUIRE(didCallbackFire());
882}
883
884template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
885{
886public:
887 AuthorizedCommandFixture()
888 {
889 const std::string regex = "^<localhost><nfd><faces>";
890 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
891 }
892
893 virtual
894 ~AuthorizedCommandFixture()
895 {
896
897 }
898};
899
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700900BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700901{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600902 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700903
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600904 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700905
906 Name commandName("/localhost/nfd/faces");
907 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600908 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700909
910 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700911 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700912
913 getFace()->onReceiveData +=
914 bind(&FaceManagerFixture::validateControlResponse, this, _1,
915 command->getName(), 501, "Unsupported command");
916
917 getManager().onFaceRequest(*command);
918
919 BOOST_REQUIRE(didCallbackFire());
920}
921
922class ValidatedFaceRequestFixture : public TestFaceTableFixture,
923 public TestFaceManagerCommon,
924 public FaceManager
925{
926public:
927
928 ValidatedFaceRequestFixture()
Vince Lehman5144f822014-07-23 15:12:56 -0700929 : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face, m_testKeyChain),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700930 m_createFaceFired(false),
931 m_destroyFaceFired(false)
932 {
933
934 }
935
936 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600937 createFace(const Interest& request,
938 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700939 {
940 m_createFaceFired = true;
941 }
942
943 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600944 destroyFace(const Interest& request,
945 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700946 {
947 m_destroyFaceFired = true;
948 }
949
950 virtual
951 ~ValidatedFaceRequestFixture()
952 {
953
954 }
955
956 bool
957 didCreateFaceFire() const
958 {
959 return m_createFaceFired;
960 }
961
962 bool
963 didDestroyFaceFire() const
964 {
965 return m_destroyFaceFired;
966 }
967
968private:
969 bool m_createFaceFired;
970 bool m_destroyFaceFired;
971};
972
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700973BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse,
974 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700975{
976 Name commandName("/localhost/nfd/faces");
977 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600978 commandName.append("NotReallyParameters");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700979
980 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700981 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700982
983 getFace()->onReceiveData +=
984 bind(&ValidatedFaceRequestFixture::validateControlResponse, this, _1,
985 command->getName(), 400, "Malformed command");
986
987 onValidatedFaceRequest(command);
988
989 BOOST_REQUIRE(didCallbackFire());
990}
991
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700992BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace,
993 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700994{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600995 ControlParameters parameters;
996 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700997
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600998 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700999
1000 Name commandName("/localhost/nfd/faces");
1001 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001002 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001003
1004 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001005 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001006
1007 onValidatedFaceRequest(command);
1008 BOOST_CHECK(didCreateFaceFire());
1009}
1010
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001011BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace,
1012 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001013{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001014 ControlParameters parameters;
1015 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001016
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001017 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001018
1019 Name commandName("/localhost/nfd/faces");
1020 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001021 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001022
1023 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001024 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001025
1026 onValidatedFaceRequest(command);
1027 BOOST_CHECK(didDestroyFaceFire());
1028}
1029
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001030class FaceTableFixture
1031{
1032public:
1033 FaceTableFixture()
1034 : m_faceTable(m_forwarder)
1035 {
1036 }
1037
1038 virtual
1039 ~FaceTableFixture()
1040 {
1041 }
1042
1043protected:
1044 Forwarder m_forwarder;
1045 FaceTable m_faceTable;
1046};
1047
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001048class LocalControlFixture : public FaceTableFixture,
1049 public TestFaceManagerCommon,
1050 public FaceManager
1051{
1052public:
1053 LocalControlFixture()
Vince Lehman5144f822014-07-23 15:12:56 -07001054 : FaceManager(FaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face, m_testKeyChain)
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001055 {
1056 }
1057};
1058
1059BOOST_FIXTURE_TEST_CASE(LocalControlInFaceId,
1060 AuthorizedCommandFixture<LocalControlFixture>)
1061{
1062 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1063 BOOST_REQUIRE(dummy->isLocal());
1064 FaceTableFixture::m_faceTable.add(dummy);
1065
1066 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001067 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1068
1069 Block encodedParameters(parameters.wireEncode());
1070
1071 Name enable("/localhost/nfd/faces/enable-local-control");
1072 enable.append(encodedParameters);
1073
1074 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1075 enableCommand->setIncomingFaceId(dummy->getId());
1076
1077 generateCommand(*enableCommand);
1078
1079 TestFaceManagerCommon::m_face->onReceiveData +=
1080 bind(&LocalControlFixture::validateControlResponse, this, _1,
1081 enableCommand->getName(), 200, "Success", encodedParameters);
1082
1083 onValidatedFaceRequest(enableCommand);
1084
1085 BOOST_REQUIRE(didCallbackFire());
1086 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1087 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1088
1089 TestFaceManagerCommon::m_face->onReceiveData.clear();
1090 resetCallbackFired();
1091
1092 Name disable("/localhost/nfd/faces/disable-local-control");
1093 disable.append(encodedParameters);
1094
1095 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1096 disableCommand->setIncomingFaceId(dummy->getId());
1097
1098 generateCommand(*disableCommand);
1099
1100 TestFaceManagerCommon::m_face->onReceiveData +=
1101 bind(&LocalControlFixture::validateControlResponse, this, _1,
1102 disableCommand->getName(), 200, "Success", encodedParameters);
1103
1104 onValidatedFaceRequest(disableCommand);
1105
1106 BOOST_REQUIRE(didCallbackFire());
1107 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1108 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1109}
1110
1111BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound,
1112 AuthorizedCommandFixture<LocalControlFixture>)
1113{
1114 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1115 BOOST_REQUIRE(dummy->isLocal());
1116 FaceTableFixture::m_faceTable.add(dummy);
1117
1118 ControlParameters parameters;
1119 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1120
1121 Block encodedParameters(parameters.wireEncode());
1122
1123 Name enable("/localhost/nfd/faces/enable-local-control");
1124 enable.append(encodedParameters);
1125
1126 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1127 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1128
1129 generateCommand(*enableCommand);
1130
1131 TestFaceManagerCommon::m_face->onReceiveData +=
1132 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001133 enableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001134
1135 onValidatedFaceRequest(enableCommand);
1136
1137 BOOST_REQUIRE(didCallbackFire());
1138 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1139 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1140
1141 TestFaceManagerCommon::m_face->onReceiveData.clear();
1142 resetCallbackFired();
1143
1144 Name disable("/localhost/nfd/faces/disable-local-control");
1145 disable.append(encodedParameters);
1146
1147 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1148 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1149
1150 generateCommand(*disableCommand);
1151
1152 TestFaceManagerCommon::m_face->onReceiveData +=
1153 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001154 disableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001155
1156 onValidatedFaceRequest(disableCommand);
1157
1158 BOOST_REQUIRE(didCallbackFire());
1159 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1160 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1161}
1162
1163BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature,
1164 AuthorizedCommandFixture<LocalControlFixture>)
1165{
1166 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1167 BOOST_REQUIRE(dummy->isLocal());
1168 FaceTableFixture::m_faceTable.add(dummy);
1169
1170 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001171
1172 Block encodedParameters(parameters.wireEncode());
1173
1174 Name enable("/localhost/nfd/faces/enable-local-control");
1175 enable.append(encodedParameters);
1176
1177 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1178 enableCommand->setIncomingFaceId(dummy->getId());
1179
1180 generateCommand(*enableCommand);
1181
1182 TestFaceManagerCommon::m_face->onReceiveData +=
1183 bind(&LocalControlFixture::validateControlResponse, this, _1,
1184 enableCommand->getName(), 400, "Malformed command");
1185
1186 onValidatedFaceRequest(enableCommand);
1187
1188 BOOST_REQUIRE(didCallbackFire());
1189 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1190 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1191
1192 TestFaceManagerCommon::m_face->onReceiveData.clear();
1193 resetCallbackFired();
1194
1195 Name disable("/localhost/nfd/faces/disable-local-control");
1196 disable.append(encodedParameters);
1197
1198 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1199 disableCommand->setIncomingFaceId(dummy->getId());
1200
1201 generateCommand(*disableCommand);
1202
1203 TestFaceManagerCommon::m_face->onReceiveData +=
1204 bind(&LocalControlFixture::validateControlResponse, this, _1,
1205 disableCommand->getName(), 400, "Malformed command");
1206
1207 onValidatedFaceRequest(disableCommand);
1208
1209 BOOST_REQUIRE(didCallbackFire());
1210 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1211 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1212}
1213
1214BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal,
1215 AuthorizedCommandFixture<LocalControlFixture>)
1216{
1217 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1218 BOOST_REQUIRE(!dummy->isLocal());
1219 FaceTableFixture::m_faceTable.add(dummy);
1220
1221 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001222 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1223
1224 Block encodedParameters(parameters.wireEncode());
1225
1226 Name enable("/localhost/nfd/faces/enable-local-control");
1227 enable.append(encodedParameters);
1228
1229 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1230 enableCommand->setIncomingFaceId(dummy->getId());
1231
1232 generateCommand(*enableCommand);
1233
1234 TestFaceManagerCommon::m_face->onReceiveData +=
1235 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001236 enableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001237
1238 onValidatedFaceRequest(enableCommand);
1239
1240 BOOST_REQUIRE(didCallbackFire());
1241
1242 TestFaceManagerCommon::m_face->onReceiveData.clear();
1243 resetCallbackFired();
1244
1245 Name disable("/localhost/nfd/faces/disable-local-control");
1246 enable.append(encodedParameters);
1247
1248 shared_ptr<Interest> disableCommand(make_shared<Interest>(enable));
1249 disableCommand->setIncomingFaceId(dummy->getId());
1250
1251 generateCommand(*disableCommand);
1252
1253 TestFaceManagerCommon::m_face->onReceiveData +=
1254 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001255 disableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001256
1257 onValidatedFaceRequest(disableCommand);
1258
1259 BOOST_REQUIRE(didCallbackFire());
1260}
1261
1262BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId,
1263 AuthorizedCommandFixture<LocalControlFixture>)
1264{
1265 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1266 BOOST_REQUIRE(dummy->isLocal());
1267 FaceTableFixture::m_faceTable.add(dummy);
1268
1269 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001270 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1271
1272 Block encodedParameters(parameters.wireEncode());
1273
1274 Name enable("/localhost/nfd/faces/enable-local-control");
1275 enable.append(encodedParameters);
1276
1277 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1278 enableCommand->setIncomingFaceId(dummy->getId());
1279
1280 generateCommand(*enableCommand);
1281
1282 TestFaceManagerCommon::m_face->onReceiveData +=
1283 bind(&LocalControlFixture::validateControlResponse, this, _1,
1284 enableCommand->getName(), 200, "Success", encodedParameters);
1285
1286 onValidatedFaceRequest(enableCommand);
1287
1288 BOOST_REQUIRE(didCallbackFire());
1289 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1290 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1291
1292
1293 TestFaceManagerCommon::m_face->onReceiveData.clear();
1294 resetCallbackFired();
1295
1296 Name disable("/localhost/nfd/faces/disable-local-control");
1297 disable.append(encodedParameters);
1298
1299 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1300 disableCommand->setIncomingFaceId(dummy->getId());
1301
1302 generateCommand(*disableCommand);
1303
1304 TestFaceManagerCommon::m_face->onReceiveData +=
1305 bind(&LocalControlFixture::validateControlResponse, this, _1,
1306 disableCommand->getName(), 200, "Success", encodedParameters);
1307
1308 onValidatedFaceRequest(disableCommand);
1309
1310 BOOST_REQUIRE(didCallbackFire());
1311 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1312 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1313}
1314
1315BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound,
1316 AuthorizedCommandFixture<LocalControlFixture>)
1317{
1318 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1319 BOOST_REQUIRE(dummy->isLocal());
1320 FaceTableFixture::m_faceTable.add(dummy);
1321
1322 ControlParameters parameters;
1323 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1324
1325 Block encodedParameters(parameters.wireEncode());
1326
1327 Name enable("/localhost/nfd/faces/enable-local-control");
1328 enable.append(encodedParameters);
1329
1330 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1331 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1332
1333 generateCommand(*enableCommand);
1334
1335 TestFaceManagerCommon::m_face->onReceiveData +=
1336 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001337 enableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001338
1339 onValidatedFaceRequest(enableCommand);
1340
1341 BOOST_REQUIRE(didCallbackFire());
1342 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1343 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1344
1345
1346 TestFaceManagerCommon::m_face->onReceiveData.clear();
1347 resetCallbackFired();
1348
1349 Name disable("/localhost/nfd/faces/disable-local-control");
1350 disable.append(encodedParameters);
1351
1352 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1353 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1354
1355 generateCommand(*disableCommand);
1356
1357 TestFaceManagerCommon::m_face->onReceiveData +=
1358 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001359 disableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001360
1361 onValidatedFaceRequest(disableCommand);
1362
1363 BOOST_REQUIRE(didCallbackFire());
1364 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1365 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1366}
1367
1368BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal,
1369 AuthorizedCommandFixture<LocalControlFixture>)
1370{
1371 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1372 BOOST_REQUIRE(!dummy->isLocal());
1373 FaceTableFixture::m_faceTable.add(dummy);
1374
1375 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001376 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1377
1378 Block encodedParameters(parameters.wireEncode());
1379
1380 Name enable("/localhost/nfd/faces/enable-local-control");
1381 enable.append(encodedParameters);
1382
1383 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1384 enableCommand->setIncomingFaceId(dummy->getId());
1385
1386 generateCommand(*enableCommand);
1387
1388 TestFaceManagerCommon::m_face->onReceiveData +=
1389 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001390 enableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001391
1392 onValidatedFaceRequest(enableCommand);
1393
1394 BOOST_REQUIRE(didCallbackFire());
1395
1396 TestFaceManagerCommon::m_face->onReceiveData.clear();
1397 resetCallbackFired();
1398
1399 Name disable("/localhost/nfd/faces/disable-local-control");
1400 disable.append(encodedParameters);
1401
1402 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1403 disableCommand->setIncomingFaceId(dummy->getId());
1404
1405 generateCommand(*disableCommand);
1406
1407 TestFaceManagerCommon::m_face->onReceiveData +=
1408 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001409 disableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001410
1411 onValidatedFaceRequest(disableCommand);
1412
1413 BOOST_REQUIRE(didCallbackFire());
1414}
1415
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001416class FaceFixture : public FaceTableFixture,
1417 public TestFaceManagerCommon,
1418 public FaceManager
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001419{
1420public:
1421 FaceFixture()
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001422 : FaceManager(FaceTableFixture::m_faceTable,
Vince Lehman5144f822014-07-23 15:12:56 -07001423 TestFaceManagerCommon::m_face,
1424 m_testKeyChain)
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001425 , m_receivedNotification(false)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001426 {
1427
1428 }
1429
1430 virtual
1431 ~FaceFixture()
1432 {
1433
1434 }
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001435
1436 void
1437 callbackDispatch(const Data& response,
1438 const Name& expectedName,
1439 uint32_t expectedCode,
1440 const std::string& expectedText,
1441 const Block& expectedBody,
1442 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1443 {
1444 Block payload = response.getContent().blockFromValue();
1445 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1446 {
1447 validateControlResponse(response, expectedName, expectedCode,
1448 expectedText, expectedBody);
1449 }
1450 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1451 {
1452 validateFaceEvent(payload, expectedFaceEvent);
1453 }
1454 else
1455 {
1456 BOOST_FAIL("Received unknown message type: #" << payload.type());
1457 }
1458 }
1459
1460 void
1461 callbackDispatch(const Data& response,
1462 const Name& expectedName,
1463 uint32_t expectedCode,
1464 const std::string& expectedText,
1465 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1466 {
1467 Block payload = response.getContent().blockFromValue();
1468 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1469 {
1470 validateControlResponse(response, expectedName,
1471 expectedCode, expectedText);
1472 }
1473 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1474 {
1475 validateFaceEvent(payload, expectedFaceEvent);
1476 }
1477 else
1478 {
1479 BOOST_FAIL("Received unknown message type: #" << payload.type());
1480 }
1481 }
1482
1483 void
1484 validateFaceEvent(const Block& wire,
1485 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1486 {
1487
1488 m_receivedNotification = true;
1489
1490 ndn::nfd::FaceEventNotification notification(wire);
1491
Junxiao Shi6e694322014-04-03 10:27:13 -07001492 BOOST_CHECK_EQUAL(notification.getKind(), expectedFaceEvent.getKind());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001493 BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId());
Junxiao Shi6e694322014-04-03 10:27:13 -07001494 BOOST_CHECK_EQUAL(notification.getRemoteUri(), expectedFaceEvent.getRemoteUri());
1495 BOOST_CHECK_EQUAL(notification.getLocalUri(), expectedFaceEvent.getLocalUri());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001496 }
1497
1498 bool
1499 didReceiveNotication() const
1500 {
1501 return m_receivedNotification;
1502 }
1503
1504protected:
1505 bool m_receivedNotification;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001506};
1507
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001508BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001509{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001510 ControlParameters parameters;
1511 parameters.setUri("tcp:/127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001512
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001513 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001514
1515 Name commandName("/localhost/nfd/faces");
1516 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001517 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001518
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001519 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1520 generateCommand(*command);
1521
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001522 getFace()->onReceiveData +=
1523 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001524 command->getName(), 400, "Malformed command");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001525
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001526 createFace(*command, parameters);
1527
1528 BOOST_REQUIRE(didCallbackFire());
1529}
1530
1531BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>)
1532{
1533 ControlParameters parameters;
1534
1535 Block encodedParameters(parameters.wireEncode());
1536
1537 Name commandName("/localhost/nfd/faces");
1538 commandName.append("create");
1539 commandName.append(encodedParameters);
1540
1541 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1542 generateCommand(*command);
1543
1544 getFace()->onReceiveData +=
1545 bind(&FaceFixture::validateControlResponse, this, _1,
1546 command->getName(), 400, "Malformed command");
1547
1548 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001549
1550 BOOST_REQUIRE(didCallbackFire());
1551}
1552
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001553BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001554{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001555 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001556 // this will be an unsupported protocol because no factories have been
1557 // added to the face manager
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001558 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001559
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001560 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001561
1562 Name commandName("/localhost/nfd/faces");
1563 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001564 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001565
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001566 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1567 generateCommand(*command);
1568
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001569 getFace()->onReceiveData +=
1570 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001571 command->getName(), 501, "Unsupported protocol");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001572
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001573 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001574
1575 BOOST_REQUIRE(didCallbackFire());
1576}
1577
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001578BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001579{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001580 ControlParameters parameters;
1581 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001582
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001583 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001584
1585 Name commandName("/localhost/nfd/faces");
1586 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001587 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001588
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001589 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1590 generateCommand(*command);
1591
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001592 ControlParameters resultParameters;
Steve DiBenedetto25999282014-05-22 15:25:12 -06001593 resultParameters.setUri("dummy://");
Junxiao Shi7b984c62014-07-17 22:18:34 -07001594 resultParameters.setFaceId(FACEID_RESERVED_MAX + 1);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001595
1596 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1597
Junxiao Shi6e694322014-04-03 10:27:13 -07001598 ndn::nfd::FaceEventNotification expectedFaceEvent;
1599 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED)
Junxiao Shi7b984c62014-07-17 22:18:34 -07001600 .setFaceId(FACEID_RESERVED_MAX + 1)
Junxiao Shi6e694322014-04-03 10:27:13 -07001601 .setRemoteUri(dummy->getRemoteUri().toString())
1602 .setLocalUri(dummy->getLocalUri().toString())
1603 .setFlags(0);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001604
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001605 Block encodedResultParameters(resultParameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001606
1607 getFace()->onReceiveData +=
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001608 bind(&FaceFixture::callbackDispatch, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001609 command->getName(), 200, "Success",
1610 encodedResultParameters, expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001611
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001612 onCreated(command->getName(), parameters, dummy);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001613
1614 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001615 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001616}
1617
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001618BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001619{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001620 ControlParameters parameters;
1621 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001622
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001623 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001624
1625 Name commandName("/localhost/nfd/faces");
1626 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001627 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001628
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001629 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1630 generateCommand(*command);
1631
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001632 getFace()->onReceiveData +=
1633 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedettoca53ac62014-03-27 19:58:40 -06001634 command->getName(), 408, "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001635
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001636 onConnectFailed(command->getName(), "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001637
1638 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001639 BOOST_CHECK_EQUAL(didReceiveNotication(), false);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001640}
1641
1642
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001643BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001644{
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001645 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1646 FaceTableFixture::m_faceTable.add(dummy);
1647
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001648 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001649 parameters.setFaceId(dummy->getId());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001650
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001651 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001652
1653 Name commandName("/localhost/nfd/faces");
1654 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001655 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001656
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001657 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1658 generateCommand(*command);
1659
Junxiao Shi6e694322014-04-03 10:27:13 -07001660 ndn::nfd::FaceEventNotification expectedFaceEvent;
1661 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
1662 .setFaceId(dummy->getId())
1663 .setRemoteUri(dummy->getRemoteUri().toString())
1664 .setLocalUri(dummy->getLocalUri().toString())
1665 .setFlags(0);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001666
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001667 getFace()->onReceiveData +=
Alexander Afanasyevf6980282014-05-13 18:28:40 -07001668 bind(&FaceFixture::callbackDispatch, this, _1, command->getName(),
1669 200, "Success", ref(encodedParameters), expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001670
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001671 destroyFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001672
1673 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001674 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001675}
1676
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001677class FaceListFixture : public FaceStatusPublisherFixture
1678{
1679public:
1680 FaceListFixture()
Vince Lehman5144f822014-07-23 15:12:56 -07001681 : m_manager(m_table, m_face, m_testKeyChain)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001682 {
1683
1684 }
1685
1686 virtual
1687 ~FaceListFixture()
1688 {
1689
1690 }
1691
1692protected:
1693 FaceManager m_manager;
Vince Lehman5144f822014-07-23 15:12:56 -07001694 ndn::KeyChain m_testKeyChain;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001695};
1696
1697BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001698{
1699 Name commandName("/localhost/nfd/faces/list");
1700 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1701
Junxiao Shi632a6202014-07-20 01:14:30 -07001702 // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 75
1703 // use 59 FaceStatuses to force a FaceStatus to span Data packets
1704 for (int i = 0; i < 59; i++)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001705 {
1706 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1707
1708 uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
Junxiao Shi632a6202014-07-20 01:14:30 -07001709 dummy->setCounters(filler, filler, filler, filler, filler, filler);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001710
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001711 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001712
1713 add(dummy);
1714 }
1715
1716 ndn::EncodingBuffer buffer;
1717
1718 m_face->onReceiveData +=
1719 bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, this, _1);
1720
1721 m_manager.listFaces(*command);
1722 BOOST_REQUIRE(m_finished);
1723}
1724
Steve DiBenedettoef04f272014-06-04 14:28:31 -06001725class ChannelStatusFixture : public FaceManagerFixture
1726{
1727public:
1728 void
1729 validatePublish(const Data& data, const ndn::nfd::ChannelStatus& expectedEntry)
1730 {
1731 m_callbackFired = true;
1732 Block b = data.getContent().blockFromValue();
1733 ndn::nfd::ChannelStatus entry(b);
1734 BOOST_CHECK_EQUAL(entry.getLocalUri(), expectedEntry.getLocalUri());
1735 }
1736
1737 virtual shared_ptr<DummyProtocolFactory>
1738 addProtocolFactory(const std::string& protocol)
1739 {
1740 shared_ptr<DummyProtocolFactory> factory(make_shared<DummyProtocolFactory>());
1741 m_manager.m_factories[protocol] = factory;
1742
1743 return factory;
1744 }
1745};
1746
1747BOOST_FIXTURE_TEST_CASE(TestChannelStatus, ChannelStatusFixture)
1748{
1749 shared_ptr<DummyProtocolFactory> factory(addProtocolFactory("dummy"));
1750 factory->addChannel("dummy://");
1751
1752 Name requestName("/localhost/nfd/faces/channels");
1753 shared_ptr<Interest> request(make_shared<Interest>(requestName));
1754
1755 ndn::nfd::ChannelStatus expectedEntry;
1756 expectedEntry.setLocalUri(DummyChannel("dummy://").getUri().toString());
1757
1758 m_face->onReceiveData +=
1759 bind(&ChannelStatusFixture::validatePublish, this, _1, expectedEntry);
1760
1761 m_manager.listChannels(*request);
1762 BOOST_REQUIRE(m_callbackFired);
1763}
1764
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001765BOOST_AUTO_TEST_SUITE_END()
1766
1767} // namespace tests
1768} // namespace nfd