blob: 9cfca66bd1636f440417282951e1801f15d398ea [file] [log] [blame]
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07006
7#include "mgmt/face-manager.hpp"
8#include "mgmt/internal-face.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06009#include "mgmt/face-status-publisher.hpp"
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060010
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070011#include "face/face.hpp"
12#include "../face/dummy-face.hpp"
13#include "fw/face-table.hpp"
14#include "fw/forwarder.hpp"
15
16#include "common.hpp"
17#include "tests/test-common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070018#include "validation-common.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060019#include "face-status-publisher-common.hpp"
20
21#include <ndn-cpp-dev/encoding/tlv.hpp>
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060022#include <ndn-cpp-dev/management/nfd-face-event-notification.hpp>
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070023
24namespace nfd {
25namespace tests {
26
27NFD_LOG_INIT("FaceManagerTest");
28
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060029class FaceManagerTestFace : public DummyFace
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070030{
31public:
32
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060033 FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070034 : m_closeFired(false)
35 {
36
37 }
38
39 virtual
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060040 ~FaceManagerTestFace()
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070041 {
42
43 }
44
45 virtual void
46 close()
47 {
48 m_closeFired = true;
49 }
50
51 bool
52 didCloseFire() const
53 {
54 return m_closeFired;
55 }
56
57private:
58 bool m_closeFired;
59};
60
61class TestFaceTable : public FaceTable
62{
63public:
64 TestFaceTable(Forwarder& forwarder)
65 : FaceTable(forwarder),
66 m_addFired(false),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070067 m_getFired(false),
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060068 m_dummy(make_shared<FaceManagerTestFace>())
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070069 {
70
71 }
72
73 virtual
74 ~TestFaceTable()
75 {
76
77 }
78
79 virtual void
80 add(shared_ptr<Face> face)
81 {
82 m_addFired = true;
83 }
84
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070085 virtual shared_ptr<Face>
86 get(FaceId id) const
87 {
88 m_getFired = true;
89 return m_dummy;
90 }
91
92 bool
93 didAddFire() const
94 {
95 return m_addFired;
96 }
97
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070098 bool
99 didGetFire() const
100 {
101 return m_getFired;
102 }
103
104 void
105 reset()
106 {
107 m_addFired = false;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700108 m_getFired = false;
109 }
110
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600111 shared_ptr<FaceManagerTestFace>&
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700112 getDummyFace()
113 {
114 return m_dummy;
115 }
116
117private:
118 bool m_addFired;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700119 mutable bool m_getFired;
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600120 shared_ptr<FaceManagerTestFace> m_dummy;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700121};
122
123
124class TestFaceTableFixture : public BaseFixture
125{
126public:
127 TestFaceTableFixture()
128 : m_faceTable(m_forwarder)
129 {
130
131 }
132
133 virtual
134 ~TestFaceTableFixture()
135 {
136
137 }
138
139protected:
140 Forwarder m_forwarder;
141 TestFaceTable m_faceTable;
142};
143
144class TestFaceManagerCommon
145{
146public:
147 TestFaceManagerCommon()
148 : m_face(make_shared<InternalFace>()),
149 m_callbackFired(false)
150 {
151
152 }
153
154 virtual
155 ~TestFaceManagerCommon()
156 {
157
158 }
159
160 shared_ptr<InternalFace>&
161 getFace()
162 {
163 return m_face;
164 }
165
166 void
167 validateControlResponseCommon(const Data& response,
168 const Name& expectedName,
169 uint32_t expectedCode,
170 const std::string& expectedText,
171 ControlResponse& control)
172 {
173 m_callbackFired = true;
174 Block controlRaw = response.getContent().blockFromValue();
175
176 control.wireDecode(controlRaw);
177
178 // NFD_LOG_DEBUG("received control response"
179 // << " Name: " << response.getName()
180 // << " code: " << control.getCode()
181 // << " text: " << control.getText());
182
183 BOOST_CHECK_EQUAL(response.getName(), expectedName);
184 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
185 BOOST_CHECK_EQUAL(control.getText(), expectedText);
186 }
187
188 void
189 validateControlResponse(const Data& response,
190 const Name& expectedName,
191 uint32_t expectedCode,
192 const std::string& expectedText)
193 {
194 ControlResponse control;
195 validateControlResponseCommon(response, expectedName,
196 expectedCode, expectedText, control);
197
198 if (!control.getBody().empty())
199 {
200 BOOST_FAIL("found unexpected control response body");
201 }
202 }
203
204 void
205 validateControlResponse(const Data& response,
206 const Name& expectedName,
207 uint32_t expectedCode,
208 const std::string& expectedText,
209 const Block& expectedBody)
210 {
211 ControlResponse control;
212 validateControlResponseCommon(response, expectedName,
213 expectedCode, expectedText, control);
214
215 BOOST_REQUIRE(!control.getBody().empty());
216 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
217
218 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
219 expectedBody.value_size()) == 0);
220
221 }
222
223 bool
224 didCallbackFire() const
225 {
226 return m_callbackFired;
227 }
228
229 void
230 resetCallbackFired()
231 {
232 m_callbackFired = false;
233 }
234
235protected:
236 shared_ptr<InternalFace> m_face;
237
238private:
239 bool m_callbackFired;
240};
241
242class FaceManagerFixture : public TestFaceTableFixture, public TestFaceManagerCommon
243{
244public:
245 FaceManagerFixture()
246 : m_manager(m_faceTable, m_face)
247 {
248 m_manager.setConfigFile(m_config);
249 }
250
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700251 virtual
252 ~FaceManagerFixture()
253 {
254
255 }
256
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600257 void
258 parseConfig(const std::string configuration, bool isDryRun)
259 {
260 m_config.parse(configuration, isDryRun, "dummy-config");
261 }
262
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700263 FaceManager&
264 getManager()
265 {
266 return m_manager;
267 }
268
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700269 void
270 addInterestRule(const std::string& regex,
271 ndn::IdentityCertificate& certificate)
272 {
273 m_manager.addInterestRule(regex, certificate);
274 }
275
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700276 bool
277 didFaceTableAddFire() const
278 {
279 return m_faceTable.didAddFire();
280 }
281
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700282 bool
283 didFaceTableGetFire() const
284 {
285 return m_faceTable.didGetFire();
286 }
287
288 void
289 resetFaceTable()
290 {
291 m_faceTable.reset();
292 }
293
294private:
295 FaceManager m_manager;
296 ConfigFile m_config;
297};
298
299BOOST_FIXTURE_TEST_SUITE(MgmtFaceManager, FaceManagerFixture)
300
301bool
302isExpectedException(const ConfigFile::Error& error, const std::string& expectedMessage)
303{
304 if (error.what() != expectedMessage)
305 {
306 NFD_LOG_ERROR("expected: " << expectedMessage << "\tgot: " << error.what());
307 }
308 return error.what() == expectedMessage;
309}
310
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600311#ifdef HAVE_UNIX_SOCKETS
312
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700313BOOST_AUTO_TEST_CASE(TestProcessSectionUnix)
314{
315 const std::string CONFIG =
316 "face_system\n"
317 "{\n"
318 " unix\n"
319 " {\n"
320 " listen yes\n"
321 " path /tmp/nfd.sock\n"
322 " }\n"
323 "}\n";
324 BOOST_TEST_CHECKPOINT("Calling parse");
325 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
326}
327
328BOOST_AUTO_TEST_CASE(TestProcessSectionUnixDryRun)
329{
330 const std::string CONFIG =
331 "face_system\n"
332 "{\n"
333 " unix\n"
334 " {\n"
335 " listen yes\n"
336 " path /var/run/nfd.sock\n"
337 " }\n"
338 "}\n";
339
340 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
341}
342
343BOOST_AUTO_TEST_CASE(TestProcessSectionUnixBadListen)
344{
345 const std::string CONFIG =
346 "face_system\n"
347 "{\n"
348 " unix\n"
349 " {\n"
350 " listen hello\n"
351 " }\n"
352 "}\n";
353 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
354 bind(&isExpectedException, _1,
355 "Invalid value for option \"listen\" in \"unix\" section"));
356}
357
358BOOST_AUTO_TEST_CASE(TestProcessSectionUnixUnknownOption)
359{
360 const std::string CONFIG =
361 "face_system\n"
362 "{\n"
363 " unix\n"
364 " {\n"
365 " hello\n"
366 " }\n"
367 "}\n";
368 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
369 bind(&isExpectedException, _1,
370 "Unrecognized option \"hello\" in \"unix\" section"));
371}
372
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600373#endif // HAVE_UNIX_SOCKETS
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700374
375
376BOOST_AUTO_TEST_CASE(TestProcessSectionTcp)
377{
378 const std::string CONFIG =
379 "face_system\n"
380 "{\n"
381 " tcp\n"
382 " {\n"
383 " listen yes\n"
384 " port 6363\n"
385 " }\n"
386 "}\n";
387 try
388 {
389 parseConfig(CONFIG, false);
390 }
391 catch (const std::runtime_error& e)
392 {
393 const std::string reason = e.what();
394 if (reason.find("Address in use") != std::string::npos)
395 {
396 BOOST_FAIL(reason);
397 }
398 }
399}
400
401BOOST_AUTO_TEST_CASE(TestProcessSectionTcpDryRun)
402{
403 const std::string CONFIG =
404 "face_system\n"
405 "{\n"
406 " tcp\n"
407 " {\n"
408 " listen yes\n"
409 " port 6363\n"
410 " }\n"
411 "}\n";
412 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
413}
414
415BOOST_AUTO_TEST_CASE(TestProcessSectionTcpBadListen)
416{
417 const std::string CONFIG =
418 "face_system\n"
419 "{\n"
420 " tcp\n"
421 " {\n"
422 " listen hello\n"
423 " }\n"
424 "}\n";
425 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
426 bind(&isExpectedException, _1,
427 "Invalid value for option \"listen\" in \"tcp\" section"));
428}
429
430BOOST_AUTO_TEST_CASE(TestProcessSectionTcpUnknownOption)
431{
432 const std::string CONFIG =
433 "face_system\n"
434 "{\n"
435 " tcp\n"
436 " {\n"
437 " hello\n"
438 " }\n"
439 "}\n";
440 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
441 bind(&isExpectedException, _1,
442 "Unrecognized option \"hello\" in \"tcp\" section"));
443}
444
445BOOST_AUTO_TEST_CASE(TestProcessSectionUdp)
446{
447 const std::string CONFIG =
448 "face_system\n"
449 "{\n"
450 " udp\n"
451 " {\n"
452 " port 6363\n"
453 " idle_timeout 30\n"
454 " keep_alive_interval 25\n"
455 " mcast yes\n"
456 " mcast_port 56363\n"
457 " mcast_group 224.0.23.170\n"
458 " }\n"
459 "}\n";
460 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
461}
462
463BOOST_AUTO_TEST_CASE(TestProcessSectionUdpDryRun)
464{
465 const std::string CONFIG =
466 "face_system\n"
467 "{\n"
468 " udp\n"
469 " {\n"
470 " port 6363\n"
471 " idle_timeout 30\n"
472 " keep_alive_interval 25\n"
473 " mcast yes\n"
474 " mcast_port 56363\n"
475 " mcast_group 224.0.23.170\n"
476 " }\n"
477 "}\n";
478 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
479}
480
481BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadIdleTimeout)
482{
483 const std::string CONFIG =
484 "face_system\n"
485 "{\n"
486 " udp\n"
487 " {\n"
488 " idle_timeout hello\n"
489 " }\n"
490 "}\n";
491
492 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
493 bind(&isExpectedException, _1,
494 "Invalid value for option \"idle_timeout\" in \"udp\" section"));
495}
496
497BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcast)
498{
499 const std::string CONFIG =
500 "face_system\n"
501 "{\n"
502 " udp\n"
503 " {\n"
504 " mcast hello\n"
505 " }\n"
506 "}\n";
507
508 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
509 bind(&isExpectedException, _1,
510 "Invalid value for option \"mcast\" in \"udp\" section"));
511}
512
513BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroup)
514{
515 const std::string CONFIG =
516 "face_system\n"
517 "{\n"
518 " udp\n"
519 " {\n"
520 " mcast no\n"
521 " mcast_port 50\n"
522 " mcast_group hello\n"
523 " }\n"
524 "}\n";
525
526 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
527 bind(&isExpectedException, _1,
528 "Invalid value for option \"mcast_group\" in \"udp\" section"));
529}
530
531BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroupV6)
532{
533 const std::string CONFIG =
534 "face_system\n"
535 "{\n"
536 " udp\n"
537 " {\n"
538 " mcast no\n"
539 " mcast_port 50\n"
540 " mcast_group ::1\n"
541 " }\n"
542 "}\n";
543
544 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
545 bind(&isExpectedException, _1,
546 "Invalid value for option \"mcast_group\" in \"udp\" section"));
547}
548
549BOOST_AUTO_TEST_CASE(TestProcessSectionUdpUnknownOption)
550{
551 const std::string CONFIG =
552 "face_system\n"
553 "{\n"
554 " udp\n"
555 " {\n"
556 " hello\n"
557 " }\n"
558 "}\n";
559 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
560 bind(&isExpectedException, _1,
561 "Unrecognized option \"hello\" in \"udp\" section"));
562}
563
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600564#ifdef HAVE_PCAP
565
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700566BOOST_AUTO_TEST_CASE(TestProcessSectionEther)
567{
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600568
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700569 const std::string CONFIG =
570 "face_system\n"
571 "{\n"
572 " ether\n"
573 " {\n"
574 " mcast yes\n"
575 " mcast_group 01:00:5E:00:17:AA\n"
576 " }\n"
577 "}\n";
578
579 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
580}
581
582BOOST_AUTO_TEST_CASE(TestProcessSectionEtherDryRun)
583{
584 const std::string CONFIG =
585 "face_system\n"
586 "{\n"
587 " ether\n"
588 " {\n"
589 " mcast yes\n"
590 " mcast_group 01:00:5E:00:17:AA\n"
591 " }\n"
592 "}\n";
593
594 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
595}
596
597BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcast)
598{
599 const std::string CONFIG =
600 "face_system\n"
601 "{\n"
602 " ether\n"
603 " {\n"
604 " mcast hello\n"
605 " }\n"
606 "}\n";
607
608 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
609 bind(&isExpectedException, _1,
610 "Invalid value for option \"mcast\" in \"ether\" section"));
611}
612
613BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcastGroup)
614{
615 const std::string CONFIG =
616 "face_system\n"
617 "{\n"
618 " ether\n"
619 " {\n"
620 " mcast yes\n"
621 " mcast_group\n"
622 " }\n"
623 "}\n";
624
625 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
626 bind(&isExpectedException, _1,
627 "Invalid value for option \"mcast_group\" in \"ether\" section"));
628}
629
630BOOST_AUTO_TEST_CASE(TestProcessSectionEtherUnknownOption)
631{
632 const std::string CONFIG =
633 "face_system\n"
634 "{\n"
635 " ether\n"
636 " {\n"
637 " hello\n"
638 " }\n"
639 "}\n";
640 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
641 bind(&isExpectedException, _1,
642 "Unrecognized option \"hello\" in \"ether\" section"));
643}
644
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600645#endif
646
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700647BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
648{
649 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
650
651 getFace()->onReceiveData +=
652 bind(&FaceManagerFixture::validateControlResponse, this, _1,
653 command->getName(), 400, "Malformed command");
654
655 getFace()->sendInterest(*command);
656
657 BOOST_REQUIRE(didCallbackFire());
658}
659
660BOOST_AUTO_TEST_CASE(MalformedCommmand)
661{
662 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
663
664 getFace()->onReceiveData +=
665 bind(&FaceManagerFixture::validateControlResponse, this, _1,
666 command->getName(), 400, "Malformed command");
667
668 getManager().onFaceRequest(*command);
669
670 BOOST_REQUIRE(didCallbackFire());
671}
672
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700673BOOST_AUTO_TEST_CASE(UnsignedCommand)
674{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600675 ControlParameters parameters;
676 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700677
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600678 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700679
680 Name commandName("/localhost/nfd/faces");
681 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600682 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700683
684 shared_ptr<Interest> command(make_shared<Interest>(commandName));
685
686 getFace()->onReceiveData +=
687 bind(&FaceManagerFixture::validateControlResponse, this, _1,
688 command->getName(), 401, "Signature required");
689
690 getManager().onFaceRequest(*command);
691
692 BOOST_REQUIRE(didCallbackFire());
693}
694
695BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>)
696{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600697 ControlParameters parameters;
698 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700699
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600700 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700701
702 Name commandName("/localhost/nfd/faces");
703 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600704 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700705
706 shared_ptr<Interest> command(make_shared<Interest>(commandName));
707 generateCommand(*command);
708
709 getFace()->onReceiveData +=
710 bind(&FaceManagerFixture::validateControlResponse, this, _1,
711 command->getName(), 403, "Unauthorized command");
712
713 getManager().onFaceRequest(*command);
714
715 BOOST_REQUIRE(didCallbackFire());
716}
717
718template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
719{
720public:
721 AuthorizedCommandFixture()
722 {
723 const std::string regex = "^<localhost><nfd><faces>";
724 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
725 }
726
727 virtual
728 ~AuthorizedCommandFixture()
729 {
730
731 }
732};
733
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700734BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700735{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600736 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700737
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600738 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700739
740 Name commandName("/localhost/nfd/faces");
741 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600742 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700743
744 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700745 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700746
747 getFace()->onReceiveData +=
748 bind(&FaceManagerFixture::validateControlResponse, this, _1,
749 command->getName(), 501, "Unsupported command");
750
751 getManager().onFaceRequest(*command);
752
753 BOOST_REQUIRE(didCallbackFire());
754}
755
756class ValidatedFaceRequestFixture : public TestFaceTableFixture,
757 public TestFaceManagerCommon,
758 public FaceManager
759{
760public:
761
762 ValidatedFaceRequestFixture()
763 : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face),
764 m_createFaceFired(false),
765 m_destroyFaceFired(false)
766 {
767
768 }
769
770 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600771 createFace(const Interest& request,
772 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700773 {
774 m_createFaceFired = true;
775 }
776
777 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600778 destroyFace(const Interest& request,
779 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700780 {
781 m_destroyFaceFired = true;
782 }
783
784 virtual
785 ~ValidatedFaceRequestFixture()
786 {
787
788 }
789
790 bool
791 didCreateFaceFire() const
792 {
793 return m_createFaceFired;
794 }
795
796 bool
797 didDestroyFaceFire() const
798 {
799 return m_destroyFaceFired;
800 }
801
802private:
803 bool m_createFaceFired;
804 bool m_destroyFaceFired;
805};
806
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700807BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse,
808 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700809{
810 Name commandName("/localhost/nfd/faces");
811 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600812 commandName.append("NotReallyParameters");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700813
814 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700815 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700816
817 getFace()->onReceiveData +=
818 bind(&ValidatedFaceRequestFixture::validateControlResponse, this, _1,
819 command->getName(), 400, "Malformed command");
820
821 onValidatedFaceRequest(command);
822
823 BOOST_REQUIRE(didCallbackFire());
824}
825
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700826BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace,
827 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700828{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600829 ControlParameters parameters;
830 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700831
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600832 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700833
834 Name commandName("/localhost/nfd/faces");
835 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600836 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700837
838 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700839 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700840
841 onValidatedFaceRequest(command);
842 BOOST_CHECK(didCreateFaceFire());
843}
844
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700845BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace,
846 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700847{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600848 ControlParameters parameters;
849 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700850
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600851 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700852
853 Name commandName("/localhost/nfd/faces");
854 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600855 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700856
857 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700858 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700859
860 onValidatedFaceRequest(command);
861 BOOST_CHECK(didDestroyFaceFire());
862}
863
Steve DiBenedettofbb40a82014-03-11 19:40:15 -0600864class FaceTableFixture
865{
866public:
867 FaceTableFixture()
868 : m_faceTable(m_forwarder)
869 {
870 }
871
872 virtual
873 ~FaceTableFixture()
874 {
875 }
876
877protected:
878 Forwarder m_forwarder;
879 FaceTable m_faceTable;
880};
881
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600882class LocalControlFixture : public FaceTableFixture,
883 public TestFaceManagerCommon,
884 public FaceManager
885{
886public:
887 LocalControlFixture()
888 : FaceManager(FaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face)
889 {
890 }
891};
892
893BOOST_FIXTURE_TEST_CASE(LocalControlInFaceId,
894 AuthorizedCommandFixture<LocalControlFixture>)
895{
896 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
897 BOOST_REQUIRE(dummy->isLocal());
898 FaceTableFixture::m_faceTable.add(dummy);
899
900 ControlParameters parameters;
901 parameters.setFaceId(dummy->getId());
902 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
903
904 Block encodedParameters(parameters.wireEncode());
905
906 Name enable("/localhost/nfd/faces/enable-local-control");
907 enable.append(encodedParameters);
908
909 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
910 enableCommand->setIncomingFaceId(dummy->getId());
911
912 generateCommand(*enableCommand);
913
914 TestFaceManagerCommon::m_face->onReceiveData +=
915 bind(&LocalControlFixture::validateControlResponse, this, _1,
916 enableCommand->getName(), 200, "Success", encodedParameters);
917
918 onValidatedFaceRequest(enableCommand);
919
920 BOOST_REQUIRE(didCallbackFire());
921 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
922 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
923
924 TestFaceManagerCommon::m_face->onReceiveData.clear();
925 resetCallbackFired();
926
927 Name disable("/localhost/nfd/faces/disable-local-control");
928 disable.append(encodedParameters);
929
930 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
931 disableCommand->setIncomingFaceId(dummy->getId());
932
933 generateCommand(*disableCommand);
934
935 TestFaceManagerCommon::m_face->onReceiveData +=
936 bind(&LocalControlFixture::validateControlResponse, this, _1,
937 disableCommand->getName(), 200, "Success", encodedParameters);
938
939 onValidatedFaceRequest(disableCommand);
940
941 BOOST_REQUIRE(didCallbackFire());
942 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
943 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
944}
945
946BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound,
947 AuthorizedCommandFixture<LocalControlFixture>)
948{
949 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
950 BOOST_REQUIRE(dummy->isLocal());
951 FaceTableFixture::m_faceTable.add(dummy);
952
953 ControlParameters parameters;
954 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
955
956 Block encodedParameters(parameters.wireEncode());
957
958 Name enable("/localhost/nfd/faces/enable-local-control");
959 enable.append(encodedParameters);
960
961 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
962 enableCommand->setIncomingFaceId(dummy->getId() + 100);
963
964 generateCommand(*enableCommand);
965
966 TestFaceManagerCommon::m_face->onReceiveData +=
967 bind(&LocalControlFixture::validateControlResponse, this, _1,
968 enableCommand->getName(), 410, "Requested face not found");
969
970 onValidatedFaceRequest(enableCommand);
971
972 BOOST_REQUIRE(didCallbackFire());
973 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
974 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
975
976 TestFaceManagerCommon::m_face->onReceiveData.clear();
977 resetCallbackFired();
978
979 Name disable("/localhost/nfd/faces/disable-local-control");
980 disable.append(encodedParameters);
981
982 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
983 disableCommand->setIncomingFaceId(dummy->getId() + 100);
984
985 generateCommand(*disableCommand);
986
987 TestFaceManagerCommon::m_face->onReceiveData +=
988 bind(&LocalControlFixture::validateControlResponse, this, _1,
989 disableCommand->getName(), 410, "Requested face not found");
990
991 onValidatedFaceRequest(disableCommand);
992
993 BOOST_REQUIRE(didCallbackFire());
994 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
995 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
996}
997
998BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature,
999 AuthorizedCommandFixture<LocalControlFixture>)
1000{
1001 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1002 BOOST_REQUIRE(dummy->isLocal());
1003 FaceTableFixture::m_faceTable.add(dummy);
1004
1005 ControlParameters parameters;
1006 parameters.setFaceId(dummy->getId());
1007
1008 Block encodedParameters(parameters.wireEncode());
1009
1010 Name enable("/localhost/nfd/faces/enable-local-control");
1011 enable.append(encodedParameters);
1012
1013 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1014 enableCommand->setIncomingFaceId(dummy->getId());
1015
1016 generateCommand(*enableCommand);
1017
1018 TestFaceManagerCommon::m_face->onReceiveData +=
1019 bind(&LocalControlFixture::validateControlResponse, this, _1,
1020 enableCommand->getName(), 400, "Malformed command");
1021
1022 onValidatedFaceRequest(enableCommand);
1023
1024 BOOST_REQUIRE(didCallbackFire());
1025 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1026 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1027
1028 TestFaceManagerCommon::m_face->onReceiveData.clear();
1029 resetCallbackFired();
1030
1031 Name disable("/localhost/nfd/faces/disable-local-control");
1032 disable.append(encodedParameters);
1033
1034 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1035 disableCommand->setIncomingFaceId(dummy->getId());
1036
1037 generateCommand(*disableCommand);
1038
1039 TestFaceManagerCommon::m_face->onReceiveData +=
1040 bind(&LocalControlFixture::validateControlResponse, this, _1,
1041 disableCommand->getName(), 400, "Malformed command");
1042
1043 onValidatedFaceRequest(disableCommand);
1044
1045 BOOST_REQUIRE(didCallbackFire());
1046 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1047 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1048}
1049
1050BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal,
1051 AuthorizedCommandFixture<LocalControlFixture>)
1052{
1053 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1054 BOOST_REQUIRE(!dummy->isLocal());
1055 FaceTableFixture::m_faceTable.add(dummy);
1056
1057 ControlParameters parameters;
1058 parameters.setFaceId(dummy->getId());
1059 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1060
1061 Block encodedParameters(parameters.wireEncode());
1062
1063 Name enable("/localhost/nfd/faces/enable-local-control");
1064 enable.append(encodedParameters);
1065
1066 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1067 enableCommand->setIncomingFaceId(dummy->getId());
1068
1069 generateCommand(*enableCommand);
1070
1071 TestFaceManagerCommon::m_face->onReceiveData +=
1072 bind(&LocalControlFixture::validateControlResponse, this, _1,
1073 enableCommand->getName(), 412, "Requested face is non-local");
1074
1075 onValidatedFaceRequest(enableCommand);
1076
1077 BOOST_REQUIRE(didCallbackFire());
1078
1079 TestFaceManagerCommon::m_face->onReceiveData.clear();
1080 resetCallbackFired();
1081
1082 Name disable("/localhost/nfd/faces/disable-local-control");
1083 enable.append(encodedParameters);
1084
1085 shared_ptr<Interest> disableCommand(make_shared<Interest>(enable));
1086 disableCommand->setIncomingFaceId(dummy->getId());
1087
1088 generateCommand(*disableCommand);
1089
1090 TestFaceManagerCommon::m_face->onReceiveData +=
1091 bind(&LocalControlFixture::validateControlResponse, this, _1,
1092 disableCommand->getName(), 412, "Requested face is non-local");
1093
1094 onValidatedFaceRequest(disableCommand);
1095
1096 BOOST_REQUIRE(didCallbackFire());
1097}
1098
1099BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId,
1100 AuthorizedCommandFixture<LocalControlFixture>)
1101{
1102 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1103 BOOST_REQUIRE(dummy->isLocal());
1104 FaceTableFixture::m_faceTable.add(dummy);
1105
1106 ControlParameters parameters;
1107 parameters.setFaceId(dummy->getId());
1108 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1109
1110 Block encodedParameters(parameters.wireEncode());
1111
1112 Name enable("/localhost/nfd/faces/enable-local-control");
1113 enable.append(encodedParameters);
1114
1115 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1116 enableCommand->setIncomingFaceId(dummy->getId());
1117
1118 generateCommand(*enableCommand);
1119
1120 TestFaceManagerCommon::m_face->onReceiveData +=
1121 bind(&LocalControlFixture::validateControlResponse, this, _1,
1122 enableCommand->getName(), 200, "Success", encodedParameters);
1123
1124 onValidatedFaceRequest(enableCommand);
1125
1126 BOOST_REQUIRE(didCallbackFire());
1127 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1128 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1129
1130
1131 TestFaceManagerCommon::m_face->onReceiveData.clear();
1132 resetCallbackFired();
1133
1134 Name disable("/localhost/nfd/faces/disable-local-control");
1135 disable.append(encodedParameters);
1136
1137 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1138 disableCommand->setIncomingFaceId(dummy->getId());
1139
1140 generateCommand(*disableCommand);
1141
1142 TestFaceManagerCommon::m_face->onReceiveData +=
1143 bind(&LocalControlFixture::validateControlResponse, this, _1,
1144 disableCommand->getName(), 200, "Success", encodedParameters);
1145
1146 onValidatedFaceRequest(disableCommand);
1147
1148 BOOST_REQUIRE(didCallbackFire());
1149 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1150 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1151}
1152
1153BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound,
1154 AuthorizedCommandFixture<LocalControlFixture>)
1155{
1156 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1157 BOOST_REQUIRE(dummy->isLocal());
1158 FaceTableFixture::m_faceTable.add(dummy);
1159
1160 ControlParameters parameters;
1161 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1162
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() + 100);
1170
1171 generateCommand(*enableCommand);
1172
1173 TestFaceManagerCommon::m_face->onReceiveData +=
1174 bind(&LocalControlFixture::validateControlResponse, this, _1,
1175 enableCommand->getName(), 410, "Requested face not found");
1176
1177 onValidatedFaceRequest(enableCommand);
1178
1179 BOOST_REQUIRE(didCallbackFire());
1180 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1181 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1182
1183
1184 TestFaceManagerCommon::m_face->onReceiveData.clear();
1185 resetCallbackFired();
1186
1187 Name disable("/localhost/nfd/faces/disable-local-control");
1188 disable.append(encodedParameters);
1189
1190 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1191 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1192
1193 generateCommand(*disableCommand);
1194
1195 TestFaceManagerCommon::m_face->onReceiveData +=
1196 bind(&LocalControlFixture::validateControlResponse, this, _1,
1197 disableCommand->getName(), 410, "Requested face not found");
1198
1199 onValidatedFaceRequest(disableCommand);
1200
1201 BOOST_REQUIRE(didCallbackFire());
1202 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1203 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1204}
1205
1206BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal,
1207 AuthorizedCommandFixture<LocalControlFixture>)
1208{
1209 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1210 BOOST_REQUIRE(!dummy->isLocal());
1211 FaceTableFixture::m_faceTable.add(dummy);
1212
1213 ControlParameters parameters;
1214 parameters.setFaceId(dummy->getId());
1215 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1216
1217 Block encodedParameters(parameters.wireEncode());
1218
1219 Name enable("/localhost/nfd/faces/enable-local-control");
1220 enable.append(encodedParameters);
1221
1222 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1223 enableCommand->setIncomingFaceId(dummy->getId());
1224
1225 generateCommand(*enableCommand);
1226
1227 TestFaceManagerCommon::m_face->onReceiveData +=
1228 bind(&LocalControlFixture::validateControlResponse, this, _1,
1229 enableCommand->getName(), 412, "Requested face is non-local");
1230
1231 onValidatedFaceRequest(enableCommand);
1232
1233 BOOST_REQUIRE(didCallbackFire());
1234
1235 TestFaceManagerCommon::m_face->onReceiveData.clear();
1236 resetCallbackFired();
1237
1238 Name disable("/localhost/nfd/faces/disable-local-control");
1239 disable.append(encodedParameters);
1240
1241 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1242 disableCommand->setIncomingFaceId(dummy->getId());
1243
1244 generateCommand(*disableCommand);
1245
1246 TestFaceManagerCommon::m_face->onReceiveData +=
1247 bind(&LocalControlFixture::validateControlResponse, this, _1,
1248 disableCommand->getName(), 412, "Requested face is non-local");
1249
1250 onValidatedFaceRequest(disableCommand);
1251
1252 BOOST_REQUIRE(didCallbackFire());
1253}
1254
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001255class FaceFixture : public FaceTableFixture,
1256 public TestFaceManagerCommon,
1257 public FaceManager
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001258{
1259public:
1260 FaceFixture()
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001261 : FaceManager(FaceTableFixture::m_faceTable,
1262 TestFaceManagerCommon::m_face)
1263 , m_receivedNotification(false)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001264 {
1265
1266 }
1267
1268 virtual
1269 ~FaceFixture()
1270 {
1271
1272 }
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001273
1274 void
1275 callbackDispatch(const Data& response,
1276 const Name& expectedName,
1277 uint32_t expectedCode,
1278 const std::string& expectedText,
1279 const Block& expectedBody,
1280 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1281 {
1282 Block payload = response.getContent().blockFromValue();
1283 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1284 {
1285 validateControlResponse(response, expectedName, expectedCode,
1286 expectedText, expectedBody);
1287 }
1288 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1289 {
1290 validateFaceEvent(payload, expectedFaceEvent);
1291 }
1292 else
1293 {
1294 BOOST_FAIL("Received unknown message type: #" << payload.type());
1295 }
1296 }
1297
1298 void
1299 callbackDispatch(const Data& response,
1300 const Name& expectedName,
1301 uint32_t expectedCode,
1302 const std::string& expectedText,
1303 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1304 {
1305 Block payload = response.getContent().blockFromValue();
1306 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1307 {
1308 validateControlResponse(response, expectedName,
1309 expectedCode, expectedText);
1310 }
1311 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1312 {
1313 validateFaceEvent(payload, expectedFaceEvent);
1314 }
1315 else
1316 {
1317 BOOST_FAIL("Received unknown message type: #" << payload.type());
1318 }
1319 }
1320
1321 void
1322 validateFaceEvent(const Block& wire,
1323 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1324 {
1325
1326 m_receivedNotification = true;
1327
1328 ndn::nfd::FaceEventNotification notification(wire);
1329
1330 BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId());
1331 BOOST_CHECK_EQUAL(notification.getUri(), expectedFaceEvent.getUri());
1332 BOOST_CHECK_EQUAL(notification.getEventKind(), expectedFaceEvent.getEventKind());
1333 }
1334
1335 bool
1336 didReceiveNotication() const
1337 {
1338 return m_receivedNotification;
1339 }
1340
1341protected:
1342 bool m_receivedNotification;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001343};
1344
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001345BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001346{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001347 ControlParameters parameters;
1348 parameters.setUri("tcp:/127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001349
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001350 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001351
1352 Name commandName("/localhost/nfd/faces");
1353 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001354 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001355
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001356 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1357 generateCommand(*command);
1358
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001359 getFace()->onReceiveData +=
1360 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001361 command->getName(), 400, "Malformed command");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001362
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001363 createFace(*command, parameters);
1364
1365 BOOST_REQUIRE(didCallbackFire());
1366}
1367
1368BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>)
1369{
1370 ControlParameters parameters;
1371
1372 Block encodedParameters(parameters.wireEncode());
1373
1374 Name commandName("/localhost/nfd/faces");
1375 commandName.append("create");
1376 commandName.append(encodedParameters);
1377
1378 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1379 generateCommand(*command);
1380
1381 getFace()->onReceiveData +=
1382 bind(&FaceFixture::validateControlResponse, this, _1,
1383 command->getName(), 400, "Malformed command");
1384
1385 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001386
1387 BOOST_REQUIRE(didCallbackFire());
1388}
1389
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001390BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001391{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001392 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001393 // this will be an unsupported protocol because no factories have been
1394 // added to the face manager
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001395 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001396
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001397 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001398
1399 Name commandName("/localhost/nfd/faces");
1400 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001401 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001402
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001403 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1404 generateCommand(*command);
1405
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001406 getFace()->onReceiveData +=
1407 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001408 command->getName(), 501, "Unsupported protocol");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001409
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001410 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001411
1412 BOOST_REQUIRE(didCallbackFire());
1413}
1414
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001415BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001416{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001417 ControlParameters parameters;
1418 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001419
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001420 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001421
1422 Name commandName("/localhost/nfd/faces");
1423 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001424 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001425
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001426 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1427 generateCommand(*command);
1428
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001429 ControlParameters resultParameters;
1430 resultParameters.setUri("tcp://127.0.0.1");
1431 resultParameters.setFaceId(1);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001432
1433 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1434
1435 ndn::nfd::FaceEventNotification expectedFaceEvent(ndn::nfd::FACE_EVENT_CREATED,
1436 1,
Alexander Afanasyev355c0662014-03-20 18:08:17 -07001437 dummy->getUri().toString(),
1438 0);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001439
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001440 Block encodedResultParameters(resultParameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001441
1442 getFace()->onReceiveData +=
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001443 bind(&FaceFixture::callbackDispatch, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001444 command->getName(), 200, "Success",
1445 encodedResultParameters, expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001446
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001447 onCreated(command->getName(), parameters, dummy);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001448
1449 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001450 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001451}
1452
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001453BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001454{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001455 ControlParameters parameters;
1456 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001457
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001458 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001459
1460 Name commandName("/localhost/nfd/faces");
1461 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001462 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001463
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001464 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1465 generateCommand(*command);
1466
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001467 getFace()->onReceiveData +=
1468 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001469 command->getName(), 400, "Failed to create face");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001470
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001471 onConnectFailed(command->getName(), "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001472
1473 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001474 BOOST_CHECK_EQUAL(didReceiveNotication(), false);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001475}
1476
1477
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001478BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001479{
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001480 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1481 FaceTableFixture::m_faceTable.add(dummy);
1482
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001483 ControlParameters parameters;
1484 parameters.setUri("tcp://127.0.0.1");
1485 parameters.setFaceId(dummy->getId());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001486
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001487 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001488
1489 Name commandName("/localhost/nfd/faces");
1490 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001491 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001492
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001493 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1494 generateCommand(*command);
1495
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001496 ndn::nfd::FaceEventNotification expectedFaceEvent(ndn::nfd::FACE_EVENT_DESTROYED,
1497 dummy->getId(),
Alexander Afanasyev355c0662014-03-20 18:08:17 -07001498 dummy->getUri().toString(), 0);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001499
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001500 getFace()->onReceiveData +=
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001501 bind(&FaceFixture::callbackDispatch, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001502 command->getName(), 200, "Success", boost::ref(encodedParameters), expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001503
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001504 destroyFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001505
1506 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001507 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001508}
1509
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001510class FaceListFixture : public FaceStatusPublisherFixture
1511{
1512public:
1513 FaceListFixture()
1514 : m_manager(m_table, m_face)
1515 {
1516
1517 }
1518
1519 virtual
1520 ~FaceListFixture()
1521 {
1522
1523 }
1524
1525protected:
1526 FaceManager m_manager;
1527};
1528
1529BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture)
1530
1531{
1532 Name commandName("/localhost/nfd/faces/list");
1533 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1534
1535 // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 55
1536 // 55 divides 4400 (== 80), so only use 79 FaceStatuses and then two smaller ones
1537 // to force a FaceStatus to span Data packets
1538 for (int i = 0; i < 79; i++)
1539 {
1540 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1541
1542 uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
1543 dummy->setCounters(filler, filler, filler, filler);
1544
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001545 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001546
1547 add(dummy);
1548 }
1549
1550 for (int i = 0; i < 2; i++)
1551 {
1552 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1553 uint64_t filler = std::numeric_limits<uint32_t>::max() - 1;
1554 dummy->setCounters(filler, filler, filler, filler);
1555
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001556 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001557
1558 add(dummy);
1559 }
1560
1561 ndn::EncodingBuffer buffer;
1562
1563 m_face->onReceiveData +=
1564 bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, this, _1);
1565
1566 m_manager.listFaces(*command);
1567 BOOST_REQUIRE(m_finished);
1568}
1569
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001570BOOST_AUTO_TEST_SUITE_END()
1571
1572} // namespace tests
1573} // namespace nfd
1574
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001575