blob: aa1bf32fa3ad8aaa9d46dde16df0c1f6fc352c90 [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
Junxiao Shicd55cde2014-11-13 16:03:24 -0700816 getFace()->onReceiveData += [this, command] (const Data& response) {
817 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
818 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700819
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
Junxiao Shicd55cde2014-11-13 16:03:24 -0700830 getFace()->onReceiveData += [this, command] (const Data& response) {
831 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
832 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700833
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
Junxiao Shicd55cde2014-11-13 16:03:24 -0700852 getFace()->onReceiveData += [this, command] (const Data& response) {
853 this->validateControlResponse(response, command->getName(), 401, "Signature required");
854 };
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700855
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
Junxiao Shicd55cde2014-11-13 16:03:24 -0700875 getFace()->onReceiveData += [this, command] (const Data& response) {
876 this->validateControlResponse(response, command->getName(), 403, "Unauthorized command");
877 };
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700878
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
Junxiao Shicd55cde2014-11-13 16:03:24 -0700913 getFace()->onReceiveData += [this, command] (const Data& response) {
914 this->validateControlResponse(response, command->getName(), 501, "Unsupported command");
915 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700916
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
Junxiao Shicd55cde2014-11-13 16:03:24 -0700983 getFace()->onReceiveData += [this, command] (const Data& response) {
984 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
985 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700986
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 +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001080 [this, enableCommand, encodedParameters] (const Data& response) {
1081 this->validateControlResponse(response, enableCommand->getName(),
1082 200, "Success", encodedParameters);
1083 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001084
1085 onValidatedFaceRequest(enableCommand);
1086
1087 BOOST_REQUIRE(didCallbackFire());
1088 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1089 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1090
1091 TestFaceManagerCommon::m_face->onReceiveData.clear();
1092 resetCallbackFired();
1093
1094 Name disable("/localhost/nfd/faces/disable-local-control");
1095 disable.append(encodedParameters);
1096
1097 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1098 disableCommand->setIncomingFaceId(dummy->getId());
1099
1100 generateCommand(*disableCommand);
1101
1102 TestFaceManagerCommon::m_face->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001103 [this, disableCommand, encodedParameters] (const Data& response) {
1104 this->validateControlResponse(response, disableCommand->getName(),
1105 200, "Success", encodedParameters);
1106 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001107
1108 onValidatedFaceRequest(disableCommand);
1109
1110 BOOST_REQUIRE(didCallbackFire());
1111 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1112 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1113}
1114
1115BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound,
1116 AuthorizedCommandFixture<LocalControlFixture>)
1117{
1118 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1119 BOOST_REQUIRE(dummy->isLocal());
1120 FaceTableFixture::m_faceTable.add(dummy);
1121
1122 ControlParameters parameters;
1123 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1124
1125 Block encodedParameters(parameters.wireEncode());
1126
1127 Name enable("/localhost/nfd/faces/enable-local-control");
1128 enable.append(encodedParameters);
1129
1130 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1131 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1132
1133 generateCommand(*enableCommand);
1134
Junxiao Shicd55cde2014-11-13 16:03:24 -07001135 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1136 this->validateControlResponse(response, enableCommand->getName(), 410, "Face not found");
1137 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001138
1139 onValidatedFaceRequest(enableCommand);
1140
1141 BOOST_REQUIRE(didCallbackFire());
1142 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1143 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1144
1145 TestFaceManagerCommon::m_face->onReceiveData.clear();
1146 resetCallbackFired();
1147
1148 Name disable("/localhost/nfd/faces/disable-local-control");
1149 disable.append(encodedParameters);
1150
1151 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1152 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1153
1154 generateCommand(*disableCommand);
1155
Junxiao Shicd55cde2014-11-13 16:03:24 -07001156 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1157 this->validateControlResponse(response, disableCommand->getName(), 410, "Face not found");
1158 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001159
1160 onValidatedFaceRequest(disableCommand);
1161
1162 BOOST_REQUIRE(didCallbackFire());
1163 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1164 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1165}
1166
1167BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature,
1168 AuthorizedCommandFixture<LocalControlFixture>)
1169{
1170 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1171 BOOST_REQUIRE(dummy->isLocal());
1172 FaceTableFixture::m_faceTable.add(dummy);
1173
1174 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001175
1176 Block encodedParameters(parameters.wireEncode());
1177
1178 Name enable("/localhost/nfd/faces/enable-local-control");
1179 enable.append(encodedParameters);
1180
1181 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1182 enableCommand->setIncomingFaceId(dummy->getId());
1183
1184 generateCommand(*enableCommand);
1185
Junxiao Shicd55cde2014-11-13 16:03:24 -07001186 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1187 this->validateControlResponse(response, enableCommand->getName(), 400, "Malformed command");
1188 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001189
1190 onValidatedFaceRequest(enableCommand);
1191
1192 BOOST_REQUIRE(didCallbackFire());
1193 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1194 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1195
1196 TestFaceManagerCommon::m_face->onReceiveData.clear();
1197 resetCallbackFired();
1198
1199 Name disable("/localhost/nfd/faces/disable-local-control");
1200 disable.append(encodedParameters);
1201
1202 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1203 disableCommand->setIncomingFaceId(dummy->getId());
1204
1205 generateCommand(*disableCommand);
1206
Junxiao Shicd55cde2014-11-13 16:03:24 -07001207 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1208 this->validateControlResponse(response, disableCommand->getName(), 400, "Malformed command");
1209 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001210
1211 onValidatedFaceRequest(disableCommand);
1212
1213 BOOST_REQUIRE(didCallbackFire());
1214 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1215 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1216}
1217
1218BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal,
1219 AuthorizedCommandFixture<LocalControlFixture>)
1220{
1221 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1222 BOOST_REQUIRE(!dummy->isLocal());
1223 FaceTableFixture::m_faceTable.add(dummy);
1224
1225 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001226 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1227
1228 Block encodedParameters(parameters.wireEncode());
1229
1230 Name enable("/localhost/nfd/faces/enable-local-control");
1231 enable.append(encodedParameters);
1232
1233 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1234 enableCommand->setIncomingFaceId(dummy->getId());
1235
1236 generateCommand(*enableCommand);
1237
Junxiao Shicd55cde2014-11-13 16:03:24 -07001238 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1239 this->validateControlResponse(response, enableCommand->getName(), 412, "Face is non-local");
1240 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001241
1242 onValidatedFaceRequest(enableCommand);
1243
1244 BOOST_REQUIRE(didCallbackFire());
1245
1246 TestFaceManagerCommon::m_face->onReceiveData.clear();
1247 resetCallbackFired();
1248
1249 Name disable("/localhost/nfd/faces/disable-local-control");
1250 enable.append(encodedParameters);
1251
1252 shared_ptr<Interest> disableCommand(make_shared<Interest>(enable));
1253 disableCommand->setIncomingFaceId(dummy->getId());
1254
1255 generateCommand(*disableCommand);
1256
Junxiao Shicd55cde2014-11-13 16:03:24 -07001257 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1258 this->validateControlResponse(response, disableCommand->getName(), 412, "Face is non-local");
1259 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001260
1261 onValidatedFaceRequest(disableCommand);
1262
1263 BOOST_REQUIRE(didCallbackFire());
1264}
1265
1266BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId,
1267 AuthorizedCommandFixture<LocalControlFixture>)
1268{
1269 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1270 BOOST_REQUIRE(dummy->isLocal());
1271 FaceTableFixture::m_faceTable.add(dummy);
1272
1273 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001274 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1275
1276 Block encodedParameters(parameters.wireEncode());
1277
1278 Name enable("/localhost/nfd/faces/enable-local-control");
1279 enable.append(encodedParameters);
1280
1281 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1282 enableCommand->setIncomingFaceId(dummy->getId());
1283
1284 generateCommand(*enableCommand);
1285
1286 TestFaceManagerCommon::m_face->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001287 [this, enableCommand, encodedParameters] (const Data& response) {
1288 this->validateControlResponse(response, enableCommand->getName(),
1289 200, "Success", encodedParameters);
1290 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001291
1292 onValidatedFaceRequest(enableCommand);
1293
1294 BOOST_REQUIRE(didCallbackFire());
1295 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1296 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1297
1298
1299 TestFaceManagerCommon::m_face->onReceiveData.clear();
1300 resetCallbackFired();
1301
1302 Name disable("/localhost/nfd/faces/disable-local-control");
1303 disable.append(encodedParameters);
1304
1305 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1306 disableCommand->setIncomingFaceId(dummy->getId());
1307
1308 generateCommand(*disableCommand);
1309
1310 TestFaceManagerCommon::m_face->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001311 [this, disableCommand, encodedParameters] (const Data& response) {
1312 this->validateControlResponse(response, disableCommand->getName(),
1313 200, "Success", encodedParameters);
1314 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001315
1316 onValidatedFaceRequest(disableCommand);
1317
1318 BOOST_REQUIRE(didCallbackFire());
1319 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1320 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1321}
1322
1323BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound,
1324 AuthorizedCommandFixture<LocalControlFixture>)
1325{
1326 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1327 BOOST_REQUIRE(dummy->isLocal());
1328 FaceTableFixture::m_faceTable.add(dummy);
1329
1330 ControlParameters parameters;
1331 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1332
1333 Block encodedParameters(parameters.wireEncode());
1334
1335 Name enable("/localhost/nfd/faces/enable-local-control");
1336 enable.append(encodedParameters);
1337
1338 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1339 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1340
1341 generateCommand(*enableCommand);
1342
Junxiao Shicd55cde2014-11-13 16:03:24 -07001343 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1344 this->validateControlResponse(response, enableCommand->getName(), 410, "Face not found");
1345 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001346
1347 onValidatedFaceRequest(enableCommand);
1348
1349 BOOST_REQUIRE(didCallbackFire());
1350 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1351 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1352
1353
1354 TestFaceManagerCommon::m_face->onReceiveData.clear();
1355 resetCallbackFired();
1356
1357 Name disable("/localhost/nfd/faces/disable-local-control");
1358 disable.append(encodedParameters);
1359
1360 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1361 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1362
1363 generateCommand(*disableCommand);
1364
Junxiao Shicd55cde2014-11-13 16:03:24 -07001365 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1366 this->validateControlResponse(response, disableCommand->getName(), 410, "Face not found");
1367 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001368
1369 onValidatedFaceRequest(disableCommand);
1370
1371 BOOST_REQUIRE(didCallbackFire());
1372 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1373 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1374}
1375
1376BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal,
1377 AuthorizedCommandFixture<LocalControlFixture>)
1378{
1379 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1380 BOOST_REQUIRE(!dummy->isLocal());
1381 FaceTableFixture::m_faceTable.add(dummy);
1382
1383 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001384 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1385
1386 Block encodedParameters(parameters.wireEncode());
1387
1388 Name enable("/localhost/nfd/faces/enable-local-control");
1389 enable.append(encodedParameters);
1390
1391 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1392 enableCommand->setIncomingFaceId(dummy->getId());
1393
1394 generateCommand(*enableCommand);
1395
Junxiao Shicd55cde2014-11-13 16:03:24 -07001396 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1397 this->validateControlResponse(response, enableCommand->getName(), 412, "Face is non-local");
1398 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001399
1400 onValidatedFaceRequest(enableCommand);
1401
1402 BOOST_REQUIRE(didCallbackFire());
1403
1404 TestFaceManagerCommon::m_face->onReceiveData.clear();
1405 resetCallbackFired();
1406
1407 Name disable("/localhost/nfd/faces/disable-local-control");
1408 disable.append(encodedParameters);
1409
1410 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1411 disableCommand->setIncomingFaceId(dummy->getId());
1412
1413 generateCommand(*disableCommand);
1414
Junxiao Shicd55cde2014-11-13 16:03:24 -07001415 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1416 this->validateControlResponse(response, disableCommand->getName(), 412, "Face is non-local");
1417 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001418
1419 onValidatedFaceRequest(disableCommand);
1420
1421 BOOST_REQUIRE(didCallbackFire());
1422}
1423
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001424class FaceFixture : public FaceTableFixture,
1425 public TestFaceManagerCommon,
1426 public FaceManager
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001427{
1428public:
1429 FaceFixture()
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001430 : FaceManager(FaceTableFixture::m_faceTable,
Vince Lehman5144f822014-07-23 15:12:56 -07001431 TestFaceManagerCommon::m_face,
1432 m_testKeyChain)
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001433 , m_receivedNotification(false)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001434 {
1435
1436 }
1437
1438 virtual
1439 ~FaceFixture()
1440 {
1441
1442 }
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001443
1444 void
1445 callbackDispatch(const Data& response,
1446 const Name& expectedName,
1447 uint32_t expectedCode,
1448 const std::string& expectedText,
1449 const Block& expectedBody,
1450 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1451 {
1452 Block payload = response.getContent().blockFromValue();
1453 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1454 {
1455 validateControlResponse(response, expectedName, expectedCode,
1456 expectedText, expectedBody);
1457 }
1458 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1459 {
1460 validateFaceEvent(payload, expectedFaceEvent);
1461 }
1462 else
1463 {
1464 BOOST_FAIL("Received unknown message type: #" << payload.type());
1465 }
1466 }
1467
1468 void
1469 callbackDispatch(const Data& response,
1470 const Name& expectedName,
1471 uint32_t expectedCode,
1472 const std::string& expectedText,
1473 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1474 {
1475 Block payload = response.getContent().blockFromValue();
1476 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1477 {
1478 validateControlResponse(response, expectedName,
1479 expectedCode, expectedText);
1480 }
1481 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1482 {
1483 validateFaceEvent(payload, expectedFaceEvent);
1484 }
1485 else
1486 {
1487 BOOST_FAIL("Received unknown message type: #" << payload.type());
1488 }
1489 }
1490
1491 void
1492 validateFaceEvent(const Block& wire,
1493 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1494 {
1495
1496 m_receivedNotification = true;
1497
1498 ndn::nfd::FaceEventNotification notification(wire);
1499
Junxiao Shi6e694322014-04-03 10:27:13 -07001500 BOOST_CHECK_EQUAL(notification.getKind(), expectedFaceEvent.getKind());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001501 BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId());
Junxiao Shi6e694322014-04-03 10:27:13 -07001502 BOOST_CHECK_EQUAL(notification.getRemoteUri(), expectedFaceEvent.getRemoteUri());
1503 BOOST_CHECK_EQUAL(notification.getLocalUri(), expectedFaceEvent.getLocalUri());
Chengyu Fanf9c2bb12014-10-06 11:52:44 -06001504 BOOST_CHECK_EQUAL(notification.getFaceScope(), expectedFaceEvent.getFaceScope());
1505 BOOST_CHECK_EQUAL(notification.getFacePersistency(), expectedFaceEvent.getFacePersistency());
1506 BOOST_CHECK_EQUAL(notification.getLinkType(), expectedFaceEvent.getLinkType());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001507 }
1508
1509 bool
1510 didReceiveNotication() const
1511 {
1512 return m_receivedNotification;
1513 }
1514
1515protected:
1516 bool m_receivedNotification;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001517};
1518
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001519BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001520{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001521 ControlParameters parameters;
1522 parameters.setUri("tcp:/127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001523
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001524 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001525
1526 Name commandName("/localhost/nfd/faces");
1527 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001528 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001529
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001530 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1531 generateCommand(*command);
1532
Junxiao Shicd55cde2014-11-13 16:03:24 -07001533 getFace()->onReceiveData += [this, command] (const Data& response) {
1534 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
1535 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001536
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001537 createFace(*command, parameters);
1538
1539 BOOST_REQUIRE(didCallbackFire());
1540}
1541
1542BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>)
1543{
1544 ControlParameters parameters;
1545
1546 Block encodedParameters(parameters.wireEncode());
1547
1548 Name commandName("/localhost/nfd/faces");
1549 commandName.append("create");
1550 commandName.append(encodedParameters);
1551
1552 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1553 generateCommand(*command);
1554
Junxiao Shicd55cde2014-11-13 16:03:24 -07001555 getFace()->onReceiveData += [this, command] (const Data& response) {
1556 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
1557 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001558
1559 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001560
1561 BOOST_REQUIRE(didCallbackFire());
1562}
1563
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001564BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001565{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001566 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001567 // this will be an unsupported protocol because no factories have been
1568 // added to the face manager
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001569 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001570
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001571 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001572
1573 Name commandName("/localhost/nfd/faces");
1574 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001575 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001576
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001577 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1578 generateCommand(*command);
1579
Junxiao Shicd55cde2014-11-13 16:03:24 -07001580 getFace()->onReceiveData += [this, command] (const Data& response) {
1581 this->validateControlResponse(response, command->getName(), 501, "Unsupported protocol");
1582 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001583
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001584 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001585
1586 BOOST_REQUIRE(didCallbackFire());
1587}
1588
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001589BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001590{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001591 ControlParameters parameters;
1592 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001593
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001594 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001595
1596 Name commandName("/localhost/nfd/faces");
1597 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001598 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001599
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001600 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1601 generateCommand(*command);
1602
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001603 ControlParameters resultParameters;
Steve DiBenedetto25999282014-05-22 15:25:12 -06001604 resultParameters.setUri("dummy://");
Junxiao Shi7b984c62014-07-17 22:18:34 -07001605 resultParameters.setFaceId(FACEID_RESERVED_MAX + 1);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001606
1607 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1608
Junxiao Shi6e694322014-04-03 10:27:13 -07001609 ndn::nfd::FaceEventNotification expectedFaceEvent;
1610 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED)
Junxiao Shi7b984c62014-07-17 22:18:34 -07001611 .setFaceId(FACEID_RESERVED_MAX + 1)
Junxiao Shi6e694322014-04-03 10:27:13 -07001612 .setRemoteUri(dummy->getRemoteUri().toString())
1613 .setLocalUri(dummy->getLocalUri().toString())
Chengyu Fan9942cea2014-10-13 14:47:13 -06001614 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
1615 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001616
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001617 Block encodedResultParameters(resultParameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001618
1619 getFace()->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001620 [this, command, encodedResultParameters, expectedFaceEvent] (const Data& response) {
1621 this->callbackDispatch(response,command->getName(), 200, "Success",
1622 encodedResultParameters, expectedFaceEvent);
1623 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001624
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001625 onCreated(command->getName(), parameters, dummy);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001626
1627 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001628 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001629}
1630
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001631BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001632{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001633 ControlParameters parameters;
1634 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001635
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001636 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001637
1638 Name commandName("/localhost/nfd/faces");
1639 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001640 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001641
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001642 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1643 generateCommand(*command);
1644
Junxiao Shicd55cde2014-11-13 16:03:24 -07001645 getFace()->onReceiveData += [this, command] (const Data& response) {
1646 this->validateControlResponse(response, command->getName(), 408, "unit-test-reason");
1647 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001648
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001649 onConnectFailed(command->getName(), "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001650
1651 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001652 BOOST_CHECK_EQUAL(didReceiveNotication(), false);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001653}
1654
1655
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001656BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001657{
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001658 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1659 FaceTableFixture::m_faceTable.add(dummy);
1660
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001661 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001662 parameters.setFaceId(dummy->getId());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001663
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001664 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001665
1666 Name commandName("/localhost/nfd/faces");
1667 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001668 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001669
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001670 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1671 generateCommand(*command);
1672
Junxiao Shi6e694322014-04-03 10:27:13 -07001673 ndn::nfd::FaceEventNotification expectedFaceEvent;
1674 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
1675 .setFaceId(dummy->getId())
1676 .setRemoteUri(dummy->getRemoteUri().toString())
1677 .setLocalUri(dummy->getLocalUri().toString())
Chengyu Fan9942cea2014-10-13 14:47:13 -06001678 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
1679 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001680
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001681 getFace()->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001682 [this, command, encodedParameters, expectedFaceEvent] (const Data& response) {
1683 this->callbackDispatch(response,command->getName(), 200, "Success",
1684 encodedParameters, expectedFaceEvent);
1685 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001686
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001687 destroyFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001688
1689 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001690 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001691}
1692
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001693class FaceListFixture : public FaceStatusPublisherFixture
1694{
1695public:
1696 FaceListFixture()
Vince Lehman5144f822014-07-23 15:12:56 -07001697 : m_manager(m_table, m_face, m_testKeyChain)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001698 {
1699
1700 }
1701
1702 virtual
1703 ~FaceListFixture()
1704 {
1705
1706 }
1707
1708protected:
1709 FaceManager m_manager;
Vince Lehman5144f822014-07-23 15:12:56 -07001710 ndn::KeyChain m_testKeyChain;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001711};
1712
1713BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001714{
1715 Name commandName("/localhost/nfd/faces/list");
1716 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1717
Junxiao Shi632a6202014-07-20 01:14:30 -07001718 // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 75
1719 // use 59 FaceStatuses to force a FaceStatus to span Data packets
1720 for (int i = 0; i < 59; i++)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001721 {
1722 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1723
1724 uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
Junxiao Shi632a6202014-07-20 01:14:30 -07001725 dummy->setCounters(filler, filler, filler, filler, filler, filler);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001726
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001727 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001728
1729 add(dummy);
1730 }
1731
1732 ndn::EncodingBuffer buffer;
1733
1734 m_face->onReceiveData +=
1735 bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, this, _1);
1736
1737 m_manager.listFaces(*command);
1738 BOOST_REQUIRE(m_finished);
1739}
1740
Steve DiBenedettoef04f272014-06-04 14:28:31 -06001741class ChannelStatusFixture : public FaceManagerFixture
1742{
1743public:
1744 void
1745 validatePublish(const Data& data, const ndn::nfd::ChannelStatus& expectedEntry)
1746 {
1747 m_callbackFired = true;
1748 Block b = data.getContent().blockFromValue();
1749 ndn::nfd::ChannelStatus entry(b);
1750 BOOST_CHECK_EQUAL(entry.getLocalUri(), expectedEntry.getLocalUri());
1751 }
1752
1753 virtual shared_ptr<DummyProtocolFactory>
1754 addProtocolFactory(const std::string& protocol)
1755 {
1756 shared_ptr<DummyProtocolFactory> factory(make_shared<DummyProtocolFactory>());
1757 m_manager.m_factories[protocol] = factory;
1758
1759 return factory;
1760 }
1761};
1762
1763BOOST_FIXTURE_TEST_CASE(TestChannelStatus, ChannelStatusFixture)
1764{
1765 shared_ptr<DummyProtocolFactory> factory(addProtocolFactory("dummy"));
1766 factory->addChannel("dummy://");
1767
1768 Name requestName("/localhost/nfd/faces/channels");
1769 shared_ptr<Interest> request(make_shared<Interest>(requestName));
1770
1771 ndn::nfd::ChannelStatus expectedEntry;
1772 expectedEntry.setLocalUri(DummyChannel("dummy://").getUri().toString());
1773
1774 m_face->onReceiveData +=
1775 bind(&ChannelStatusFixture::validatePublish, this, _1, expectedEntry);
1776
1777 m_manager.listChannels(*request);
1778 BOOST_REQUIRE(m_callbackFired);
1779}
1780
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001781BOOST_AUTO_TEST_SUITE_END()
1782
1783} // namespace tests
1784} // namespace nfd