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 | /* |
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 | |
Davide Pesavento | b5eee20 | 2017-09-21 23:59:22 -0400 | [diff] [blame] | 28 | #include <ndn-cxx/net/network-monitor-stub.hpp> |
| 29 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 30 | namespace nfd { |
| 31 | namespace tests { |
| 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 | |
| 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 | |
| 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 | { |
| 112 | advanceClocks(time::milliseconds(1), 5); |
| 113 | } |
| 114 | |
| 115 | FaceManagerCommandFixture::~FaceManagerCommandFixture() |
| 116 | { |
| 117 | advanceClocks(time::milliseconds(1), 5); |
| 118 | } |
| 119 | |
| 120 | } // namespace tests |
| 121 | } // namespace nfd |