blob: 36e9e8a7da8388fe904d5c14bd8ab6e4d7fbfb9a [file] [log] [blame]
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08003 * Copyright (c) 2014-2015, 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 DiBenedettocd4ee5f2014-12-08 16:09:11 -0700796BOOST_AUTO_TEST_CASE(ShortName)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700797{
798 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
799
Junxiao Shic099ddb2014-12-25 20:53:20 -0700800 getFace()->onReceiveData.connect([this, command] (const Data& response) {
Junxiao Shicd55cde2014-11-13 16:03:24 -0700801 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
Junxiao Shic099ddb2014-12-25 20:53:20 -0700802 });
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 Shic099ddb2014-12-25 20:53:20 -0700814 getFace()->onReceiveData.connect([this, command] (const Data& response) {
Junxiao Shicd55cde2014-11-13 16:03:24 -0700815 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
Junxiao Shic099ddb2014-12-25 20:53:20 -0700816 });
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;
Chengyu Fanb94af7c2014-12-17 11:46:47 +0800826 parameters.setUri("tcp4://127.0.0.1:6363");
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 Shic099ddb2014-12-25 20:53:20 -0700836 getFace()->onReceiveData.connect([this, command] (const Data& response) {
Junxiao Shicd55cde2014-11-13 16:03:24 -0700837 this->validateControlResponse(response, command->getName(), 401, "Signature required");
Junxiao Shic099ddb2014-12-25 20:53:20 -0700838 });
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;
Chengyu Fanb94af7c2014-12-17 11:46:47 +0800848 parameters.setUri("tcp4://127.0.0.1:6363");
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 Shic099ddb2014-12-25 20:53:20 -0700859 getFace()->onReceiveData.connect([this, command] (const Data& response) {
Junxiao Shicd55cde2014-11-13 16:03:24 -0700860 this->validateControlResponse(response, command->getName(), 403, "Unauthorized command");
Junxiao Shic099ddb2014-12-25 20:53:20 -0700861 });
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 Shic099ddb2014-12-25 20:53:20 -0700897 getFace()->onReceiveData.connect([this, command] (const Data& response) {
Junxiao Shicd55cde2014-11-13 16:03:24 -0700898 this->validateControlResponse(response, command->getName(), 501, "Unsupported command");
Junxiao Shic099ddb2014-12-25 20:53:20 -0700899 });
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()
Junxiao Shic099ddb2014-12-25 20:53:20 -0700913 : FaceManager(TestFaceTableFixture::m_faceTable, getFace(), 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 Shic099ddb2014-12-25 20:53:20 -0700967 getFace()->onReceiveData.connect([this, command] (const Data& response) {
Junxiao Shicd55cde2014-11-13 16:03:24 -0700968 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
Junxiao Shic099ddb2014-12-25 20:53:20 -0700969 });
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;
Chengyu Fanb94af7c2014-12-17 11:46:47 +0800980 parameters.setUri("tcp4://127.0.0.1:6363");
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;
Chengyu Fanb94af7c2014-12-17 11:46:47 +0800999 parameters.setUri("tcp4://127.0.0.1:6363");
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()
Junxiao Shic099ddb2014-12-25 20:53:20 -07001038 : FaceManager(FaceTableFixture::m_faceTable, getFace(), 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
Junxiao Shic099ddb2014-12-25 20:53:20 -07001063 signal::Connection conn = getFace()->onReceiveData.connect(
1064 [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
Junxiao Shic099ddb2014-12-25 20:53:20 -07001075 conn.disconnect();
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001076 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
Junxiao Shic099ddb2014-12-25 20:53:20 -07001086 getFace()->onReceiveData.connect(
1087 [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 Shic099ddb2014-12-25 20:53:20 -07001119 signal::Connection conn = getFace()->onReceiveData.connect(
1120 [this, enableCommand] (const Data& response) {
1121 this->validateControlResponse(response, enableCommand->getName(), 410, "Face not found");
1122 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001123
1124 onValidatedFaceRequest(enableCommand);
1125
1126 BOOST_REQUIRE(didCallbackFire());
1127 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1128 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1129
Junxiao Shic099ddb2014-12-25 20:53:20 -07001130 conn.disconnect();
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001131 resetCallbackFired();
1132
1133 Name disable("/localhost/nfd/faces/disable-local-control");
1134 disable.append(encodedParameters);
1135
1136 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1137 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1138
1139 generateCommand(*disableCommand);
1140
Junxiao Shic099ddb2014-12-25 20:53:20 -07001141 getFace()->onReceiveData.connect(
1142 [this, disableCommand] (const Data& response) {
1143 this->validateControlResponse(response, disableCommand->getName(), 410, "Face not found");
1144 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001145
1146 onValidatedFaceRequest(disableCommand);
1147
1148 BOOST_REQUIRE(didCallbackFire());
1149 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1150 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1151}
1152
1153BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature,
1154 AuthorizedCommandFixture<LocalControlFixture>)
1155{
1156 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1157 BOOST_REQUIRE(dummy->isLocal());
1158 FaceTableFixture::m_faceTable.add(dummy);
1159
1160 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001161
1162 Block encodedParameters(parameters.wireEncode());
1163
1164 Name enable("/localhost/nfd/faces/enable-local-control");
1165 enable.append(encodedParameters);
1166
1167 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1168 enableCommand->setIncomingFaceId(dummy->getId());
1169
1170 generateCommand(*enableCommand);
1171
Junxiao Shic099ddb2014-12-25 20:53:20 -07001172 signal::Connection conn = getFace()->onReceiveData.connect(
1173 [this, enableCommand] (const Data& response) {
1174 this->validateControlResponse(response, enableCommand->getName(),
1175 400, "Malformed command");
1176 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001177
1178 onValidatedFaceRequest(enableCommand);
1179
1180 BOOST_REQUIRE(didCallbackFire());
1181 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1182 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1183
Junxiao Shic099ddb2014-12-25 20:53:20 -07001184 conn.disconnect();
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001185 resetCallbackFired();
1186
1187 Name disable("/localhost/nfd/faces/disable-local-control");
1188 disable.append(encodedParameters);
1189
1190 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1191 disableCommand->setIncomingFaceId(dummy->getId());
1192
1193 generateCommand(*disableCommand);
1194
Junxiao Shic099ddb2014-12-25 20:53:20 -07001195 getFace()->onReceiveData.connect(
1196 [this, disableCommand] (const Data& response) {
1197 this->validateControlResponse(response, disableCommand->getName(),
1198 400, "Malformed command");
1199 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001200
1201 onValidatedFaceRequest(disableCommand);
1202
1203 BOOST_REQUIRE(didCallbackFire());
1204 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1205 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1206}
1207
1208BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal,
1209 AuthorizedCommandFixture<LocalControlFixture>)
1210{
1211 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1212 BOOST_REQUIRE(!dummy->isLocal());
1213 FaceTableFixture::m_faceTable.add(dummy);
1214
1215 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001216 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1217
1218 Block encodedParameters(parameters.wireEncode());
1219
1220 Name enable("/localhost/nfd/faces/enable-local-control");
1221 enable.append(encodedParameters);
1222
1223 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1224 enableCommand->setIncomingFaceId(dummy->getId());
1225
1226 generateCommand(*enableCommand);
1227
Junxiao Shic099ddb2014-12-25 20:53:20 -07001228 signal::Connection conn = getFace()->onReceiveData.connect(
1229 [this, enableCommand] (const Data& response) {
1230 this->validateControlResponse(response, enableCommand->getName(),
1231 412, "Face is non-local");
1232 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001233
1234 onValidatedFaceRequest(enableCommand);
1235
1236 BOOST_REQUIRE(didCallbackFire());
1237
Junxiao Shic099ddb2014-12-25 20:53:20 -07001238 conn.disconnect();
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001239 resetCallbackFired();
1240
1241 Name disable("/localhost/nfd/faces/disable-local-control");
1242 enable.append(encodedParameters);
1243
1244 shared_ptr<Interest> disableCommand(make_shared<Interest>(enable));
1245 disableCommand->setIncomingFaceId(dummy->getId());
1246
1247 generateCommand(*disableCommand);
1248
Junxiao Shic099ddb2014-12-25 20:53:20 -07001249 getFace()->onReceiveData.connect(
1250 [this, disableCommand] (const Data& response) {
1251 this->validateControlResponse(response, disableCommand->getName(),
1252 412, "Face is non-local");
1253 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001254
1255 onValidatedFaceRequest(disableCommand);
1256
1257 BOOST_REQUIRE(didCallbackFire());
1258}
1259
1260BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId,
1261 AuthorizedCommandFixture<LocalControlFixture>)
1262{
1263 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1264 BOOST_REQUIRE(dummy->isLocal());
1265 FaceTableFixture::m_faceTable.add(dummy);
1266
1267 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001268 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1269
1270 Block encodedParameters(parameters.wireEncode());
1271
1272 Name enable("/localhost/nfd/faces/enable-local-control");
1273 enable.append(encodedParameters);
1274
1275 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1276 enableCommand->setIncomingFaceId(dummy->getId());
1277
1278 generateCommand(*enableCommand);
1279
Junxiao Shic099ddb2014-12-25 20:53:20 -07001280 signal::Connection conn = getFace()->onReceiveData.connect(
1281 [this, enableCommand, encodedParameters] (const Data& response) {
1282 this->validateControlResponse(response, enableCommand->getName(),
1283 200, "Success", encodedParameters);
1284 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001285
1286 onValidatedFaceRequest(enableCommand);
1287
1288 BOOST_REQUIRE(didCallbackFire());
1289 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1290 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1291
1292
Junxiao Shic099ddb2014-12-25 20:53:20 -07001293 conn.disconnect();
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001294 resetCallbackFired();
1295
1296 Name disable("/localhost/nfd/faces/disable-local-control");
1297 disable.append(encodedParameters);
1298
1299 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1300 disableCommand->setIncomingFaceId(dummy->getId());
1301
1302 generateCommand(*disableCommand);
1303
Junxiao Shic099ddb2014-12-25 20:53:20 -07001304 getFace()->onReceiveData.connect(
1305 [this, disableCommand, encodedParameters] (const Data& response) {
1306 this->validateControlResponse(response, disableCommand->getName(),
1307 200, "Success", encodedParameters);
1308 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001309
1310 onValidatedFaceRequest(disableCommand);
1311
1312 BOOST_REQUIRE(didCallbackFire());
1313 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1314 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1315}
1316
1317BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound,
1318 AuthorizedCommandFixture<LocalControlFixture>)
1319{
1320 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1321 BOOST_REQUIRE(dummy->isLocal());
1322 FaceTableFixture::m_faceTable.add(dummy);
1323
1324 ControlParameters parameters;
1325 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1326
1327 Block encodedParameters(parameters.wireEncode());
1328
1329 Name enable("/localhost/nfd/faces/enable-local-control");
1330 enable.append(encodedParameters);
1331
1332 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1333 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1334
1335 generateCommand(*enableCommand);
1336
Junxiao Shic099ddb2014-12-25 20:53:20 -07001337 signal::Connection conn = getFace()->onReceiveData.connect(
1338 [this, enableCommand] (const Data& response) {
1339 this->validateControlResponse(response, enableCommand->getName(), 410, "Face not found");
1340 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001341
1342 onValidatedFaceRequest(enableCommand);
1343
1344 BOOST_REQUIRE(didCallbackFire());
1345 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1346 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1347
1348
Junxiao Shic099ddb2014-12-25 20:53:20 -07001349 conn.disconnect();
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001350 resetCallbackFired();
1351
1352 Name disable("/localhost/nfd/faces/disable-local-control");
1353 disable.append(encodedParameters);
1354
1355 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1356 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1357
1358 generateCommand(*disableCommand);
1359
Junxiao Shic099ddb2014-12-25 20:53:20 -07001360 getFace()->onReceiveData.connect(
1361 [this, disableCommand] (const Data& response) {
1362 this->validateControlResponse(response, disableCommand->getName(),
1363 410, "Face not found");
1364 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001365
1366 onValidatedFaceRequest(disableCommand);
1367
1368 BOOST_REQUIRE(didCallbackFire());
1369 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1370 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1371}
1372
1373BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal,
1374 AuthorizedCommandFixture<LocalControlFixture>)
1375{
1376 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1377 BOOST_REQUIRE(!dummy->isLocal());
1378 FaceTableFixture::m_faceTable.add(dummy);
1379
1380 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001381 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1382
1383 Block encodedParameters(parameters.wireEncode());
1384
1385 Name enable("/localhost/nfd/faces/enable-local-control");
1386 enable.append(encodedParameters);
1387
1388 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1389 enableCommand->setIncomingFaceId(dummy->getId());
1390
1391 generateCommand(*enableCommand);
1392
Junxiao Shic099ddb2014-12-25 20:53:20 -07001393 signal::Connection conn = getFace()->onReceiveData.connect(
1394 [this, enableCommand] (const Data& response) {
1395 this->validateControlResponse(response, enableCommand->getName(),
1396 412, "Face is non-local");
1397 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001398
1399 onValidatedFaceRequest(enableCommand);
1400
1401 BOOST_REQUIRE(didCallbackFire());
1402
Junxiao Shic099ddb2014-12-25 20:53:20 -07001403 conn.disconnect();
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001404 resetCallbackFired();
1405
1406 Name disable("/localhost/nfd/faces/disable-local-control");
1407 disable.append(encodedParameters);
1408
1409 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1410 disableCommand->setIncomingFaceId(dummy->getId());
1411
1412 generateCommand(*disableCommand);
1413
Junxiao Shic099ddb2014-12-25 20:53:20 -07001414 getFace()->onReceiveData.connect(
1415 [this, disableCommand] (const Data& response) {
1416 this->validateControlResponse(response, disableCommand->getName(),
1417 412, "Face is non-local");
1418 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001419
1420 onValidatedFaceRequest(disableCommand);
1421
1422 BOOST_REQUIRE(didCallbackFire());
1423}
1424
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001425class FaceFixture : public FaceTableFixture,
1426 public TestFaceManagerCommon,
1427 public FaceManager
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001428{
1429public:
1430 FaceFixture()
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001431 : FaceManager(FaceTableFixture::m_faceTable,
Junxiao Shic099ddb2014-12-25 20:53:20 -07001432 getFace(),
Vince Lehman5144f822014-07-23 15:12:56 -07001433 m_testKeyChain)
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001434 , m_receivedNotification(false)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001435 {
1436
1437 }
1438
1439 virtual
1440 ~FaceFixture()
1441 {
1442
1443 }
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001444
1445 void
1446 callbackDispatch(const Data& response,
1447 const Name& expectedName,
1448 uint32_t expectedCode,
1449 const std::string& expectedText,
1450 const Block& expectedBody,
1451 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1452 {
1453 Block payload = response.getContent().blockFromValue();
1454 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1455 {
1456 validateControlResponse(response, expectedName, expectedCode,
1457 expectedText, expectedBody);
1458 }
1459 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1460 {
1461 validateFaceEvent(payload, expectedFaceEvent);
1462 }
1463 else
1464 {
1465 BOOST_FAIL("Received unknown message type: #" << payload.type());
1466 }
1467 }
1468
1469 void
1470 callbackDispatch(const Data& response,
1471 const Name& expectedName,
1472 uint32_t expectedCode,
1473 const std::string& expectedText,
1474 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1475 {
1476 Block payload = response.getContent().blockFromValue();
1477 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1478 {
1479 validateControlResponse(response, expectedName,
1480 expectedCode, expectedText);
1481 }
1482 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1483 {
1484 validateFaceEvent(payload, expectedFaceEvent);
1485 }
1486 else
1487 {
1488 BOOST_FAIL("Received unknown message type: #" << payload.type());
1489 }
1490 }
1491
1492 void
1493 validateFaceEvent(const Block& wire,
1494 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1495 {
1496
1497 m_receivedNotification = true;
1498
1499 ndn::nfd::FaceEventNotification notification(wire);
1500
Junxiao Shi6e694322014-04-03 10:27:13 -07001501 BOOST_CHECK_EQUAL(notification.getKind(), expectedFaceEvent.getKind());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001502 BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId());
Junxiao Shi6e694322014-04-03 10:27:13 -07001503 BOOST_CHECK_EQUAL(notification.getRemoteUri(), expectedFaceEvent.getRemoteUri());
1504 BOOST_CHECK_EQUAL(notification.getLocalUri(), expectedFaceEvent.getLocalUri());
Chengyu Fanf9c2bb12014-10-06 11:52:44 -06001505 BOOST_CHECK_EQUAL(notification.getFaceScope(), expectedFaceEvent.getFaceScope());
1506 BOOST_CHECK_EQUAL(notification.getFacePersistency(), expectedFaceEvent.getFacePersistency());
1507 BOOST_CHECK_EQUAL(notification.getLinkType(), expectedFaceEvent.getLinkType());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001508 }
1509
1510 bool
1511 didReceiveNotication() const
1512 {
1513 return m_receivedNotification;
1514 }
1515
1516protected:
1517 bool m_receivedNotification;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001518};
1519
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001520BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001521{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001522 ControlParameters parameters;
Chengyu Fanb94af7c2014-12-17 11:46:47 +08001523 parameters.setUri("tcp4:/127.0.0.1:6363");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001524
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001525 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001526
1527 Name commandName("/localhost/nfd/faces");
1528 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001529 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001530
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001531 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1532 generateCommand(*command);
1533
Junxiao Shic099ddb2014-12-25 20:53:20 -07001534 getFace()->onReceiveData.connect([this, command] (const Data& response) {
Junxiao Shicd55cde2014-11-13 16:03:24 -07001535 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
Junxiao Shic099ddb2014-12-25 20:53:20 -07001536 });
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001537
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001538 createFace(*command, parameters);
1539
1540 BOOST_REQUIRE(didCallbackFire());
1541}
Chengyu Fanb94af7c2014-12-17 11:46:47 +08001542BOOST_FIXTURE_TEST_CASE(CreateFaceNoncanonicalUri, AuthorizedCommandFixture<FaceFixture>)
1543{
1544 ControlParameters parameters;
1545 parameters.setUri("tcp://127.0.0.1");
1546
1547 Block encodedParameters(parameters.wireEncode());
1548
1549 Name commandName("/localhost/nfd/faces");
1550 commandName.append("create");
1551 commandName.append(encodedParameters);
1552
1553 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1554 generateCommand(*command);
1555
Junxiao Shic099ddb2014-12-25 20:53:20 -07001556 getFace()->onReceiveData.connect([this, command] (const Data& response) {
Chengyu Fanb94af7c2014-12-17 11:46:47 +08001557 this->validateControlResponse(response, command->getName(), 400, "Non-canonical URI");
Junxiao Shic099ddb2014-12-25 20:53:20 -07001558 });
Chengyu Fanb94af7c2014-12-17 11:46:47 +08001559
1560 createFace(*command, parameters);
1561
1562 BOOST_REQUIRE(didCallbackFire());
1563}
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001564
1565BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>)
1566{
1567 ControlParameters parameters;
1568
1569 Block encodedParameters(parameters.wireEncode());
1570
1571 Name commandName("/localhost/nfd/faces");
1572 commandName.append("create");
1573 commandName.append(encodedParameters);
1574
1575 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1576 generateCommand(*command);
1577
Junxiao Shic099ddb2014-12-25 20:53:20 -07001578 getFace()->onReceiveData.connect([this, command] (const Data& response) {
Junxiao Shicd55cde2014-11-13 16:03:24 -07001579 this->validateControlResponse(response, command->getName(), 400, "Malformed command");
Junxiao Shic099ddb2014-12-25 20:53:20 -07001580 });
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001581
1582 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001583
1584 BOOST_REQUIRE(didCallbackFire());
1585}
1586
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001587BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001588{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001589 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001590 // this will be an unsupported protocol because no factories have been
1591 // added to the face manager
Chengyu Fanb94af7c2014-12-17 11:46:47 +08001592 parameters.setUri("tcp4://127.0.0.1:6363");
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
Junxiao Shic099ddb2014-12-25 20:53:20 -07001603 getFace()->onReceiveData.connect([this, command] (const Data& response) {
Junxiao Shicd55cde2014-11-13 16:03:24 -07001604 this->validateControlResponse(response, command->getName(), 501, "Unsupported protocol");
Junxiao Shic099ddb2014-12-25 20:53:20 -07001605 });
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001606
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001607 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001608
1609 BOOST_REQUIRE(didCallbackFire());
1610}
1611
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001612BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001613{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001614 ControlParameters parameters;
Chengyu Fanb94af7c2014-12-17 11:46:47 +08001615 parameters.setUri("tcp4://127.0.0.1:6363");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001616
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001617 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001618
1619 Name commandName("/localhost/nfd/faces");
1620 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001621 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001622
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001623 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1624 generateCommand(*command);
1625
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001626 ControlParameters resultParameters;
Steve DiBenedetto25999282014-05-22 15:25:12 -06001627 resultParameters.setUri("dummy://");
Junxiao Shi7b984c62014-07-17 22:18:34 -07001628 resultParameters.setFaceId(FACEID_RESERVED_MAX + 1);
Yukai Tu8149d102015-09-04 06:57:01 +08001629 resultParameters.setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001630
1631 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1632
Junxiao Shi6e694322014-04-03 10:27:13 -07001633 ndn::nfd::FaceEventNotification expectedFaceEvent;
1634 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED)
Junxiao Shi7b984c62014-07-17 22:18:34 -07001635 .setFaceId(FACEID_RESERVED_MAX + 1)
Junxiao Shi6e694322014-04-03 10:27:13 -07001636 .setRemoteUri(dummy->getRemoteUri().toString())
1637 .setLocalUri(dummy->getLocalUri().toString())
Chengyu Fan9942cea2014-10-13 14:47:13 -06001638 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
1639 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001640
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001641 Block encodedResultParameters(resultParameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001642
Junxiao Shic099ddb2014-12-25 20:53:20 -07001643 getFace()->onReceiveData.connect(
1644 [this, command, encodedResultParameters, expectedFaceEvent] (const Data& response) {
1645 this->callbackDispatch(response,command->getName(), 200, "Success",
1646 encodedResultParameters, expectedFaceEvent);
1647 });
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001648
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001649 onCreated(command->getName(), parameters, dummy);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001650
1651 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001652 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001653}
1654
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001655BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001656{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001657 ControlParameters parameters;
Chengyu Fanb94af7c2014-12-17 11:46:47 +08001658 parameters.setUri("tcp4://127.0.0.1:6363");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001659
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001660 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001661
1662 Name commandName("/localhost/nfd/faces");
1663 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001664 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001665
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001666 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1667 generateCommand(*command);
1668
Junxiao Shic099ddb2014-12-25 20:53:20 -07001669 getFace()->onReceiveData.connect([this, command] (const Data& response) {
Junxiao Shicd55cde2014-11-13 16:03:24 -07001670 this->validateControlResponse(response, command->getName(), 408, "unit-test-reason");
Junxiao Shic099ddb2014-12-25 20:53:20 -07001671 });
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001672
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001673 onConnectFailed(command->getName(), "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001674
1675 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001676 BOOST_CHECK_EQUAL(didReceiveNotication(), false);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001677}
1678
1679
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001680BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001681{
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001682 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1683 FaceTableFixture::m_faceTable.add(dummy);
1684
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001685 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001686 parameters.setFaceId(dummy->getId());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001687
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001688 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001689
1690 Name commandName("/localhost/nfd/faces");
1691 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001692 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001693
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001694 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1695 generateCommand(*command);
1696
Junxiao Shi6e694322014-04-03 10:27:13 -07001697 ndn::nfd::FaceEventNotification expectedFaceEvent;
1698 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
1699 .setFaceId(dummy->getId())
1700 .setRemoteUri(dummy->getRemoteUri().toString())
1701 .setLocalUri(dummy->getLocalUri().toString())
Chengyu Fan9942cea2014-10-13 14:47:13 -06001702 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
1703 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001704
Junxiao Shic099ddb2014-12-25 20:53:20 -07001705 getFace()->onReceiveData.connect(
1706 [this, command, encodedParameters, expectedFaceEvent] (const Data& response) {
1707 this->callbackDispatch(response,command->getName(), 200, "Success",
1708 encodedParameters, expectedFaceEvent);
1709 });
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001710
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001711 destroyFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001712
1713 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001714 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001715}
1716
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001717class FaceListFixture : public FaceStatusPublisherFixture
1718{
1719public:
1720 FaceListFixture()
Vince Lehman5144f822014-07-23 15:12:56 -07001721 : m_manager(m_table, m_face, m_testKeyChain)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001722 {
1723
1724 }
1725
1726 virtual
1727 ~FaceListFixture()
1728 {
1729
1730 }
1731
1732protected:
1733 FaceManager m_manager;
Vince Lehman5144f822014-07-23 15:12:56 -07001734 ndn::KeyChain m_testKeyChain;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001735};
1736
1737BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001738{
1739 Name commandName("/localhost/nfd/faces/list");
1740 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1741
Junxiao Shi632a6202014-07-20 01:14:30 -07001742 // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 75
1743 // use 59 FaceStatuses to force a FaceStatus to span Data packets
1744 for (int i = 0; i < 59; i++)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001745 {
1746 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1747
1748 uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
Junxiao Shi632a6202014-07-20 01:14:30 -07001749 dummy->setCounters(filler, filler, filler, filler, filler, filler);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001750
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001751 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001752
1753 add(dummy);
1754 }
1755
1756 ndn::EncodingBuffer buffer;
1757
Junxiao Shic099ddb2014-12-25 20:53:20 -07001758 m_face->onReceiveData.connect(bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock,
1759 this, _1));
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001760
1761 m_manager.listFaces(*command);
1762 BOOST_REQUIRE(m_finished);
1763}
1764
Steve DiBenedettoef04f272014-06-04 14:28:31 -06001765class ChannelStatusFixture : public FaceManagerFixture
1766{
1767public:
1768 void
1769 validatePublish(const Data& data, const ndn::nfd::ChannelStatus& expectedEntry)
1770 {
1771 m_callbackFired = true;
1772 Block b = data.getContent().blockFromValue();
1773 ndn::nfd::ChannelStatus entry(b);
1774 BOOST_CHECK_EQUAL(entry.getLocalUri(), expectedEntry.getLocalUri());
1775 }
1776
1777 virtual shared_ptr<DummyProtocolFactory>
1778 addProtocolFactory(const std::string& protocol)
1779 {
1780 shared_ptr<DummyProtocolFactory> factory(make_shared<DummyProtocolFactory>());
1781 m_manager.m_factories[protocol] = factory;
1782
1783 return factory;
1784 }
1785};
1786
1787BOOST_FIXTURE_TEST_CASE(TestChannelStatus, ChannelStatusFixture)
1788{
1789 shared_ptr<DummyProtocolFactory> factory(addProtocolFactory("dummy"));
1790 factory->addChannel("dummy://");
1791
1792 Name requestName("/localhost/nfd/faces/channels");
1793 shared_ptr<Interest> request(make_shared<Interest>(requestName));
1794
1795 ndn::nfd::ChannelStatus expectedEntry;
1796 expectedEntry.setLocalUri(DummyChannel("dummy://").getUri().toString());
1797
Junxiao Shic099ddb2014-12-25 20:53:20 -07001798 m_face->onReceiveData.connect(bind(&ChannelStatusFixture::validatePublish,
1799 this, _1, expectedEntry));
Steve DiBenedettoef04f272014-06-04 14:28:31 -06001800
1801 m_manager.listChannels(*request);
1802 BOOST_REQUIRE(m_callbackFired);
1803}
1804
Chengyu Fan320d2332014-10-29 16:40:33 -06001805class FaceQueryListFixture : public FaceQueryStatusPublisherFixture
1806{
1807public:
1808 FaceQueryListFixture()
1809 : m_manager(m_table, m_face, m_testKeyChain)
1810 {
1811
1812 }
1813
1814 virtual
1815 ~FaceQueryListFixture()
1816 {
1817
1818 }
1819
1820protected:
1821 FaceManager m_manager;
1822 ndn::KeyChain m_testKeyChain;
1823};
1824
1825BOOST_FIXTURE_TEST_CASE(TestValidQueryFilter, FaceQueryListFixture)
1826{
1827 Name queryName("/localhost/nfd/faces/query");
1828 ndn::nfd::FaceQueryFilter queryFilter;
1829 queryFilter.setUriScheme("dummy");
1830 queryName.append(queryFilter.wireEncode());
1831
1832 shared_ptr<Interest> query(make_shared<Interest>(queryName));
1833
1834 // add expected faces
1835 shared_ptr<DummyLocalFace> expectedFace1(make_shared<DummyLocalFace>());
1836 m_referenceFaces.push_back(expectedFace1);
1837 add(expectedFace1);
1838
1839 shared_ptr<DummyFace> expectedFace2(make_shared<DummyFace>());
1840 m_referenceFaces.push_back(expectedFace2);
1841 add(expectedFace2);
1842
1843 // add other faces
1844 shared_ptr<DummyFace> face1(make_shared<DummyFace>("udp://", "udp://"));
1845 add(face1);
1846 shared_ptr<DummyLocalFace> face2(make_shared<DummyLocalFace>("tcp://", "tcp://"));
1847 add(face2);
1848
Junxiao Shic099ddb2014-12-25 20:53:20 -07001849 m_face->onReceiveData.connect(bind(&FaceQueryStatusPublisherFixture::decodeFaceStatusBlock,
1850 this, _1));
Chengyu Fan320d2332014-10-29 16:40:33 -06001851
1852 m_manager.listQueriedFaces(*query);
1853 BOOST_REQUIRE(m_finished);
1854}
1855
Chengyu Fanab205c22014-11-18 10:58:41 -07001856BOOST_FIXTURE_TEST_CASE(TestInvalidQueryFilter, FaceQueryListFixture)
1857{
1858 Name queryName("/localhost/nfd/faces/query");
1859 ndn::nfd::FaceStatus queryFilter;
1860 queryName.append(queryFilter.wireEncode());
1861
1862 shared_ptr<Interest> query(make_shared<Interest>(queryName));
1863
1864 shared_ptr<DummyLocalFace> face(make_shared<DummyLocalFace>());
1865 add(face);
1866
Junxiao Shic099ddb2014-12-25 20:53:20 -07001867 m_face->onReceiveData.connect(bind(&FaceQueryStatusPublisherFixture::decodeNackBlock, this, _1));
Chengyu Fanab205c22014-11-18 10:58:41 -07001868
1869 m_manager.listQueriedFaces(*query);
1870 BOOST_REQUIRE(m_finished);
1871}
Chengyu Fan320d2332014-10-29 16:40:33 -06001872
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001873BOOST_AUTO_TEST_SUITE_END()
1874
1875} // namespace tests
1876} // namespace nfd