blob: 239faa931673f1097cde1bd87350290b02fe1db3 [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/*
Eric Newberryd656aff2020-04-03 00:30:38 -07003 * Copyright (c) 2014-2020, 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
31namespace nfd {
32namespace tools {
33namespace nfdc {
34namespace tests {
35
36using namespace nfd::tests;
37
38/** \brief fixture to emulate NFD management
39 */
Junxiao Shicb766862017-07-07 22:21:04 +000040class MockNfdMgmtFixture : public nfd::tools::tests::MockNfdMgmtFixture
Junxiao Shi1f481fa2017-01-26 15:14:43 +000041{
42protected:
Eric Newberryd656aff2020-04-03 00:30:38 -070043 /** \brief respond to FaceQuery requests
Junxiao Shi918e5d42017-02-25 03:58:21 +000044 * \retval true the Interest matches one of the defined patterns and is responded
45 * \retval false the Interest is not responded
46 */
47 bool
48 respondFaceQuery(const Interest& interest)
49 {
50 using ndn::nfd::FacePersistency;
51 using ndn::nfd::FaceQueryFilter;
52 using ndn::nfd::FaceStatus;
53
54 if (!Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) {
55 return false;
56 }
Eric Newberryd656aff2020-04-03 00:30:38 -070057 BOOST_REQUIRE_EQUAL(interest.getName().size(), 5);
58 FaceQueryFilter filter(interest.getName()[-1].blockFromValue());
Junxiao Shi918e5d42017-02-25 03:58:21 +000059
60 if (filter == FaceQueryFilter().setFaceId(10156)) {
61 FaceStatus faceStatus;
62 faceStatus.setFaceId(10156)
63 .setLocalUri("tcp4://151.26.163.27:22967")
64 .setRemoteUri("tcp4://198.57.27.40:6363")
65 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT);
66 this->sendDataset(interest.getName(), faceStatus);
67 return true;
68 }
69
70 if (filter == FaceQueryFilter().setRemoteUri("tcp4://32.121.182.82:6363")) {
71 FaceStatus faceStatus;
72 faceStatus.setFaceId(2249)
73 .setLocalUri("tcp4://30.99.87.98:31414")
74 .setRemoteUri("tcp4://32.121.182.82:6363")
75 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT);
76 this->sendDataset(interest.getName(), faceStatus);
77 return true;
78 }
79
80 if (filter == FaceQueryFilter().setFaceId(23728)) {
81 this->sendEmptyDataset(interest.getName());
82 return true;
83 }
84
85 if (filter == FaceQueryFilter().setRemoteUri("udp4://225.131.75.231:56363")) {
86 FaceStatus faceStatus1, faceStatus2;
87 faceStatus1.setFaceId(6720)
88 .setLocalUri("udp4://202.83.168.28:56363")
89 .setRemoteUri("udp4://225.131.75.231:56363")
90 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERMANENT);
91 faceStatus2.setFaceId(31066)
92 .setLocalUri("udp4://25.90.26.32:56363")
93 .setRemoteUri("udp4://225.131.75.231:56363")
94 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERMANENT);
95 this->sendDataset(interest.getName(), faceStatus1, faceStatus2);
96 return true;
97 }
98
Eric Newberryd656aff2020-04-03 00:30:38 -070099 // Return empty dataset
100 this->sendEmptyDataset(interest.getName());
Junxiao Shi918e5d42017-02-25 03:58:21 +0000101 return false;
102 }
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000103};
104
105} // namespace tests
106} // namespace nfdc
107} // namespace tools
108} // namespace nfd
109
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000110#endif // NFD_TESTS_TOOLS_NFDC_MOCK_NFD_MGMT_FIXTURE_HPP