blob: 16e99c6720adc38c10fee33d92ab34076661848f [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 Pesavento3dade002019-03-19 11:29:56 -06003 * Copyright (c) 2014-2019, 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 Pesavento3dade002019-03-19 11:29:56 -060027#include "daemon/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
Eric Newberry42602412016-08-27 09:33:18 -070031namespace nfd {
32namespace tests {
33
34FaceManagerCommandNode::FaceManagerCommandNode(ndn::KeyChain& keyChain, uint16_t port)
35 : face(getGlobalIoService(), keyChain, {true, true})
36 , dispatcher(face, keyChain, ndn::security::SigningInfo())
37 , authenticator(CommandAuthenticator::create())
Davide Pesaventob5eee202017-09-21 23:59:22 -040038 , faceSystem(faceTable, make_shared<ndn::net::NetworkMonitorStub>(0))
Junxiao Shiea47bde2017-01-26 17:49:16 +000039 , manager(faceSystem, dispatcher, *authenticator)
Eric Newberry42602412016-08-27 09:33:18 -070040{
41 dispatcher.addTopPrefix("/localhost/nfd");
42
Davide Pesaventocfb1a312018-03-01 01:30:56 -050043 const std::string config =
Eric Newberry42602412016-08-27 09:33:18 -070044 "face_system\n"
45 "{\n"
46 " tcp\n"
47 " {\n"
48 " port " + to_string(port) + "\n"
49 " }\n"
50 " udp\n"
51 " {\n"
52 " port " + to_string(port) + "\n"
53 " mcast no\n"
54 " }\n"
55 " ether\n"
56 " {\n"
57 " mcast no\n"
58 " }\n"
59 "}\n"
60 "authorizations\n"
61 "{\n"
62 " authorize\n"
63 " {\n"
64 " certfile any\n"
65 " privileges\n"
66 " {\n"
67 " faces\n"
68 " }\n"
69 " }\n"
70 "}\n"
71 "\n";
72
73 ConfigFile cf;
Davide Pesaventocfb1a312018-03-01 01:30:56 -050074 faceSystem.setConfigFile(cf);
Eric Newberry42602412016-08-27 09:33:18 -070075 authenticator->setConfigFile(cf);
76 cf.parse(config, false, "dummy-config");
77}
78
79FaceManagerCommandNode::~FaceManagerCommandNode()
80{
81 // Explicitly closing faces is necessary. Otherwise, in a subsequent test case,
82 // incoming packets may be delivered to an old socket from a previous test case.
83 // This should be handled by the FaceTable destructor - see #2517
84 std::vector<std::reference_wrapper<Face>> facesToClose;
85 std::copy(faceTable.begin(), faceTable.end(), std::back_inserter(facesToClose));
86 for (Face& face : facesToClose) {
87 face.close();
88 }
89}
90
Yanbiao Li58ba3f92017-02-15 14:27:18 +000091const Face*
92FaceManagerCommandNode::findFaceByUri(const std::string& uri) const
93{
94 for (const auto& face : faceTable) {
95 if (face.getRemoteUri().toString() == uri) {
96 return &face;
97 }
98 }
99 return nullptr;
100}
101
102FaceId
103FaceManagerCommandNode::findFaceIdByUri(const std::string& uri) const
104{
105 auto face = findFaceByUri(uri);
106 return face != nullptr ? face->getId() : face::INVALID_FACEID;
107}
108
Eric Newberry42602412016-08-27 09:33:18 -0700109FaceManagerCommandFixture::FaceManagerCommandFixture()
110 : node1(m_keyChain, 16363)
111 , node2(m_keyChain, 26363)
112{
Davide Pesaventocfb1a312018-03-01 01:30:56 -0500113 advanceClocks(1_ms, 5);
Eric Newberry42602412016-08-27 09:33:18 -0700114}
115
116FaceManagerCommandFixture::~FaceManagerCommandFixture()
117{
Davide Pesaventocfb1a312018-03-01 01:30:56 -0500118 advanceClocks(1_ms, 5);
Eric Newberry42602412016-08-27 09:33:18 -0700119}
120
121} // namespace tests
122} // namespace nfd