Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Alexander Afanasyev | 7c10b3b | 2015-01-20 12:24:27 -0800 | [diff] [blame] | 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. |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 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 RIB_TESTS_UNIT_TESTS_RIB_STATUS_PUBLISHER_COMMON_HPP |
| 27 | #define RIB_TESTS_UNIT_TESTS_RIB_STATUS_PUBLISHER_COMMON_HPP |
| 28 | |
| 29 | #include "rib/rib-status-publisher.hpp" |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame^] | 30 | #include "rib/rib.hpp" |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 31 | |
| 32 | #include "tests/test-common.hpp" |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame^] | 33 | #include "tests/identity-management-fixture.hpp" |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 34 | |
| 35 | #include <ndn-cxx/management/nfd-control-parameters.hpp> |
| 36 | #include <ndn-cxx/management/nfd-rib-entry.hpp> |
| 37 | #include <ndn-cxx/encoding/tlv.hpp> |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 38 | #include <ndn-cxx/encoding/tlv-nfd.hpp> |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 39 | |
| 40 | namespace nfd { |
| 41 | namespace rib { |
| 42 | namespace tests { |
| 43 | |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame^] | 44 | using namespace nfd::tests; |
| 45 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 46 | using ndn::nfd::ControlParameters; |
| 47 | |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame^] | 48 | class RibStatusPublisherFixture : public IdentityManagementFixture |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 49 | { |
| 50 | public: |
| 51 | static void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 52 | validateRibEntry(const Block& block, const Name& referenceName, const Route& referenceRoute) |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 53 | { |
| 54 | ndn::nfd::RibEntry entry; |
| 55 | BOOST_REQUIRE_NO_THROW(entry.wireDecode(block)); |
| 56 | |
| 57 | BOOST_CHECK_EQUAL(entry.getName(), referenceName); |
| 58 | |
| 59 | std::list<ndn::nfd::Route> routes = entry.getRoutes(); |
| 60 | |
| 61 | std::list<ndn::nfd::Route>::iterator it = routes.begin(); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 62 | BOOST_CHECK_EQUAL(it->getFaceId(), referenceRoute.faceId); |
| 63 | BOOST_CHECK_EQUAL(it->getOrigin(), referenceRoute.origin); |
| 64 | BOOST_CHECK_EQUAL(it->getCost(), referenceRoute.cost); |
| 65 | BOOST_CHECK_EQUAL(it->getFlags(), referenceRoute.flags); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 69 | decodeRibEntryBlock(const Data& data, const Name& referenceName, const Route& referenceRoute) |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 70 | { |
| 71 | ndn::EncodingBuffer buffer; |
| 72 | |
| 73 | Block payload = data.getContent(); |
| 74 | |
| 75 | buffer.appendByteArray(payload.value(), payload.value_size()); |
| 76 | buffer.prependVarNumber(buffer.size()); |
Junxiao Shi | 67f11ac | 2014-10-19 09:29:13 -0700 | [diff] [blame] | 77 | buffer.prependVarNumber(tlv::Content); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 78 | |
| 79 | ndn::Block parser(buffer.buf(), buffer.size()); |
| 80 | parser.parse(); |
| 81 | |
| 82 | Block::element_const_iterator i = parser.elements_begin(); |
| 83 | |
| 84 | if (i->type() != ndn::tlv::nfd::RibEntry) { |
| 85 | BOOST_FAIL("expected RibEntry, got type #" << i->type()); |
| 86 | } |
| 87 | else { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 88 | validateRibEntry(*i, referenceName, referenceRoute); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | #endif // RIB_TESTS_UNIT_TESTS_RIB_STATUS_PUBLISHER_COMMON_HPP |
| 94 | |
| 95 | } // namespace tests |
| 96 | } // namespace rib |
| 97 | } // namespace nfd |