blob: ab2ec396c0669891813436c8048145951fe902b2 [file] [log] [blame]
Junxiao Shi1f481fa2017-01-26 15:14:43 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shicb766862017-07-07 22:21:04 +00002/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shi1f481fa2017-01-26 15:14:43 +00004 * 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 Pesaventocf7db2f2019-03-24 23:17:28 -040029#include "tests/tools/mock-nfd-mgmt-fixture.hpp"
Junxiao Shi1f481fa2017-01-26 15:14:43 +000030
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040031#include <ndn-cxx/mgmt/nfd/face-query-filter.hpp>
32#include <ndn-cxx/mgmt/nfd/face-status.hpp>
Junxiao Shi1f481fa2017-01-26 15:14:43 +000033
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040034namespace nfd::tools::nfdc::tests {
Junxiao Shi1f481fa2017-01-26 15:14:43 +000035
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040036/**
37 * \brief Fixture to emulate NFD management.
Junxiao Shi1f481fa2017-01-26 15:14:43 +000038 */
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040039class MockNfdMgmtFixture : public nfd::tests::MockNfdMgmtFixture
Junxiao Shi1f481fa2017-01-26 15:14:43 +000040{
41protected:
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040042 /** \brief Respond to FaceQuery requests.
Junxiao Shi918e5d42017-02-25 03:58:21 +000043 * \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 Newberryd656aff2020-04-03 00:30:38 -070056 BOOST_REQUIRE_EQUAL(interest.getName().size(), 5);
57 FaceQueryFilter filter(interest.getName()[-1].blockFromValue());
Junxiao Shi918e5d42017-02-25 03:58:21 +000058
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 Newberryd656aff2020-04-03 00:30:38 -070098 // Return empty dataset
99 this->sendEmptyDataset(interest.getName());
Junxiao Shi918e5d42017-02-25 03:58:21 +0000100 return false;
101 }
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000102};
103
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400104} // namespace nfd::tools::nfdc::tests
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000105
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000106#endif // NFD_TESTS_TOOLS_NFDC_MOCK_NFD_MGMT_FIXTURE_HPP