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