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 | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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 | |
| 33 | namespace ndn { |
| 34 | namespace tools { |
| 35 | namespace autoconfig { |
| 36 | namespace tests { |
| 37 | |
| 38 | using namespace ::nfd::tools::tests; |
| 39 | using nfd::ControlParameters; |
| 40 | |
| 41 | BOOST_AUTO_TEST_SUITE(NdnAutoconfig) |
| 42 | BOOST_FIXTURE_TEST_SUITE(TestMulticastDiscovery, MockNfdMgmtFixture) |
| 43 | |
| 44 | BOOST_AUTO_TEST_CASE(Normal) |
| 45 | { |
| 46 | this->processInterest = [this] (const Interest& interest) { |
| 47 | if (Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) { |
| 48 | nfd::FaceStatus payload1, payload2; |
| 49 | payload1.setFaceId(860) |
| 50 | .setRemoteUri("ether://[ff:ff:ff:ff:ff:ff]") |
| 51 | .setLocalUri("dev://eth0") |
| 52 | .setFaceScope(nfd::FACE_SCOPE_NON_LOCAL) |
| 53 | .setFacePersistency(nfd::FACE_PERSISTENCY_PERMANENT) |
| 54 | .setLinkType(nfd::LINK_TYPE_MULTI_ACCESS); |
| 55 | payload2.setFaceId(861) |
| 56 | .setRemoteUri("ether://[ff:ff:ff:ff:ff:ff]") |
| 57 | .setLocalUri("dev://eth1") |
| 58 | .setFaceScope(nfd::FACE_SCOPE_NON_LOCAL) |
| 59 | .setFacePersistency(nfd::FACE_PERSISTENCY_PERMANENT) |
| 60 | .setLinkType(nfd::LINK_TYPE_MULTI_ACCESS); |
| 61 | this->sendDataset(interest.getName(), payload1, payload2); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | optional<ControlParameters> req = parseCommand(interest, "/localhost/nfd/rib/register"); |
| 66 | if (req) { |
| 67 | BOOST_REQUIRE(req->hasName()); |
| 68 | BOOST_CHECK_EQUAL(req->getName(), "/localhop/ndn-autoconf/hub"); |
| 69 | BOOST_REQUIRE(req->hasFaceId()); |
| 70 | |
| 71 | if (req->getFaceId() == 860) { |
| 72 | ControlParameters resp; |
| 73 | resp.setName("/localhop/ndn-autoconf/hub") |
| 74 | .setFaceId(860) |
| 75 | .setOrigin(nfd::ROUTE_ORIGIN_APP) |
| 76 | .setCost(1) |
| 77 | .setFlags(0); |
| 78 | this->succeedCommand(interest, resp); |
| 79 | } |
| 80 | else if (req->getFaceId() == 861) { |
| 81 | // no reply, but stage should continue when there is at least one successful registration |
| 82 | } |
| 83 | else { |
| 84 | BOOST_ERROR("unexpected rib/register command"); |
| 85 | } |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | req = parseCommand(interest, "/localhost/nfd/strategy-choice/set"); |
| 90 | if (req) { |
| 91 | BOOST_REQUIRE(req->hasName()); |
| 92 | BOOST_CHECK_EQUAL(req->getName(), "/localhop/ndn-autoconf/hub"); |
| 93 | BOOST_REQUIRE(req->hasStrategy()); |
| 94 | BOOST_CHECK_EQUAL(req->getStrategy(), "/localhost/nfd/strategy/multicast"); |
| 95 | |
| 96 | this->succeedCommand(interest, *req); |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | if (interest.getName() == "/localhop/ndn-autoconf/hub") { |
| 101 | const char FACEURI[] = "udp://router.example.net"; |
| 102 | auto data = makeData(Name("/localhop/ndn-autoconf/hub").appendVersion()); |
| 103 | data->setContent(makeBinaryBlock(tlv::nfd::Uri, FACEURI, ::strlen(FACEURI))); |
| 104 | face.receive(*data); |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | BOOST_ERROR("unexpected Interest " << interest); |
| 109 | }; |
| 110 | |
| 111 | nfd::Controller controller(face, m_keyChain); |
| 112 | MulticastDiscovery stage(face, controller); |
| 113 | |
| 114 | bool hasSuccess = false; |
| 115 | stage.onSuccess.connect([&hasSuccess] (const FaceUri& u) { |
| 116 | BOOST_CHECK(!hasSuccess); |
| 117 | hasSuccess = true; |
| 118 | |
| 119 | BOOST_CHECK(u == FaceUri("udp://router.example.net")); |
| 120 | }); |
| 121 | |
| 122 | stage.onFailure.connect([] (const std::string& reason) { |
| 123 | BOOST_ERROR("unexpected failure: " << reason); |
| 124 | }); |
| 125 | |
| 126 | stage.start(); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 127 | face.processEvents(20_s); |
Junxiao Shi | a5a3a87 | 2017-07-08 12:42:11 +0000 | [diff] [blame] | 128 | BOOST_CHECK(hasSuccess); |
| 129 | } |
| 130 | |
| 131 | BOOST_AUTO_TEST_SUITE_END() // TestMulticastDiscovery |
| 132 | BOOST_AUTO_TEST_SUITE_END() // NdnAutoconfig |
| 133 | |
| 134 | } // namespace tests |
| 135 | } // namespace autoconfig |
| 136 | } // namespace tools |
| 137 | } // namespace ndn |