blob: 3fc7fad83d2301440cf527c0da4292ad2955f7bd [file] [log] [blame]
Vince Lehmancd16c832014-07-23 15:14:55 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi221b6fe2016-07-14 18:21:56 +00003 * Copyright (c) 2014-2016, Regents of the University of California,
Alexander Afanasyev7c10b3b2015-01-20 12:24:27 -08004 * 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"
Junxiao Shi221b6fe2016-07-14 18:21:56 +000030#include "rib/rib.hpp"
Vince Lehmancd16c832014-07-23 15:14:55 -070031
32#include "tests/test-common.hpp"
Junxiao Shi221b6fe2016-07-14 18:21:56 +000033#include "tests/identity-management-fixture.hpp"
Vince Lehmancd16c832014-07-23 15:14:55 -070034
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 Shi0de23a22015-12-03 20:07:02 +000038#include <ndn-cxx/encoding/tlv-nfd.hpp>
Vince Lehmancd16c832014-07-23 15:14:55 -070039
40namespace nfd {
41namespace rib {
42namespace tests {
43
Junxiao Shi221b6fe2016-07-14 18:21:56 +000044using namespace nfd::tests;
45
Vince Lehmancd16c832014-07-23 15:14:55 -070046using ndn::nfd::ControlParameters;
47
Junxiao Shi221b6fe2016-07-14 18:21:56 +000048class RibStatusPublisherFixture : public IdentityManagementFixture
Vince Lehmancd16c832014-07-23 15:14:55 -070049{
50public:
51 static void
Vince Lehman218be0a2015-01-15 17:25:20 -060052 validateRibEntry(const Block& block, const Name& referenceName, const Route& referenceRoute)
Vince Lehmancd16c832014-07-23 15:14:55 -070053 {
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 Lehman218be0a2015-01-15 17:25:20 -060062 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 Lehmancd16c832014-07-23 15:14:55 -070066 }
67
68 static void
Vince Lehman218be0a2015-01-15 17:25:20 -060069 decodeRibEntryBlock(const Data& data, const Name& referenceName, const Route& referenceRoute)
Vince Lehmancd16c832014-07-23 15:14:55 -070070 {
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 Shi67f11ac2014-10-19 09:29:13 -070077 buffer.prependVarNumber(tlv::Content);
Vince Lehmancd16c832014-07-23 15:14:55 -070078
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 Lehman218be0a2015-01-15 17:25:20 -060088 validateRibEntry(*i, referenceName, referenceRoute);
Vince Lehmancd16c832014-07-23 15:14:55 -070089 }
90 }
91};
92
93#endif // RIB_TESTS_UNIT_TESTS_RIB_STATUS_PUBLISHER_COMMON_HPP
94
95} // namespace tests
96} // namespace rib
97} // namespace nfd