Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 1 | /* -*- 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 | |
| 40 | namespace nfd { |
| 41 | namespace tests { |
| 42 | |
| 43 | class FaceQueryStatusPublisherFixture : public BaseFixture |
| 44 | { |
| 45 | public: |
| 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 | |
Yukai Tu | 731f0d7 | 2015-07-04 11:14:44 +0800 | [diff] [blame] | 86 | BOOST_CHECK_EQUAL(status.getFacePersistency(), reference->getPersistency()); |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 87 | |
| 88 | if (reference->isMultiAccess()) { |
| 89 | BOOST_CHECK_EQUAL(status.getLinkType(), ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
| 90 | } |
| 91 | else { |
| 92 | BOOST_CHECK_EQUAL(status.getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | void |
| 97 | decodeFaceStatusBlock(const Data& data) |
| 98 | { |
Alexander Afanasyev | ec3e4fc | 2014-11-18 11:56:30 -0500 | [diff] [blame] | 99 | BOOST_REQUIRE_EQUAL(data.getContentType(), tlv::ContentType_Blob); |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 100 | |
| 101 | Block payload = data.getContent(); |
| 102 | m_buffer.appendByteArray(payload.value(), payload.value_size()); |
| 103 | |
| 104 | BOOST_CHECK_NO_THROW(data.getName()[-1].toSegment()); |
| 105 | if (data.getFinalBlockId() != data.getName()[-1]) { |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | // wrap the Face Statuses in a single Content TLV for easy parsing |
| 110 | m_buffer.prependVarNumber(m_buffer.size()); |
| 111 | m_buffer.prependVarNumber(tlv::Content); |
| 112 | |
| 113 | ndn::Block parser(m_buffer.buf(), m_buffer.size()); |
| 114 | parser.parse(); |
| 115 | |
| 116 | BOOST_REQUIRE_EQUAL(parser.elements_size(), m_referenceFaces.size()); |
| 117 | |
| 118 | std::list<shared_ptr<Face> >::const_iterator iReference = m_referenceFaces.begin(); |
| 119 | for (Block::element_const_iterator i = parser.elements_begin(); |
| 120 | i != parser.elements_end(); |
| 121 | ++i) { |
| 122 | if (i->type() != ndn::tlv::nfd::FaceStatus) { |
| 123 | BOOST_FAIL("expected face status, got type #" << i->type()); |
| 124 | } |
| 125 | validateFaceStatus(*i, *iReference); |
| 126 | ++iReference; |
| 127 | } |
| 128 | m_finished = true; |
| 129 | } |
| 130 | |
Chengyu Fan | ab205c2 | 2014-11-18 10:58:41 -0700 | [diff] [blame] | 131 | void |
| 132 | decodeNackBlock(const Data& data) |
| 133 | { |
| 134 | BOOST_REQUIRE_EQUAL(data.getContentType(), tlv::ContentType_Nack); |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 135 | |
Chengyu Fan | ab205c2 | 2014-11-18 10:58:41 -0700 | [diff] [blame] | 136 | m_finished = true; |
| 137 | } |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 138 | |
| 139 | protected: |
| 140 | Forwarder m_forwarder; |
| 141 | FaceTable m_table; |
| 142 | shared_ptr<InternalFace> m_face; |
| 143 | ndn::EncodingBuffer m_buffer; |
| 144 | std::list<shared_ptr<Face> > m_referenceFaces; |
| 145 | ndn::KeyChain m_keyChain; |
| 146 | shared_ptr<DummyFace> m_dummyFace; |
| 147 | shared_ptr<DummyLocalFace> m_dummyLocalFace; |
| 148 | shared_ptr<DummyFace> m_dummyUri; |
| 149 | UdpFactory m_factory; |
| 150 | |
| 151 | protected: |
| 152 | bool m_finished; |
| 153 | }; |
| 154 | |
| 155 | } // namespace tests |
| 156 | } // namespace nfd |
| 157 | |
| 158 | #endif // NFD_TESTS_NFD_MGMT_FACE_QUERY_STATUS_PUBLISHER_COMMON_HPP |