blob: 186a5dbe9d405d089b5098ad8587cabd88af9f77 [file] [log] [blame]
Yanbiao Li698f4fe2015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi8a1f1702017-07-03 00:05:08 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Yanbiao Li698f4fe2015-08-19 16:30:16 -07004 * 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
Yanbiao Lidf846e52016-01-30 21:53:47 -080026#ifndef NFD_TESTS_MANAGER_COMMON_FIXTURE_HPP
27#define NFD_TESTS_MANAGER_COMMON_FIXTURE_HPP
Yanbiao Li698f4fe2015-08-19 16:30:16 -070028
29#include "tests/test-common.hpp"
30#include "tests/identity-management-fixture.hpp"
Yanbiao Lidf846e52016-01-30 21:53:47 -080031#include "core/manager-base.hpp"
Yanbiao Li698f4fe2015-08-19 16:30:16 -070032
33#include <ndn-cxx/mgmt/dispatcher.hpp>
Junxiao Shi8a1f1702017-07-03 00:05:08 +000034#include <ndn-cxx/security/command-interest-signer.hpp>
Yanbiao Li698f4fe2015-08-19 16:30:16 -070035#include <ndn-cxx/util/dummy-client-face.hpp>
36
37namespace nfd {
38namespace tests {
39
Junxiao Shi8a1f1702017-07-03 00:05:08 +000040/** \brief a fixture that provides a CommandInterestSigner
41 */
42class CommandInterestSignerFixture : public IdentityManagementTimeFixture
43{
44protected:
45 CommandInterestSignerFixture();
46
47 /** \brief sign a command Interest
48 * \param name command name include prefix and parameters
49 * \param identity signing identity
50 * \return a command Interest
51 */
52 Interest
53 makeCommandInterest(const Name& name, const Name& identity = DEFAULT_COMMAND_SIGNER_IDENTITY);
54
55 /** \brief create a ControlCommand request
56 * \param commandName command name including prefix, such as "/localhost/nfd/fib/add-nexthop"
57 * \param params command parameters
58 * \param identity signing identity
59 * \return a command Interest
60 */
61 Interest
62 makeControlCommandRequest(Name commandName, const ControlParameters& params,
63 const Name& identity = DEFAULT_COMMAND_SIGNER_IDENTITY);
64
65protected:
66 static const Name DEFAULT_COMMAND_SIGNER_IDENTITY;
67
68private:
69 ndn::security::CommandInterestSigner m_commandInterestSigner;
70};
71
Yanbiao Li698f4fe2015-08-19 16:30:16 -070072/**
73 * @brief a collection of common functions shared by all manager's testing fixtures.
74 */
Junxiao Shi8a1f1702017-07-03 00:05:08 +000075class ManagerCommonFixture : public CommandInterestSignerFixture
Yanbiao Li698f4fe2015-08-19 16:30:16 -070076{
77public: // initialize
78 ManagerCommonFixture();
79
80 /**
Yanbiao Lidf846e52016-01-30 21:53:47 -080081 * @brief set topPrefix to the dispatcher.
Yanbiao Li698f4fe2015-08-19 16:30:16 -070082 *
83 * after setting @param topPrefix, call advanceClocks to ensure all added filters take effects.
84 *
85 * @param topPrefix top prefix for the dispatcher
Yanbiao Li698f4fe2015-08-19 16:30:16 -070086 */
87 void
Yanbiao Lidf846e52016-01-30 21:53:47 -080088 setTopPrefix(const Name& topPrefix);
Yanbiao Li698f4fe2015-08-19 16:30:16 -070089
90public: // test
Yanbiao Li698f4fe2015-08-19 16:30:16 -070091 /**
92 * @brief cause management to receive an Interest
93 *
94 * call DummyClientFace::receive to receive Interest and then call advanceClocks to ensure
95 * the Interest dispatched
96 *
97 * @param interest the Interest to receive
98 */
99 void
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000100 receiveInterest(const Interest& interest);
Yanbiao Li698f4fe2015-08-19 16:30:16 -0700101
102public: // verify
103 ControlResponse
104 makeResponse(uint32_t code, const std::string& text,
105 const ControlParameters& parameters);
106
107 enum class CheckResponseResult
108 {
109 OK,
110 OUT_OF_BOUNDARY,
111 WRONG_NAME,
112 WRONG_CONTENT_TYPE,
113 INVALID_RESPONSE,
114 WRONG_CODE,
115 WRONG_TEXT,
116 WRONG_BODY_SIZE,
117 WRONG_BODY_VALUE
Davide Pesavento35120ea2015-11-17 21:13:18 +0100118 };
Yanbiao Li698f4fe2015-08-19 16:30:16 -0700119
120 /**
121 * @brief check a specified response data with the expected ControlResponse
122 *
123 * @param idx the index of the specified Data in m_responses
124 * @param expectedDataName the expected name of this Data
125 * @param expectedResponse the expected ControlResponse
126 * @param expectedContentType the expected content type of this Data, use -1 to skip this check
127 *
128 * @retval OK the response at the specified index can be decoded from the response data,
129 * and its code, text and response body are all matched with the expected response
130 * @retval OUT_OF_BOUNDARY the specified index out of boundary
131 * @retval WRONG_NAME the name of the specified response data does not match
132 * @retval WRONG_CONTENT_TYPE the content type of the specified response data does not match
133 * @retval INVALID_RESPONSE the data name matches but it fails in decoding a ControlResponse from
134 * the content of the specified response data
135 * @retval WRONG_CODE a valid ControlResponse can be decoded but has a wrong code
136 * @retval WRONG_TEXT a valid ControlResponse can be decoded but has a wrong text
137 * @retval WRONG_BODY_SIZE the body size of decoded ControlResponse does not match
138 * @retval WRONT_BODY_VALUE the body value of decoded ControlResponse does not match
139 */
140 CheckResponseResult
141 checkResponse(size_t idx,
142 const Name& expectedName,
143 const ControlResponse& expectedResponse,
144 int expectedContentType = -1);
145
146 /**
147 * @brief concatenate specified response Data into a single block
148 *
149 * @param startIndex the start index in m_responses
150 * @param nResponses the number of response to concatenate
151 *
152 * @return the generated block
153 */
154 Block
155 concatenateResponses(size_t startIndex = 0, size_t nResponses = 0);
156
157protected:
Junxiao Shi221b6fe2016-07-14 18:21:56 +0000158 ndn::util::DummyClientFace m_face;
159 ndn::mgmt::Dispatcher m_dispatcher;
160 std::vector<Data>& m_responses; ///< a reference of m_face->sentData
Yanbiao Li698f4fe2015-08-19 16:30:16 -0700161};
162
163std::ostream&
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000164operator<<(std::ostream& os, const ManagerCommonFixture::CheckResponseResult& result);
Yanbiao Li698f4fe2015-08-19 16:30:16 -0700165
166} // namespace tests
167} // namespace nfd
168
Yanbiao Lidf846e52016-01-30 21:53:47 -0800169#endif // NFD_TESTS_MANAGER_COMMON_FIXTURE_HPP