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