blob: eee9a5edab70cb88aab451a439cd8c0fcbd01d43 [file] [log] [blame]
Vince Lehmancd16c832014-07-23 15:14:55 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev7c10b3b2015-01-20 12:24:27 -08003 * 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 Lehmancd16c832014-07-23 15:14:55 -070010 *
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 Shi0de23a22015-12-03 20:07:02 +000037#include <ndn-cxx/encoding/tlv-nfd.hpp>
Vince Lehmancd16c832014-07-23 15:14:55 -070038
39namespace nfd {
40namespace rib {
41namespace tests {
42
43using ndn::nfd::ControlParameters;
44
45class RibStatusPublisherFixture : public nfd::tests::BaseFixture
46{
47public:
48 static void
Vince Lehman218be0a2015-01-15 17:25:20 -060049 validateRibEntry(const Block& block, const Name& referenceName, const Route& referenceRoute)
Vince Lehmancd16c832014-07-23 15:14:55 -070050 {
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 Lehman218be0a2015-01-15 17:25:20 -060059 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 Lehmancd16c832014-07-23 15:14:55 -070063 }
64
65 static void
Vince Lehman218be0a2015-01-15 17:25:20 -060066 decodeRibEntryBlock(const Data& data, const Name& referenceName, const Route& referenceRoute)
Vince Lehmancd16c832014-07-23 15:14:55 -070067 {
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 Shi67f11ac2014-10-19 09:29:13 -070074 buffer.prependVarNumber(tlv::Content);
Vince Lehmancd16c832014-07-23 15:14:55 -070075
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 Lehman218be0a2015-01-15 17:25:20 -060085 validateRibEntry(*i, referenceName, referenceRoute);
Vince Lehmancd16c832014-07-23 15:14:55 -070086 }
87 }
88};
89
90#endif // RIB_TESTS_UNIT_TESTS_RIB_STATUS_PUBLISHER_COMMON_HPP
91
92} // namespace tests
93} // namespace rib
94} // namespace nfd