Junxiao Shi | a5a3a87 | 2017-07-08 12:42:11 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | a599d2a | 2022-02-16 18:52:43 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Junxiao Shi | a5a3a87 | 2017-07-08 12:42:11 +0000 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "ndn-autoconfig/multicast-discovery.hpp" |
| 27 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 28 | #include "tests/tools/mock-nfd-mgmt-fixture.hpp" |
| 29 | |
Junxiao Shi | a5a3a87 | 2017-07-08 12:42:11 +0000 | [diff] [blame] | 30 | #include <ndn-cxx/encoding/block-helpers.hpp> |
| 31 | #include <ndn-cxx/encoding/tlv-nfd.hpp> |
| 32 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 33 | namespace ndn::autoconfig::tests { |
Junxiao Shi | a5a3a87 | 2017-07-08 12:42:11 +0000 | [diff] [blame] | 34 | |
| 35 | BOOST_AUTO_TEST_SUITE(NdnAutoconfig) |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 36 | BOOST_FIXTURE_TEST_SUITE(TestMulticastDiscovery, ::nfd::tests::MockNfdMgmtFixture) |
Junxiao Shi | a5a3a87 | 2017-07-08 12:42:11 +0000 | [diff] [blame] | 37 | |
| 38 | BOOST_AUTO_TEST_CASE(Normal) |
| 39 | { |
| 40 | this->processInterest = [this] (const Interest& interest) { |
| 41 | if (Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) { |
| 42 | nfd::FaceStatus payload1, payload2; |
| 43 | payload1.setFaceId(860) |
| 44 | .setRemoteUri("ether://[ff:ff:ff:ff:ff:ff]") |
| 45 | .setLocalUri("dev://eth0") |
| 46 | .setFaceScope(nfd::FACE_SCOPE_NON_LOCAL) |
| 47 | .setFacePersistency(nfd::FACE_PERSISTENCY_PERMANENT) |
| 48 | .setLinkType(nfd::LINK_TYPE_MULTI_ACCESS); |
| 49 | payload2.setFaceId(861) |
| 50 | .setRemoteUri("ether://[ff:ff:ff:ff:ff:ff]") |
| 51 | .setLocalUri("dev://eth1") |
| 52 | .setFaceScope(nfd::FACE_SCOPE_NON_LOCAL) |
| 53 | .setFacePersistency(nfd::FACE_PERSISTENCY_PERMANENT) |
| 54 | .setLinkType(nfd::LINK_TYPE_MULTI_ACCESS); |
| 55 | this->sendDataset(interest.getName(), payload1, payload2); |
| 56 | return; |
| 57 | } |
| 58 | |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 59 | auto req = parseCommand(interest, "/localhost/nfd/rib/register"); |
Junxiao Shi | a5a3a87 | 2017-07-08 12:42:11 +0000 | [diff] [blame] | 60 | if (req) { |
| 61 | BOOST_REQUIRE(req->hasName()); |
| 62 | BOOST_CHECK_EQUAL(req->getName(), "/localhop/ndn-autoconf/hub"); |
| 63 | BOOST_REQUIRE(req->hasFaceId()); |
| 64 | |
| 65 | if (req->getFaceId() == 860) { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 66 | nfd::ControlParameters resp; |
Junxiao Shi | a5a3a87 | 2017-07-08 12:42:11 +0000 | [diff] [blame] | 67 | resp.setName("/localhop/ndn-autoconf/hub") |
| 68 | .setFaceId(860) |
| 69 | .setOrigin(nfd::ROUTE_ORIGIN_APP) |
| 70 | .setCost(1) |
| 71 | .setFlags(0); |
| 72 | this->succeedCommand(interest, resp); |
| 73 | } |
| 74 | else if (req->getFaceId() == 861) { |
| 75 | // no reply, but stage should continue when there is at least one successful registration |
| 76 | } |
| 77 | else { |
| 78 | BOOST_ERROR("unexpected rib/register command"); |
| 79 | } |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | req = parseCommand(interest, "/localhost/nfd/strategy-choice/set"); |
| 84 | if (req) { |
| 85 | BOOST_REQUIRE(req->hasName()); |
| 86 | BOOST_CHECK_EQUAL(req->getName(), "/localhop/ndn-autoconf/hub"); |
| 87 | BOOST_REQUIRE(req->hasStrategy()); |
| 88 | BOOST_CHECK_EQUAL(req->getStrategy(), "/localhost/nfd/strategy/multicast"); |
| 89 | |
| 90 | this->succeedCommand(interest, *req); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | if (interest.getName() == "/localhop/ndn-autoconf/hub") { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 95 | auto data = ::nfd::tests::makeData(Name("/localhop/ndn-autoconf/hub").appendVersion()); |
Junxiao Shi | 73b4980 | 2019-05-25 07:52:26 +0000 | [diff] [blame] | 96 | data->setFreshnessPeriod(1_s); |
Davide Pesavento | a599d2a | 2022-02-16 18:52:43 -0500 | [diff] [blame] | 97 | data->setContent(makeStringBlock(tlv::nfd::Uri, "udp://router.example.net")); |
Junxiao Shi | a5a3a87 | 2017-07-08 12:42:11 +0000 | [diff] [blame] | 98 | face.receive(*data); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | BOOST_ERROR("unexpected Interest " << interest); |
| 103 | }; |
| 104 | |
| 105 | nfd::Controller controller(face, m_keyChain); |
| 106 | MulticastDiscovery stage(face, controller); |
| 107 | |
| 108 | bool hasSuccess = false; |
| 109 | stage.onSuccess.connect([&hasSuccess] (const FaceUri& u) { |
| 110 | BOOST_CHECK(!hasSuccess); |
| 111 | hasSuccess = true; |
| 112 | |
| 113 | BOOST_CHECK(u == FaceUri("udp://router.example.net")); |
| 114 | }); |
| 115 | |
| 116 | stage.onFailure.connect([] (const std::string& reason) { |
| 117 | BOOST_ERROR("unexpected failure: " << reason); |
| 118 | }); |
| 119 | |
| 120 | stage.start(); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 121 | face.processEvents(20_s); |
Junxiao Shi | a5a3a87 | 2017-07-08 12:42:11 +0000 | [diff] [blame] | 122 | BOOST_CHECK(hasSuccess); |
| 123 | } |
| 124 | |
| 125 | BOOST_AUTO_TEST_SUITE_END() // TestMulticastDiscovery |
| 126 | BOOST_AUTO_TEST_SUITE_END() // NdnAutoconfig |
| 127 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 128 | } // namespace ndn::autoconfig::tests |