blob: 4053682602115019c582332ffb565652a7959b7b [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/*
Junxiao Shiea47bde2017-01-26 17:49:16 +00003 * Copyright (c) 2014-2017, 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"
27
Davide Pesaventob5eee202017-09-21 23:59:22 -040028#include <ndn-cxx/net/network-monitor-stub.hpp>
29
Eric Newberry42602412016-08-27 09:33:18 -070030namespace nfd {
31namespace tests {
32
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
42 std::string config =
43 "face_system\n"
44 "{\n"
45 " tcp\n"
46 " {\n"
47 " port " + to_string(port) + "\n"
48 " }\n"
49 " udp\n"
50 " {\n"
51 " port " + to_string(port) + "\n"
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;
73 manager.setConfigFile(cf);
74 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{
112 advanceClocks(time::milliseconds(1), 5);
113}
114
115FaceManagerCommandFixture::~FaceManagerCommandFixture()
116{
117 advanceClocks(time::milliseconds(1), 5);
118}
119
120} // namespace tests
121} // namespace nfd