blob: 2b2a15e84f7bb5e5aab33d749176ee8dcf1efa11 [file] [log] [blame]
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Steve DiBenedettoef04f272014-06-04 14:28:31 -06003 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Steve DiBenedettoef04f272014-06-04 14:28:31 -060024 */
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070025
26#include "mgmt/face-manager.hpp"
27#include "mgmt/internal-face.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060028#include "mgmt/face-status-publisher.hpp"
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060029
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070030#include "face/face.hpp"
31#include "../face/dummy-face.hpp"
32#include "fw/face-table.hpp"
33#include "fw/forwarder.hpp"
Alexander Afanasyev5959b012014-06-02 19:18:12 +030034#include "face/udp-factory.hpp"
Alexander Afanasyeve9186212014-08-23 20:15:48 -070035
36#ifdef HAVE_LIBPCAP
Alexander Afanasyev5959b012014-06-02 19:18:12 +030037#include "face/ethernet-factory.hpp"
Alexander Afanasyeve9186212014-08-23 20:15:48 -070038#endif // HAVE_LIBPCAP
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070039
40#include "common.hpp"
41#include "tests/test-common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070042#include "validation-common.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060043#include "face-status-publisher-common.hpp"
Chengyu Fan320d2332014-10-29 16:40:33 -060044#include "face-query-status-publisher-common.hpp"
Steve DiBenedettoef04f272014-06-04 14:28:31 -060045#include "channel-status-common.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060046
Alexander Afanasyev4a771362014-04-24 21:29:33 -070047#include <ndn-cxx/encoding/tlv.hpp>
48#include <ndn-cxx/management/nfd-face-event-notification.hpp>
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070049
50namespace nfd {
51namespace tests {
52
53NFD_LOG_INIT("FaceManagerTest");
54
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060055class FaceManagerTestFace : public DummyFace
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070056{
57public:
58
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060059 FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070060 : m_closeFired(false)
61 {
62
63 }
64
65 virtual
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060066 ~FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070067 {
68
69 }
70
71 virtual void
72 close()
73 {
74 m_closeFired = true;
75 }
76
77 bool
78 didCloseFire() const
79 {
80 return m_closeFired;
81 }
82
83private:
84 bool m_closeFired;
85};
86
87class TestFaceTable : public FaceTable
88{
89public:
90 TestFaceTable(Forwarder& forwarder)
91 : FaceTable(forwarder),
92 m_addFired(false),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070093 m_getFired(false),
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060094 m_dummy(make_shared<FaceManagerTestFace>())
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070095 {
96
97 }
98
99 virtual
100 ~TestFaceTable()
101 {
102
103 }
104
105 virtual void
106 add(shared_ptr<Face> face)
107 {
108 m_addFired = true;
109 }
110
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700111 virtual shared_ptr<Face>
112 get(FaceId id) const
113 {
114 m_getFired = true;
115 return m_dummy;
116 }
117
118 bool
119 didAddFire() const
120 {
121 return m_addFired;
122 }
123
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700124 bool
125 didGetFire() const
126 {
127 return m_getFired;
128 }
129
130 void
131 reset()
132 {
133 m_addFired = false;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700134 m_getFired = false;
135 }
136
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600137 shared_ptr<FaceManagerTestFace>&
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700138 getDummyFace()
139 {
140 return m_dummy;
141 }
142
143private:
144 bool m_addFired;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700145 mutable bool m_getFired;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600146 shared_ptr<FaceManagerTestFace> m_dummy;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700147};
148
149
150class TestFaceTableFixture : public BaseFixture
151{
152public:
153 TestFaceTableFixture()
154 : m_faceTable(m_forwarder)
155 {
156
157 }
158
159 virtual
160 ~TestFaceTableFixture()
161 {
162
163 }
164
165protected:
166 Forwarder m_forwarder;
167 TestFaceTable m_faceTable;
168};
169
170class TestFaceManagerCommon
171{
172public:
173 TestFaceManagerCommon()
174 : m_face(make_shared<InternalFace>()),
175 m_callbackFired(false)
176 {
177
178 }
179
180 virtual
181 ~TestFaceManagerCommon()
182 {
183
184 }
185
186 shared_ptr<InternalFace>&
187 getFace()
188 {
189 return m_face;
190 }
191
192 void
193 validateControlResponseCommon(const Data& response,
194 const Name& expectedName,
195 uint32_t expectedCode,
196 const std::string& expectedText,
197 ControlResponse& control)
198 {
199 m_callbackFired = true;
200 Block controlRaw = response.getContent().blockFromValue();
201
202 control.wireDecode(controlRaw);
203
204 // NFD_LOG_DEBUG("received control response"
205 // << " Name: " << response.getName()
206 // << " code: " << control.getCode()
207 // << " text: " << control.getText());
208
209 BOOST_CHECK_EQUAL(response.getName(), expectedName);
210 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
211 BOOST_CHECK_EQUAL(control.getText(), expectedText);
212 }
213
214 void
215 validateControlResponse(const Data& response,
216 const Name& expectedName,
217 uint32_t expectedCode,
218 const std::string& expectedText)
219 {
220 ControlResponse control;
221 validateControlResponseCommon(response, expectedName,
222 expectedCode, expectedText, control);
223
224 if (!control.getBody().empty())
225 {
226 BOOST_FAIL("found unexpected control response body");
227 }
228 }
229
230 void
231 validateControlResponse(const Data& response,
232 const Name& expectedName,
233 uint32_t expectedCode,
234 const std::string& expectedText,
235 const Block& expectedBody)
236 {
237 ControlResponse control;
238 validateControlResponseCommon(response, expectedName,
239 expectedCode, expectedText, control);
240
241 BOOST_REQUIRE(!control.getBody().empty());
242 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
243
244 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
245 expectedBody.value_size()) == 0);
246
247 }
248
249 bool
250 didCallbackFire() const
251 {
252 return m_callbackFired;
253 }
254
255 void
256 resetCallbackFired()
257 {
258 m_callbackFired = false;
259 }
260
261protected:
262 shared_ptr<InternalFace> m_face;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700263 bool m_callbackFired;
Vince Lehman5144f822014-07-23 15:12:56 -0700264 ndn::KeyChain m_testKeyChain;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700265};
266
267class FaceManagerFixture : public TestFaceTableFixture, public TestFaceManagerCommon
268{
269public:
270 FaceManagerFixture()
Vince Lehman5144f822014-07-23 15:12:56 -0700271 : m_manager(m_faceTable, m_face, m_testKeyChain)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700272 {
273 m_manager.setConfigFile(m_config);
274 }
275
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700276 virtual
277 ~FaceManagerFixture()
278 {
279
280 }
281
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600282 void
283 parseConfig(const std::string configuration, bool isDryRun)
284 {
285 m_config.parse(configuration, isDryRun, "dummy-config");
286 }
287
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700288 FaceManager&
289 getManager()
290 {
291 return m_manager;
292 }
293
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700294 void
295 addInterestRule(const std::string& regex,
296 ndn::IdentityCertificate& certificate)
297 {
298 m_manager.addInterestRule(regex, certificate);
299 }
300
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700301 bool
302 didFaceTableAddFire() const
303 {
304 return m_faceTable.didAddFire();
305 }
306
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700307 bool
308 didFaceTableGetFire() const
309 {
310 return m_faceTable.didGetFire();
311 }
312
313 void
314 resetFaceTable()
315 {
316 m_faceTable.reset();
317 }
318
Steve DiBenedettoef04f272014-06-04 14:28:31 -0600319protected:
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700320 FaceManager m_manager;
321 ConfigFile m_config;
322};
323
324BOOST_FIXTURE_TEST_SUITE(MgmtFaceManager, FaceManagerFixture)
325
326bool
327isExpectedException(const ConfigFile::Error& error, const std::string& expectedMessage)
328{
329 if (error.what() != expectedMessage)
330 {
331 NFD_LOG_ERROR("expected: " << expectedMessage << "\tgot: " << error.what());
332 }
333 return error.what() == expectedMessage;
334}
335
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600336#ifdef HAVE_UNIX_SOCKETS
337
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700338BOOST_AUTO_TEST_CASE(TestProcessSectionUnix)
339{
340 const std::string CONFIG =
341 "face_system\n"
342 "{\n"
343 " unix\n"
344 " {\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700345 " 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"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700359 " path /var/run/nfd.sock\n"
360 " }\n"
361 "}\n";
362
363 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
364}
365
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700366BOOST_AUTO_TEST_CASE(TestProcessSectionUnixUnknownOption)
367{
368 const std::string CONFIG =
369 "face_system\n"
370 "{\n"
371 " unix\n"
372 " {\n"
373 " hello\n"
374 " }\n"
375 "}\n";
376 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
377 bind(&isExpectedException, _1,
378 "Unrecognized option \"hello\" in \"unix\" section"));
379}
380
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600381#endif // HAVE_UNIX_SOCKETS
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700382
383
384BOOST_AUTO_TEST_CASE(TestProcessSectionTcp)
385{
386 const std::string CONFIG =
387 "face_system\n"
388 "{\n"
389 " tcp\n"
390 " {\n"
391 " listen yes\n"
392 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600393 " enable_v4 yes\n"
394 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700395 " }\n"
396 "}\n";
397 try
398 {
399 parseConfig(CONFIG, false);
400 }
401 catch (const std::runtime_error& e)
402 {
403 const std::string reason = e.what();
404 if (reason.find("Address in use") != std::string::npos)
405 {
406 BOOST_FAIL(reason);
407 }
408 }
409}
410
411BOOST_AUTO_TEST_CASE(TestProcessSectionTcpDryRun)
412{
413 const std::string CONFIG =
414 "face_system\n"
415 "{\n"
416 " tcp\n"
417 " {\n"
418 " listen yes\n"
419 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600420 " enable_v4 yes\n"
421 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700422 " }\n"
423 "}\n";
424 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
425}
426
427BOOST_AUTO_TEST_CASE(TestProcessSectionTcpBadListen)
428{
429 const std::string CONFIG =
430 "face_system\n"
431 "{\n"
432 " tcp\n"
433 " {\n"
434 " listen hello\n"
435 " }\n"
436 "}\n";
437 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
438 bind(&isExpectedException, _1,
439 "Invalid value for option \"listen\" in \"tcp\" section"));
440}
441
Steve DiBenedetto95152872014-04-11 12:40:59 -0600442BOOST_AUTO_TEST_CASE(TestProcessSectionTcpChannelsDisabled)
443{
444 const std::string CONFIG =
445 "face_system\n"
446 "{\n"
447 " tcp\n"
448 " {\n"
449 " port 6363\n"
450 " enable_v4 no\n"
451 " enable_v6 no\n"
452 " }\n"
453 "}\n";
454 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
455 bind(&isExpectedException, _1,
456 "IPv4 and IPv6 channels have been disabled."
457 " Remove \"tcp\" section to disable TCP channels or"
458 " re-enable at least one channel type."));
459}
460
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700461BOOST_AUTO_TEST_CASE(TestProcessSectionTcpUnknownOption)
462{
463 const std::string CONFIG =
464 "face_system\n"
465 "{\n"
466 " tcp\n"
467 " {\n"
468 " hello\n"
469 " }\n"
470 "}\n";
471 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
472 bind(&isExpectedException, _1,
473 "Unrecognized option \"hello\" in \"tcp\" section"));
474}
475
476BOOST_AUTO_TEST_CASE(TestProcessSectionUdp)
477{
478 const std::string CONFIG =
479 "face_system\n"
480 "{\n"
481 " udp\n"
482 " {\n"
483 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600484 " enable_v4 yes\n"
485 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700486 " idle_timeout 30\n"
487 " keep_alive_interval 25\n"
488 " mcast yes\n"
489 " mcast_port 56363\n"
490 " mcast_group 224.0.23.170\n"
491 " }\n"
492 "}\n";
493 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
494}
495
496BOOST_AUTO_TEST_CASE(TestProcessSectionUdpDryRun)
497{
498 const std::string CONFIG =
499 "face_system\n"
500 "{\n"
501 " udp\n"
502 " {\n"
503 " port 6363\n"
504 " idle_timeout 30\n"
505 " keep_alive_interval 25\n"
506 " mcast yes\n"
507 " mcast_port 56363\n"
508 " mcast_group 224.0.23.170\n"
509 " }\n"
510 "}\n";
511 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
512}
513
514BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadIdleTimeout)
515{
516 const std::string CONFIG =
517 "face_system\n"
518 "{\n"
519 " udp\n"
520 " {\n"
521 " idle_timeout hello\n"
522 " }\n"
523 "}\n";
524
525 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
526 bind(&isExpectedException, _1,
527 "Invalid value for option \"idle_timeout\" in \"udp\" section"));
528}
529
530BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcast)
531{
532 const std::string CONFIG =
533 "face_system\n"
534 "{\n"
535 " udp\n"
536 " {\n"
537 " mcast 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 \"mcast\" in \"udp\" section"));
544}
545
546BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroup)
547{
548 const std::string CONFIG =
549 "face_system\n"
550 "{\n"
551 " udp\n"
552 " {\n"
553 " mcast no\n"
554 " mcast_port 50\n"
555 " mcast_group hello\n"
556 " }\n"
557 "}\n";
558
559 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
560 bind(&isExpectedException, _1,
561 "Invalid value for option \"mcast_group\" in \"udp\" section"));
562}
563
564BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroupV6)
565{
566 const std::string CONFIG =
567 "face_system\n"
568 "{\n"
569 " udp\n"
570 " {\n"
571 " mcast no\n"
572 " mcast_port 50\n"
573 " mcast_group ::1\n"
574 " }\n"
575 "}\n";
576
577 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
578 bind(&isExpectedException, _1,
579 "Invalid value for option \"mcast_group\" in \"udp\" section"));
580}
581
Steve DiBenedetto95152872014-04-11 12:40:59 -0600582BOOST_AUTO_TEST_CASE(TestProcessSectionUdpChannelsDisabled)
583{
584 const std::string CONFIG =
585 "face_system\n"
586 "{\n"
587 " udp\n"
588 " {\n"
589 " port 6363\n"
590 " enable_v4 no\n"
591 " enable_v6 no\n"
592 " idle_timeout 30\n"
593 " keep_alive_interval 25\n"
594 " mcast yes\n"
595 " mcast_port 56363\n"
596 " mcast_group 224.0.23.170\n"
597 " }\n"
598 "}\n";
599 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
600 bind(&isExpectedException, _1,
601 "IPv4 and IPv6 channels have been disabled."
602 " Remove \"udp\" section to disable UDP channels or"
603 " re-enable at least one channel type."));
604}
605
606BOOST_AUTO_TEST_CASE(TestProcessSectionUdpConflictingMcast)
607{
608 const std::string CONFIG =
609 "face_system\n"
610 "{\n"
611 " udp\n"
612 " {\n"
613 " port 6363\n"
614 " enable_v4 no\n"
615 " enable_v6 yes\n"
616 " idle_timeout 30\n"
617 " keep_alive_interval 25\n"
618 " mcast yes\n"
619 " mcast_port 56363\n"
620 " mcast_group 224.0.23.170\n"
621 " }\n"
622 "}\n";
623 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
624 bind(&isExpectedException, _1,
625 "IPv4 multicast requested, but IPv4 channels"
626 " have been disabled (conflicting configuration options set)"));
627}
628
629
630
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700631BOOST_AUTO_TEST_CASE(TestProcessSectionUdpUnknownOption)
632{
633 const std::string CONFIG =
634 "face_system\n"
635 "{\n"
636 " udp\n"
637 " {\n"
638 " hello\n"
639 " }\n"
640 "}\n";
641 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
642 bind(&isExpectedException, _1,
643 "Unrecognized option \"hello\" in \"udp\" section"));
644}
645
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300646
647BOOST_AUTO_TEST_CASE(TestProcessSectionUdpMulticastReinit)
648{
649 const std::string CONFIG_WITH_MCAST =
650 "face_system\n"
651 "{\n"
652 " udp\n"
653 " {\n"
654 " mcast yes\n"
655 " }\n"
656 "}\n";
657 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
658
659 shared_ptr<UdpFactory> factory = static_pointer_cast<UdpFactory>(getManager().findFactory("udp"));
660 BOOST_REQUIRE(static_cast<bool>(factory));
661
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300662 if (factory->getMulticastFaces().size() == 0) {
663 BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
664 "no UDP multicast faces are available");
665 }
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300666
667 const std::string CONFIG_WITHOUT_MCAST =
668 "face_system\n"
669 "{\n"
670 " udp\n"
671 " {\n"
672 " mcast no\n"
673 " }\n"
674 "}\n";
675 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
676 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
677}
678
679
Alexander Afanasyev885a85b2014-04-12 21:01:13 -0700680#ifdef HAVE_LIBPCAP
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600681
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700682BOOST_AUTO_TEST_CASE(TestProcessSectionEther)
683{
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600684
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700685 const std::string CONFIG =
686 "face_system\n"
687 "{\n"
688 " ether\n"
689 " {\n"
690 " mcast yes\n"
691 " mcast_group 01:00:5E:00:17:AA\n"
692 " }\n"
693 "}\n";
694
695 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
696}
697
698BOOST_AUTO_TEST_CASE(TestProcessSectionEtherDryRun)
699{
700 const std::string CONFIG =
701 "face_system\n"
702 "{\n"
703 " ether\n"
704 " {\n"
705 " mcast yes\n"
706 " mcast_group 01:00:5E:00:17:AA\n"
707 " }\n"
708 "}\n";
709
710 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
711}
712
713BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcast)
714{
715 const std::string CONFIG =
716 "face_system\n"
717 "{\n"
718 " ether\n"
719 " {\n"
720 " mcast hello\n"
721 " }\n"
722 "}\n";
723
724 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
725 bind(&isExpectedException, _1,
726 "Invalid value for option \"mcast\" in \"ether\" section"));
727}
728
729BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcastGroup)
730{
731 const std::string CONFIG =
732 "face_system\n"
733 "{\n"
734 " ether\n"
735 " {\n"
736 " mcast yes\n"
737 " mcast_group\n"
738 " }\n"
739 "}\n";
740
741 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
742 bind(&isExpectedException, _1,
743 "Invalid value for option \"mcast_group\" in \"ether\" section"));
744}
745
746BOOST_AUTO_TEST_CASE(TestProcessSectionEtherUnknownOption)
747{
748 const std::string CONFIG =
749 "face_system\n"
750 "{\n"
751 " ether\n"
752 " {\n"
753 " hello\n"
754 " }\n"
755 "}\n";
756 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
757 bind(&isExpectedException, _1,
758 "Unrecognized option \"hello\" in \"ether\" section"));
759}
760
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300761BOOST_AUTO_TEST_CASE(TestProcessSectionEtherMulticastReinit)
762{
763 const std::string CONFIG_WITH_MCAST =
764 "face_system\n"
765 "{\n"
766 " ether\n"
767 " {\n"
768 " mcast yes\n"
769 " }\n"
770 "}\n";
771 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
772
773 shared_ptr<EthernetFactory> factory =
774 static_pointer_cast<EthernetFactory>(getManager().findFactory("ether"));
775 BOOST_REQUIRE(static_cast<bool>(factory));
776
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300777 if (factory->getMulticastFaces().size() == 0) {
778 BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
779 "no Ethernet multicast faces are available");
780 }
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300781
782 const std::string CONFIG_WITHOUT_MCAST =
783 "face_system\n"
784 "{\n"
785 " ether\n"
786 " {\n"
787 " mcast no\n"
788 " }\n"
789 "}\n";
790 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
791 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
792}
793
Alexander Afanasyeve9186212014-08-23 20:15:48 -0700794#endif // HAVE_LIBPCAP
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600795
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700796BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
797{
798 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
799
Junxiao Shicd55cde2014-11-13 16:03:24 -0700800 getFace()->onReceiveData += [this, command] (const Data& response) {
801 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
802 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700803
804 getFace()->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700805 g_io.run_one();
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700806
807 BOOST_REQUIRE(didCallbackFire());
808}
809
810BOOST_AUTO_TEST_CASE(MalformedCommmand)
811{
812 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
813
Junxiao Shicd55cde2014-11-13 16:03:24 -0700814 getFace()->onReceiveData += [this, command] (const Data& response) {
815 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
816 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700817
818 getManager().onFaceRequest(*command);
819
820 BOOST_REQUIRE(didCallbackFire());
821}
822
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700823BOOST_AUTO_TEST_CASE(UnsignedCommand)
824{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600825 ControlParameters parameters;
826 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700827
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600828 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700829
830 Name commandName("/localhost/nfd/faces");
831 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600832 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700833
834 shared_ptr<Interest> command(make_shared<Interest>(commandName));
835
Junxiao Shicd55cde2014-11-13 16:03:24 -0700836 getFace()->onReceiveData += [this, command] (const Data& response) {
837 this->validateControlResponse(response, command->getName(), 401, "Signature required");
838 };
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700839
840 getManager().onFaceRequest(*command);
841
842 BOOST_REQUIRE(didCallbackFire());
843}
844
845BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>)
846{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600847 ControlParameters parameters;
848 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700849
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600850 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700851
852 Name commandName("/localhost/nfd/faces");
853 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600854 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700855
856 shared_ptr<Interest> command(make_shared<Interest>(commandName));
857 generateCommand(*command);
858
Junxiao Shicd55cde2014-11-13 16:03:24 -0700859 getFace()->onReceiveData += [this, command] (const Data& response) {
860 this->validateControlResponse(response, command->getName(), 403, "Unauthorized command");
861 };
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700862
863 getManager().onFaceRequest(*command);
864
865 BOOST_REQUIRE(didCallbackFire());
866}
867
868template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
869{
870public:
871 AuthorizedCommandFixture()
872 {
873 const std::string regex = "^<localhost><nfd><faces>";
874 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
875 }
876
877 virtual
878 ~AuthorizedCommandFixture()
879 {
880
881 }
882};
883
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700884BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700885{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600886 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700887
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600888 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700889
890 Name commandName("/localhost/nfd/faces");
891 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600892 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700893
894 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700895 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700896
Junxiao Shicd55cde2014-11-13 16:03:24 -0700897 getFace()->onReceiveData += [this, command] (const Data& response) {
898 this->validateControlResponse(response, command->getName(), 501, "Unsupported command");
899 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700900
901 getManager().onFaceRequest(*command);
902
903 BOOST_REQUIRE(didCallbackFire());
904}
905
906class ValidatedFaceRequestFixture : public TestFaceTableFixture,
907 public TestFaceManagerCommon,
908 public FaceManager
909{
910public:
911
912 ValidatedFaceRequestFixture()
Vince Lehman5144f822014-07-23 15:12:56 -0700913 : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face, m_testKeyChain),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700914 m_createFaceFired(false),
915 m_destroyFaceFired(false)
916 {
917
918 }
919
920 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600921 createFace(const Interest& request,
922 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700923 {
924 m_createFaceFired = true;
925 }
926
927 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600928 destroyFace(const Interest& request,
929 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700930 {
931 m_destroyFaceFired = true;
932 }
933
934 virtual
935 ~ValidatedFaceRequestFixture()
936 {
937
938 }
939
940 bool
941 didCreateFaceFire() const
942 {
943 return m_createFaceFired;
944 }
945
946 bool
947 didDestroyFaceFire() const
948 {
949 return m_destroyFaceFired;
950 }
951
952private:
953 bool m_createFaceFired;
954 bool m_destroyFaceFired;
955};
956
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700957BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse,
958 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700959{
960 Name commandName("/localhost/nfd/faces");
961 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600962 commandName.append("NotReallyParameters");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700963
964 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700965 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700966
Junxiao Shicd55cde2014-11-13 16:03:24 -0700967 getFace()->onReceiveData += [this, command] (const Data& response) {
968 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
969 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700970
971 onValidatedFaceRequest(command);
972
973 BOOST_REQUIRE(didCallbackFire());
974}
975
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700976BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace,
977 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700978{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600979 ControlParameters parameters;
980 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700981
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600982 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700983
984 Name commandName("/localhost/nfd/faces");
985 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600986 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700987
988 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700989 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700990
991 onValidatedFaceRequest(command);
992 BOOST_CHECK(didCreateFaceFire());
993}
994
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700995BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace,
996 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700997{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600998 ControlParameters parameters;
999 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001000
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001001 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001002
1003 Name commandName("/localhost/nfd/faces");
1004 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001005 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001006
1007 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001008 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001009
1010 onValidatedFaceRequest(command);
1011 BOOST_CHECK(didDestroyFaceFire());
1012}
1013
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001014class FaceTableFixture
1015{
1016public:
1017 FaceTableFixture()
1018 : m_faceTable(m_forwarder)
1019 {
1020 }
1021
1022 virtual
1023 ~FaceTableFixture()
1024 {
1025 }
1026
1027protected:
1028 Forwarder m_forwarder;
1029 FaceTable m_faceTable;
1030};
1031
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001032class LocalControlFixture : public FaceTableFixture,
1033 public TestFaceManagerCommon,
1034 public FaceManager
1035{
1036public:
1037 LocalControlFixture()
Vince Lehman5144f822014-07-23 15:12:56 -07001038 : FaceManager(FaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face, m_testKeyChain)
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001039 {
1040 }
1041};
1042
1043BOOST_FIXTURE_TEST_CASE(LocalControlInFaceId,
1044 AuthorizedCommandFixture<LocalControlFixture>)
1045{
1046 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1047 BOOST_REQUIRE(dummy->isLocal());
1048 FaceTableFixture::m_faceTable.add(dummy);
1049
1050 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001051 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1052
1053 Block encodedParameters(parameters.wireEncode());
1054
1055 Name enable("/localhost/nfd/faces/enable-local-control");
1056 enable.append(encodedParameters);
1057
1058 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1059 enableCommand->setIncomingFaceId(dummy->getId());
1060
1061 generateCommand(*enableCommand);
1062
1063 TestFaceManagerCommon::m_face->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001064 [this, enableCommand, encodedParameters] (const Data& response) {
1065 this->validateControlResponse(response, enableCommand->getName(),
1066 200, "Success", encodedParameters);
1067 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001068
1069 onValidatedFaceRequest(enableCommand);
1070
1071 BOOST_REQUIRE(didCallbackFire());
1072 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1073 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1074
1075 TestFaceManagerCommon::m_face->onReceiveData.clear();
1076 resetCallbackFired();
1077
1078 Name disable("/localhost/nfd/faces/disable-local-control");
1079 disable.append(encodedParameters);
1080
1081 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1082 disableCommand->setIncomingFaceId(dummy->getId());
1083
1084 generateCommand(*disableCommand);
1085
1086 TestFaceManagerCommon::m_face->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001087 [this, disableCommand, encodedParameters] (const Data& response) {
1088 this->validateControlResponse(response, disableCommand->getName(),
1089 200, "Success", encodedParameters);
1090 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001091
1092 onValidatedFaceRequest(disableCommand);
1093
1094 BOOST_REQUIRE(didCallbackFire());
1095 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1096 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1097}
1098
1099BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound,
1100 AuthorizedCommandFixture<LocalControlFixture>)
1101{
1102 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1103 BOOST_REQUIRE(dummy->isLocal());
1104 FaceTableFixture::m_faceTable.add(dummy);
1105
1106 ControlParameters parameters;
1107 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1108
1109 Block encodedParameters(parameters.wireEncode());
1110
1111 Name enable("/localhost/nfd/faces/enable-local-control");
1112 enable.append(encodedParameters);
1113
1114 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1115 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1116
1117 generateCommand(*enableCommand);
1118
Junxiao Shicd55cde2014-11-13 16:03:24 -07001119 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1120 this->validateControlResponse(response, enableCommand->getName(), 410, "Face not found");
1121 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001122
1123 onValidatedFaceRequest(enableCommand);
1124
1125 BOOST_REQUIRE(didCallbackFire());
1126 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1127 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1128
1129 TestFaceManagerCommon::m_face->onReceiveData.clear();
1130 resetCallbackFired();
1131
1132 Name disable("/localhost/nfd/faces/disable-local-control");
1133 disable.append(encodedParameters);
1134
1135 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1136 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1137
1138 generateCommand(*disableCommand);
1139
Junxiao Shicd55cde2014-11-13 16:03:24 -07001140 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1141 this->validateControlResponse(response, disableCommand->getName(), 410, "Face not found");
1142 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001143
1144 onValidatedFaceRequest(disableCommand);
1145
1146 BOOST_REQUIRE(didCallbackFire());
1147 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1148 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1149}
1150
1151BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature,
1152 AuthorizedCommandFixture<LocalControlFixture>)
1153{
1154 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1155 BOOST_REQUIRE(dummy->isLocal());
1156 FaceTableFixture::m_faceTable.add(dummy);
1157
1158 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001159
1160 Block encodedParameters(parameters.wireEncode());
1161
1162 Name enable("/localhost/nfd/faces/enable-local-control");
1163 enable.append(encodedParameters);
1164
1165 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1166 enableCommand->setIncomingFaceId(dummy->getId());
1167
1168 generateCommand(*enableCommand);
1169
Junxiao Shicd55cde2014-11-13 16:03:24 -07001170 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1171 this->validateControlResponse(response, enableCommand->getName(), 400, "Malformed command");
1172 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001173
1174 onValidatedFaceRequest(enableCommand);
1175
1176 BOOST_REQUIRE(didCallbackFire());
1177 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1178 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1179
1180 TestFaceManagerCommon::m_face->onReceiveData.clear();
1181 resetCallbackFired();
1182
1183 Name disable("/localhost/nfd/faces/disable-local-control");
1184 disable.append(encodedParameters);
1185
1186 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1187 disableCommand->setIncomingFaceId(dummy->getId());
1188
1189 generateCommand(*disableCommand);
1190
Junxiao Shicd55cde2014-11-13 16:03:24 -07001191 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1192 this->validateControlResponse(response, disableCommand->getName(), 400, "Malformed command");
1193 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001194
1195 onValidatedFaceRequest(disableCommand);
1196
1197 BOOST_REQUIRE(didCallbackFire());
1198 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1199 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1200}
1201
1202BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal,
1203 AuthorizedCommandFixture<LocalControlFixture>)
1204{
1205 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1206 BOOST_REQUIRE(!dummy->isLocal());
1207 FaceTableFixture::m_faceTable.add(dummy);
1208
1209 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001210 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1211
1212 Block encodedParameters(parameters.wireEncode());
1213
1214 Name enable("/localhost/nfd/faces/enable-local-control");
1215 enable.append(encodedParameters);
1216
1217 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1218 enableCommand->setIncomingFaceId(dummy->getId());
1219
1220 generateCommand(*enableCommand);
1221
Junxiao Shicd55cde2014-11-13 16:03:24 -07001222 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1223 this->validateControlResponse(response, enableCommand->getName(), 412, "Face is non-local");
1224 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001225
1226 onValidatedFaceRequest(enableCommand);
1227
1228 BOOST_REQUIRE(didCallbackFire());
1229
1230 TestFaceManagerCommon::m_face->onReceiveData.clear();
1231 resetCallbackFired();
1232
1233 Name disable("/localhost/nfd/faces/disable-local-control");
1234 enable.append(encodedParameters);
1235
1236 shared_ptr<Interest> disableCommand(make_shared<Interest>(enable));
1237 disableCommand->setIncomingFaceId(dummy->getId());
1238
1239 generateCommand(*disableCommand);
1240
Junxiao Shicd55cde2014-11-13 16:03:24 -07001241 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1242 this->validateControlResponse(response, disableCommand->getName(), 412, "Face is non-local");
1243 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001244
1245 onValidatedFaceRequest(disableCommand);
1246
1247 BOOST_REQUIRE(didCallbackFire());
1248}
1249
1250BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId,
1251 AuthorizedCommandFixture<LocalControlFixture>)
1252{
1253 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1254 BOOST_REQUIRE(dummy->isLocal());
1255 FaceTableFixture::m_faceTable.add(dummy);
1256
1257 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001258 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1259
1260 Block encodedParameters(parameters.wireEncode());
1261
1262 Name enable("/localhost/nfd/faces/enable-local-control");
1263 enable.append(encodedParameters);
1264
1265 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1266 enableCommand->setIncomingFaceId(dummy->getId());
1267
1268 generateCommand(*enableCommand);
1269
1270 TestFaceManagerCommon::m_face->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001271 [this, enableCommand, encodedParameters] (const Data& response) {
1272 this->validateControlResponse(response, enableCommand->getName(),
1273 200, "Success", encodedParameters);
1274 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001275
1276 onValidatedFaceRequest(enableCommand);
1277
1278 BOOST_REQUIRE(didCallbackFire());
1279 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1280 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1281
1282
1283 TestFaceManagerCommon::m_face->onReceiveData.clear();
1284 resetCallbackFired();
1285
1286 Name disable("/localhost/nfd/faces/disable-local-control");
1287 disable.append(encodedParameters);
1288
1289 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1290 disableCommand->setIncomingFaceId(dummy->getId());
1291
1292 generateCommand(*disableCommand);
1293
1294 TestFaceManagerCommon::m_face->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001295 [this, disableCommand, encodedParameters] (const Data& response) {
1296 this->validateControlResponse(response, disableCommand->getName(),
1297 200, "Success", encodedParameters);
1298 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001299
1300 onValidatedFaceRequest(disableCommand);
1301
1302 BOOST_REQUIRE(didCallbackFire());
1303 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1304 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1305}
1306
1307BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound,
1308 AuthorizedCommandFixture<LocalControlFixture>)
1309{
1310 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1311 BOOST_REQUIRE(dummy->isLocal());
1312 FaceTableFixture::m_faceTable.add(dummy);
1313
1314 ControlParameters parameters;
1315 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1316
1317 Block encodedParameters(parameters.wireEncode());
1318
1319 Name enable("/localhost/nfd/faces/enable-local-control");
1320 enable.append(encodedParameters);
1321
1322 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1323 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1324
1325 generateCommand(*enableCommand);
1326
Junxiao Shicd55cde2014-11-13 16:03:24 -07001327 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1328 this->validateControlResponse(response, enableCommand->getName(), 410, "Face not found");
1329 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001330
1331 onValidatedFaceRequest(enableCommand);
1332
1333 BOOST_REQUIRE(didCallbackFire());
1334 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1335 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1336
1337
1338 TestFaceManagerCommon::m_face->onReceiveData.clear();
1339 resetCallbackFired();
1340
1341 Name disable("/localhost/nfd/faces/disable-local-control");
1342 disable.append(encodedParameters);
1343
1344 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1345 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1346
1347 generateCommand(*disableCommand);
1348
Junxiao Shicd55cde2014-11-13 16:03:24 -07001349 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1350 this->validateControlResponse(response, disableCommand->getName(), 410, "Face not found");
1351 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001352
1353 onValidatedFaceRequest(disableCommand);
1354
1355 BOOST_REQUIRE(didCallbackFire());
1356 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1357 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1358}
1359
1360BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal,
1361 AuthorizedCommandFixture<LocalControlFixture>)
1362{
1363 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1364 BOOST_REQUIRE(!dummy->isLocal());
1365 FaceTableFixture::m_faceTable.add(dummy);
1366
1367 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001368 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1369
1370 Block encodedParameters(parameters.wireEncode());
1371
1372 Name enable("/localhost/nfd/faces/enable-local-control");
1373 enable.append(encodedParameters);
1374
1375 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1376 enableCommand->setIncomingFaceId(dummy->getId());
1377
1378 generateCommand(*enableCommand);
1379
Junxiao Shicd55cde2014-11-13 16:03:24 -07001380 TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) {
1381 this->validateControlResponse(response, enableCommand->getName(), 412, "Face is non-local");
1382 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001383
1384 onValidatedFaceRequest(enableCommand);
1385
1386 BOOST_REQUIRE(didCallbackFire());
1387
1388 TestFaceManagerCommon::m_face->onReceiveData.clear();
1389 resetCallbackFired();
1390
1391 Name disable("/localhost/nfd/faces/disable-local-control");
1392 disable.append(encodedParameters);
1393
1394 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1395 disableCommand->setIncomingFaceId(dummy->getId());
1396
1397 generateCommand(*disableCommand);
1398
Junxiao Shicd55cde2014-11-13 16:03:24 -07001399 TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) {
1400 this->validateControlResponse(response, disableCommand->getName(), 412, "Face is non-local");
1401 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001402
1403 onValidatedFaceRequest(disableCommand);
1404
1405 BOOST_REQUIRE(didCallbackFire());
1406}
1407
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001408class FaceFixture : public FaceTableFixture,
1409 public TestFaceManagerCommon,
1410 public FaceManager
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001411{
1412public:
1413 FaceFixture()
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001414 : FaceManager(FaceTableFixture::m_faceTable,
Vince Lehman5144f822014-07-23 15:12:56 -07001415 TestFaceManagerCommon::m_face,
1416 m_testKeyChain)
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001417 , m_receivedNotification(false)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001418 {
1419
1420 }
1421
1422 virtual
1423 ~FaceFixture()
1424 {
1425
1426 }
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001427
1428 void
1429 callbackDispatch(const Data& response,
1430 const Name& expectedName,
1431 uint32_t expectedCode,
1432 const std::string& expectedText,
1433 const Block& expectedBody,
1434 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1435 {
1436 Block payload = response.getContent().blockFromValue();
1437 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1438 {
1439 validateControlResponse(response, expectedName, expectedCode,
1440 expectedText, expectedBody);
1441 }
1442 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1443 {
1444 validateFaceEvent(payload, expectedFaceEvent);
1445 }
1446 else
1447 {
1448 BOOST_FAIL("Received unknown message type: #" << payload.type());
1449 }
1450 }
1451
1452 void
1453 callbackDispatch(const Data& response,
1454 const Name& expectedName,
1455 uint32_t expectedCode,
1456 const std::string& expectedText,
1457 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1458 {
1459 Block payload = response.getContent().blockFromValue();
1460 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1461 {
1462 validateControlResponse(response, expectedName,
1463 expectedCode, expectedText);
1464 }
1465 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1466 {
1467 validateFaceEvent(payload, expectedFaceEvent);
1468 }
1469 else
1470 {
1471 BOOST_FAIL("Received unknown message type: #" << payload.type());
1472 }
1473 }
1474
1475 void
1476 validateFaceEvent(const Block& wire,
1477 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1478 {
1479
1480 m_receivedNotification = true;
1481
1482 ndn::nfd::FaceEventNotification notification(wire);
1483
Junxiao Shi6e694322014-04-03 10:27:13 -07001484 BOOST_CHECK_EQUAL(notification.getKind(), expectedFaceEvent.getKind());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001485 BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId());
Junxiao Shi6e694322014-04-03 10:27:13 -07001486 BOOST_CHECK_EQUAL(notification.getRemoteUri(), expectedFaceEvent.getRemoteUri());
1487 BOOST_CHECK_EQUAL(notification.getLocalUri(), expectedFaceEvent.getLocalUri());
Chengyu Fanf9c2bb12014-10-06 11:52:44 -06001488 BOOST_CHECK_EQUAL(notification.getFaceScope(), expectedFaceEvent.getFaceScope());
1489 BOOST_CHECK_EQUAL(notification.getFacePersistency(), expectedFaceEvent.getFacePersistency());
1490 BOOST_CHECK_EQUAL(notification.getLinkType(), expectedFaceEvent.getLinkType());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001491 }
1492
1493 bool
1494 didReceiveNotication() const
1495 {
1496 return m_receivedNotification;
1497 }
1498
1499protected:
1500 bool m_receivedNotification;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001501};
1502
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001503BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001504{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001505 ControlParameters parameters;
1506 parameters.setUri("tcp:/127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001507
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001508 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001509
1510 Name commandName("/localhost/nfd/faces");
1511 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001512 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001513
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001514 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1515 generateCommand(*command);
1516
Junxiao Shicd55cde2014-11-13 16:03:24 -07001517 getFace()->onReceiveData += [this, command] (const Data& response) {
1518 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
1519 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001520
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001521 createFace(*command, parameters);
1522
1523 BOOST_REQUIRE(didCallbackFire());
1524}
1525
1526BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>)
1527{
1528 ControlParameters parameters;
1529
1530 Block encodedParameters(parameters.wireEncode());
1531
1532 Name commandName("/localhost/nfd/faces");
1533 commandName.append("create");
1534 commandName.append(encodedParameters);
1535
1536 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1537 generateCommand(*command);
1538
Junxiao Shicd55cde2014-11-13 16:03:24 -07001539 getFace()->onReceiveData += [this, command] (const Data& response) {
1540 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
1541 };
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001542
1543 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001544
1545 BOOST_REQUIRE(didCallbackFire());
1546}
1547
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001548BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001549{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001550 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001551 // this will be an unsupported protocol because no factories have been
1552 // added to the face manager
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001553 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001554
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001555 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001556
1557 Name commandName("/localhost/nfd/faces");
1558 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001559 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001560
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001561 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1562 generateCommand(*command);
1563
Junxiao Shicd55cde2014-11-13 16:03:24 -07001564 getFace()->onReceiveData += [this, command] (const Data& response) {
1565 this->validateControlResponse(response, command->getName(), 501, "Unsupported protocol");
1566 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001567
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001568 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001569
1570 BOOST_REQUIRE(didCallbackFire());
1571}
1572
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001573BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001574{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001575 ControlParameters parameters;
1576 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001577
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001578 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001579
1580 Name commandName("/localhost/nfd/faces");
1581 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001582 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001583
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001584 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1585 generateCommand(*command);
1586
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001587 ControlParameters resultParameters;
Steve DiBenedetto25999282014-05-22 15:25:12 -06001588 resultParameters.setUri("dummy://");
Junxiao Shi7b984c62014-07-17 22:18:34 -07001589 resultParameters.setFaceId(FACEID_RESERVED_MAX + 1);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001590
1591 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1592
Junxiao Shi6e694322014-04-03 10:27:13 -07001593 ndn::nfd::FaceEventNotification expectedFaceEvent;
1594 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED)
Junxiao Shi7b984c62014-07-17 22:18:34 -07001595 .setFaceId(FACEID_RESERVED_MAX + 1)
Junxiao Shi6e694322014-04-03 10:27:13 -07001596 .setRemoteUri(dummy->getRemoteUri().toString())
1597 .setLocalUri(dummy->getLocalUri().toString())
Chengyu Fan9942cea2014-10-13 14:47:13 -06001598 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
1599 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001600
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001601 Block encodedResultParameters(resultParameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001602
1603 getFace()->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001604 [this, command, encodedResultParameters, expectedFaceEvent] (const Data& response) {
1605 this->callbackDispatch(response,command->getName(), 200, "Success",
1606 encodedResultParameters, expectedFaceEvent);
1607 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001608
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001609 onCreated(command->getName(), parameters, dummy);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001610
1611 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001612 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001613}
1614
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001615BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001616{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001617 ControlParameters parameters;
1618 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001619
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001620 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001621
1622 Name commandName("/localhost/nfd/faces");
1623 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001624 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001625
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001626 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1627 generateCommand(*command);
1628
Junxiao Shicd55cde2014-11-13 16:03:24 -07001629 getFace()->onReceiveData += [this, command] (const Data& response) {
1630 this->validateControlResponse(response, command->getName(), 408, "unit-test-reason");
1631 };
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001632
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001633 onConnectFailed(command->getName(), "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001634
1635 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001636 BOOST_CHECK_EQUAL(didReceiveNotication(), false);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001637}
1638
1639
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001640BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001641{
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001642 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1643 FaceTableFixture::m_faceTable.add(dummy);
1644
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001645 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001646 parameters.setFaceId(dummy->getId());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001647
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001648 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001649
1650 Name commandName("/localhost/nfd/faces");
1651 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001652 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001653
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001654 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1655 generateCommand(*command);
1656
Junxiao Shi6e694322014-04-03 10:27:13 -07001657 ndn::nfd::FaceEventNotification expectedFaceEvent;
1658 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
1659 .setFaceId(dummy->getId())
1660 .setRemoteUri(dummy->getRemoteUri().toString())
1661 .setLocalUri(dummy->getLocalUri().toString())
Chengyu Fan9942cea2014-10-13 14:47:13 -06001662 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
1663 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001664
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001665 getFace()->onReceiveData +=
Junxiao Shicd55cde2014-11-13 16:03:24 -07001666 [this, command, encodedParameters, expectedFaceEvent] (const Data& response) {
1667 this->callbackDispatch(response,command->getName(), 200, "Success",
1668 encodedParameters, expectedFaceEvent);
1669 };
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
Chengyu Fan320d2332014-10-29 16:40:33 -06001765class FaceQueryListFixture : public FaceQueryStatusPublisherFixture
1766{
1767public:
1768 FaceQueryListFixture()
1769 : m_manager(m_table, m_face, m_testKeyChain)
1770 {
1771
1772 }
1773
1774 virtual
1775 ~FaceQueryListFixture()
1776 {
1777
1778 }
1779
1780protected:
1781 FaceManager m_manager;
1782 ndn::KeyChain m_testKeyChain;
1783};
1784
1785BOOST_FIXTURE_TEST_CASE(TestValidQueryFilter, FaceQueryListFixture)
1786{
1787 Name queryName("/localhost/nfd/faces/query");
1788 ndn::nfd::FaceQueryFilter queryFilter;
1789 queryFilter.setUriScheme("dummy");
1790 queryName.append(queryFilter.wireEncode());
1791
1792 shared_ptr<Interest> query(make_shared<Interest>(queryName));
1793
1794 // add expected faces
1795 shared_ptr<DummyLocalFace> expectedFace1(make_shared<DummyLocalFace>());
1796 m_referenceFaces.push_back(expectedFace1);
1797 add(expectedFace1);
1798
1799 shared_ptr<DummyFace> expectedFace2(make_shared<DummyFace>());
1800 m_referenceFaces.push_back(expectedFace2);
1801 add(expectedFace2);
1802
1803 // add other faces
1804 shared_ptr<DummyFace> face1(make_shared<DummyFace>("udp://", "udp://"));
1805 add(face1);
1806 shared_ptr<DummyLocalFace> face2(make_shared<DummyLocalFace>("tcp://", "tcp://"));
1807 add(face2);
1808
1809 m_face->onReceiveData +=
1810 bind(&FaceQueryStatusPublisherFixture::decodeFaceStatusBlock, this, _1);
1811
1812 m_manager.listQueriedFaces(*query);
1813 BOOST_REQUIRE(m_finished);
1814}
1815
Chengyu Fanab205c22014-11-18 10:58:41 -07001816BOOST_FIXTURE_TEST_CASE(TestInvalidQueryFilter, FaceQueryListFixture)
1817{
1818 Name queryName("/localhost/nfd/faces/query");
1819 ndn::nfd::FaceStatus queryFilter;
1820 queryName.append(queryFilter.wireEncode());
1821
1822 shared_ptr<Interest> query(make_shared<Interest>(queryName));
1823
1824 shared_ptr<DummyLocalFace> face(make_shared<DummyLocalFace>());
1825 add(face);
1826
1827 m_face->onReceiveData +=
1828 bind(&FaceQueryStatusPublisherFixture::decodeNackBlock, this, _1);
1829
1830 m_manager.listQueriedFaces(*query);
1831 BOOST_REQUIRE(m_finished);
1832}
Chengyu Fan320d2332014-10-29 16:40:33 -06001833
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001834BOOST_AUTO_TEST_SUITE_END()
1835
1836} // namespace tests
1837} // namespace nfd