blob: 9841de8333672ea6609e8e24e52ed90afe3519b1 [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/*
Junxiao Shi1f481fa2017-01-26 15:14:43 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
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
Junxiao Shicb766862017-07-07 22:21:04 +000029#include "../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:
Junxiao Shi918e5d42017-02-25 03:58:21 +000043 /** \brief respond to specific FaceQuery requests
44 * \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 }
57 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
58 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
59
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
99 return false;
100 }
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000101};
102
103} // namespace tests
104} // namespace nfdc
105} // namespace tools
106} // namespace nfd
107
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000108#endif // NFD_TESTS_TOOLS_NFDC_MOCK_NFD_MGMT_FIXTURE_HPP