Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | cb76686 | 2017-07-07 22:21:04 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [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 | #ifndef NFD_TESTS_TOOLS_NFDC_MOCK_NFD_MGMT_FIXTURE_HPP |
| 27 | #define NFD_TESTS_TOOLS_NFDC_MOCK_NFD_MGMT_FIXTURE_HPP |
| 28 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 29 | #include "tests/tools/mock-nfd-mgmt-fixture.hpp" |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 30 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 31 | #include <ndn-cxx/mgmt/nfd/face-query-filter.hpp> |
| 32 | #include <ndn-cxx/mgmt/nfd/face-status.hpp> |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 33 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 34 | namespace nfd::tools::nfdc::tests { |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 35 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 36 | /** |
| 37 | * \brief Fixture to emulate NFD management. |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 38 | */ |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 39 | class MockNfdMgmtFixture : public nfd::tests::MockNfdMgmtFixture |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 40 | { |
| 41 | protected: |
Eric Newberry | d656aff | 2020-04-03 00:30:38 -0700 | [diff] [blame] | 42 | /** \brief respond to FaceQuery requests |
Junxiao Shi | 918e5d4 | 2017-02-25 03:58:21 +0000 | [diff] [blame] | 43 | * \retval true the Interest matches one of the defined patterns and is responded |
| 44 | * \retval false the Interest is not responded |
| 45 | */ |
| 46 | bool |
| 47 | respondFaceQuery(const Interest& interest) |
| 48 | { |
| 49 | using ndn::nfd::FacePersistency; |
| 50 | using ndn::nfd::FaceQueryFilter; |
| 51 | using ndn::nfd::FaceStatus; |
| 52 | |
| 53 | if (!Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) { |
| 54 | return false; |
| 55 | } |
Eric Newberry | d656aff | 2020-04-03 00:30:38 -0700 | [diff] [blame] | 56 | BOOST_REQUIRE_EQUAL(interest.getName().size(), 5); |
| 57 | FaceQueryFilter filter(interest.getName()[-1].blockFromValue()); |
Junxiao Shi | 918e5d4 | 2017-02-25 03:58:21 +0000 | [diff] [blame] | 58 | |
| 59 | if (filter == FaceQueryFilter().setFaceId(10156)) { |
| 60 | FaceStatus faceStatus; |
| 61 | faceStatus.setFaceId(10156) |
| 62 | .setLocalUri("tcp4://151.26.163.27:22967") |
| 63 | .setRemoteUri("tcp4://198.57.27.40:6363") |
| 64 | .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 65 | this->sendDataset(interest.getName(), faceStatus); |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | if (filter == FaceQueryFilter().setRemoteUri("tcp4://32.121.182.82:6363")) { |
| 70 | FaceStatus faceStatus; |
| 71 | faceStatus.setFaceId(2249) |
| 72 | .setLocalUri("tcp4://30.99.87.98:31414") |
| 73 | .setRemoteUri("tcp4://32.121.182.82:6363") |
| 74 | .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 75 | this->sendDataset(interest.getName(), faceStatus); |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | if (filter == FaceQueryFilter().setFaceId(23728)) { |
| 80 | this->sendEmptyDataset(interest.getName()); |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | if (filter == FaceQueryFilter().setRemoteUri("udp4://225.131.75.231:56363")) { |
| 85 | FaceStatus faceStatus1, faceStatus2; |
| 86 | faceStatus1.setFaceId(6720) |
| 87 | .setLocalUri("udp4://202.83.168.28:56363") |
| 88 | .setRemoteUri("udp4://225.131.75.231:56363") |
| 89 | .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERMANENT); |
| 90 | faceStatus2.setFaceId(31066) |
| 91 | .setLocalUri("udp4://25.90.26.32:56363") |
| 92 | .setRemoteUri("udp4://225.131.75.231:56363") |
| 93 | .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERMANENT); |
| 94 | this->sendDataset(interest.getName(), faceStatus1, faceStatus2); |
| 95 | return true; |
| 96 | } |
| 97 | |
Eric Newberry | d656aff | 2020-04-03 00:30:38 -0700 | [diff] [blame] | 98 | // Return empty dataset |
| 99 | this->sendEmptyDataset(interest.getName()); |
Junxiao Shi | 918e5d4 | 2017-02-25 03:58:21 +0000 | [diff] [blame] | 100 | return false; |
| 101 | } |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 104 | } // namespace nfd::tools::nfdc::tests |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 105 | |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 106 | #endif // NFD_TESTS_TOOLS_NFDC_MOCK_NFD_MGMT_FIXTURE_HPP |