blob: 6ad61979843036964e748d8bec69579428c4edca [file] [log] [blame]
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * 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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070024
25#include "mgmt/face-manager.hpp"
26#include "mgmt/internal-face.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060027#include "mgmt/face-status-publisher.hpp"
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060028
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070029#include "face/face.hpp"
30#include "../face/dummy-face.hpp"
31#include "fw/face-table.hpp"
32#include "fw/forwarder.hpp"
Alexander Afanasyev5959b012014-06-02 19:18:12 +030033#include "face/udp-factory.hpp"
34#include "face/ethernet-factory.hpp"
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070035
36#include "common.hpp"
37#include "tests/test-common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070038#include "validation-common.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060039#include "face-status-publisher-common.hpp"
40
Alexander Afanasyev4a771362014-04-24 21:29:33 -070041#include <ndn-cxx/encoding/tlv.hpp>
42#include <ndn-cxx/management/nfd-face-event-notification.hpp>
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070043
44namespace nfd {
45namespace tests {
46
47NFD_LOG_INIT("FaceManagerTest");
48
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060049class FaceManagerTestFace : public DummyFace
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070050{
51public:
52
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060053 FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070054 : m_closeFired(false)
55 {
56
57 }
58
59 virtual
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060060 ~FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070061 {
62
63 }
64
65 virtual void
66 close()
67 {
68 m_closeFired = true;
69 }
70
71 bool
72 didCloseFire() const
73 {
74 return m_closeFired;
75 }
76
77private:
78 bool m_closeFired;
79};
80
81class TestFaceTable : public FaceTable
82{
83public:
84 TestFaceTable(Forwarder& forwarder)
85 : FaceTable(forwarder),
86 m_addFired(false),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070087 m_getFired(false),
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060088 m_dummy(make_shared<FaceManagerTestFace>())
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070089 {
90
91 }
92
93 virtual
94 ~TestFaceTable()
95 {
96
97 }
98
99 virtual void
100 add(shared_ptr<Face> face)
101 {
102 m_addFired = true;
103 }
104
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700105 virtual shared_ptr<Face>
106 get(FaceId id) const
107 {
108 m_getFired = true;
109 return m_dummy;
110 }
111
112 bool
113 didAddFire() const
114 {
115 return m_addFired;
116 }
117
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700118 bool
119 didGetFire() const
120 {
121 return m_getFired;
122 }
123
124 void
125 reset()
126 {
127 m_addFired = false;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700128 m_getFired = false;
129 }
130
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600131 shared_ptr<FaceManagerTestFace>&
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700132 getDummyFace()
133 {
134 return m_dummy;
135 }
136
137private:
138 bool m_addFired;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700139 mutable bool m_getFired;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600140 shared_ptr<FaceManagerTestFace> m_dummy;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700141};
142
143
144class TestFaceTableFixture : public BaseFixture
145{
146public:
147 TestFaceTableFixture()
148 : m_faceTable(m_forwarder)
149 {
150
151 }
152
153 virtual
154 ~TestFaceTableFixture()
155 {
156
157 }
158
159protected:
160 Forwarder m_forwarder;
161 TestFaceTable m_faceTable;
162};
163
164class TestFaceManagerCommon
165{
166public:
167 TestFaceManagerCommon()
168 : m_face(make_shared<InternalFace>()),
169 m_callbackFired(false)
170 {
171
172 }
173
174 virtual
175 ~TestFaceManagerCommon()
176 {
177
178 }
179
180 shared_ptr<InternalFace>&
181 getFace()
182 {
183 return m_face;
184 }
185
186 void
187 validateControlResponseCommon(const Data& response,
188 const Name& expectedName,
189 uint32_t expectedCode,
190 const std::string& expectedText,
191 ControlResponse& control)
192 {
193 m_callbackFired = true;
194 Block controlRaw = response.getContent().blockFromValue();
195
196 control.wireDecode(controlRaw);
197
198 // NFD_LOG_DEBUG("received control response"
199 // << " Name: " << response.getName()
200 // << " code: " << control.getCode()
201 // << " text: " << control.getText());
202
203 BOOST_CHECK_EQUAL(response.getName(), expectedName);
204 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
205 BOOST_CHECK_EQUAL(control.getText(), expectedText);
206 }
207
208 void
209 validateControlResponse(const Data& response,
210 const Name& expectedName,
211 uint32_t expectedCode,
212 const std::string& expectedText)
213 {
214 ControlResponse control;
215 validateControlResponseCommon(response, expectedName,
216 expectedCode, expectedText, control);
217
218 if (!control.getBody().empty())
219 {
220 BOOST_FAIL("found unexpected control response body");
221 }
222 }
223
224 void
225 validateControlResponse(const Data& response,
226 const Name& expectedName,
227 uint32_t expectedCode,
228 const std::string& expectedText,
229 const Block& expectedBody)
230 {
231 ControlResponse control;
232 validateControlResponseCommon(response, expectedName,
233 expectedCode, expectedText, control);
234
235 BOOST_REQUIRE(!control.getBody().empty());
236 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
237
238 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
239 expectedBody.value_size()) == 0);
240
241 }
242
243 bool
244 didCallbackFire() const
245 {
246 return m_callbackFired;
247 }
248
249 void
250 resetCallbackFired()
251 {
252 m_callbackFired = false;
253 }
254
255protected:
256 shared_ptr<InternalFace> m_face;
257
258private:
259 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
314private:
315 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
674 BOOST_CHECK_GT(factory->getMulticastFaces().size(), 0);
675
676 const std::string CONFIG_WITHOUT_MCAST =
677 "face_system\n"
678 "{\n"
679 " udp\n"
680 " {\n"
681 " mcast no\n"
682 " }\n"
683 "}\n";
684 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
685 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
686}
687
688
Alexander Afanasyev885a85b2014-04-12 21:01:13 -0700689#ifdef HAVE_LIBPCAP
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600690
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700691BOOST_AUTO_TEST_CASE(TestProcessSectionEther)
692{
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600693
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700694 const std::string CONFIG =
695 "face_system\n"
696 "{\n"
697 " ether\n"
698 " {\n"
699 " mcast yes\n"
700 " mcast_group 01:00:5E:00:17:AA\n"
701 " }\n"
702 "}\n";
703
704 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
705}
706
707BOOST_AUTO_TEST_CASE(TestProcessSectionEtherDryRun)
708{
709 const std::string CONFIG =
710 "face_system\n"
711 "{\n"
712 " ether\n"
713 " {\n"
714 " mcast yes\n"
715 " mcast_group 01:00:5E:00:17:AA\n"
716 " }\n"
717 "}\n";
718
719 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
720}
721
722BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcast)
723{
724 const std::string CONFIG =
725 "face_system\n"
726 "{\n"
727 " ether\n"
728 " {\n"
729 " mcast hello\n"
730 " }\n"
731 "}\n";
732
733 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
734 bind(&isExpectedException, _1,
735 "Invalid value for option \"mcast\" in \"ether\" section"));
736}
737
738BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcastGroup)
739{
740 const std::string CONFIG =
741 "face_system\n"
742 "{\n"
743 " ether\n"
744 " {\n"
745 " mcast yes\n"
746 " mcast_group\n"
747 " }\n"
748 "}\n";
749
750 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
751 bind(&isExpectedException, _1,
752 "Invalid value for option \"mcast_group\" in \"ether\" section"));
753}
754
755BOOST_AUTO_TEST_CASE(TestProcessSectionEtherUnknownOption)
756{
757 const std::string CONFIG =
758 "face_system\n"
759 "{\n"
760 " ether\n"
761 " {\n"
762 " hello\n"
763 " }\n"
764 "}\n";
765 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
766 bind(&isExpectedException, _1,
767 "Unrecognized option \"hello\" in \"ether\" section"));
768}
769
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300770BOOST_AUTO_TEST_CASE(TestProcessSectionEtherMulticastReinit)
771{
772 const std::string CONFIG_WITH_MCAST =
773 "face_system\n"
774 "{\n"
775 " ether\n"
776 " {\n"
777 " mcast yes\n"
778 " }\n"
779 "}\n";
780 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
781
782 shared_ptr<EthernetFactory> factory =
783 static_pointer_cast<EthernetFactory>(getManager().findFactory("ether"));
784 BOOST_REQUIRE(static_cast<bool>(factory));
785
786 BOOST_CHECK_GT(factory->getMulticastFaces().size(), 0);
787
788 const std::string CONFIG_WITHOUT_MCAST =
789 "face_system\n"
790 "{\n"
791 " ether\n"
792 " {\n"
793 " mcast no\n"
794 " }\n"
795 "}\n";
796 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
797 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
798}
799
800
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600801#endif
802
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700803BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
804{
805 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
806
807 getFace()->onReceiveData +=
808 bind(&FaceManagerFixture::validateControlResponse, this, _1,
809 command->getName(), 400, "Malformed command");
810
811 getFace()->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700812 g_io.run_one();
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700813
814 BOOST_REQUIRE(didCallbackFire());
815}
816
817BOOST_AUTO_TEST_CASE(MalformedCommmand)
818{
819 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
820
821 getFace()->onReceiveData +=
822 bind(&FaceManagerFixture::validateControlResponse, this, _1,
823 command->getName(), 400, "Malformed command");
824
825 getManager().onFaceRequest(*command);
826
827 BOOST_REQUIRE(didCallbackFire());
828}
829
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700830BOOST_AUTO_TEST_CASE(UnsignedCommand)
831{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600832 ControlParameters parameters;
833 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700834
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600835 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700836
837 Name commandName("/localhost/nfd/faces");
838 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600839 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700840
841 shared_ptr<Interest> command(make_shared<Interest>(commandName));
842
843 getFace()->onReceiveData +=
844 bind(&FaceManagerFixture::validateControlResponse, this, _1,
845 command->getName(), 401, "Signature required");
846
847 getManager().onFaceRequest(*command);
848
849 BOOST_REQUIRE(didCallbackFire());
850}
851
852BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>)
853{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600854 ControlParameters parameters;
855 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700856
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600857 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700858
859 Name commandName("/localhost/nfd/faces");
860 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600861 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700862
863 shared_ptr<Interest> command(make_shared<Interest>(commandName));
864 generateCommand(*command);
865
866 getFace()->onReceiveData +=
867 bind(&FaceManagerFixture::validateControlResponse, this, _1,
868 command->getName(), 403, "Unauthorized command");
869
870 getManager().onFaceRequest(*command);
871
872 BOOST_REQUIRE(didCallbackFire());
873}
874
875template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
876{
877public:
878 AuthorizedCommandFixture()
879 {
880 const std::string regex = "^<localhost><nfd><faces>";
881 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
882 }
883
884 virtual
885 ~AuthorizedCommandFixture()
886 {
887
888 }
889};
890
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700891BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700892{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600893 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700894
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600895 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700896
897 Name commandName("/localhost/nfd/faces");
898 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600899 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700900
901 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700902 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700903
904 getFace()->onReceiveData +=
905 bind(&FaceManagerFixture::validateControlResponse, this, _1,
906 command->getName(), 501, "Unsupported command");
907
908 getManager().onFaceRequest(*command);
909
910 BOOST_REQUIRE(didCallbackFire());
911}
912
913class ValidatedFaceRequestFixture : public TestFaceTableFixture,
914 public TestFaceManagerCommon,
915 public FaceManager
916{
917public:
918
919 ValidatedFaceRequestFixture()
920 : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face),
921 m_createFaceFired(false),
922 m_destroyFaceFired(false)
923 {
924
925 }
926
927 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600928 createFace(const Interest& request,
929 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700930 {
931 m_createFaceFired = true;
932 }
933
934 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600935 destroyFace(const Interest& request,
936 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700937 {
938 m_destroyFaceFired = true;
939 }
940
941 virtual
942 ~ValidatedFaceRequestFixture()
943 {
944
945 }
946
947 bool
948 didCreateFaceFire() const
949 {
950 return m_createFaceFired;
951 }
952
953 bool
954 didDestroyFaceFire() const
955 {
956 return m_destroyFaceFired;
957 }
958
959private:
960 bool m_createFaceFired;
961 bool m_destroyFaceFired;
962};
963
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700964BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse,
965 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700966{
967 Name commandName("/localhost/nfd/faces");
968 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600969 commandName.append("NotReallyParameters");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700970
971 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700972 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700973
974 getFace()->onReceiveData +=
975 bind(&ValidatedFaceRequestFixture::validateControlResponse, this, _1,
976 command->getName(), 400, "Malformed command");
977
978 onValidatedFaceRequest(command);
979
980 BOOST_REQUIRE(didCallbackFire());
981}
982
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700983BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace,
984 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700985{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600986 ControlParameters parameters;
987 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700988
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600989 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700990
991 Name commandName("/localhost/nfd/faces");
992 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600993 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700994
995 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700996 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700997
998 onValidatedFaceRequest(command);
999 BOOST_CHECK(didCreateFaceFire());
1000}
1001
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001002BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace,
1003 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001004{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001005 ControlParameters parameters;
1006 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001007
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001008 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001009
1010 Name commandName("/localhost/nfd/faces");
1011 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001012 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001013
1014 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001015 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001016
1017 onValidatedFaceRequest(command);
1018 BOOST_CHECK(didDestroyFaceFire());
1019}
1020
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001021class FaceTableFixture
1022{
1023public:
1024 FaceTableFixture()
1025 : m_faceTable(m_forwarder)
1026 {
1027 }
1028
1029 virtual
1030 ~FaceTableFixture()
1031 {
1032 }
1033
1034protected:
1035 Forwarder m_forwarder;
1036 FaceTable m_faceTable;
1037};
1038
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001039class LocalControlFixture : public FaceTableFixture,
1040 public TestFaceManagerCommon,
1041 public FaceManager
1042{
1043public:
1044 LocalControlFixture()
1045 : FaceManager(FaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face)
1046 {
1047 }
1048};
1049
1050BOOST_FIXTURE_TEST_CASE(LocalControlInFaceId,
1051 AuthorizedCommandFixture<LocalControlFixture>)
1052{
1053 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1054 BOOST_REQUIRE(dummy->isLocal());
1055 FaceTableFixture::m_faceTable.add(dummy);
1056
1057 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001058 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1059
1060 Block encodedParameters(parameters.wireEncode());
1061
1062 Name enable("/localhost/nfd/faces/enable-local-control");
1063 enable.append(encodedParameters);
1064
1065 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1066 enableCommand->setIncomingFaceId(dummy->getId());
1067
1068 generateCommand(*enableCommand);
1069
1070 TestFaceManagerCommon::m_face->onReceiveData +=
1071 bind(&LocalControlFixture::validateControlResponse, this, _1,
1072 enableCommand->getName(), 200, "Success", encodedParameters);
1073
1074 onValidatedFaceRequest(enableCommand);
1075
1076 BOOST_REQUIRE(didCallbackFire());
1077 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1078 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1079
1080 TestFaceManagerCommon::m_face->onReceiveData.clear();
1081 resetCallbackFired();
1082
1083 Name disable("/localhost/nfd/faces/disable-local-control");
1084 disable.append(encodedParameters);
1085
1086 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1087 disableCommand->setIncomingFaceId(dummy->getId());
1088
1089 generateCommand(*disableCommand);
1090
1091 TestFaceManagerCommon::m_face->onReceiveData +=
1092 bind(&LocalControlFixture::validateControlResponse, this, _1,
1093 disableCommand->getName(), 200, "Success", encodedParameters);
1094
1095 onValidatedFaceRequest(disableCommand);
1096
1097 BOOST_REQUIRE(didCallbackFire());
1098 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1099 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1100}
1101
1102BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound,
1103 AuthorizedCommandFixture<LocalControlFixture>)
1104{
1105 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1106 BOOST_REQUIRE(dummy->isLocal());
1107 FaceTableFixture::m_faceTable.add(dummy);
1108
1109 ControlParameters parameters;
1110 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1111
1112 Block encodedParameters(parameters.wireEncode());
1113
1114 Name enable("/localhost/nfd/faces/enable-local-control");
1115 enable.append(encodedParameters);
1116
1117 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1118 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1119
1120 generateCommand(*enableCommand);
1121
1122 TestFaceManagerCommon::m_face->onReceiveData +=
1123 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001124 enableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001125
1126 onValidatedFaceRequest(enableCommand);
1127
1128 BOOST_REQUIRE(didCallbackFire());
1129 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1130 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1131
1132 TestFaceManagerCommon::m_face->onReceiveData.clear();
1133 resetCallbackFired();
1134
1135 Name disable("/localhost/nfd/faces/disable-local-control");
1136 disable.append(encodedParameters);
1137
1138 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1139 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1140
1141 generateCommand(*disableCommand);
1142
1143 TestFaceManagerCommon::m_face->onReceiveData +=
1144 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001145 disableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001146
1147 onValidatedFaceRequest(disableCommand);
1148
1149 BOOST_REQUIRE(didCallbackFire());
1150 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1151 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1152}
1153
1154BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature,
1155 AuthorizedCommandFixture<LocalControlFixture>)
1156{
1157 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1158 BOOST_REQUIRE(dummy->isLocal());
1159 FaceTableFixture::m_faceTable.add(dummy);
1160
1161 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001162
1163 Block encodedParameters(parameters.wireEncode());
1164
1165 Name enable("/localhost/nfd/faces/enable-local-control");
1166 enable.append(encodedParameters);
1167
1168 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1169 enableCommand->setIncomingFaceId(dummy->getId());
1170
1171 generateCommand(*enableCommand);
1172
1173 TestFaceManagerCommon::m_face->onReceiveData +=
1174 bind(&LocalControlFixture::validateControlResponse, this, _1,
1175 enableCommand->getName(), 400, "Malformed command");
1176
1177 onValidatedFaceRequest(enableCommand);
1178
1179 BOOST_REQUIRE(didCallbackFire());
1180 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1181 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1182
1183 TestFaceManagerCommon::m_face->onReceiveData.clear();
1184 resetCallbackFired();
1185
1186 Name disable("/localhost/nfd/faces/disable-local-control");
1187 disable.append(encodedParameters);
1188
1189 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1190 disableCommand->setIncomingFaceId(dummy->getId());
1191
1192 generateCommand(*disableCommand);
1193
1194 TestFaceManagerCommon::m_face->onReceiveData +=
1195 bind(&LocalControlFixture::validateControlResponse, this, _1,
1196 disableCommand->getName(), 400, "Malformed command");
1197
1198 onValidatedFaceRequest(disableCommand);
1199
1200 BOOST_REQUIRE(didCallbackFire());
1201 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1202 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1203}
1204
1205BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal,
1206 AuthorizedCommandFixture<LocalControlFixture>)
1207{
1208 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1209 BOOST_REQUIRE(!dummy->isLocal());
1210 FaceTableFixture::m_faceTable.add(dummy);
1211
1212 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001213 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1214
1215 Block encodedParameters(parameters.wireEncode());
1216
1217 Name enable("/localhost/nfd/faces/enable-local-control");
1218 enable.append(encodedParameters);
1219
1220 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1221 enableCommand->setIncomingFaceId(dummy->getId());
1222
1223 generateCommand(*enableCommand);
1224
1225 TestFaceManagerCommon::m_face->onReceiveData +=
1226 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001227 enableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001228
1229 onValidatedFaceRequest(enableCommand);
1230
1231 BOOST_REQUIRE(didCallbackFire());
1232
1233 TestFaceManagerCommon::m_face->onReceiveData.clear();
1234 resetCallbackFired();
1235
1236 Name disable("/localhost/nfd/faces/disable-local-control");
1237 enable.append(encodedParameters);
1238
1239 shared_ptr<Interest> disableCommand(make_shared<Interest>(enable));
1240 disableCommand->setIncomingFaceId(dummy->getId());
1241
1242 generateCommand(*disableCommand);
1243
1244 TestFaceManagerCommon::m_face->onReceiveData +=
1245 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001246 disableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001247
1248 onValidatedFaceRequest(disableCommand);
1249
1250 BOOST_REQUIRE(didCallbackFire());
1251}
1252
1253BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId,
1254 AuthorizedCommandFixture<LocalControlFixture>)
1255{
1256 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1257 BOOST_REQUIRE(dummy->isLocal());
1258 FaceTableFixture::m_faceTable.add(dummy);
1259
1260 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001261 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1262
1263 Block encodedParameters(parameters.wireEncode());
1264
1265 Name enable("/localhost/nfd/faces/enable-local-control");
1266 enable.append(encodedParameters);
1267
1268 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1269 enableCommand->setIncomingFaceId(dummy->getId());
1270
1271 generateCommand(*enableCommand);
1272
1273 TestFaceManagerCommon::m_face->onReceiveData +=
1274 bind(&LocalControlFixture::validateControlResponse, this, _1,
1275 enableCommand->getName(), 200, "Success", encodedParameters);
1276
1277 onValidatedFaceRequest(enableCommand);
1278
1279 BOOST_REQUIRE(didCallbackFire());
1280 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1281 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1282
1283
1284 TestFaceManagerCommon::m_face->onReceiveData.clear();
1285 resetCallbackFired();
1286
1287 Name disable("/localhost/nfd/faces/disable-local-control");
1288 disable.append(encodedParameters);
1289
1290 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1291 disableCommand->setIncomingFaceId(dummy->getId());
1292
1293 generateCommand(*disableCommand);
1294
1295 TestFaceManagerCommon::m_face->onReceiveData +=
1296 bind(&LocalControlFixture::validateControlResponse, this, _1,
1297 disableCommand->getName(), 200, "Success", encodedParameters);
1298
1299 onValidatedFaceRequest(disableCommand);
1300
1301 BOOST_REQUIRE(didCallbackFire());
1302 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1303 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1304}
1305
1306BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound,
1307 AuthorizedCommandFixture<LocalControlFixture>)
1308{
1309 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1310 BOOST_REQUIRE(dummy->isLocal());
1311 FaceTableFixture::m_faceTable.add(dummy);
1312
1313 ControlParameters parameters;
1314 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1315
1316 Block encodedParameters(parameters.wireEncode());
1317
1318 Name enable("/localhost/nfd/faces/enable-local-control");
1319 enable.append(encodedParameters);
1320
1321 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1322 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1323
1324 generateCommand(*enableCommand);
1325
1326 TestFaceManagerCommon::m_face->onReceiveData +=
1327 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001328 enableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001329
1330 onValidatedFaceRequest(enableCommand);
1331
1332 BOOST_REQUIRE(didCallbackFire());
1333 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1334 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1335
1336
1337 TestFaceManagerCommon::m_face->onReceiveData.clear();
1338 resetCallbackFired();
1339
1340 Name disable("/localhost/nfd/faces/disable-local-control");
1341 disable.append(encodedParameters);
1342
1343 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1344 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1345
1346 generateCommand(*disableCommand);
1347
1348 TestFaceManagerCommon::m_face->onReceiveData +=
1349 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001350 disableCommand->getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001351
1352 onValidatedFaceRequest(disableCommand);
1353
1354 BOOST_REQUIRE(didCallbackFire());
1355 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1356 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1357}
1358
1359BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal,
1360 AuthorizedCommandFixture<LocalControlFixture>)
1361{
1362 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1363 BOOST_REQUIRE(!dummy->isLocal());
1364 FaceTableFixture::m_faceTable.add(dummy);
1365
1366 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001367 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1368
1369 Block encodedParameters(parameters.wireEncode());
1370
1371 Name enable("/localhost/nfd/faces/enable-local-control");
1372 enable.append(encodedParameters);
1373
1374 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1375 enableCommand->setIncomingFaceId(dummy->getId());
1376
1377 generateCommand(*enableCommand);
1378
1379 TestFaceManagerCommon::m_face->onReceiveData +=
1380 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001381 enableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001382
1383 onValidatedFaceRequest(enableCommand);
1384
1385 BOOST_REQUIRE(didCallbackFire());
1386
1387 TestFaceManagerCommon::m_face->onReceiveData.clear();
1388 resetCallbackFired();
1389
1390 Name disable("/localhost/nfd/faces/disable-local-control");
1391 disable.append(encodedParameters);
1392
1393 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1394 disableCommand->setIncomingFaceId(dummy->getId());
1395
1396 generateCommand(*disableCommand);
1397
1398 TestFaceManagerCommon::m_face->onReceiveData +=
1399 bind(&LocalControlFixture::validateControlResponse, this, _1,
Steve DiBenedetto51d242a2014-03-31 13:46:43 -06001400 disableCommand->getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001401
1402 onValidatedFaceRequest(disableCommand);
1403
1404 BOOST_REQUIRE(didCallbackFire());
1405}
1406
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001407class FaceFixture : public FaceTableFixture,
1408 public TestFaceManagerCommon,
1409 public FaceManager
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001410{
1411public:
1412 FaceFixture()
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001413 : FaceManager(FaceTableFixture::m_faceTable,
1414 TestFaceManagerCommon::m_face)
1415 , m_receivedNotification(false)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001416 {
1417
1418 }
1419
1420 virtual
1421 ~FaceFixture()
1422 {
1423
1424 }
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001425
1426 void
1427 callbackDispatch(const Data& response,
1428 const Name& expectedName,
1429 uint32_t expectedCode,
1430 const std::string& expectedText,
1431 const Block& expectedBody,
1432 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1433 {
1434 Block payload = response.getContent().blockFromValue();
1435 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1436 {
1437 validateControlResponse(response, expectedName, expectedCode,
1438 expectedText, expectedBody);
1439 }
1440 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1441 {
1442 validateFaceEvent(payload, expectedFaceEvent);
1443 }
1444 else
1445 {
1446 BOOST_FAIL("Received unknown message type: #" << payload.type());
1447 }
1448 }
1449
1450 void
1451 callbackDispatch(const Data& response,
1452 const Name& expectedName,
1453 uint32_t expectedCode,
1454 const std::string& expectedText,
1455 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1456 {
1457 Block payload = response.getContent().blockFromValue();
1458 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1459 {
1460 validateControlResponse(response, expectedName,
1461 expectedCode, expectedText);
1462 }
1463 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1464 {
1465 validateFaceEvent(payload, expectedFaceEvent);
1466 }
1467 else
1468 {
1469 BOOST_FAIL("Received unknown message type: #" << payload.type());
1470 }
1471 }
1472
1473 void
1474 validateFaceEvent(const Block& wire,
1475 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1476 {
1477
1478 m_receivedNotification = true;
1479
1480 ndn::nfd::FaceEventNotification notification(wire);
1481
Junxiao Shi6e694322014-04-03 10:27:13 -07001482 BOOST_CHECK_EQUAL(notification.getKind(), expectedFaceEvent.getKind());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001483 BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId());
Junxiao Shi6e694322014-04-03 10:27:13 -07001484 BOOST_CHECK_EQUAL(notification.getRemoteUri(), expectedFaceEvent.getRemoteUri());
1485 BOOST_CHECK_EQUAL(notification.getLocalUri(), expectedFaceEvent.getLocalUri());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001486 }
1487
1488 bool
1489 didReceiveNotication() const
1490 {
1491 return m_receivedNotification;
1492 }
1493
1494protected:
1495 bool m_receivedNotification;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001496};
1497
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001498BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001499{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001500 ControlParameters parameters;
1501 parameters.setUri("tcp:/127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001502
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001503 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001504
1505 Name commandName("/localhost/nfd/faces");
1506 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001507 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001508
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001509 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1510 generateCommand(*command);
1511
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001512 getFace()->onReceiveData +=
1513 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001514 command->getName(), 400, "Malformed command");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001515
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001516 createFace(*command, parameters);
1517
1518 BOOST_REQUIRE(didCallbackFire());
1519}
1520
1521BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>)
1522{
1523 ControlParameters parameters;
1524
1525 Block encodedParameters(parameters.wireEncode());
1526
1527 Name commandName("/localhost/nfd/faces");
1528 commandName.append("create");
1529 commandName.append(encodedParameters);
1530
1531 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1532 generateCommand(*command);
1533
1534 getFace()->onReceiveData +=
1535 bind(&FaceFixture::validateControlResponse, this, _1,
1536 command->getName(), 400, "Malformed command");
1537
1538 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001539
1540 BOOST_REQUIRE(didCallbackFire());
1541}
1542
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001543BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001544{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001545 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001546 // this will be an unsupported protocol because no factories have been
1547 // added to the face manager
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001548 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001549
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001550 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001551
1552 Name commandName("/localhost/nfd/faces");
1553 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001554 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001555
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001556 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1557 generateCommand(*command);
1558
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001559 getFace()->onReceiveData +=
1560 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001561 command->getName(), 501, "Unsupported protocol");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001562
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001563 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001564
1565 BOOST_REQUIRE(didCallbackFire());
1566}
1567
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001568BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001569{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001570 ControlParameters parameters;
1571 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001572
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001573 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001574
1575 Name commandName("/localhost/nfd/faces");
1576 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001577 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001578
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001579 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1580 generateCommand(*command);
1581
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001582 ControlParameters resultParameters;
Steve DiBenedetto25999282014-05-22 15:25:12 -06001583 resultParameters.setUri("dummy://");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001584 resultParameters.setFaceId(1);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001585
1586 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1587
Junxiao Shi6e694322014-04-03 10:27:13 -07001588 ndn::nfd::FaceEventNotification expectedFaceEvent;
1589 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED)
1590 .setFaceId(1)
1591 .setRemoteUri(dummy->getRemoteUri().toString())
1592 .setLocalUri(dummy->getLocalUri().toString())
1593 .setFlags(0);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001594
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001595 Block encodedResultParameters(resultParameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001596
1597 getFace()->onReceiveData +=
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001598 bind(&FaceFixture::callbackDispatch, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001599 command->getName(), 200, "Success",
1600 encodedResultParameters, expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001601
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001602 onCreated(command->getName(), parameters, dummy);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001603
1604 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001605 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001606}
1607
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001608BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001609{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001610 ControlParameters parameters;
1611 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001612
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001613 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001614
1615 Name commandName("/localhost/nfd/faces");
1616 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001617 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001618
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001619 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1620 generateCommand(*command);
1621
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001622 getFace()->onReceiveData +=
1623 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedettoca53ac62014-03-27 19:58:40 -06001624 command->getName(), 408, "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001625
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001626 onConnectFailed(command->getName(), "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001627
1628 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001629 BOOST_CHECK_EQUAL(didReceiveNotication(), false);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001630}
1631
1632
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001633BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001634{
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001635 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1636 FaceTableFixture::m_faceTable.add(dummy);
1637
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001638 ControlParameters parameters;
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001639 parameters.setFaceId(dummy->getId());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001640
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001641 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001642
1643 Name commandName("/localhost/nfd/faces");
1644 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001645 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001646
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001647 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1648 generateCommand(*command);
1649
Junxiao Shi6e694322014-04-03 10:27:13 -07001650 ndn::nfd::FaceEventNotification expectedFaceEvent;
1651 expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
1652 .setFaceId(dummy->getId())
1653 .setRemoteUri(dummy->getRemoteUri().toString())
1654 .setLocalUri(dummy->getLocalUri().toString())
1655 .setFlags(0);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001656
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001657 getFace()->onReceiveData +=
Alexander Afanasyevf6980282014-05-13 18:28:40 -07001658 bind(&FaceFixture::callbackDispatch, this, _1, command->getName(),
1659 200, "Success", ref(encodedParameters), expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001660
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001661 destroyFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001662
1663 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001664 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001665}
1666
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001667class FaceListFixture : public FaceStatusPublisherFixture
1668{
1669public:
1670 FaceListFixture()
1671 : m_manager(m_table, m_face)
1672 {
1673
1674 }
1675
1676 virtual
1677 ~FaceListFixture()
1678 {
1679
1680 }
1681
1682protected:
1683 FaceManager m_manager;
1684};
1685
1686BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture)
1687
1688{
1689 Name commandName("/localhost/nfd/faces/list");
1690 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1691
1692 // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 55
1693 // 55 divides 4400 (== 80), so only use 79 FaceStatuses and then two smaller ones
1694 // to force a FaceStatus to span Data packets
1695 for (int i = 0; i < 79; i++)
1696 {
1697 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1698
1699 uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
1700 dummy->setCounters(filler, filler, filler, filler);
1701
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001702 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001703
1704 add(dummy);
1705 }
1706
1707 for (int i = 0; i < 2; i++)
1708 {
1709 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1710 uint64_t filler = std::numeric_limits<uint32_t>::max() - 1;
1711 dummy->setCounters(filler, filler, filler, filler);
1712
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001713 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001714
1715 add(dummy);
1716 }
1717
1718 ndn::EncodingBuffer buffer;
1719
1720 m_face->onReceiveData +=
1721 bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, this, _1);
1722
1723 m_manager.listFaces(*command);
1724 BOOST_REQUIRE(m_finished);
1725}
1726
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001727BOOST_AUTO_TEST_SUITE_END()
1728
1729} // namespace tests
1730} // namespace nfd