blob: 06d562b0ba90f309e86fc71125c53f752b25ec98 [file] [log] [blame]
Chengyu Fan320d2332014-10-29 16:40:33 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, 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_NFD_MGMT_FACE_QUERY_STATUS_PUBLISHER_COMMON_HPP
27#define NFD_TESTS_NFD_MGMT_FACE_QUERY_STATUS_PUBLISHER_COMMON_HPP
28
29#include "mgmt/face-query-status-publisher.hpp"
30#include "mgmt/app-face.hpp"
31#include "mgmt/internal-face.hpp"
32#include "fw/forwarder.hpp"
33#include "face/udp-factory.hpp"
34
35#include "tests/test-common.hpp"
36#include "tests/daemon/face/dummy-face.hpp"
37
38#include <ndn-cxx/management/nfd-face-status.hpp>
39
40namespace nfd {
41namespace tests {
42
43class FaceQueryStatusPublisherFixture : public BaseFixture
44{
45public:
46
47 FaceQueryStatusPublisherFixture()
48 : m_table(m_forwarder)
49 , m_face(make_shared<InternalFace>())
50 , m_dummyFace(make_shared<DummyFace>())
51 , m_dummyLocalFace(make_shared<DummyLocalFace>())
52 , m_dummyUri(make_shared<DummyFace>("dummy://remoteUri", "dummy://localUri"))
53 , m_factory(UdpFactory())
54 , m_finished(false)
55 {
56 }
57
58 virtual
59 ~FaceQueryStatusPublisherFixture()
60 {
61 }
62
63 void
64 add(shared_ptr<Face> face)
65 {
66 m_table.add(face);
67 }
68
69 void
70 validateFaceStatus(const Block& statusBlock, const shared_ptr<Face>& reference)
71 {
72 ndn::nfd::FaceStatus status;
73 BOOST_REQUIRE_NO_THROW(status.wireDecode(statusBlock));
74
75 BOOST_CHECK_EQUAL(status.getFaceId(), reference->getId());
76 BOOST_CHECK_EQUAL(status.getRemoteUri(), reference->getRemoteUri().toString());
77 BOOST_CHECK_EQUAL(status.getLocalUri(), reference->getLocalUri().toString());
78
79 if (reference->isLocal()) {
80 BOOST_CHECK_EQUAL(status.getFaceScope(), ndn::nfd::FACE_SCOPE_LOCAL);
81 }
82 else {
83 BOOST_CHECK_EQUAL(status.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
84 }
85
86 if (reference->isOnDemand()) {
87 BOOST_CHECK_EQUAL(status.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
88 }
89 else {
90 BOOST_CHECK_EQUAL(status.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
91 }
92
93 if (reference->isMultiAccess()) {
94 BOOST_CHECK_EQUAL(status.getLinkType(), ndn::nfd::LINK_TYPE_MULTI_ACCESS);
95 }
96 else {
97 BOOST_CHECK_EQUAL(status.getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
98 }
99 }
100
101 void
102 decodeFaceStatusBlock(const Data& data)
103 {
104 BOOST_REQUIRE_EQUAL(data.getContentType(), ndn::MetaInfo::TYPE_BLOB);
105
106 Block payload = data.getContent();
107 m_buffer.appendByteArray(payload.value(), payload.value_size());
108
109 BOOST_CHECK_NO_THROW(data.getName()[-1].toSegment());
110 if (data.getFinalBlockId() != data.getName()[-1]) {
111 return;
112 }
113
114 // wrap the Face Statuses in a single Content TLV for easy parsing
115 m_buffer.prependVarNumber(m_buffer.size());
116 m_buffer.prependVarNumber(tlv::Content);
117
118 ndn::Block parser(m_buffer.buf(), m_buffer.size());
119 parser.parse();
120
121 BOOST_REQUIRE_EQUAL(parser.elements_size(), m_referenceFaces.size());
122
123 std::list<shared_ptr<Face> >::const_iterator iReference = m_referenceFaces.begin();
124 for (Block::element_const_iterator i = parser.elements_begin();
125 i != parser.elements_end();
126 ++i) {
127 if (i->type() != ndn::tlv::nfd::FaceStatus) {
128 BOOST_FAIL("expected face status, got type #" << i->type());
129 }
130 validateFaceStatus(*i, *iReference);
131 ++iReference;
132 }
133 m_finished = true;
134 }
135
136 //void
137 //decodeNackBlock(const Data& data)
138 //{
139 // BOOST_REQUIRE_EQUAL(data.getContentType(), ndn::tlv::ContentType_Nack);
140
141 // m_finished = true;
142 //}
143
144protected:
145 Forwarder m_forwarder;
146 FaceTable m_table;
147 shared_ptr<InternalFace> m_face;
148 ndn::EncodingBuffer m_buffer;
149 std::list<shared_ptr<Face> > m_referenceFaces;
150 ndn::KeyChain m_keyChain;
151 shared_ptr<DummyFace> m_dummyFace;
152 shared_ptr<DummyLocalFace> m_dummyLocalFace;
153 shared_ptr<DummyFace> m_dummyUri;
154 UdpFactory m_factory;
155
156protected:
157 bool m_finished;
158};
159
160} // namespace tests
161} // namespace nfd
162
163#endif // NFD_TESTS_NFD_MGMT_FACE_QUERY_STATUS_PUBLISHER_COMMON_HPP