Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | b5eee20 | 2017-09-21 23:59:22 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, Regents of the University of California, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [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 "face-manager-command-fixture.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 27 | #include "common/global.hpp" |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 28 | |
Davide Pesavento | b5eee20 | 2017-09-21 23:59:22 -0400 | [diff] [blame] | 29 | #include <ndn-cxx/net/network-monitor-stub.hpp> |
| 30 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 31 | namespace nfd::tests { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 32 | |
| 33 | FaceManagerCommandNode::FaceManagerCommandNode(ndn::KeyChain& keyChain, uint16_t port) |
| 34 | : face(getGlobalIoService(), keyChain, {true, true}) |
| 35 | , dispatcher(face, keyChain, ndn::security::SigningInfo()) |
| 36 | , authenticator(CommandAuthenticator::create()) |
Davide Pesavento | b5eee20 | 2017-09-21 23:59:22 -0400 | [diff] [blame] | 37 | , faceSystem(faceTable, make_shared<ndn::net::NetworkMonitorStub>(0)) |
Junxiao Shi | ea47bde | 2017-01-26 17:49:16 +0000 | [diff] [blame] | 38 | , manager(faceSystem, dispatcher, *authenticator) |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 39 | { |
| 40 | dispatcher.addTopPrefix("/localhost/nfd"); |
| 41 | |
Davide Pesavento | cfb1a31 | 2018-03-01 01:30:56 -0500 | [diff] [blame] | 42 | const std::string config = |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 43 | "face_system\n" |
| 44 | "{\n" |
| 45 | " tcp\n" |
| 46 | " {\n" |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame] | 47 | " port " + std::to_string(port) + "\n" |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 48 | " }\n" |
| 49 | " udp\n" |
| 50 | " {\n" |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame] | 51 | " port " + std::to_string(port) + "\n" |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 52 | " mcast no\n" |
| 53 | " }\n" |
| 54 | " ether\n" |
| 55 | " {\n" |
| 56 | " mcast no\n" |
| 57 | " }\n" |
| 58 | "}\n" |
| 59 | "authorizations\n" |
| 60 | "{\n" |
| 61 | " authorize\n" |
| 62 | " {\n" |
| 63 | " certfile any\n" |
| 64 | " privileges\n" |
| 65 | " {\n" |
| 66 | " faces\n" |
| 67 | " }\n" |
| 68 | " }\n" |
| 69 | "}\n" |
| 70 | "\n"; |
| 71 | |
| 72 | ConfigFile cf; |
Davide Pesavento | cfb1a31 | 2018-03-01 01:30:56 -0500 | [diff] [blame] | 73 | faceSystem.setConfigFile(cf); |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 74 | authenticator->setConfigFile(cf); |
| 75 | cf.parse(config, false, "dummy-config"); |
| 76 | } |
| 77 | |
| 78 | FaceManagerCommandNode::~FaceManagerCommandNode() |
| 79 | { |
| 80 | // Explicitly closing faces is necessary. Otherwise, in a subsequent test case, |
| 81 | // incoming packets may be delivered to an old socket from a previous test case. |
| 82 | // This should be handled by the FaceTable destructor - see #2517 |
| 83 | std::vector<std::reference_wrapper<Face>> facesToClose; |
| 84 | std::copy(faceTable.begin(), faceTable.end(), std::back_inserter(facesToClose)); |
| 85 | for (Face& face : facesToClose) { |
| 86 | face.close(); |
| 87 | } |
| 88 | } |
| 89 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 90 | const Face* |
| 91 | FaceManagerCommandNode::findFaceByUri(const std::string& uri) const |
| 92 | { |
| 93 | for (const auto& face : faceTable) { |
| 94 | if (face.getRemoteUri().toString() == uri) { |
| 95 | return &face; |
| 96 | } |
| 97 | } |
| 98 | return nullptr; |
| 99 | } |
| 100 | |
| 101 | FaceId |
| 102 | FaceManagerCommandNode::findFaceIdByUri(const std::string& uri) const |
| 103 | { |
| 104 | auto face = findFaceByUri(uri); |
| 105 | return face != nullptr ? face->getId() : face::INVALID_FACEID; |
| 106 | } |
| 107 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 108 | FaceManagerCommandFixture::FaceManagerCommandFixture() |
| 109 | : node1(m_keyChain, 16363) |
| 110 | , node2(m_keyChain, 26363) |
| 111 | { |
Davide Pesavento | cfb1a31 | 2018-03-01 01:30:56 -0500 | [diff] [blame] | 112 | advanceClocks(1_ms, 5); |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | FaceManagerCommandFixture::~FaceManagerCommandFixture() |
| 116 | { |
Davide Pesavento | cfb1a31 | 2018-03-01 01:30:56 -0500 | [diff] [blame] | 117 | advanceClocks(1_ms, 5); |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 120 | } // namespace nfd::tests |