blob: 447176c17fa0e8c9939d88b4018ed1e265a54ee4 [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 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);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001629
1630 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1631
Junxiao Shi6e694322014-04-03 10:27:13 -07001632 ndn::nfd::FaceEventNotification expectedFaceEvent;
1633 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED)
Junxiao Shi7b984c62014-07-17 22:18:34 -07001634 .setFaceId(FACEID_RESERVED_MAX + 1)
Junxiao Shi6e694322014-04-03 10:27:13 -07001635 .setRemoteUri(dummy->getRemoteUri().toString())
1636 .setLocalUri(dummy->getLocalUri().toString())
Chengyu Fan9942cea2014-10-13 14:47:13 -06001637 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
1638 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001639
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001640 Block encodedResultParameters(resultParameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001641
Junxiao Shic099ddb2014-12-25 20:53:20 -07001642 getFace()->onReceiveData.connect(
1643 [this, command, encodedResultParameters, expectedFaceEvent] (const Data& response) {
1644 this->callbackDispatch(response,command->getName(), 200, "Success",
1645 encodedResultParameters, expectedFaceEvent);
1646 });
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001647
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001648 onCreated(command->getName(), parameters, dummy);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001649
1650 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001651 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001652}
1653
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001654BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001655{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001656 ControlParameters parameters;
Chengyu Fanb94af7c2014-12-17 11:46:47 +08001657 parameters.setUri("tcp4://127.0.0.1:6363");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001658
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001659 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001660
1661 Name commandName("/localhost/nfd/faces");
1662 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001663 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001664
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001665 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1666 generateCommand(*command);
1667
Junxiao Shic099ddb2014-12-25 20:53:20 -07001668 getFace()->onReceiveData.connect([this, command] (const Data& response) {
Junxiao Shicd55cde2014-11-13 16:03:24 -07001669 this->validateControlResponse(response, command->getName(), 408, "unit-test-reason");
Junxiao Shic099ddb2014-12-25 20:53:20 -07001670 });
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001671
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001672 onConnectFailed(command->getName(), "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001673
1674 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001675 BOOST_CHECK_EQUAL(didReceiveNotication(), false);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001676}
1677
1678
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001679BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001680{
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001681 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1682 FaceTableFixture::m_faceTable.add(dummy);
1683
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001684 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001685 parameters.setFaceId(dummy->getId());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001686
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001687 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001688
1689 Name commandName("/localhost/nfd/faces");
1690 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001691 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001692
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001693 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1694 generateCommand(*command);
1695
Junxiao Shi6e694322014-04-03 10:27:13 -07001696 ndn::nfd::FaceEventNotification expectedFaceEvent;
1697 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
1698 .setFaceId(dummy->getId())
1699 .setRemoteUri(dummy->getRemoteUri().toString())
1700 .setLocalUri(dummy->getLocalUri().toString())
Chengyu Fan9942cea2014-10-13 14:47:13 -06001701 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
1702 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001703
Junxiao Shic099ddb2014-12-25 20:53:20 -07001704 getFace()->onReceiveData.connect(
1705 [this, command, encodedParameters, expectedFaceEvent] (const Data& response) {
1706 this->callbackDispatch(response,command->getName(), 200, "Success",
1707 encodedParameters, expectedFaceEvent);
1708 });
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001709
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001710 destroyFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001711
1712 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001713 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001714}
1715
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001716class FaceListFixture : public FaceStatusPublisherFixture
1717{
1718public:
1719 FaceListFixture()
Vince Lehman5144f822014-07-23 15:12:56 -07001720 : m_manager(m_table, m_face, m_testKeyChain)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001721 {
1722
1723 }
1724
1725 virtual
1726 ~FaceListFixture()
1727 {
1728
1729 }
1730
1731protected:
1732 FaceManager m_manager;
Vince Lehman5144f822014-07-23 15:12:56 -07001733 ndn::KeyChain m_testKeyChain;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001734};
1735
1736BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001737{
1738 Name commandName("/localhost/nfd/faces/list");
1739 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1740
Junxiao Shi632a6202014-07-20 01:14:30 -07001741 // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 75
1742 // use 59 FaceStatuses to force a FaceStatus to span Data packets
1743 for (int i = 0; i < 59; i++)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001744 {
1745 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1746
1747 uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
Junxiao Shi632a6202014-07-20 01:14:30 -07001748 dummy->setCounters(filler, filler, filler, filler, filler, filler);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001749
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001750 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001751
1752 add(dummy);
1753 }
1754
1755 ndn::EncodingBuffer buffer;
1756
Junxiao Shic099ddb2014-12-25 20:53:20 -07001757 m_face->onReceiveData.connect(bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock,
1758 this, _1));
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001759
1760 m_manager.listFaces(*command);
1761 BOOST_REQUIRE(m_finished);
1762}
1763
Steve DiBenedettoef04f272014-06-04 14:28:31 -06001764class ChannelStatusFixture : public FaceManagerFixture
1765{
1766public:
1767 void
1768 validatePublish(const Data& data, const ndn::nfd::ChannelStatus& expectedEntry)
1769 {
1770 m_callbackFired = true;
1771 Block b = data.getContent().blockFromValue();
1772 ndn::nfd::ChannelStatus entry(b);
1773 BOOST_CHECK_EQUAL(entry.getLocalUri(), expectedEntry.getLocalUri());
1774 }
1775
1776 virtual shared_ptr<DummyProtocolFactory>
1777 addProtocolFactory(const std::string& protocol)
1778 {
1779 shared_ptr<DummyProtocolFactory> factory(make_shared<DummyProtocolFactory>());
1780 m_manager.m_factories[protocol] = factory;
1781
1782 return factory;
1783 }
1784};
1785
1786BOOST_FIXTURE_TEST_CASE(TestChannelStatus, ChannelStatusFixture)
1787{
1788 shared_ptr<DummyProtocolFactory> factory(addProtocolFactory("dummy"));
1789 factory->addChannel("dummy://");
1790
1791 Name requestName("/localhost/nfd/faces/channels");
1792 shared_ptr<Interest> request(make_shared<Interest>(requestName));
1793
1794 ndn::nfd::ChannelStatus expectedEntry;
1795 expectedEntry.setLocalUri(DummyChannel("dummy://").getUri().toString());
1796
Junxiao Shic099ddb2014-12-25 20:53:20 -07001797 m_face->onReceiveData.connect(bind(&ChannelStatusFixture::validatePublish,
1798 this, _1, expectedEntry));
Steve DiBenedettoef04f272014-06-04 14:28:31 -06001799
1800 m_manager.listChannels(*request);
1801 BOOST_REQUIRE(m_callbackFired);
1802}
1803
Chengyu Fan320d2332014-10-29 16:40:33 -06001804class FaceQueryListFixture : public FaceQueryStatusPublisherFixture
1805{
1806public:
1807 FaceQueryListFixture()
1808 : m_manager(m_table, m_face, m_testKeyChain)
1809 {
1810
1811 }
1812
1813 virtual
1814 ~FaceQueryListFixture()
1815 {
1816
1817 }
1818
1819protected:
1820 FaceManager m_manager;
1821 ndn::KeyChain m_testKeyChain;
1822};
1823
1824BOOST_FIXTURE_TEST_CASE(TestValidQueryFilter, FaceQueryListFixture)
1825{
1826 Name queryName("/localhost/nfd/faces/query");
1827 ndn::nfd::FaceQueryFilter queryFilter;
1828 queryFilter.setUriScheme("dummy");
1829 queryName.append(queryFilter.wireEncode());
1830
1831 shared_ptr<Interest> query(make_shared<Interest>(queryName));
1832
1833 // add expected faces
1834 shared_ptr<DummyLocalFace> expectedFace1(make_shared<DummyLocalFace>());
1835 m_referenceFaces.push_back(expectedFace1);
1836 add(expectedFace1);
1837
1838 shared_ptr<DummyFace> expectedFace2(make_shared<DummyFace>());
1839 m_referenceFaces.push_back(expectedFace2);
1840 add(expectedFace2);
1841
1842 // add other faces
1843 shared_ptr<DummyFace> face1(make_shared<DummyFace>("udp://", "udp://"));
1844 add(face1);
1845 shared_ptr<DummyLocalFace> face2(make_shared<DummyLocalFace>("tcp://", "tcp://"));
1846 add(face2);
1847
Junxiao Shic099ddb2014-12-25 20:53:20 -07001848 m_face->onReceiveData.connect(bind(&FaceQueryStatusPublisherFixture::decodeFaceStatusBlock,
1849 this, _1));
Chengyu Fan320d2332014-10-29 16:40:33 -06001850
1851 m_manager.listQueriedFaces(*query);
1852 BOOST_REQUIRE(m_finished);
1853}
1854
Chengyu Fanab205c22014-11-18 10:58:41 -07001855BOOST_FIXTURE_TEST_CASE(TestInvalidQueryFilter, FaceQueryListFixture)
1856{
1857 Name queryName("/localhost/nfd/faces/query");
1858 ndn::nfd::FaceStatus queryFilter;
1859 queryName.append(queryFilter.wireEncode());
1860
1861 shared_ptr<Interest> query(make_shared<Interest>(queryName));
1862
1863 shared_ptr<DummyLocalFace> face(make_shared<DummyLocalFace>());
1864 add(face);
1865
Junxiao Shic099ddb2014-12-25 20:53:20 -07001866 m_face->onReceiveData.connect(bind(&FaceQueryStatusPublisherFixture::decodeNackBlock, this, _1));
Chengyu Fanab205c22014-11-18 10:58:41 -07001867
1868 m_manager.listQueriedFaces(*query);
1869 BOOST_REQUIRE(m_finished);
1870}
Chengyu Fan320d2332014-10-29 16:40:33 -06001871
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001872BOOST_AUTO_TEST_SUITE_END()
1873
1874} // namespace tests
1875} // namespace nfd