blob: 92ec98794b21b6ea323a3043405ebd64586170ba [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;
260};
261
262class FaceManagerFixture : public TestFaceTableFixture, public TestFaceManagerCommon
263{
264public:
265 FaceManagerFixture()
266 : m_manager(m_faceTable, m_face)
267 {
268 m_manager.setConfigFile(m_config);
269 }
270
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700271 virtual
272 ~FaceManagerFixture()
273 {
274
275 }
276
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600277 void
278 parseConfig(const std::string configuration, bool isDryRun)
279 {
280 m_config.parse(configuration, isDryRun, "dummy-config");
281 }
282
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700283 FaceManager&
284 getManager()
285 {
286 return m_manager;
287 }
288
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700289 void
290 addInterestRule(const std::string& regex,
291 ndn::IdentityCertificate& certificate)
292 {
293 m_manager.addInterestRule(regex, certificate);
294 }
295
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700296 bool
297 didFaceTableAddFire() const
298 {
299 return m_faceTable.didAddFire();
300 }
301
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700302 bool
303 didFaceTableGetFire() const
304 {
305 return m_faceTable.didGetFire();
306 }
307
308 void
309 resetFaceTable()
310 {
311 m_faceTable.reset();
312 }
313
Steve DiBenedettoef04f272014-06-04 14:28:31 -0600314protected:
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700315 FaceManager m_manager;
316 ConfigFile m_config;
317};
318
319BOOST_FIXTURE_TEST_SUITE(MgmtFaceManager, FaceManagerFixture)
320
321bool
322isExpectedException(const ConfigFile::Error& error, const std::string& expectedMessage)
323{
324 if (error.what() != expectedMessage)
325 {
326 NFD_LOG_ERROR("expected: " << expectedMessage << "\tgot: " << error.what());
327 }
328 return error.what() == expectedMessage;
329}
330
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600331#ifdef HAVE_UNIX_SOCKETS
332
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700333BOOST_AUTO_TEST_CASE(TestProcessSectionUnix)
334{
335 const std::string CONFIG =
336 "face_system\n"
337 "{\n"
338 " unix\n"
339 " {\n"
340 " listen yes\n"
341 " path /tmp/nfd.sock\n"
342 " }\n"
343 "}\n";
344 BOOST_TEST_CHECKPOINT("Calling parse");
345 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
346}
347
348BOOST_AUTO_TEST_CASE(TestProcessSectionUnixDryRun)
349{
350 const std::string CONFIG =
351 "face_system\n"
352 "{\n"
353 " unix\n"
354 " {\n"
355 " listen yes\n"
356 " path /var/run/nfd.sock\n"
357 " }\n"
358 "}\n";
359
360 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
361}
362
363BOOST_AUTO_TEST_CASE(TestProcessSectionUnixBadListen)
364{
365 const std::string CONFIG =
366 "face_system\n"
367 "{\n"
368 " unix\n"
369 " {\n"
370 " listen hello\n"
371 " }\n"
372 "}\n";
373 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
374 bind(&isExpectedException, _1,
375 "Invalid value for option \"listen\" in \"unix\" section"));
376}
377
378BOOST_AUTO_TEST_CASE(TestProcessSectionUnixUnknownOption)
379{
380 const std::string CONFIG =
381 "face_system\n"
382 "{\n"
383 " unix\n"
384 " {\n"
385 " hello\n"
386 " }\n"
387 "}\n";
388 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
389 bind(&isExpectedException, _1,
390 "Unrecognized option \"hello\" in \"unix\" section"));
391}
392
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600393#endif // HAVE_UNIX_SOCKETS
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700394
395
396BOOST_AUTO_TEST_CASE(TestProcessSectionTcp)
397{
398 const std::string CONFIG =
399 "face_system\n"
400 "{\n"
401 " tcp\n"
402 " {\n"
403 " listen yes\n"
404 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600405 " enable_v4 yes\n"
406 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700407 " }\n"
408 "}\n";
409 try
410 {
411 parseConfig(CONFIG, false);
412 }
413 catch (const std::runtime_error& e)
414 {
415 const std::string reason = e.what();
416 if (reason.find("Address in use") != std::string::npos)
417 {
418 BOOST_FAIL(reason);
419 }
420 }
421}
422
423BOOST_AUTO_TEST_CASE(TestProcessSectionTcpDryRun)
424{
425 const std::string CONFIG =
426 "face_system\n"
427 "{\n"
428 " tcp\n"
429 " {\n"
430 " listen yes\n"
431 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600432 " enable_v4 yes\n"
433 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700434 " }\n"
435 "}\n";
436 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
437}
438
439BOOST_AUTO_TEST_CASE(TestProcessSectionTcpBadListen)
440{
441 const std::string CONFIG =
442 "face_system\n"
443 "{\n"
444 " tcp\n"
445 " {\n"
446 " listen hello\n"
447 " }\n"
448 "}\n";
449 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
450 bind(&isExpectedException, _1,
451 "Invalid value for option \"listen\" in \"tcp\" section"));
452}
453
Steve DiBenedetto95152872014-04-11 12:40:59 -0600454BOOST_AUTO_TEST_CASE(TestProcessSectionTcpChannelsDisabled)
455{
456 const std::string CONFIG =
457 "face_system\n"
458 "{\n"
459 " tcp\n"
460 " {\n"
461 " port 6363\n"
462 " enable_v4 no\n"
463 " enable_v6 no\n"
464 " }\n"
465 "}\n";
466 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
467 bind(&isExpectedException, _1,
468 "IPv4 and IPv6 channels have been disabled."
469 " Remove \"tcp\" section to disable TCP channels or"
470 " re-enable at least one channel type."));
471}
472
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700473BOOST_AUTO_TEST_CASE(TestProcessSectionTcpUnknownOption)
474{
475 const std::string CONFIG =
476 "face_system\n"
477 "{\n"
478 " tcp\n"
479 " {\n"
480 " hello\n"
481 " }\n"
482 "}\n";
483 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
484 bind(&isExpectedException, _1,
485 "Unrecognized option \"hello\" in \"tcp\" section"));
486}
487
488BOOST_AUTO_TEST_CASE(TestProcessSectionUdp)
489{
490 const std::string CONFIG =
491 "face_system\n"
492 "{\n"
493 " udp\n"
494 " {\n"
495 " port 6363\n"
Steve DiBenedetto95152872014-04-11 12:40:59 -0600496 " enable_v4 yes\n"
497 " enable_v6 yes\n"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700498 " idle_timeout 30\n"
499 " keep_alive_interval 25\n"
500 " mcast yes\n"
501 " mcast_port 56363\n"
502 " mcast_group 224.0.23.170\n"
503 " }\n"
504 "}\n";
505 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
506}
507
508BOOST_AUTO_TEST_CASE(TestProcessSectionUdpDryRun)
509{
510 const std::string CONFIG =
511 "face_system\n"
512 "{\n"
513 " udp\n"
514 " {\n"
515 " port 6363\n"
516 " idle_timeout 30\n"
517 " keep_alive_interval 25\n"
518 " mcast yes\n"
519 " mcast_port 56363\n"
520 " mcast_group 224.0.23.170\n"
521 " }\n"
522 "}\n";
523 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
524}
525
526BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadIdleTimeout)
527{
528 const std::string CONFIG =
529 "face_system\n"
530 "{\n"
531 " udp\n"
532 " {\n"
533 " idle_timeout hello\n"
534 " }\n"
535 "}\n";
536
537 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
538 bind(&isExpectedException, _1,
539 "Invalid value for option \"idle_timeout\" in \"udp\" section"));
540}
541
542BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcast)
543{
544 const std::string CONFIG =
545 "face_system\n"
546 "{\n"
547 " udp\n"
548 " {\n"
549 " mcast hello\n"
550 " }\n"
551 "}\n";
552
553 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
554 bind(&isExpectedException, _1,
555 "Invalid value for option \"mcast\" in \"udp\" section"));
556}
557
558BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroup)
559{
560 const std::string CONFIG =
561 "face_system\n"
562 "{\n"
563 " udp\n"
564 " {\n"
565 " mcast no\n"
566 " mcast_port 50\n"
567 " mcast_group hello\n"
568 " }\n"
569 "}\n";
570
571 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
572 bind(&isExpectedException, _1,
573 "Invalid value for option \"mcast_group\" in \"udp\" section"));
574}
575
576BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroupV6)
577{
578 const std::string CONFIG =
579 "face_system\n"
580 "{\n"
581 " udp\n"
582 " {\n"
583 " mcast no\n"
584 " mcast_port 50\n"
585 " mcast_group ::1\n"
586 " }\n"
587 "}\n";
588
589 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
590 bind(&isExpectedException, _1,
591 "Invalid value for option \"mcast_group\" in \"udp\" section"));
592}
593
Steve DiBenedetto95152872014-04-11 12:40:59 -0600594BOOST_AUTO_TEST_CASE(TestProcessSectionUdpChannelsDisabled)
595{
596 const std::string CONFIG =
597 "face_system\n"
598 "{\n"
599 " udp\n"
600 " {\n"
601 " port 6363\n"
602 " enable_v4 no\n"
603 " enable_v6 no\n"
604 " idle_timeout 30\n"
605 " keep_alive_interval 25\n"
606 " mcast yes\n"
607 " mcast_port 56363\n"
608 " mcast_group 224.0.23.170\n"
609 " }\n"
610 "}\n";
611 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
612 bind(&isExpectedException, _1,
613 "IPv4 and IPv6 channels have been disabled."
614 " Remove \"udp\" section to disable UDP channels or"
615 " re-enable at least one channel type."));
616}
617
618BOOST_AUTO_TEST_CASE(TestProcessSectionUdpConflictingMcast)
619{
620 const std::string CONFIG =
621 "face_system\n"
622 "{\n"
623 " udp\n"
624 " {\n"
625 " port 6363\n"
626 " enable_v4 no\n"
627 " enable_v6 yes\n"
628 " idle_timeout 30\n"
629 " keep_alive_interval 25\n"
630 " mcast yes\n"
631 " mcast_port 56363\n"
632 " mcast_group 224.0.23.170\n"
633 " }\n"
634 "}\n";
635 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
636 bind(&isExpectedException, _1,
637 "IPv4 multicast requested, but IPv4 channels"
638 " have been disabled (conflicting configuration options set)"));
639}
640
641
642
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700643BOOST_AUTO_TEST_CASE(TestProcessSectionUdpUnknownOption)
644{
645 const std::string CONFIG =
646 "face_system\n"
647 "{\n"
648 " udp\n"
649 " {\n"
650 " hello\n"
651 " }\n"
652 "}\n";
653 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
654 bind(&isExpectedException, _1,
655 "Unrecognized option \"hello\" in \"udp\" section"));
656}
657
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300658
659BOOST_AUTO_TEST_CASE(TestProcessSectionUdpMulticastReinit)
660{
661 const std::string CONFIG_WITH_MCAST =
662 "face_system\n"
663 "{\n"
664 " udp\n"
665 " {\n"
666 " mcast yes\n"
667 " }\n"
668 "}\n";
669 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
670
671 shared_ptr<UdpFactory> factory = static_pointer_cast<UdpFactory>(getManager().findFactory("udp"));
672 BOOST_REQUIRE(static_cast<bool>(factory));
673
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300674 if (factory->getMulticastFaces().size() == 0) {
675 BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
676 "no UDP multicast faces are available");
677 }
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300678
679 const std::string CONFIG_WITHOUT_MCAST =
680 "face_system\n"
681 "{\n"
682 " udp\n"
683 " {\n"
684 " mcast no\n"
685 " }\n"
686 "}\n";
687 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
688 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
689}
690
691
Alexander Afanasyev885a85b2014-04-12 21:01:13 -0700692#ifdef HAVE_LIBPCAP
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600693
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700694BOOST_AUTO_TEST_CASE(TestProcessSectionEther)
695{
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600696
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700697 const std::string CONFIG =
698 "face_system\n"
699 "{\n"
700 " ether\n"
701 " {\n"
702 " mcast yes\n"
703 " mcast_group 01:00:5E:00:17:AA\n"
704 " }\n"
705 "}\n";
706
707 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
708}
709
710BOOST_AUTO_TEST_CASE(TestProcessSectionEtherDryRun)
711{
712 const std::string CONFIG =
713 "face_system\n"
714 "{\n"
715 " ether\n"
716 " {\n"
717 " mcast yes\n"
718 " mcast_group 01:00:5E:00:17:AA\n"
719 " }\n"
720 "}\n";
721
722 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
723}
724
725BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcast)
726{
727 const std::string CONFIG =
728 "face_system\n"
729 "{\n"
730 " ether\n"
731 " {\n"
732 " mcast hello\n"
733 " }\n"
734 "}\n";
735
736 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
737 bind(&isExpectedException, _1,
738 "Invalid value for option \"mcast\" in \"ether\" section"));
739}
740
741BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcastGroup)
742{
743 const std::string CONFIG =
744 "face_system\n"
745 "{\n"
746 " ether\n"
747 " {\n"
748 " mcast yes\n"
749 " mcast_group\n"
750 " }\n"
751 "}\n";
752
753 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
754 bind(&isExpectedException, _1,
755 "Invalid value for option \"mcast_group\" in \"ether\" section"));
756}
757
758BOOST_AUTO_TEST_CASE(TestProcessSectionEtherUnknownOption)
759{
760 const std::string CONFIG =
761 "face_system\n"
762 "{\n"
763 " ether\n"
764 " {\n"
765 " hello\n"
766 " }\n"
767 "}\n";
768 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
769 bind(&isExpectedException, _1,
770 "Unrecognized option \"hello\" in \"ether\" section"));
771}
772
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300773BOOST_AUTO_TEST_CASE(TestProcessSectionEtherMulticastReinit)
774{
775 const std::string CONFIG_WITH_MCAST =
776 "face_system\n"
777 "{\n"
778 " ether\n"
779 " {\n"
780 " mcast yes\n"
781 " }\n"
782 "}\n";
783 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
784
785 shared_ptr<EthernetFactory> factory =
786 static_pointer_cast<EthernetFactory>(getManager().findFactory("ether"));
787 BOOST_REQUIRE(static_cast<bool>(factory));
788
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300789 if (factory->getMulticastFaces().size() == 0) {
790 BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
791 "no Ethernet multicast faces are available");
792 }
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300793
794 const std::string CONFIG_WITHOUT_MCAST =
795 "face_system\n"
796 "{\n"
797 " ether\n"
798 " {\n"
799 " mcast no\n"
800 " }\n"
801 "}\n";
802 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
803 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
804}
805
806
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600807#endif
808
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700809BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
810{
811 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
812
813 getFace()->onReceiveData +=
814 bind(&FaceManagerFixture::validateControlResponse, this, _1,
815 command->getName(), 400, "Malformed command");
816
817 getFace()->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700818 g_io.run_one();
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700819
820 BOOST_REQUIRE(didCallbackFire());
821}
822
823BOOST_AUTO_TEST_CASE(MalformedCommmand)
824{
825 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
826
827 getFace()->onReceiveData +=
828 bind(&FaceManagerFixture::validateControlResponse, this, _1,
829 command->getName(), 400, "Malformed command");
830
831 getManager().onFaceRequest(*command);
832
833 BOOST_REQUIRE(didCallbackFire());
834}
835
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700836BOOST_AUTO_TEST_CASE(UnsignedCommand)
837{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600838 ControlParameters parameters;
839 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700840
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600841 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700842
843 Name commandName("/localhost/nfd/faces");
844 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600845 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700846
847 shared_ptr<Interest> command(make_shared<Interest>(commandName));
848
849 getFace()->onReceiveData +=
850 bind(&FaceManagerFixture::validateControlResponse, this, _1,
851 command->getName(), 401, "Signature required");
852
853 getManager().onFaceRequest(*command);
854
855 BOOST_REQUIRE(didCallbackFire());
856}
857
858BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>)
859{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600860 ControlParameters parameters;
861 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700862
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600863 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700864
865 Name commandName("/localhost/nfd/faces");
866 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600867 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700868
869 shared_ptr<Interest> command(make_shared<Interest>(commandName));
870 generateCommand(*command);
871
872 getFace()->onReceiveData +=
873 bind(&FaceManagerFixture::validateControlResponse, this, _1,
874 command->getName(), 403, "Unauthorized command");
875
876 getManager().onFaceRequest(*command);
877
878 BOOST_REQUIRE(didCallbackFire());
879}
880
881template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
882{
883public:
884 AuthorizedCommandFixture()
885 {
886 const std::string regex = "^<localhost><nfd><faces>";
887 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
888 }
889
890 virtual
891 ~AuthorizedCommandFixture()
892 {
893
894 }
895};
896
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700897BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700898{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600899 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700900
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600901 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700902
903 Name commandName("/localhost/nfd/faces");
904 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600905 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700906
907 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700908 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700909
910 getFace()->onReceiveData +=
911 bind(&FaceManagerFixture::validateControlResponse, this, _1,
912 command->getName(), 501, "Unsupported command");
913
914 getManager().onFaceRequest(*command);
915
916 BOOST_REQUIRE(didCallbackFire());
917}
918
919class ValidatedFaceRequestFixture : public TestFaceTableFixture,
920 public TestFaceManagerCommon,
921 public FaceManager
922{
923public:
924
925 ValidatedFaceRequestFixture()
926 : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face),
927 m_createFaceFired(false),
928 m_destroyFaceFired(false)
929 {
930
931 }
932
933 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600934 createFace(const Interest& request,
935 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700936 {
937 m_createFaceFired = true;
938 }
939
940 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600941 destroyFace(const Interest& request,
942 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700943 {
944 m_destroyFaceFired = true;
945 }
946
947 virtual
948 ~ValidatedFaceRequestFixture()
949 {
950
951 }
952
953 bool
954 didCreateFaceFire() const
955 {
956 return m_createFaceFired;
957 }
958
959 bool
960 didDestroyFaceFire() const
961 {
962 return m_destroyFaceFired;
963 }
964
965private:
966 bool m_createFaceFired;
967 bool m_destroyFaceFired;
968};
969
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700970BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse,
971 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700972{
973 Name commandName("/localhost/nfd/faces");
974 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600975 commandName.append("NotReallyParameters");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700976
977 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700978 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700979
980 getFace()->onReceiveData +=
981 bind(&ValidatedFaceRequestFixture::validateControlResponse, this, _1,
982 command->getName(), 400, "Malformed command");
983
984 onValidatedFaceRequest(command);
985
986 BOOST_REQUIRE(didCallbackFire());
987}
988
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700989BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace,
990 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700991{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600992 ControlParameters parameters;
993 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700994
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600995 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700996
997 Name commandName("/localhost/nfd/faces");
998 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600999 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001000
1001 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001002 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001003
1004 onValidatedFaceRequest(command);
1005 BOOST_CHECK(didCreateFaceFire());
1006}
1007
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001008BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace,
1009 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001010{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001011 ControlParameters parameters;
1012 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001013
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001014 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001015
1016 Name commandName("/localhost/nfd/faces");
1017 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001018 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001019
1020 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001021 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001022
1023 onValidatedFaceRequest(command);
1024 BOOST_CHECK(didDestroyFaceFire());
1025}
1026
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001027class FaceTableFixture
1028{
1029public:
1030 FaceTableFixture()
1031 : m_faceTable(m_forwarder)
1032 {
1033 }
1034
1035 virtual
1036 ~FaceTableFixture()
1037 {
1038 }
1039
1040protected:
1041 Forwarder m_forwarder;
1042 FaceTable m_faceTable;
1043};
1044
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001045class LocalControlFixture : public FaceTableFixture,
1046 public TestFaceManagerCommon,
1047 public FaceManager
1048{
1049public:
1050 LocalControlFixture()
1051 : FaceManager(FaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face)
1052 {
1053 }
1054};
1055
1056BOOST_FIXTURE_TEST_CASE(LocalControlInFaceId,
1057 AuthorizedCommandFixture<LocalControlFixture>)
1058{
1059 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1060 BOOST_REQUIRE(dummy->isLocal());
1061 FaceTableFixture::m_faceTable.add(dummy);
1062
1063 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001064 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1065
1066 Block encodedParameters(parameters.wireEncode());
1067
1068 Name enable("/localhost/nfd/faces/enable-local-control");
1069 enable.append(encodedParameters);
1070
1071 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1072 enableCommand->setIncomingFaceId(dummy->getId());
1073
1074 generateCommand(*enableCommand);
1075
1076 TestFaceManagerCommon::m_face->onReceiveData +=
1077 bind(&LocalControlFixture::validateControlResponse, this, _1,
1078 enableCommand->getName(), 200, "Success", encodedParameters);
1079
1080 onValidatedFaceRequest(enableCommand);
1081
1082 BOOST_REQUIRE(didCallbackFire());
1083 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1084 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1085
1086 TestFaceManagerCommon::m_face->onReceiveData.clear();
1087 resetCallbackFired();
1088
1089 Name disable("/localhost/nfd/faces/disable-local-control");
1090 disable.append(encodedParameters);
1091
1092 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1093 disableCommand->setIncomingFaceId(dummy->getId());
1094
1095 generateCommand(*disableCommand);
1096
1097 TestFaceManagerCommon::m_face->onReceiveData +=
1098 bind(&LocalControlFixture::validateControlResponse, this, _1,
1099 disableCommand->getName(), 200, "Success", encodedParameters);
1100
1101 onValidatedFaceRequest(disableCommand);
1102
1103 BOOST_REQUIRE(didCallbackFire());
1104 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1105 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1106}
1107
1108BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound,
1109 AuthorizedCommandFixture<LocalControlFixture>)
1110{
1111 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1112 BOOST_REQUIRE(dummy->isLocal());
1113 FaceTableFixture::m_faceTable.add(dummy);
1114
1115 ControlParameters parameters;
1116 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1117
1118 Block encodedParameters(parameters.wireEncode());
1119
1120 Name enable("/localhost/nfd/faces/enable-local-control");
1121 enable.append(encodedParameters);
1122
1123 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1124 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1125
1126 generateCommand(*enableCommand);
1127
1128 TestFaceManagerCommon::m_face->onReceiveData +=
1129 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001130 enableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001131
1132 onValidatedFaceRequest(enableCommand);
1133
1134 BOOST_REQUIRE(didCallbackFire());
1135 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1136 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1137
1138 TestFaceManagerCommon::m_face->onReceiveData.clear();
1139 resetCallbackFired();
1140
1141 Name disable("/localhost/nfd/faces/disable-local-control");
1142 disable.append(encodedParameters);
1143
1144 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1145 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1146
1147 generateCommand(*disableCommand);
1148
1149 TestFaceManagerCommon::m_face->onReceiveData +=
1150 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001151 disableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001152
1153 onValidatedFaceRequest(disableCommand);
1154
1155 BOOST_REQUIRE(didCallbackFire());
1156 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1157 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1158}
1159
1160BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature,
1161 AuthorizedCommandFixture<LocalControlFixture>)
1162{
1163 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1164 BOOST_REQUIRE(dummy->isLocal());
1165 FaceTableFixture::m_faceTable.add(dummy);
1166
1167 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001168
1169 Block encodedParameters(parameters.wireEncode());
1170
1171 Name enable("/localhost/nfd/faces/enable-local-control");
1172 enable.append(encodedParameters);
1173
1174 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1175 enableCommand->setIncomingFaceId(dummy->getId());
1176
1177 generateCommand(*enableCommand);
1178
1179 TestFaceManagerCommon::m_face->onReceiveData +=
1180 bind(&LocalControlFixture::validateControlResponse, this, _1,
1181 enableCommand->getName(), 400, "Malformed command");
1182
1183 onValidatedFaceRequest(enableCommand);
1184
1185 BOOST_REQUIRE(didCallbackFire());
1186 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1187 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1188
1189 TestFaceManagerCommon::m_face->onReceiveData.clear();
1190 resetCallbackFired();
1191
1192 Name disable("/localhost/nfd/faces/disable-local-control");
1193 disable.append(encodedParameters);
1194
1195 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1196 disableCommand->setIncomingFaceId(dummy->getId());
1197
1198 generateCommand(*disableCommand);
1199
1200 TestFaceManagerCommon::m_face->onReceiveData +=
1201 bind(&LocalControlFixture::validateControlResponse, this, _1,
1202 disableCommand->getName(), 400, "Malformed command");
1203
1204 onValidatedFaceRequest(disableCommand);
1205
1206 BOOST_REQUIRE(didCallbackFire());
1207 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1208 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1209}
1210
1211BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal,
1212 AuthorizedCommandFixture<LocalControlFixture>)
1213{
1214 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1215 BOOST_REQUIRE(!dummy->isLocal());
1216 FaceTableFixture::m_faceTable.add(dummy);
1217
1218 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001219 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1220
1221 Block encodedParameters(parameters.wireEncode());
1222
1223 Name enable("/localhost/nfd/faces/enable-local-control");
1224 enable.append(encodedParameters);
1225
1226 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1227 enableCommand->setIncomingFaceId(dummy->getId());
1228
1229 generateCommand(*enableCommand);
1230
1231 TestFaceManagerCommon::m_face->onReceiveData +=
1232 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001233 enableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001234
1235 onValidatedFaceRequest(enableCommand);
1236
1237 BOOST_REQUIRE(didCallbackFire());
1238
1239 TestFaceManagerCommon::m_face->onReceiveData.clear();
1240 resetCallbackFired();
1241
1242 Name disable("/localhost/nfd/faces/disable-local-control");
1243 enable.append(encodedParameters);
1244
1245 shared_ptr<Interest> disableCommand(make_shared<Interest>(enable));
1246 disableCommand->setIncomingFaceId(dummy->getId());
1247
1248 generateCommand(*disableCommand);
1249
1250 TestFaceManagerCommon::m_face->onReceiveData +=
1251 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001252 disableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001253
1254 onValidatedFaceRequest(disableCommand);
1255
1256 BOOST_REQUIRE(didCallbackFire());
1257}
1258
1259BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId,
1260 AuthorizedCommandFixture<LocalControlFixture>)
1261{
1262 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1263 BOOST_REQUIRE(dummy->isLocal());
1264 FaceTableFixture::m_faceTable.add(dummy);
1265
1266 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001267 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1268
1269 Block encodedParameters(parameters.wireEncode());
1270
1271 Name enable("/localhost/nfd/faces/enable-local-control");
1272 enable.append(encodedParameters);
1273
1274 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1275 enableCommand->setIncomingFaceId(dummy->getId());
1276
1277 generateCommand(*enableCommand);
1278
1279 TestFaceManagerCommon::m_face->onReceiveData +=
1280 bind(&LocalControlFixture::validateControlResponse, this, _1,
1281 enableCommand->getName(), 200, "Success", encodedParameters);
1282
1283 onValidatedFaceRequest(enableCommand);
1284
1285 BOOST_REQUIRE(didCallbackFire());
1286 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1287 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1288
1289
1290 TestFaceManagerCommon::m_face->onReceiveData.clear();
1291 resetCallbackFired();
1292
1293 Name disable("/localhost/nfd/faces/disable-local-control");
1294 disable.append(encodedParameters);
1295
1296 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1297 disableCommand->setIncomingFaceId(dummy->getId());
1298
1299 generateCommand(*disableCommand);
1300
1301 TestFaceManagerCommon::m_face->onReceiveData +=
1302 bind(&LocalControlFixture::validateControlResponse, this, _1,
1303 disableCommand->getName(), 200, "Success", encodedParameters);
1304
1305 onValidatedFaceRequest(disableCommand);
1306
1307 BOOST_REQUIRE(didCallbackFire());
1308 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1309 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1310}
1311
1312BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound,
1313 AuthorizedCommandFixture<LocalControlFixture>)
1314{
1315 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1316 BOOST_REQUIRE(dummy->isLocal());
1317 FaceTableFixture::m_faceTable.add(dummy);
1318
1319 ControlParameters parameters;
1320 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1321
1322 Block encodedParameters(parameters.wireEncode());
1323
1324 Name enable("/localhost/nfd/faces/enable-local-control");
1325 enable.append(encodedParameters);
1326
1327 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1328 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1329
1330 generateCommand(*enableCommand);
1331
1332 TestFaceManagerCommon::m_face->onReceiveData +=
1333 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001334 enableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001335
1336 onValidatedFaceRequest(enableCommand);
1337
1338 BOOST_REQUIRE(didCallbackFire());
1339 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1340 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1341
1342
1343 TestFaceManagerCommon::m_face->onReceiveData.clear();
1344 resetCallbackFired();
1345
1346 Name disable("/localhost/nfd/faces/disable-local-control");
1347 disable.append(encodedParameters);
1348
1349 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1350 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1351
1352 generateCommand(*disableCommand);
1353
1354 TestFaceManagerCommon::m_face->onReceiveData +=
1355 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001356 disableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001357
1358 onValidatedFaceRequest(disableCommand);
1359
1360 BOOST_REQUIRE(didCallbackFire());
1361 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1362 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1363}
1364
1365BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal,
1366 AuthorizedCommandFixture<LocalControlFixture>)
1367{
1368 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1369 BOOST_REQUIRE(!dummy->isLocal());
1370 FaceTableFixture::m_faceTable.add(dummy);
1371
1372 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001373 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1374
1375 Block encodedParameters(parameters.wireEncode());
1376
1377 Name enable("/localhost/nfd/faces/enable-local-control");
1378 enable.append(encodedParameters);
1379
1380 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1381 enableCommand->setIncomingFaceId(dummy->getId());
1382
1383 generateCommand(*enableCommand);
1384
1385 TestFaceManagerCommon::m_face->onReceiveData +=
1386 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001387 enableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001388
1389 onValidatedFaceRequest(enableCommand);
1390
1391 BOOST_REQUIRE(didCallbackFire());
1392
1393 TestFaceManagerCommon::m_face->onReceiveData.clear();
1394 resetCallbackFired();
1395
1396 Name disable("/localhost/nfd/faces/disable-local-control");
1397 disable.append(encodedParameters);
1398
1399 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1400 disableCommand->setIncomingFaceId(dummy->getId());
1401
1402 generateCommand(*disableCommand);
1403
1404 TestFaceManagerCommon::m_face->onReceiveData +=
1405 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001406 disableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001407
1408 onValidatedFaceRequest(disableCommand);
1409
1410 BOOST_REQUIRE(didCallbackFire());
1411}
1412
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001413class FaceFixture : public FaceTableFixture,
1414 public TestFaceManagerCommon,
1415 public FaceManager
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001416{
1417public:
1418 FaceFixture()
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001419 : FaceManager(FaceTableFixture::m_faceTable,
1420 TestFaceManagerCommon::m_face)
1421 , m_receivedNotification(false)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001422 {
1423
1424 }
1425
1426 virtual
1427 ~FaceFixture()
1428 {
1429
1430 }
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001431
1432 void
1433 callbackDispatch(const Data& response,
1434 const Name& expectedName,
1435 uint32_t expectedCode,
1436 const std::string& expectedText,
1437 const Block& expectedBody,
1438 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1439 {
1440 Block payload = response.getContent().blockFromValue();
1441 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1442 {
1443 validateControlResponse(response, expectedName, expectedCode,
1444 expectedText, expectedBody);
1445 }
1446 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1447 {
1448 validateFaceEvent(payload, expectedFaceEvent);
1449 }
1450 else
1451 {
1452 BOOST_FAIL("Received unknown message type: #" << payload.type());
1453 }
1454 }
1455
1456 void
1457 callbackDispatch(const Data& response,
1458 const Name& expectedName,
1459 uint32_t expectedCode,
1460 const std::string& expectedText,
1461 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1462 {
1463 Block payload = response.getContent().blockFromValue();
1464 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1465 {
1466 validateControlResponse(response, expectedName,
1467 expectedCode, expectedText);
1468 }
1469 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1470 {
1471 validateFaceEvent(payload, expectedFaceEvent);
1472 }
1473 else
1474 {
1475 BOOST_FAIL("Received unknown message type: #" << payload.type());
1476 }
1477 }
1478
1479 void
1480 validateFaceEvent(const Block& wire,
1481 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1482 {
1483
1484 m_receivedNotification = true;
1485
1486 ndn::nfd::FaceEventNotification notification(wire);
1487
Junxiao Shi6e694322014-04-03 10:27:13 -07001488 BOOST_CHECK_EQUAL(notification.getKind(), expectedFaceEvent.getKind());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001489 BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId());
Junxiao Shi6e694322014-04-03 10:27:13 -07001490 BOOST_CHECK_EQUAL(notification.getRemoteUri(), expectedFaceEvent.getRemoteUri());
1491 BOOST_CHECK_EQUAL(notification.getLocalUri(), expectedFaceEvent.getLocalUri());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001492 }
1493
1494 bool
1495 didReceiveNotication() const
1496 {
1497 return m_receivedNotification;
1498 }
1499
1500protected:
1501 bool m_receivedNotification;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001502};
1503
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001504BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001505{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001506 ControlParameters parameters;
1507 parameters.setUri("tcp:/127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001508
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001509 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001510
1511 Name commandName("/localhost/nfd/faces");
1512 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001513 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001514
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001515 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1516 generateCommand(*command);
1517
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001518 getFace()->onReceiveData +=
1519 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001520 command->getName(), 400, "Malformed command");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001521
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001522 createFace(*command, parameters);
1523
1524 BOOST_REQUIRE(didCallbackFire());
1525}
1526
1527BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>)
1528{
1529 ControlParameters parameters;
1530
1531 Block encodedParameters(parameters.wireEncode());
1532
1533 Name commandName("/localhost/nfd/faces");
1534 commandName.append("create");
1535 commandName.append(encodedParameters);
1536
1537 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1538 generateCommand(*command);
1539
1540 getFace()->onReceiveData +=
1541 bind(&FaceFixture::validateControlResponse, this, _1,
1542 command->getName(), 400, "Malformed command");
1543
1544 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001545
1546 BOOST_REQUIRE(didCallbackFire());
1547}
1548
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001549BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001550{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001551 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001552 // this will be an unsupported protocol because no factories have been
1553 // added to the face manager
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001554 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001555
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001556 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001557
1558 Name commandName("/localhost/nfd/faces");
1559 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001560 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001561
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001562 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1563 generateCommand(*command);
1564
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001565 getFace()->onReceiveData +=
1566 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001567 command->getName(), 501, "Unsupported protocol");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001568
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001569 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001570
1571 BOOST_REQUIRE(didCallbackFire());
1572}
1573
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001574BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001575{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001576 ControlParameters parameters;
1577 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001578
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001579 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001580
1581 Name commandName("/localhost/nfd/faces");
1582 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001583 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001584
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001585 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1586 generateCommand(*command);
1587
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001588 ControlParameters resultParameters;
Steve DiBenedetto25999282014-05-22 15:25:12 -06001589 resultParameters.setUri("dummy://");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001590 resultParameters.setFaceId(1);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001591
1592 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1593
Junxiao Shi6e694322014-04-03 10:27:13 -07001594 ndn::nfd::FaceEventNotification expectedFaceEvent;
1595 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED)
1596 .setFaceId(1)
1597 .setRemoteUri(dummy->getRemoteUri().toString())
1598 .setLocalUri(dummy->getLocalUri().toString())
1599 .setFlags(0);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001600
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001601 Block encodedResultParameters(resultParameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001602
1603 getFace()->onReceiveData +=
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001604 bind(&FaceFixture::callbackDispatch, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001605 command->getName(), 200, "Success",
1606 encodedResultParameters, expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001607
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001608 onCreated(command->getName(), parameters, dummy);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001609
1610 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001611 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001612}
1613
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001614BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001615{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001616 ControlParameters parameters;
1617 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001618
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001619 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001620
1621 Name commandName("/localhost/nfd/faces");
1622 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001623 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001624
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001625 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1626 generateCommand(*command);
1627
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001628 getFace()->onReceiveData +=
1629 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedettoca53ac62014-03-27 19:58:40 -06001630 command->getName(), 408, "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001631
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001632 onConnectFailed(command->getName(), "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001633
1634 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001635 BOOST_CHECK_EQUAL(didReceiveNotication(), false);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001636}
1637
1638
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001639BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001640{
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001641 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1642 FaceTableFixture::m_faceTable.add(dummy);
1643
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001644 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001645 parameters.setFaceId(dummy->getId());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001646
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001647 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001648
1649 Name commandName("/localhost/nfd/faces");
1650 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001651 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001652
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001653 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1654 generateCommand(*command);
1655
Junxiao Shi6e694322014-04-03 10:27:13 -07001656 ndn::nfd::FaceEventNotification expectedFaceEvent;
1657 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
1658 .setFaceId(dummy->getId())
1659 .setRemoteUri(dummy->getRemoteUri().toString())
1660 .setLocalUri(dummy->getLocalUri().toString())
1661 .setFlags(0);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001662
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001663 getFace()->onReceiveData +=
Alexander Afanasyevf6980282014-05-13 18:28:40 -07001664 bind(&FaceFixture::callbackDispatch, this, _1, command->getName(),
1665 200, "Success", ref(encodedParameters), expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001666
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001667 destroyFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001668
1669 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001670 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001671}
1672
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001673class FaceListFixture : public FaceStatusPublisherFixture
1674{
1675public:
1676 FaceListFixture()
1677 : m_manager(m_table, m_face)
1678 {
1679
1680 }
1681
1682 virtual
1683 ~FaceListFixture()
1684 {
1685
1686 }
1687
1688protected:
1689 FaceManager m_manager;
1690};
1691
1692BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001693{
1694 Name commandName("/localhost/nfd/faces/list");
1695 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1696
1697 // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 55
1698 // 55 divides 4400 (== 80), so only use 79 FaceStatuses and then two smaller ones
1699 // to force a FaceStatus to span Data packets
1700 for (int i = 0; i < 79; i++)
1701 {
1702 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1703
1704 uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
1705 dummy->setCounters(filler, filler, filler, filler);
1706
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001707 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001708
1709 add(dummy);
1710 }
1711
1712 for (int i = 0; i < 2; i++)
1713 {
1714 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1715 uint64_t filler = std::numeric_limits<uint32_t>::max() - 1;
1716 dummy->setCounters(filler, filler, filler, filler);
1717
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001718 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001719
1720 add(dummy);
1721 }
1722
1723 ndn::EncodingBuffer buffer;
1724
1725 m_face->onReceiveData +=
1726 bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, this, _1);
1727
1728 m_manager.listFaces(*command);
1729 BOOST_REQUIRE(m_finished);
1730}
1731
Steve DiBenedettoef04f272014-06-04 14:28:31 -06001732class ChannelStatusFixture : public FaceManagerFixture
1733{
1734public:
1735 void
1736 validatePublish(const Data& data, const ndn::nfd::ChannelStatus& expectedEntry)
1737 {
1738 m_callbackFired = true;
1739 Block b = data.getContent().blockFromValue();
1740 ndn::nfd::ChannelStatus entry(b);
1741 BOOST_CHECK_EQUAL(entry.getLocalUri(), expectedEntry.getLocalUri());
1742 }
1743
1744 virtual shared_ptr<DummyProtocolFactory>
1745 addProtocolFactory(const std::string& protocol)
1746 {
1747 shared_ptr<DummyProtocolFactory> factory(make_shared<DummyProtocolFactory>());
1748 m_manager.m_factories[protocol] = factory;
1749
1750 return factory;
1751 }
1752};
1753
1754BOOST_FIXTURE_TEST_CASE(TestChannelStatus, ChannelStatusFixture)
1755{
1756 shared_ptr<DummyProtocolFactory> factory(addProtocolFactory("dummy"));
1757 factory->addChannel("dummy://");
1758
1759 Name requestName("/localhost/nfd/faces/channels");
1760 shared_ptr<Interest> request(make_shared<Interest>(requestName));
1761
1762 ndn::nfd::ChannelStatus expectedEntry;
1763 expectedEntry.setLocalUri(DummyChannel("dummy://").getUri().toString());
1764
1765 m_face->onReceiveData +=
1766 bind(&ChannelStatusFixture::validatePublish, this, _1, expectedEntry);
1767
1768 m_manager.listChannels(*request);
1769 BOOST_REQUIRE(m_callbackFired);
1770}
1771
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001772BOOST_AUTO_TEST_SUITE_END()
1773
1774} // namespace tests
1775} // namespace nfd