blob: a0f1f42e4d9e5c36b0b8455d066ebba2550118ea [file] [log] [blame]
Vince Lehmancd16c832014-07-23 15:14:55 -07001/* -*- 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 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>
37
38namespace nfd {
39namespace rib {
40namespace tests {
41
42using ndn::nfd::ControlParameters;
43
44class RibStatusPublisherFixture : public nfd::tests::BaseFixture
45{
46public:
47 static void
Vince Lehman218be0a2015-01-15 17:25:20 -060048 validateRibEntry(const Block& block, const Name& referenceName, const Route& referenceRoute)
Vince Lehmancd16c832014-07-23 15:14:55 -070049 {
50 ndn::nfd::RibEntry entry;
51 BOOST_REQUIRE_NO_THROW(entry.wireDecode(block));
52
53 BOOST_CHECK_EQUAL(entry.getName(), referenceName);
54
55 std::list<ndn::nfd::Route> routes = entry.getRoutes();
56
57 std::list<ndn::nfd::Route>::iterator it = routes.begin();
Vince Lehman218be0a2015-01-15 17:25:20 -060058 BOOST_CHECK_EQUAL(it->getFaceId(), referenceRoute.faceId);
59 BOOST_CHECK_EQUAL(it->getOrigin(), referenceRoute.origin);
60 BOOST_CHECK_EQUAL(it->getCost(), referenceRoute.cost);
61 BOOST_CHECK_EQUAL(it->getFlags(), referenceRoute.flags);
Vince Lehmancd16c832014-07-23 15:14:55 -070062 }
63
64 static void
Vince Lehman218be0a2015-01-15 17:25:20 -060065 decodeRibEntryBlock(const Data& data, const Name& referenceName, const Route& referenceRoute)
Vince Lehmancd16c832014-07-23 15:14:55 -070066 {
67 ndn::EncodingBuffer buffer;
68
69 Block payload = data.getContent();
70
71 buffer.appendByteArray(payload.value(), payload.value_size());
72 buffer.prependVarNumber(buffer.size());
Junxiao Shi67f11ac2014-10-19 09:29:13 -070073 buffer.prependVarNumber(tlv::Content);
Vince Lehmancd16c832014-07-23 15:14:55 -070074
75 ndn::Block parser(buffer.buf(), buffer.size());
76 parser.parse();
77
78 Block::element_const_iterator i = parser.elements_begin();
79
80 if (i->type() != ndn::tlv::nfd::RibEntry) {
81 BOOST_FAIL("expected RibEntry, got type #" << i->type());
82 }
83 else {
Vince Lehman218be0a2015-01-15 17:25:20 -060084 validateRibEntry(*i, referenceName, referenceRoute);
Vince Lehmancd16c832014-07-23 15:14:55 -070085 }
86 }
87};
88
89#endif // RIB_TESTS_UNIT_TESTS_RIB_STATUS_PUBLISHER_COMMON_HPP
90
91} // namespace tests
92} // namespace rib
93} // namespace nfd