blob: 601724af8438311de43c55115e9adfc100f4e034 [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"
35#include "face/ethernet-factory.hpp"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070036
37#include "common.hpp"
38#include "tests/test-common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070039#include "validation-common.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060040#include "face-status-publisher-common.hpp"
Steve DiBenedettoef04f272014-06-04 14:28:31 -060041#include "channel-status-common.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060042
Alexander Afanasyev4a771362014-04-24 21:29:33 -070043#include <ndn-cxx/encoding/tlv.hpp>
44#include <ndn-cxx/management/nfd-face-event-notification.hpp>
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070045
46namespace nfd {
47namespace tests {
48
49NFD_LOG_INIT("FaceManagerTest");
50
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060051class FaceManagerTestFace : public DummyFace
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070052{
53public:
54
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060055 FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070056 : m_closeFired(false)
57 {
58
59 }
60
61 virtual
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060062 ~FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070063 {
64
65 }
66
67 virtual void
68 close()
69 {
70 m_closeFired = true;
71 }
72
73 bool
74 didCloseFire() const
75 {
76 return m_closeFired;
77 }
78
79private:
80 bool m_closeFired;
81};
82
83class TestFaceTable : public FaceTable
84{
85public:
86 TestFaceTable(Forwarder& forwarder)
87 : FaceTable(forwarder),
88 m_addFired(false),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070089 m_getFired(false),
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060090 m_dummy(make_shared<FaceManagerTestFace>())
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070091 {
92
93 }
94
95 virtual
96 ~TestFaceTable()
97 {
98
99 }
100
101 virtual void
102 add(shared_ptr<Face> face)
103 {
104 m_addFired = true;
105 }
106
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700107 virtual shared_ptr<Face>
108 get(FaceId id) const
109 {
110 m_getFired = true;
111 return m_dummy;
112 }
113
114 bool
115 didAddFire() const
116 {
117 return m_addFired;
118 }
119
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700120 bool
121 didGetFire() const
122 {
123 return m_getFired;
124 }
125
126 void
127 reset()
128 {
129 m_addFired = false;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700130 m_getFired = false;
131 }
132
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600133 shared_ptr<FaceManagerTestFace>&
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700134 getDummyFace()
135 {
136 return m_dummy;
137 }
138
139private:
140 bool m_addFired;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700141 mutable bool m_getFired;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600142 shared_ptr<FaceManagerTestFace> m_dummy;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700143};
144
145
146class TestFaceTableFixture : public BaseFixture
147{
148public:
149 TestFaceTableFixture()
150 : m_faceTable(m_forwarder)
151 {
152
153 }
154
155 virtual
156 ~TestFaceTableFixture()
157 {
158
159 }
160
161protected:
162 Forwarder m_forwarder;
163 TestFaceTable m_faceTable;
164};
165
166class TestFaceManagerCommon
167{
168public:
169 TestFaceManagerCommon()
170 : m_face(make_shared<InternalFace>()),
171 m_callbackFired(false)
172 {
173
174 }
175
176 virtual
177 ~TestFaceManagerCommon()
178 {
179
180 }
181
182 shared_ptr<InternalFace>&
183 getFace()
184 {
185 return m_face;
186 }
187
188 void
189 validateControlResponseCommon(const Data& response,
190 const Name& expectedName,
191 uint32_t expectedCode,
192 const std::string& expectedText,
193 ControlResponse& control)
194 {
195 m_callbackFired = true;
196 Block controlRaw = response.getContent().blockFromValue();
197
198 control.wireDecode(controlRaw);
199
200 // NFD_LOG_DEBUG("received control response"
201 // << " Name: " << response.getName()
202 // << " code: " << control.getCode()
203 // << " text: " << control.getText());
204
205 BOOST_CHECK_EQUAL(response.getName(), expectedName);
206 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
207 BOOST_CHECK_EQUAL(control.getText(), expectedText);
208 }
209
210 void
211 validateControlResponse(const Data& response,
212 const Name& expectedName,
213 uint32_t expectedCode,
214 const std::string& expectedText)
215 {
216 ControlResponse control;
217 validateControlResponseCommon(response, expectedName,
218 expectedCode, expectedText, control);
219
220 if (!control.getBody().empty())
221 {
222 BOOST_FAIL("found unexpected control response body");
223 }
224 }
225
226 void
227 validateControlResponse(const Data& response,
228 const Name& expectedName,
229 uint32_t expectedCode,
230 const std::string& expectedText,
231 const Block& expectedBody)
232 {
233 ControlResponse control;
234 validateControlResponseCommon(response, expectedName,
235 expectedCode, expectedText, control);
236
237 BOOST_REQUIRE(!control.getBody().empty());
238 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
239
240 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
241 expectedBody.value_size()) == 0);
242
243 }
244
245 bool
246 didCallbackFire() const
247 {
248 return m_callbackFired;
249 }
250
251 void
252 resetCallbackFired()
253 {
254 m_callbackFired = false;
255 }
256
257protected:
258 shared_ptr<InternalFace> m_face;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700259 bool m_callbackFired;
Vince Lehman5144f822014-07-23 15:12:56 -0700260 ndn::KeyChain m_testKeyChain;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700261};
262
263class FaceManagerFixture : public TestFaceTableFixture, public TestFaceManagerCommon
264{
265public:
266 FaceManagerFixture()
Vince Lehman5144f822014-07-23 15:12:56 -0700267 : m_manager(m_faceTable, m_face, m_testKeyChain)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700268 {
269 m_manager.setConfigFile(m_config);
270 }
271
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700272 virtual
273 ~FaceManagerFixture()
274 {
275
276 }
277
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600278 void
279 parseConfig(const std::string configuration, bool isDryRun)
280 {
281 m_config.parse(configuration, isDryRun, "dummy-config");
282 }
283
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700284 FaceManager&
285 getManager()
286 {
287 return m_manager;
288 }
289
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700290 void
291 addInterestRule(const std::string& regex,
292 ndn::IdentityCertificate& certificate)
293 {
294 m_manager.addInterestRule(regex, certificate);
295 }
296
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700297 bool
298 didFaceTableAddFire() const
299 {
300 return m_faceTable.didAddFire();
301 }
302
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700303 bool
304 didFaceTableGetFire() const
305 {
306 return m_faceTable.didGetFire();
307 }
308
309 void
310 resetFaceTable()
311 {
312 m_faceTable.reset();
313 }
314
Steve DiBenedettoef04f272014-06-04 14:28:31 -0600315protected:
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700316 FaceManager m_manager;
317 ConfigFile m_config;
318};
319
320BOOST_FIXTURE_TEST_SUITE(MgmtFaceManager, FaceManagerFixture)
321
322bool
323isExpectedException(const ConfigFile::Error& error, const std::string& expectedMessage)
324{
325 if (error.what() != expectedMessage)
326 {
327 NFD_LOG_ERROR("expected: " << expectedMessage << "\tgot: " << error.what());
328 }
329 return error.what() == expectedMessage;
330}
331
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600332#ifdef HAVE_UNIX_SOCKETS
333
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700334BOOST_AUTO_TEST_CASE(TestProcessSectionUnix)
335{
336 const std::string CONFIG =
337 "face_system\n"
338 "{\n"
339 " unix\n"
340 " {\n"
341 " listen yes\n"
342 " path /tmp/nfd.sock\n"
343 " }\n"
344 "}\n";
345 BOOST_TEST_CHECKPOINT("Calling parse");
346 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
347}
348
349BOOST_AUTO_TEST_CASE(TestProcessSectionUnixDryRun)
350{
351 const std::string CONFIG =
352 "face_system\n"
353 "{\n"
354 " unix\n"
355 " {\n"
356 " listen yes\n"
357 " path /var/run/nfd.sock\n"
358 " }\n"
359 "}\n";
360
361 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
362}
363
364BOOST_AUTO_TEST_CASE(TestProcessSectionUnixBadListen)
365{
366 const std::string CONFIG =
367 "face_system\n"
368 "{\n"
369 " unix\n"
370 " {\n"
371 " listen hello\n"
372 " }\n"
373 "}\n";
374 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
375 bind(&isExpectedException, _1,
376 "Invalid value for option \"listen\" in \"unix\" section"));
377}
378
379BOOST_AUTO_TEST_CASE(TestProcessSectionUnixUnknownOption)
380{
381 const std::string CONFIG =
382 "face_system\n"
383 "{\n"
384 " unix\n"
385 " {\n"
386 " hello\n"
387 " }\n"
388 "}\n";
389 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
390 bind(&isExpectedException, _1,
391 "Unrecognized option \"hello\" in \"unix\" section"));
392}
393
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600394#endif // HAVE_UNIX_SOCKETS
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700395
396
397BOOST_AUTO_TEST_CASE(TestProcessSectionTcp)
398{
399 const std::string CONFIG =
400 "face_system\n"
401 "{\n"
402 " tcp\n"
403 " {\n"
404 " listen yes\n"
405 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600406 " enable_v4 yes\n"
407 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700408 " }\n"
409 "}\n";
410 try
411 {
412 parseConfig(CONFIG, false);
413 }
414 catch (const std::runtime_error& e)
415 {
416 const std::string reason = e.what();
417 if (reason.find("Address in use") != std::string::npos)
418 {
419 BOOST_FAIL(reason);
420 }
421 }
422}
423
424BOOST_AUTO_TEST_CASE(TestProcessSectionTcpDryRun)
425{
426 const std::string CONFIG =
427 "face_system\n"
428 "{\n"
429 " tcp\n"
430 " {\n"
431 " listen yes\n"
432 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600433 " enable_v4 yes\n"
434 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700435 " }\n"
436 "}\n";
437 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
438}
439
440BOOST_AUTO_TEST_CASE(TestProcessSectionTcpBadListen)
441{
442 const std::string CONFIG =
443 "face_system\n"
444 "{\n"
445 " tcp\n"
446 " {\n"
447 " listen hello\n"
448 " }\n"
449 "}\n";
450 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
451 bind(&isExpectedException, _1,
452 "Invalid value for option \"listen\" in \"tcp\" section"));
453}
454
Steve DiBenedetto95152872014-04-11 12:40:59 -0600455BOOST_AUTO_TEST_CASE(TestProcessSectionTcpChannelsDisabled)
456{
457 const std::string CONFIG =
458 "face_system\n"
459 "{\n"
460 " tcp\n"
461 " {\n"
462 " port 6363\n"
463 " enable_v4 no\n"
464 " enable_v6 no\n"
465 " }\n"
466 "}\n";
467 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
468 bind(&isExpectedException, _1,
469 "IPv4 and IPv6 channels have been disabled."
470 " Remove \"tcp\" section to disable TCP channels or"
471 " re-enable at least one channel type."));
472}
473
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700474BOOST_AUTO_TEST_CASE(TestProcessSectionTcpUnknownOption)
475{
476 const std::string CONFIG =
477 "face_system\n"
478 "{\n"
479 " tcp\n"
480 " {\n"
481 " hello\n"
482 " }\n"
483 "}\n";
484 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
485 bind(&isExpectedException, _1,
486 "Unrecognized option \"hello\" in \"tcp\" section"));
487}
488
489BOOST_AUTO_TEST_CASE(TestProcessSectionUdp)
490{
491 const std::string CONFIG =
492 "face_system\n"
493 "{\n"
494 " udp\n"
495 " {\n"
496 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600497 " enable_v4 yes\n"
498 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700499 " idle_timeout 30\n"
500 " keep_alive_interval 25\n"
501 " mcast yes\n"
502 " mcast_port 56363\n"
503 " mcast_group 224.0.23.170\n"
504 " }\n"
505 "}\n";
506 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
507}
508
509BOOST_AUTO_TEST_CASE(TestProcessSectionUdpDryRun)
510{
511 const std::string CONFIG =
512 "face_system\n"
513 "{\n"
514 " udp\n"
515 " {\n"
516 " port 6363\n"
517 " idle_timeout 30\n"
518 " keep_alive_interval 25\n"
519 " mcast yes\n"
520 " mcast_port 56363\n"
521 " mcast_group 224.0.23.170\n"
522 " }\n"
523 "}\n";
524 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
525}
526
527BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadIdleTimeout)
528{
529 const std::string CONFIG =
530 "face_system\n"
531 "{\n"
532 " udp\n"
533 " {\n"
534 " idle_timeout hello\n"
535 " }\n"
536 "}\n";
537
538 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
539 bind(&isExpectedException, _1,
540 "Invalid value for option \"idle_timeout\" in \"udp\" section"));
541}
542
543BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcast)
544{
545 const std::string CONFIG =
546 "face_system\n"
547 "{\n"
548 " udp\n"
549 " {\n"
550 " mcast hello\n"
551 " }\n"
552 "}\n";
553
554 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
555 bind(&isExpectedException, _1,
556 "Invalid value for option \"mcast\" in \"udp\" section"));
557}
558
559BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroup)
560{
561 const std::string CONFIG =
562 "face_system\n"
563 "{\n"
564 " udp\n"
565 " {\n"
566 " mcast no\n"
567 " mcast_port 50\n"
568 " mcast_group hello\n"
569 " }\n"
570 "}\n";
571
572 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
573 bind(&isExpectedException, _1,
574 "Invalid value for option \"mcast_group\" in \"udp\" section"));
575}
576
577BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroupV6)
578{
579 const std::string CONFIG =
580 "face_system\n"
581 "{\n"
582 " udp\n"
583 " {\n"
584 " mcast no\n"
585 " mcast_port 50\n"
586 " mcast_group ::1\n"
587 " }\n"
588 "}\n";
589
590 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
591 bind(&isExpectedException, _1,
592 "Invalid value for option \"mcast_group\" in \"udp\" section"));
593}
594
Steve DiBenedetto95152872014-04-11 12:40:59 -0600595BOOST_AUTO_TEST_CASE(TestProcessSectionUdpChannelsDisabled)
596{
597 const std::string CONFIG =
598 "face_system\n"
599 "{\n"
600 " udp\n"
601 " {\n"
602 " port 6363\n"
603 " enable_v4 no\n"
604 " enable_v6 no\n"
605 " idle_timeout 30\n"
606 " keep_alive_interval 25\n"
607 " mcast yes\n"
608 " mcast_port 56363\n"
609 " mcast_group 224.0.23.170\n"
610 " }\n"
611 "}\n";
612 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
613 bind(&isExpectedException, _1,
614 "IPv4 and IPv6 channels have been disabled."
615 " Remove \"udp\" section to disable UDP channels or"
616 " re-enable at least one channel type."));
617}
618
619BOOST_AUTO_TEST_CASE(TestProcessSectionUdpConflictingMcast)
620{
621 const std::string CONFIG =
622 "face_system\n"
623 "{\n"
624 " udp\n"
625 " {\n"
626 " port 6363\n"
627 " enable_v4 no\n"
628 " enable_v6 yes\n"
629 " idle_timeout 30\n"
630 " keep_alive_interval 25\n"
631 " mcast yes\n"
632 " mcast_port 56363\n"
633 " mcast_group 224.0.23.170\n"
634 " }\n"
635 "}\n";
636 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
637 bind(&isExpectedException, _1,
638 "IPv4 multicast requested, but IPv4 channels"
639 " have been disabled (conflicting configuration options set)"));
640}
641
642
643
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700644BOOST_AUTO_TEST_CASE(TestProcessSectionUdpUnknownOption)
645{
646 const std::string CONFIG =
647 "face_system\n"
648 "{\n"
649 " udp\n"
650 " {\n"
651 " hello\n"
652 " }\n"
653 "}\n";
654 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
655 bind(&isExpectedException, _1,
656 "Unrecognized option \"hello\" in \"udp\" section"));
657}
658
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300659
660BOOST_AUTO_TEST_CASE(TestProcessSectionUdpMulticastReinit)
661{
662 const std::string CONFIG_WITH_MCAST =
663 "face_system\n"
664 "{\n"
665 " udp\n"
666 " {\n"
667 " mcast yes\n"
668 " }\n"
669 "}\n";
670 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
671
672 shared_ptr<UdpFactory> factory = static_pointer_cast<UdpFactory>(getManager().findFactory("udp"));
673 BOOST_REQUIRE(static_cast<bool>(factory));
674
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300675 if (factory->getMulticastFaces().size() == 0) {
676 BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
677 "no UDP multicast faces are available");
678 }
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300679
680 const std::string CONFIG_WITHOUT_MCAST =
681 "face_system\n"
682 "{\n"
683 " udp\n"
684 " {\n"
685 " mcast no\n"
686 " }\n"
687 "}\n";
688 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
689 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
690}
691
692
Alexander Afanasyev885a85b2014-04-12 21:01:13 -0700693#ifdef HAVE_LIBPCAP
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600694
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700695BOOST_AUTO_TEST_CASE(TestProcessSectionEther)
696{
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600697
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700698 const std::string CONFIG =
699 "face_system\n"
700 "{\n"
701 " ether\n"
702 " {\n"
703 " mcast yes\n"
704 " mcast_group 01:00:5E:00:17:AA\n"
705 " }\n"
706 "}\n";
707
708 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
709}
710
711BOOST_AUTO_TEST_CASE(TestProcessSectionEtherDryRun)
712{
713 const std::string CONFIG =
714 "face_system\n"
715 "{\n"
716 " ether\n"
717 " {\n"
718 " mcast yes\n"
719 " mcast_group 01:00:5E:00:17:AA\n"
720 " }\n"
721 "}\n";
722
723 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
724}
725
726BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcast)
727{
728 const std::string CONFIG =
729 "face_system\n"
730 "{\n"
731 " ether\n"
732 " {\n"
733 " mcast hello\n"
734 " }\n"
735 "}\n";
736
737 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
738 bind(&isExpectedException, _1,
739 "Invalid value for option \"mcast\" in \"ether\" section"));
740}
741
742BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcastGroup)
743{
744 const std::string CONFIG =
745 "face_system\n"
746 "{\n"
747 " ether\n"
748 " {\n"
749 " mcast yes\n"
750 " mcast_group\n"
751 " }\n"
752 "}\n";
753
754 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
755 bind(&isExpectedException, _1,
756 "Invalid value for option \"mcast_group\" in \"ether\" section"));
757}
758
759BOOST_AUTO_TEST_CASE(TestProcessSectionEtherUnknownOption)
760{
761 const std::string CONFIG =
762 "face_system\n"
763 "{\n"
764 " ether\n"
765 " {\n"
766 " hello\n"
767 " }\n"
768 "}\n";
769 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
770 bind(&isExpectedException, _1,
771 "Unrecognized option \"hello\" in \"ether\" section"));
772}
773
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300774BOOST_AUTO_TEST_CASE(TestProcessSectionEtherMulticastReinit)
775{
776 const std::string CONFIG_WITH_MCAST =
777 "face_system\n"
778 "{\n"
779 " ether\n"
780 " {\n"
781 " mcast yes\n"
782 " }\n"
783 "}\n";
784 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
785
786 shared_ptr<EthernetFactory> factory =
787 static_pointer_cast<EthernetFactory>(getManager().findFactory("ether"));
788 BOOST_REQUIRE(static_cast<bool>(factory));
789
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300790 if (factory->getMulticastFaces().size() == 0) {
791 BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
792 "no Ethernet multicast faces are available");
793 }
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300794
795 const std::string CONFIG_WITHOUT_MCAST =
796 "face_system\n"
797 "{\n"
798 " ether\n"
799 " {\n"
800 " mcast no\n"
801 " }\n"
802 "}\n";
803 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
804 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
805}
806
807
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600808#endif
809
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700810BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
811{
812 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
813
814 getFace()->onReceiveData +=
815 bind(&FaceManagerFixture::validateControlResponse, this, _1,
816 command->getName(), 400, "Malformed command");
817
818 getFace()->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700819 g_io.run_one();
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700820
821 BOOST_REQUIRE(didCallbackFire());
822}
823
824BOOST_AUTO_TEST_CASE(MalformedCommmand)
825{
826 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
827
828 getFace()->onReceiveData +=
829 bind(&FaceManagerFixture::validateControlResponse, this, _1,
830 command->getName(), 400, "Malformed command");
831
832 getManager().onFaceRequest(*command);
833
834 BOOST_REQUIRE(didCallbackFire());
835}
836
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700837BOOST_AUTO_TEST_CASE(UnsignedCommand)
838{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600839 ControlParameters parameters;
840 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700841
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600842 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700843
844 Name commandName("/localhost/nfd/faces");
845 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600846 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700847
848 shared_ptr<Interest> command(make_shared<Interest>(commandName));
849
850 getFace()->onReceiveData +=
851 bind(&FaceManagerFixture::validateControlResponse, this, _1,
852 command->getName(), 401, "Signature required");
853
854 getManager().onFaceRequest(*command);
855
856 BOOST_REQUIRE(didCallbackFire());
857}
858
859BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>)
860{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600861 ControlParameters parameters;
862 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700863
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600864 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700865
866 Name commandName("/localhost/nfd/faces");
867 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600868 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700869
870 shared_ptr<Interest> command(make_shared<Interest>(commandName));
871 generateCommand(*command);
872
873 getFace()->onReceiveData +=
874 bind(&FaceManagerFixture::validateControlResponse, this, _1,
875 command->getName(), 403, "Unauthorized command");
876
877 getManager().onFaceRequest(*command);
878
879 BOOST_REQUIRE(didCallbackFire());
880}
881
882template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
883{
884public:
885 AuthorizedCommandFixture()
886 {
887 const std::string regex = "^<localhost><nfd><faces>";
888 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
889 }
890
891 virtual
892 ~AuthorizedCommandFixture()
893 {
894
895 }
896};
897
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700898BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700899{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600900 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700901
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600902 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700903
904 Name commandName("/localhost/nfd/faces");
905 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600906 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700907
908 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700909 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700910
911 getFace()->onReceiveData +=
912 bind(&FaceManagerFixture::validateControlResponse, this, _1,
913 command->getName(), 501, "Unsupported command");
914
915 getManager().onFaceRequest(*command);
916
917 BOOST_REQUIRE(didCallbackFire());
918}
919
920class ValidatedFaceRequestFixture : public TestFaceTableFixture,
921 public TestFaceManagerCommon,
922 public FaceManager
923{
924public:
925
926 ValidatedFaceRequestFixture()
Vince Lehman5144f822014-07-23 15:12:56 -0700927 : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face, m_testKeyChain),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700928 m_createFaceFired(false),
929 m_destroyFaceFired(false)
930 {
931
932 }
933
934 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600935 createFace(const Interest& request,
936 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700937 {
938 m_createFaceFired = true;
939 }
940
941 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600942 destroyFace(const Interest& request,
943 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700944 {
945 m_destroyFaceFired = true;
946 }
947
948 virtual
949 ~ValidatedFaceRequestFixture()
950 {
951
952 }
953
954 bool
955 didCreateFaceFire() const
956 {
957 return m_createFaceFired;
958 }
959
960 bool
961 didDestroyFaceFire() const
962 {
963 return m_destroyFaceFired;
964 }
965
966private:
967 bool m_createFaceFired;
968 bool m_destroyFaceFired;
969};
970
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700971BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse,
972 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700973{
974 Name commandName("/localhost/nfd/faces");
975 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600976 commandName.append("NotReallyParameters");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700977
978 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700979 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700980
981 getFace()->onReceiveData +=
982 bind(&ValidatedFaceRequestFixture::validateControlResponse, this, _1,
983 command->getName(), 400, "Malformed command");
984
985 onValidatedFaceRequest(command);
986
987 BOOST_REQUIRE(didCallbackFire());
988}
989
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700990BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace,
991 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700992{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600993 ControlParameters parameters;
994 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700995
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600996 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700997
998 Name commandName("/localhost/nfd/faces");
999 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001000 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001001
1002 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001003 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001004
1005 onValidatedFaceRequest(command);
1006 BOOST_CHECK(didCreateFaceFire());
1007}
1008
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001009BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace,
1010 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001011{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001012 ControlParameters parameters;
1013 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001014
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001015 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001016
1017 Name commandName("/localhost/nfd/faces");
1018 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001019 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001020
1021 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001022 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001023
1024 onValidatedFaceRequest(command);
1025 BOOST_CHECK(didDestroyFaceFire());
1026}
1027
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001028class FaceTableFixture
1029{
1030public:
1031 FaceTableFixture()
1032 : m_faceTable(m_forwarder)
1033 {
1034 }
1035
1036 virtual
1037 ~FaceTableFixture()
1038 {
1039 }
1040
1041protected:
1042 Forwarder m_forwarder;
1043 FaceTable m_faceTable;
1044};
1045
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001046class LocalControlFixture : public FaceTableFixture,
1047 public TestFaceManagerCommon,
1048 public FaceManager
1049{
1050public:
1051 LocalControlFixture()
Vince Lehman5144f822014-07-23 15:12:56 -07001052 : FaceManager(FaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face, m_testKeyChain)
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001053 {
1054 }
1055};
1056
1057BOOST_FIXTURE_TEST_CASE(LocalControlInFaceId,
1058 AuthorizedCommandFixture<LocalControlFixture>)
1059{
1060 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1061 BOOST_REQUIRE(dummy->isLocal());
1062 FaceTableFixture::m_faceTable.add(dummy);
1063
1064 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001065 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1066
1067 Block encodedParameters(parameters.wireEncode());
1068
1069 Name enable("/localhost/nfd/faces/enable-local-control");
1070 enable.append(encodedParameters);
1071
1072 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1073 enableCommand->setIncomingFaceId(dummy->getId());
1074
1075 generateCommand(*enableCommand);
1076
1077 TestFaceManagerCommon::m_face->onReceiveData +=
1078 bind(&LocalControlFixture::validateControlResponse, this, _1,
1079 enableCommand->getName(), 200, "Success", encodedParameters);
1080
1081 onValidatedFaceRequest(enableCommand);
1082
1083 BOOST_REQUIRE(didCallbackFire());
1084 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1085 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1086
1087 TestFaceManagerCommon::m_face->onReceiveData.clear();
1088 resetCallbackFired();
1089
1090 Name disable("/localhost/nfd/faces/disable-local-control");
1091 disable.append(encodedParameters);
1092
1093 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1094 disableCommand->setIncomingFaceId(dummy->getId());
1095
1096 generateCommand(*disableCommand);
1097
1098 TestFaceManagerCommon::m_face->onReceiveData +=
1099 bind(&LocalControlFixture::validateControlResponse, this, _1,
1100 disableCommand->getName(), 200, "Success", encodedParameters);
1101
1102 onValidatedFaceRequest(disableCommand);
1103
1104 BOOST_REQUIRE(didCallbackFire());
1105 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1106 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1107}
1108
1109BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound,
1110 AuthorizedCommandFixture<LocalControlFixture>)
1111{
1112 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1113 BOOST_REQUIRE(dummy->isLocal());
1114 FaceTableFixture::m_faceTable.add(dummy);
1115
1116 ControlParameters parameters;
1117 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1118
1119 Block encodedParameters(parameters.wireEncode());
1120
1121 Name enable("/localhost/nfd/faces/enable-local-control");
1122 enable.append(encodedParameters);
1123
1124 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1125 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1126
1127 generateCommand(*enableCommand);
1128
1129 TestFaceManagerCommon::m_face->onReceiveData +=
1130 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001131 enableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001132
1133 onValidatedFaceRequest(enableCommand);
1134
1135 BOOST_REQUIRE(didCallbackFire());
1136 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1137 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1138
1139 TestFaceManagerCommon::m_face->onReceiveData.clear();
1140 resetCallbackFired();
1141
1142 Name disable("/localhost/nfd/faces/disable-local-control");
1143 disable.append(encodedParameters);
1144
1145 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1146 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1147
1148 generateCommand(*disableCommand);
1149
1150 TestFaceManagerCommon::m_face->onReceiveData +=
1151 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001152 disableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001153
1154 onValidatedFaceRequest(disableCommand);
1155
1156 BOOST_REQUIRE(didCallbackFire());
1157 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1158 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1159}
1160
1161BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature,
1162 AuthorizedCommandFixture<LocalControlFixture>)
1163{
1164 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1165 BOOST_REQUIRE(dummy->isLocal());
1166 FaceTableFixture::m_faceTable.add(dummy);
1167
1168 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001169
1170 Block encodedParameters(parameters.wireEncode());
1171
1172 Name enable("/localhost/nfd/faces/enable-local-control");
1173 enable.append(encodedParameters);
1174
1175 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1176 enableCommand->setIncomingFaceId(dummy->getId());
1177
1178 generateCommand(*enableCommand);
1179
1180 TestFaceManagerCommon::m_face->onReceiveData +=
1181 bind(&LocalControlFixture::validateControlResponse, this, _1,
1182 enableCommand->getName(), 400, "Malformed command");
1183
1184 onValidatedFaceRequest(enableCommand);
1185
1186 BOOST_REQUIRE(didCallbackFire());
1187 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1188 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1189
1190 TestFaceManagerCommon::m_face->onReceiveData.clear();
1191 resetCallbackFired();
1192
1193 Name disable("/localhost/nfd/faces/disable-local-control");
1194 disable.append(encodedParameters);
1195
1196 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1197 disableCommand->setIncomingFaceId(dummy->getId());
1198
1199 generateCommand(*disableCommand);
1200
1201 TestFaceManagerCommon::m_face->onReceiveData +=
1202 bind(&LocalControlFixture::validateControlResponse, this, _1,
1203 disableCommand->getName(), 400, "Malformed command");
1204
1205 onValidatedFaceRequest(disableCommand);
1206
1207 BOOST_REQUIRE(didCallbackFire());
1208 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1209 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1210}
1211
1212BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal,
1213 AuthorizedCommandFixture<LocalControlFixture>)
1214{
1215 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1216 BOOST_REQUIRE(!dummy->isLocal());
1217 FaceTableFixture::m_faceTable.add(dummy);
1218
1219 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001220 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1221
1222 Block encodedParameters(parameters.wireEncode());
1223
1224 Name enable("/localhost/nfd/faces/enable-local-control");
1225 enable.append(encodedParameters);
1226
1227 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1228 enableCommand->setIncomingFaceId(dummy->getId());
1229
1230 generateCommand(*enableCommand);
1231
1232 TestFaceManagerCommon::m_face->onReceiveData +=
1233 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001234 enableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001235
1236 onValidatedFaceRequest(enableCommand);
1237
1238 BOOST_REQUIRE(didCallbackFire());
1239
1240 TestFaceManagerCommon::m_face->onReceiveData.clear();
1241 resetCallbackFired();
1242
1243 Name disable("/localhost/nfd/faces/disable-local-control");
1244 enable.append(encodedParameters);
1245
1246 shared_ptr<Interest> disableCommand(make_shared<Interest>(enable));
1247 disableCommand->setIncomingFaceId(dummy->getId());
1248
1249 generateCommand(*disableCommand);
1250
1251 TestFaceManagerCommon::m_face->onReceiveData +=
1252 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001253 disableCommand->getName(), 412, "Face is non-local");
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
1280 TestFaceManagerCommon::m_face->onReceiveData +=
1281 bind(&LocalControlFixture::validateControlResponse, this, _1,
1282 enableCommand->getName(), 200, "Success", encodedParameters);
1283
1284 onValidatedFaceRequest(enableCommand);
1285
1286 BOOST_REQUIRE(didCallbackFire());
1287 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1288 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1289
1290
1291 TestFaceManagerCommon::m_face->onReceiveData.clear();
1292 resetCallbackFired();
1293
1294 Name disable("/localhost/nfd/faces/disable-local-control");
1295 disable.append(encodedParameters);
1296
1297 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1298 disableCommand->setIncomingFaceId(dummy->getId());
1299
1300 generateCommand(*disableCommand);
1301
1302 TestFaceManagerCommon::m_face->onReceiveData +=
1303 bind(&LocalControlFixture::validateControlResponse, this, _1,
1304 disableCommand->getName(), 200, "Success", encodedParameters);
1305
1306 onValidatedFaceRequest(disableCommand);
1307
1308 BOOST_REQUIRE(didCallbackFire());
1309 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1310 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1311}
1312
1313BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound,
1314 AuthorizedCommandFixture<LocalControlFixture>)
1315{
1316 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1317 BOOST_REQUIRE(dummy->isLocal());
1318 FaceTableFixture::m_faceTable.add(dummy);
1319
1320 ControlParameters parameters;
1321 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1322
1323 Block encodedParameters(parameters.wireEncode());
1324
1325 Name enable("/localhost/nfd/faces/enable-local-control");
1326 enable.append(encodedParameters);
1327
1328 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1329 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1330
1331 generateCommand(*enableCommand);
1332
1333 TestFaceManagerCommon::m_face->onReceiveData +=
1334 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001335 enableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001336
1337 onValidatedFaceRequest(enableCommand);
1338
1339 BOOST_REQUIRE(didCallbackFire());
1340 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1341 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1342
1343
1344 TestFaceManagerCommon::m_face->onReceiveData.clear();
1345 resetCallbackFired();
1346
1347 Name disable("/localhost/nfd/faces/disable-local-control");
1348 disable.append(encodedParameters);
1349
1350 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1351 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1352
1353 generateCommand(*disableCommand);
1354
1355 TestFaceManagerCommon::m_face->onReceiveData +=
1356 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001357 disableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001358
1359 onValidatedFaceRequest(disableCommand);
1360
1361 BOOST_REQUIRE(didCallbackFire());
1362 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1363 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1364}
1365
1366BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal,
1367 AuthorizedCommandFixture<LocalControlFixture>)
1368{
1369 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1370 BOOST_REQUIRE(!dummy->isLocal());
1371 FaceTableFixture::m_faceTable.add(dummy);
1372
1373 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001374 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1375
1376 Block encodedParameters(parameters.wireEncode());
1377
1378 Name enable("/localhost/nfd/faces/enable-local-control");
1379 enable.append(encodedParameters);
1380
1381 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1382 enableCommand->setIncomingFaceId(dummy->getId());
1383
1384 generateCommand(*enableCommand);
1385
1386 TestFaceManagerCommon::m_face->onReceiveData +=
1387 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001388 enableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001389
1390 onValidatedFaceRequest(enableCommand);
1391
1392 BOOST_REQUIRE(didCallbackFire());
1393
1394 TestFaceManagerCommon::m_face->onReceiveData.clear();
1395 resetCallbackFired();
1396
1397 Name disable("/localhost/nfd/faces/disable-local-control");
1398 disable.append(encodedParameters);
1399
1400 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1401 disableCommand->setIncomingFaceId(dummy->getId());
1402
1403 generateCommand(*disableCommand);
1404
1405 TestFaceManagerCommon::m_face->onReceiveData +=
1406 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001407 disableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001408
1409 onValidatedFaceRequest(disableCommand);
1410
1411 BOOST_REQUIRE(didCallbackFire());
1412}
1413
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001414class FaceFixture : public FaceTableFixture,
1415 public TestFaceManagerCommon,
1416 public FaceManager
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001417{
1418public:
1419 FaceFixture()
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001420 : FaceManager(FaceTableFixture::m_faceTable,
Vince Lehman5144f822014-07-23 15:12:56 -07001421 TestFaceManagerCommon::m_face,
1422 m_testKeyChain)
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001423 , m_receivedNotification(false)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001424 {
1425
1426 }
1427
1428 virtual
1429 ~FaceFixture()
1430 {
1431
1432 }
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001433
1434 void
1435 callbackDispatch(const Data& response,
1436 const Name& expectedName,
1437 uint32_t expectedCode,
1438 const std::string& expectedText,
1439 const Block& expectedBody,
1440 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1441 {
1442 Block payload = response.getContent().blockFromValue();
1443 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1444 {
1445 validateControlResponse(response, expectedName, expectedCode,
1446 expectedText, expectedBody);
1447 }
1448 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1449 {
1450 validateFaceEvent(payload, expectedFaceEvent);
1451 }
1452 else
1453 {
1454 BOOST_FAIL("Received unknown message type: #" << payload.type());
1455 }
1456 }
1457
1458 void
1459 callbackDispatch(const Data& response,
1460 const Name& expectedName,
1461 uint32_t expectedCode,
1462 const std::string& expectedText,
1463 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1464 {
1465 Block payload = response.getContent().blockFromValue();
1466 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1467 {
1468 validateControlResponse(response, expectedName,
1469 expectedCode, expectedText);
1470 }
1471 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1472 {
1473 validateFaceEvent(payload, expectedFaceEvent);
1474 }
1475 else
1476 {
1477 BOOST_FAIL("Received unknown message type: #" << payload.type());
1478 }
1479 }
1480
1481 void
1482 validateFaceEvent(const Block& wire,
1483 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1484 {
1485
1486 m_receivedNotification = true;
1487
1488 ndn::nfd::FaceEventNotification notification(wire);
1489
Junxiao Shi6e694322014-04-03 10:27:13 -07001490 BOOST_CHECK_EQUAL(notification.getKind(), expectedFaceEvent.getKind());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001491 BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId());
Junxiao Shi6e694322014-04-03 10:27:13 -07001492 BOOST_CHECK_EQUAL(notification.getRemoteUri(), expectedFaceEvent.getRemoteUri());
1493 BOOST_CHECK_EQUAL(notification.getLocalUri(), expectedFaceEvent.getLocalUri());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001494 }
1495
1496 bool
1497 didReceiveNotication() const
1498 {
1499 return m_receivedNotification;
1500 }
1501
1502protected:
1503 bool m_receivedNotification;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001504};
1505
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001506BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001507{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001508 ControlParameters parameters;
1509 parameters.setUri("tcp:/127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001510
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001511 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001512
1513 Name commandName("/localhost/nfd/faces");
1514 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001515 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001516
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001517 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1518 generateCommand(*command);
1519
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001520 getFace()->onReceiveData +=
1521 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001522 command->getName(), 400, "Malformed command");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001523
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001524 createFace(*command, parameters);
1525
1526 BOOST_REQUIRE(didCallbackFire());
1527}
1528
1529BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>)
1530{
1531 ControlParameters parameters;
1532
1533 Block encodedParameters(parameters.wireEncode());
1534
1535 Name commandName("/localhost/nfd/faces");
1536 commandName.append("create");
1537 commandName.append(encodedParameters);
1538
1539 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1540 generateCommand(*command);
1541
1542 getFace()->onReceiveData +=
1543 bind(&FaceFixture::validateControlResponse, this, _1,
1544 command->getName(), 400, "Malformed command");
1545
1546 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001547
1548 BOOST_REQUIRE(didCallbackFire());
1549}
1550
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001551BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001552{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001553 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001554 // this will be an unsupported protocol because no factories have been
1555 // added to the face manager
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001556 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001557
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001558 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001559
1560 Name commandName("/localhost/nfd/faces");
1561 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001562 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001563
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001564 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1565 generateCommand(*command);
1566
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001567 getFace()->onReceiveData +=
1568 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001569 command->getName(), 501, "Unsupported protocol");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001570
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001571 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001572
1573 BOOST_REQUIRE(didCallbackFire());
1574}
1575
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001576BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001577{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001578 ControlParameters parameters;
1579 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001580
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001581 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001582
1583 Name commandName("/localhost/nfd/faces");
1584 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001585 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001586
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001587 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1588 generateCommand(*command);
1589
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001590 ControlParameters resultParameters;
Steve DiBenedetto25999282014-05-22 15:25:12 -06001591 resultParameters.setUri("dummy://");
Junxiao Shi7b984c62014-07-17 22:18:34 -07001592 resultParameters.setFaceId(FACEID_RESERVED_MAX + 1);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001593
1594 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1595
Junxiao Shi6e694322014-04-03 10:27:13 -07001596 ndn::nfd::FaceEventNotification expectedFaceEvent;
1597 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED)
Junxiao Shi7b984c62014-07-17 22:18:34 -07001598 .setFaceId(FACEID_RESERVED_MAX + 1)
Junxiao Shi6e694322014-04-03 10:27:13 -07001599 .setRemoteUri(dummy->getRemoteUri().toString())
1600 .setLocalUri(dummy->getLocalUri().toString())
1601 .setFlags(0);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001602
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001603 Block encodedResultParameters(resultParameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001604
1605 getFace()->onReceiveData +=
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001606 bind(&FaceFixture::callbackDispatch, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001607 command->getName(), 200, "Success",
1608 encodedResultParameters, expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001609
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001610 onCreated(command->getName(), parameters, dummy);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001611
1612 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001613 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001614}
1615
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001616BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001617{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001618 ControlParameters parameters;
1619 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001620
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001621 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001622
1623 Name commandName("/localhost/nfd/faces");
1624 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001625 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001626
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001627 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1628 generateCommand(*command);
1629
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001630 getFace()->onReceiveData +=
1631 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedettoca53ac62014-03-27 19:58:40 -06001632 command->getName(), 408, "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001633
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001634 onConnectFailed(command->getName(), "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001635
1636 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001637 BOOST_CHECK_EQUAL(didReceiveNotication(), false);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001638}
1639
1640
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001641BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001642{
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001643 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1644 FaceTableFixture::m_faceTable.add(dummy);
1645
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001646 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001647 parameters.setFaceId(dummy->getId());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001648
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001649 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001650
1651 Name commandName("/localhost/nfd/faces");
1652 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001653 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001654
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001655 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1656 generateCommand(*command);
1657
Junxiao Shi6e694322014-04-03 10:27:13 -07001658 ndn::nfd::FaceEventNotification expectedFaceEvent;
1659 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
1660 .setFaceId(dummy->getId())
1661 .setRemoteUri(dummy->getRemoteUri().toString())
1662 .setLocalUri(dummy->getLocalUri().toString())
1663 .setFlags(0);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001664
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001665 getFace()->onReceiveData +=
Alexander Afanasyevf6980282014-05-13 18:28:40 -07001666 bind(&FaceFixture::callbackDispatch, this, _1, command->getName(),
1667 200, "Success", ref(encodedParameters), expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001668
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001669 destroyFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001670
1671 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001672 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001673}
1674
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001675class FaceListFixture : public FaceStatusPublisherFixture
1676{
1677public:
1678 FaceListFixture()
Vince Lehman5144f822014-07-23 15:12:56 -07001679 : m_manager(m_table, m_face, m_testKeyChain)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001680 {
1681
1682 }
1683
1684 virtual
1685 ~FaceListFixture()
1686 {
1687
1688 }
1689
1690protected:
1691 FaceManager m_manager;
Vince Lehman5144f822014-07-23 15:12:56 -07001692 ndn::KeyChain m_testKeyChain;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001693};
1694
1695BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001696{
1697 Name commandName("/localhost/nfd/faces/list");
1698 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1699
Junxiao Shi632a6202014-07-20 01:14:30 -07001700 // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 75
1701 // use 59 FaceStatuses to force a FaceStatus to span Data packets
1702 for (int i = 0; i < 59; i++)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001703 {
1704 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1705
1706 uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
Junxiao Shi632a6202014-07-20 01:14:30 -07001707 dummy->setCounters(filler, filler, filler, filler, filler, filler);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001708
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001709 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001710
1711 add(dummy);
1712 }
1713
1714 ndn::EncodingBuffer buffer;
1715
1716 m_face->onReceiveData +=
1717 bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, this, _1);
1718
1719 m_manager.listFaces(*command);
1720 BOOST_REQUIRE(m_finished);
1721}
1722
Steve DiBenedettoef04f272014-06-04 14:28:31 -06001723class ChannelStatusFixture : public FaceManagerFixture
1724{
1725public:
1726 void
1727 validatePublish(const Data& data, const ndn::nfd::ChannelStatus& expectedEntry)
1728 {
1729 m_callbackFired = true;
1730 Block b = data.getContent().blockFromValue();
1731 ndn::nfd::ChannelStatus entry(b);
1732 BOOST_CHECK_EQUAL(entry.getLocalUri(), expectedEntry.getLocalUri());
1733 }
1734
1735 virtual shared_ptr<DummyProtocolFactory>
1736 addProtocolFactory(const std::string& protocol)
1737 {
1738 shared_ptr<DummyProtocolFactory> factory(make_shared<DummyProtocolFactory>());
1739 m_manager.m_factories[protocol] = factory;
1740
1741 return factory;
1742 }
1743};
1744
1745BOOST_FIXTURE_TEST_CASE(TestChannelStatus, ChannelStatusFixture)
1746{
1747 shared_ptr<DummyProtocolFactory> factory(addProtocolFactory("dummy"));
1748 factory->addChannel("dummy://");
1749
1750 Name requestName("/localhost/nfd/faces/channels");
1751 shared_ptr<Interest> request(make_shared<Interest>(requestName));
1752
1753 ndn::nfd::ChannelStatus expectedEntry;
1754 expectedEntry.setLocalUri(DummyChannel("dummy://").getUri().toString());
1755
1756 m_face->onReceiveData +=
1757 bind(&ChannelStatusFixture::validatePublish, this, _1, expectedEntry);
1758
1759 m_manager.listChannels(*request);
1760 BOOST_REQUIRE(m_callbackFired);
1761}
1762
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001763BOOST_AUTO_TEST_SUITE_END()
1764
1765} // namespace tests
1766} // namespace nfd