blob: 0771e8cc90e8509cc6c4c7ba1c67e59ace5a1279 [file] [log] [blame]
Eric Newberry42602412016-08-27 09:33:18 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventob5eee202017-09-21 23:59:22 -04002/*
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -05003 * Copyright (c) 2014-2024, Regents of the University of California,
Eric Newberry42602412016-08-27 09:33:18 -07004 * 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 Pesavento2cae8ca2019-04-18 20:48:05 -040027#include "common/global.hpp"
Eric Newberry42602412016-08-27 09:33:18 -070028
Davide Pesaventob5eee202017-09-21 23:59:22 -040029#include <ndn-cxx/net/network-monitor-stub.hpp>
30
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040031namespace nfd::tests {
Eric Newberry42602412016-08-27 09:33:18 -070032
33FaceManagerCommandNode::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 Pesaventob5eee202017-09-21 23:59:22 -040037 , faceSystem(faceTable, make_shared<ndn::net::NetworkMonitorStub>(0))
Junxiao Shiea47bde2017-01-26 17:49:16 +000038 , manager(faceSystem, dispatcher, *authenticator)
Eric Newberry42602412016-08-27 09:33:18 -070039{
40 dispatcher.addTopPrefix("/localhost/nfd");
41
Davide Pesaventocfb1a312018-03-01 01:30:56 -050042 const std::string config =
Eric Newberry42602412016-08-27 09:33:18 -070043 "face_system\n"
44 "{\n"
45 " tcp\n"
46 " {\n"
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -050047 " port " + std::to_string(port) + "\n"
Eric Newberry42602412016-08-27 09:33:18 -070048 " }\n"
49 " udp\n"
50 " {\n"
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -050051 " port " + std::to_string(port) + "\n"
Eric Newberry42602412016-08-27 09:33:18 -070052 " 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 Pesaventocfb1a312018-03-01 01:30:56 -050073 faceSystem.setConfigFile(cf);
Eric Newberry42602412016-08-27 09:33:18 -070074 authenticator->setConfigFile(cf);
75 cf.parse(config, false, "dummy-config");
76}
77
78FaceManagerCommandNode::~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 Li58ba3f92017-02-15 14:27:18 +000090const Face*
91FaceManagerCommandNode::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
101FaceId
102FaceManagerCommandNode::findFaceIdByUri(const std::string& uri) const
103{
104 auto face = findFaceByUri(uri);
105 return face != nullptr ? face->getId() : face::INVALID_FACEID;
106}
107
Eric Newberry42602412016-08-27 09:33:18 -0700108FaceManagerCommandFixture::FaceManagerCommandFixture()
109 : node1(m_keyChain, 16363)
110 , node2(m_keyChain, 26363)
111{
Davide Pesaventocfb1a312018-03-01 01:30:56 -0500112 advanceClocks(1_ms, 5);
Eric Newberry42602412016-08-27 09:33:18 -0700113}
114
115FaceManagerCommandFixture::~FaceManagerCommandFixture()
116{
Davide Pesaventocfb1a312018-03-01 01:30:56 -0500117 advanceClocks(1_ms, 5);
Eric Newberry42602412016-08-27 09:33:18 -0700118}
119
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400120} // namespace nfd::tests