blob: d439ea4e7fcb8d844a05f956195852d5ce2d13b4 [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);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700656 g_io.run_one();
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700657
658 BOOST_REQUIRE(didCallbackFire());
659}
660
661BOOST_AUTO_TEST_CASE(MalformedCommmand)
662{
663 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
664
665 getFace()->onReceiveData +=
666 bind(&FaceManagerFixture::validateControlResponse, this, _1,
667 command->getName(), 400, "Malformed command");
668
669 getManager().onFaceRequest(*command);
670
671 BOOST_REQUIRE(didCallbackFire());
672}
673
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700674BOOST_AUTO_TEST_CASE(UnsignedCommand)
675{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600676 ControlParameters parameters;
677 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700678
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600679 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700680
681 Name commandName("/localhost/nfd/faces");
682 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600683 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700684
685 shared_ptr<Interest> command(make_shared<Interest>(commandName));
686
687 getFace()->onReceiveData +=
688 bind(&FaceManagerFixture::validateControlResponse, this, _1,
689 command->getName(), 401, "Signature required");
690
691 getManager().onFaceRequest(*command);
692
693 BOOST_REQUIRE(didCallbackFire());
694}
695
696BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>)
697{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600698 ControlParameters parameters;
699 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700700
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600701 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700702
703 Name commandName("/localhost/nfd/faces");
704 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600705 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700706
707 shared_ptr<Interest> command(make_shared<Interest>(commandName));
708 generateCommand(*command);
709
710 getFace()->onReceiveData +=
711 bind(&FaceManagerFixture::validateControlResponse, this, _1,
712 command->getName(), 403, "Unauthorized command");
713
714 getManager().onFaceRequest(*command);
715
716 BOOST_REQUIRE(didCallbackFire());
717}
718
719template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
720{
721public:
722 AuthorizedCommandFixture()
723 {
724 const std::string regex = "^<localhost><nfd><faces>";
725 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
726 }
727
728 virtual
729 ~AuthorizedCommandFixture()
730 {
731
732 }
733};
734
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700735BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700736{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600737 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700738
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600739 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700740
741 Name commandName("/localhost/nfd/faces");
742 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600743 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700744
745 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700746 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700747
748 getFace()->onReceiveData +=
749 bind(&FaceManagerFixture::validateControlResponse, this, _1,
750 command->getName(), 501, "Unsupported command");
751
752 getManager().onFaceRequest(*command);
753
754 BOOST_REQUIRE(didCallbackFire());
755}
756
757class ValidatedFaceRequestFixture : public TestFaceTableFixture,
758 public TestFaceManagerCommon,
759 public FaceManager
760{
761public:
762
763 ValidatedFaceRequestFixture()
764 : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face),
765 m_createFaceFired(false),
766 m_destroyFaceFired(false)
767 {
768
769 }
770
771 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600772 createFace(const Interest& request,
773 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700774 {
775 m_createFaceFired = true;
776 }
777
778 virtual void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600779 destroyFace(const Interest& request,
780 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700781 {
782 m_destroyFaceFired = true;
783 }
784
785 virtual
786 ~ValidatedFaceRequestFixture()
787 {
788
789 }
790
791 bool
792 didCreateFaceFire() const
793 {
794 return m_createFaceFired;
795 }
796
797 bool
798 didDestroyFaceFire() const
799 {
800 return m_destroyFaceFired;
801 }
802
803private:
804 bool m_createFaceFired;
805 bool m_destroyFaceFired;
806};
807
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700808BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse,
809 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700810{
811 Name commandName("/localhost/nfd/faces");
812 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600813 commandName.append("NotReallyParameters");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700814
815 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700816 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700817
818 getFace()->onReceiveData +=
819 bind(&ValidatedFaceRequestFixture::validateControlResponse, this, _1,
820 command->getName(), 400, "Malformed command");
821
822 onValidatedFaceRequest(command);
823
824 BOOST_REQUIRE(didCallbackFire());
825}
826
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700827BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace,
828 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700829{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600830 ControlParameters parameters;
831 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700832
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600833 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700834
835 Name commandName("/localhost/nfd/faces");
836 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600837 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700838
839 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700840 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700841
842 onValidatedFaceRequest(command);
843 BOOST_CHECK(didCreateFaceFire());
844}
845
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700846BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace,
847 AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700848{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600849 ControlParameters parameters;
850 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700851
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600852 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700853
854 Name commandName("/localhost/nfd/faces");
855 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600856 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700857
858 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700859 generateCommand(*command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700860
861 onValidatedFaceRequest(command);
862 BOOST_CHECK(didDestroyFaceFire());
863}
864
Steve DiBenedettofbb40a82014-03-11 19:40:15 -0600865class FaceTableFixture
866{
867public:
868 FaceTableFixture()
869 : m_faceTable(m_forwarder)
870 {
871 }
872
873 virtual
874 ~FaceTableFixture()
875 {
876 }
877
878protected:
879 Forwarder m_forwarder;
880 FaceTable m_faceTable;
881};
882
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600883class LocalControlFixture : public FaceTableFixture,
884 public TestFaceManagerCommon,
885 public FaceManager
886{
887public:
888 LocalControlFixture()
889 : FaceManager(FaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face)
890 {
891 }
892};
893
894BOOST_FIXTURE_TEST_CASE(LocalControlInFaceId,
895 AuthorizedCommandFixture<LocalControlFixture>)
896{
897 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
898 BOOST_REQUIRE(dummy->isLocal());
899 FaceTableFixture::m_faceTable.add(dummy);
900
901 ControlParameters parameters;
902 parameters.setFaceId(dummy->getId());
903 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
904
905 Block encodedParameters(parameters.wireEncode());
906
907 Name enable("/localhost/nfd/faces/enable-local-control");
908 enable.append(encodedParameters);
909
910 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
911 enableCommand->setIncomingFaceId(dummy->getId());
912
913 generateCommand(*enableCommand);
914
915 TestFaceManagerCommon::m_face->onReceiveData +=
916 bind(&LocalControlFixture::validateControlResponse, this, _1,
917 enableCommand->getName(), 200, "Success", encodedParameters);
918
919 onValidatedFaceRequest(enableCommand);
920
921 BOOST_REQUIRE(didCallbackFire());
922 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
923 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
924
925 TestFaceManagerCommon::m_face->onReceiveData.clear();
926 resetCallbackFired();
927
928 Name disable("/localhost/nfd/faces/disable-local-control");
929 disable.append(encodedParameters);
930
931 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
932 disableCommand->setIncomingFaceId(dummy->getId());
933
934 generateCommand(*disableCommand);
935
936 TestFaceManagerCommon::m_face->onReceiveData +=
937 bind(&LocalControlFixture::validateControlResponse, this, _1,
938 disableCommand->getName(), 200, "Success", encodedParameters);
939
940 onValidatedFaceRequest(disableCommand);
941
942 BOOST_REQUIRE(didCallbackFire());
943 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
944 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
945}
946
947BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound,
948 AuthorizedCommandFixture<LocalControlFixture>)
949{
950 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
951 BOOST_REQUIRE(dummy->isLocal());
952 FaceTableFixture::m_faceTable.add(dummy);
953
954 ControlParameters parameters;
955 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
956
957 Block encodedParameters(parameters.wireEncode());
958
959 Name enable("/localhost/nfd/faces/enable-local-control");
960 enable.append(encodedParameters);
961
962 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
963 enableCommand->setIncomingFaceId(dummy->getId() + 100);
964
965 generateCommand(*enableCommand);
966
967 TestFaceManagerCommon::m_face->onReceiveData +=
968 bind(&LocalControlFixture::validateControlResponse, this, _1,
969 enableCommand->getName(), 410, "Requested face not found");
970
971 onValidatedFaceRequest(enableCommand);
972
973 BOOST_REQUIRE(didCallbackFire());
974 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
975 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
976
977 TestFaceManagerCommon::m_face->onReceiveData.clear();
978 resetCallbackFired();
979
980 Name disable("/localhost/nfd/faces/disable-local-control");
981 disable.append(encodedParameters);
982
983 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
984 disableCommand->setIncomingFaceId(dummy->getId() + 100);
985
986 generateCommand(*disableCommand);
987
988 TestFaceManagerCommon::m_face->onReceiveData +=
989 bind(&LocalControlFixture::validateControlResponse, this, _1,
990 disableCommand->getName(), 410, "Requested face not found");
991
992 onValidatedFaceRequest(disableCommand);
993
994 BOOST_REQUIRE(didCallbackFire());
995 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
996 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
997}
998
999BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature,
1000 AuthorizedCommandFixture<LocalControlFixture>)
1001{
1002 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1003 BOOST_REQUIRE(dummy->isLocal());
1004 FaceTableFixture::m_faceTable.add(dummy);
1005
1006 ControlParameters parameters;
1007 parameters.setFaceId(dummy->getId());
1008
1009 Block encodedParameters(parameters.wireEncode());
1010
1011 Name enable("/localhost/nfd/faces/enable-local-control");
1012 enable.append(encodedParameters);
1013
1014 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1015 enableCommand->setIncomingFaceId(dummy->getId());
1016
1017 generateCommand(*enableCommand);
1018
1019 TestFaceManagerCommon::m_face->onReceiveData +=
1020 bind(&LocalControlFixture::validateControlResponse, this, _1,
1021 enableCommand->getName(), 400, "Malformed command");
1022
1023 onValidatedFaceRequest(enableCommand);
1024
1025 BOOST_REQUIRE(didCallbackFire());
1026 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1027 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1028
1029 TestFaceManagerCommon::m_face->onReceiveData.clear();
1030 resetCallbackFired();
1031
1032 Name disable("/localhost/nfd/faces/disable-local-control");
1033 disable.append(encodedParameters);
1034
1035 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1036 disableCommand->setIncomingFaceId(dummy->getId());
1037
1038 generateCommand(*disableCommand);
1039
1040 TestFaceManagerCommon::m_face->onReceiveData +=
1041 bind(&LocalControlFixture::validateControlResponse, this, _1,
1042 disableCommand->getName(), 400, "Malformed command");
1043
1044 onValidatedFaceRequest(disableCommand);
1045
1046 BOOST_REQUIRE(didCallbackFire());
1047 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1048 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1049}
1050
1051BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal,
1052 AuthorizedCommandFixture<LocalControlFixture>)
1053{
1054 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1055 BOOST_REQUIRE(!dummy->isLocal());
1056 FaceTableFixture::m_faceTable.add(dummy);
1057
1058 ControlParameters parameters;
1059 parameters.setFaceId(dummy->getId());
1060 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
1061
1062 Block encodedParameters(parameters.wireEncode());
1063
1064 Name enable("/localhost/nfd/faces/enable-local-control");
1065 enable.append(encodedParameters);
1066
1067 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1068 enableCommand->setIncomingFaceId(dummy->getId());
1069
1070 generateCommand(*enableCommand);
1071
1072 TestFaceManagerCommon::m_face->onReceiveData +=
1073 bind(&LocalControlFixture::validateControlResponse, this, _1,
1074 enableCommand->getName(), 412, "Requested face is non-local");
1075
1076 onValidatedFaceRequest(enableCommand);
1077
1078 BOOST_REQUIRE(didCallbackFire());
1079
1080 TestFaceManagerCommon::m_face->onReceiveData.clear();
1081 resetCallbackFired();
1082
1083 Name disable("/localhost/nfd/faces/disable-local-control");
1084 enable.append(encodedParameters);
1085
1086 shared_ptr<Interest> disableCommand(make_shared<Interest>(enable));
1087 disableCommand->setIncomingFaceId(dummy->getId());
1088
1089 generateCommand(*disableCommand);
1090
1091 TestFaceManagerCommon::m_face->onReceiveData +=
1092 bind(&LocalControlFixture::validateControlResponse, this, _1,
1093 disableCommand->getName(), 412, "Requested face is non-local");
1094
1095 onValidatedFaceRequest(disableCommand);
1096
1097 BOOST_REQUIRE(didCallbackFire());
1098}
1099
1100BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId,
1101 AuthorizedCommandFixture<LocalControlFixture>)
1102{
1103 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
1104 BOOST_REQUIRE(dummy->isLocal());
1105 FaceTableFixture::m_faceTable.add(dummy);
1106
1107 ControlParameters parameters;
1108 parameters.setFaceId(dummy->getId());
1109 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1110
1111 Block encodedParameters(parameters.wireEncode());
1112
1113 Name enable("/localhost/nfd/faces/enable-local-control");
1114 enable.append(encodedParameters);
1115
1116 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1117 enableCommand->setIncomingFaceId(dummy->getId());
1118
1119 generateCommand(*enableCommand);
1120
1121 TestFaceManagerCommon::m_face->onReceiveData +=
1122 bind(&LocalControlFixture::validateControlResponse, this, _1,
1123 enableCommand->getName(), 200, "Success", encodedParameters);
1124
1125 onValidatedFaceRequest(enableCommand);
1126
1127 BOOST_REQUIRE(didCallbackFire());
1128 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1129 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1130
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());
1140
1141 generateCommand(*disableCommand);
1142
1143 TestFaceManagerCommon::m_face->onReceiveData +=
1144 bind(&LocalControlFixture::validateControlResponse, this, _1,
1145 disableCommand->getName(), 200, "Success", encodedParameters);
1146
1147 onValidatedFaceRequest(disableCommand);
1148
1149 BOOST_REQUIRE(didCallbackFire());
1150 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1151 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1152}
1153
1154BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound,
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;
1162 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1163
1164 Block encodedParameters(parameters.wireEncode());
1165
1166 Name enable("/localhost/nfd/faces/enable-local-control");
1167 enable.append(encodedParameters);
1168
1169 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1170 enableCommand->setIncomingFaceId(dummy->getId() + 100);
1171
1172 generateCommand(*enableCommand);
1173
1174 TestFaceManagerCommon::m_face->onReceiveData +=
1175 bind(&LocalControlFixture::validateControlResponse, this, _1,
1176 enableCommand->getName(), 410, "Requested face not found");
1177
1178 onValidatedFaceRequest(enableCommand);
1179
1180 BOOST_REQUIRE(didCallbackFire());
1181 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1182 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1183
1184
1185 TestFaceManagerCommon::m_face->onReceiveData.clear();
1186 resetCallbackFired();
1187
1188 Name disable("/localhost/nfd/faces/disable-local-control");
1189 disable.append(encodedParameters);
1190
1191 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1192 disableCommand->setIncomingFaceId(dummy->getId() + 100);
1193
1194 generateCommand(*disableCommand);
1195
1196 TestFaceManagerCommon::m_face->onReceiveData +=
1197 bind(&LocalControlFixture::validateControlResponse, this, _1,
1198 disableCommand->getName(), 410, "Requested face not found");
1199
1200 onValidatedFaceRequest(disableCommand);
1201
1202 BOOST_REQUIRE(didCallbackFire());
1203 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
1204 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
1205}
1206
1207BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal,
1208 AuthorizedCommandFixture<LocalControlFixture>)
1209{
1210 shared_ptr<DummyFace> dummy = make_shared<DummyFace>();
1211 BOOST_REQUIRE(!dummy->isLocal());
1212 FaceTableFixture::m_faceTable.add(dummy);
1213
1214 ControlParameters parameters;
1215 parameters.setFaceId(dummy->getId());
1216 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
1217
1218 Block encodedParameters(parameters.wireEncode());
1219
1220 Name enable("/localhost/nfd/faces/enable-local-control");
1221 enable.append(encodedParameters);
1222
1223 shared_ptr<Interest> enableCommand(make_shared<Interest>(enable));
1224 enableCommand->setIncomingFaceId(dummy->getId());
1225
1226 generateCommand(*enableCommand);
1227
1228 TestFaceManagerCommon::m_face->onReceiveData +=
1229 bind(&LocalControlFixture::validateControlResponse, this, _1,
1230 enableCommand->getName(), 412, "Requested face is non-local");
1231
1232 onValidatedFaceRequest(enableCommand);
1233
1234 BOOST_REQUIRE(didCallbackFire());
1235
1236 TestFaceManagerCommon::m_face->onReceiveData.clear();
1237 resetCallbackFired();
1238
1239 Name disable("/localhost/nfd/faces/disable-local-control");
1240 disable.append(encodedParameters);
1241
1242 shared_ptr<Interest> disableCommand(make_shared<Interest>(disable));
1243 disableCommand->setIncomingFaceId(dummy->getId());
1244
1245 generateCommand(*disableCommand);
1246
1247 TestFaceManagerCommon::m_face->onReceiveData +=
1248 bind(&LocalControlFixture::validateControlResponse, this, _1,
1249 disableCommand->getName(), 412, "Requested face is non-local");
1250
1251 onValidatedFaceRequest(disableCommand);
1252
1253 BOOST_REQUIRE(didCallbackFire());
1254}
1255
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001256class FaceFixture : public FaceTableFixture,
1257 public TestFaceManagerCommon,
1258 public FaceManager
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001259{
1260public:
1261 FaceFixture()
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001262 : FaceManager(FaceTableFixture::m_faceTable,
1263 TestFaceManagerCommon::m_face)
1264 , m_receivedNotification(false)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001265 {
1266
1267 }
1268
1269 virtual
1270 ~FaceFixture()
1271 {
1272
1273 }
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001274
1275 void
1276 callbackDispatch(const Data& response,
1277 const Name& expectedName,
1278 uint32_t expectedCode,
1279 const std::string& expectedText,
1280 const Block& expectedBody,
1281 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1282 {
1283 Block payload = response.getContent().blockFromValue();
1284 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1285 {
1286 validateControlResponse(response, expectedName, expectedCode,
1287 expectedText, expectedBody);
1288 }
1289 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1290 {
1291 validateFaceEvent(payload, expectedFaceEvent);
1292 }
1293 else
1294 {
1295 BOOST_FAIL("Received unknown message type: #" << payload.type());
1296 }
1297 }
1298
1299 void
1300 callbackDispatch(const Data& response,
1301 const Name& expectedName,
1302 uint32_t expectedCode,
1303 const std::string& expectedText,
1304 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1305 {
1306 Block payload = response.getContent().blockFromValue();
1307 if (payload.type() == ndn::tlv::nfd::ControlResponse)
1308 {
1309 validateControlResponse(response, expectedName,
1310 expectedCode, expectedText);
1311 }
1312 else if (payload.type() == ndn::tlv::nfd::FaceEventNotification)
1313 {
1314 validateFaceEvent(payload, expectedFaceEvent);
1315 }
1316 else
1317 {
1318 BOOST_FAIL("Received unknown message type: #" << payload.type());
1319 }
1320 }
1321
1322 void
1323 validateFaceEvent(const Block& wire,
1324 const ndn::nfd::FaceEventNotification& expectedFaceEvent)
1325 {
1326
1327 m_receivedNotification = true;
1328
1329 ndn::nfd::FaceEventNotification notification(wire);
1330
1331 BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId());
1332 BOOST_CHECK_EQUAL(notification.getUri(), expectedFaceEvent.getUri());
1333 BOOST_CHECK_EQUAL(notification.getEventKind(), expectedFaceEvent.getEventKind());
1334 }
1335
1336 bool
1337 didReceiveNotication() const
1338 {
1339 return m_receivedNotification;
1340 }
1341
1342protected:
1343 bool m_receivedNotification;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001344};
1345
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001346BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001347{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001348 ControlParameters parameters;
1349 parameters.setUri("tcp:/127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001350
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001351 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001352
1353 Name commandName("/localhost/nfd/faces");
1354 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001355 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001356
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001357 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1358 generateCommand(*command);
1359
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001360 getFace()->onReceiveData +=
1361 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001362 command->getName(), 400, "Malformed command");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001363
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001364 createFace(*command, parameters);
1365
1366 BOOST_REQUIRE(didCallbackFire());
1367}
1368
1369BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>)
1370{
1371 ControlParameters parameters;
1372
1373 Block encodedParameters(parameters.wireEncode());
1374
1375 Name commandName("/localhost/nfd/faces");
1376 commandName.append("create");
1377 commandName.append(encodedParameters);
1378
1379 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1380 generateCommand(*command);
1381
1382 getFace()->onReceiveData +=
1383 bind(&FaceFixture::validateControlResponse, this, _1,
1384 command->getName(), 400, "Malformed command");
1385
1386 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001387
1388 BOOST_REQUIRE(didCallbackFire());
1389}
1390
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001391BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001392{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001393 ControlParameters parameters;
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001394 // this will be an unsupported protocol because no factories have been
1395 // added to the face manager
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001396 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001397
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001398 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001399
1400 Name commandName("/localhost/nfd/faces");
1401 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001402 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001403
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001404 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1405 generateCommand(*command);
1406
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001407 getFace()->onReceiveData +=
1408 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001409 command->getName(), 501, "Unsupported protocol");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001410
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001411 createFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001412
1413 BOOST_REQUIRE(didCallbackFire());
1414}
1415
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001416BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001417{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001418 ControlParameters parameters;
1419 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001420
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001421 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001422
1423 Name commandName("/localhost/nfd/faces");
1424 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001425 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001426
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001427 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1428 generateCommand(*command);
1429
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001430 ControlParameters resultParameters;
1431 resultParameters.setUri("tcp://127.0.0.1");
1432 resultParameters.setFaceId(1);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001433
1434 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1435
1436 ndn::nfd::FaceEventNotification expectedFaceEvent(ndn::nfd::FACE_EVENT_CREATED,
1437 1,
Alexander Afanasyev355c0662014-03-20 18:08:17 -07001438 dummy->getUri().toString(),
1439 0);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001440
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001441 Block encodedResultParameters(resultParameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001442
1443 getFace()->onReceiveData +=
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001444 bind(&FaceFixture::callbackDispatch, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001445 command->getName(), 200, "Success",
1446 encodedResultParameters, expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001447
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001448 onCreated(command->getName(), parameters, dummy);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001449
1450 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001451 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001452}
1453
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001454BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001455{
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001456 ControlParameters parameters;
1457 parameters.setUri("tcp://127.0.0.1");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001458
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001459 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001460
1461 Name commandName("/localhost/nfd/faces");
1462 commandName.append("create");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001463 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001464
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001465 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1466 generateCommand(*command);
1467
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001468 getFace()->onReceiveData +=
1469 bind(&FaceFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001470 command->getName(), 400, "Failed to create face");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001471
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001472 onConnectFailed(command->getName(), "unit-test-reason");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001473
1474 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001475 BOOST_CHECK_EQUAL(didReceiveNotication(), false);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001476}
1477
1478
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001479BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001480{
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001481 shared_ptr<DummyFace> dummy(make_shared<DummyFace>());
1482 FaceTableFixture::m_faceTable.add(dummy);
1483
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001484 ControlParameters parameters;
1485 parameters.setUri("tcp://127.0.0.1");
1486 parameters.setFaceId(dummy->getId());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001487
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001488 Block encodedParameters(parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001489
1490 Name commandName("/localhost/nfd/faces");
1491 commandName.append("destroy");
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001492 commandName.append(encodedParameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001493
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001494 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1495 generateCommand(*command);
1496
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001497 ndn::nfd::FaceEventNotification expectedFaceEvent(ndn::nfd::FACE_EVENT_DESTROYED,
1498 dummy->getId(),
Alexander Afanasyev355c0662014-03-20 18:08:17 -07001499 dummy->getUri().toString(), 0);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001500
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001501 getFace()->onReceiveData +=
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001502 bind(&FaceFixture::callbackDispatch, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001503 command->getName(), 200, "Success", boost::ref(encodedParameters), expectedFaceEvent);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001504
Steve DiBenedetto7564d972014-03-24 14:28:46 -06001505 destroyFace(*command, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001506
1507 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001508 BOOST_REQUIRE(didReceiveNotication());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001509}
1510
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001511class FaceListFixture : public FaceStatusPublisherFixture
1512{
1513public:
1514 FaceListFixture()
1515 : m_manager(m_table, m_face)
1516 {
1517
1518 }
1519
1520 virtual
1521 ~FaceListFixture()
1522 {
1523
1524 }
1525
1526protected:
1527 FaceManager m_manager;
1528};
1529
1530BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture)
1531
1532{
1533 Name commandName("/localhost/nfd/faces/list");
1534 shared_ptr<Interest> command(make_shared<Interest>(commandName));
1535
1536 // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 55
1537 // 55 divides 4400 (== 80), so only use 79 FaceStatuses and then two smaller ones
1538 // to force a FaceStatus to span Data packets
1539 for (int i = 0; i < 79; i++)
1540 {
1541 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1542
1543 uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
1544 dummy->setCounters(filler, filler, filler, filler);
1545
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001546 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001547
1548 add(dummy);
1549 }
1550
1551 for (int i = 0; i < 2; i++)
1552 {
1553 shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
1554 uint64_t filler = std::numeric_limits<uint32_t>::max() - 1;
1555 dummy->setCounters(filler, filler, filler, filler);
1556
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -07001557 m_referenceFaces.push_back(dummy);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001558
1559 add(dummy);
1560 }
1561
1562 ndn::EncodingBuffer buffer;
1563
1564 m_face->onReceiveData +=
1565 bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, this, _1);
1566
1567 m_manager.listFaces(*command);
1568 BOOST_REQUIRE(m_finished);
1569}
1570
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001571BOOST_AUTO_TEST_SUITE_END()
1572
1573} // namespace tests
1574} // namespace nfd
1575
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001576