blob: e04869e0699eb4f926bc8c14de664815288efeec [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -07002/*
Davide Pesavento288141a2024-02-13 17:30:35 -05003 * Copyright (c) 2014-2024, The University of Memphis,
Jiewen Tana0497d82015-02-02 21:59:18 -08004 * Regents of the University of California,
5 * Arizona Board of Regents.
6 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070020 */
Jiewen Tana0497d82015-02-02 21:59:18 -080021
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040022#ifndef NLSR_TESTS_PUBLISHER_FIXTURE_HPP
23#define NLSR_TESTS_PUBLISHER_FIXTURE_HPP
dmcoomes9f936662017-03-02 10:33:09 -060024
laqinfan35731852017-08-08 06:17:39 -050025#include "publisher/dataset-interest-handler.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080026#include "nlsr.hpp"
27
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040028#include "tests/io-key-chain-fixture.hpp"
Davide Pesaventocb065f12019-12-27 01:03:34 -050029#include "tests/test-common.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080030
Davide Pesavento288141a2024-02-13 17:30:35 -050031namespace nlsr::tests {
Jiewen Tana0497d82015-02-02 21:59:18 -080032
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040033class PublisherFixture : public IoKeyChainFixture
Jiewen Tana0497d82015-02-02 21:59:18 -080034{
35public:
36 PublisherFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040037 : face(m_io, m_keyChain, {true, true})
Saurab Dulal427e0122019-11-28 11:58:02 -060038 , conf(face, m_keyChain)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060039 , confProcessor(conf)
40 , nlsr(face, m_keyChain, conf)
41 , lsdb(nlsr.m_lsdb)
42 , rt1(nlsr.m_routingTable)
Jiewen Tana0497d82015-02-02 21:59:18 -080043 {
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040044 routerId = m_keyChain.createIdentity(conf.getRouterPrefix());
45 advanceClocks(100_ms);
Jiewen Tana0497d82015-02-02 21:59:18 -080046 }
47
48 void
49 addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost)
50 {
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050051 Adjacent adjacency(name, ndn::FaceUri(faceUri), cost, Adjacent::STATUS_ACTIVE, 0, 0);
Nick Gordone9733ed2017-04-26 10:48:39 -050052 lsa.addAdjacent(std::move(adjacency));
Jiewen Tana0497d82015-02-02 21:59:18 -080053 }
54
laqinfan35731852017-08-08 06:17:39 -050055 NextHop
56 createNextHop(const std::string& faceUri, double cost)
57 {
Junxiao Shi6593a432023-08-21 10:50:28 +000058 return {ndn::FaceUri(faceUri), cost};
laqinfan35731852017-08-08 06:17:39 -050059 }
60
Jiewen Tana0497d82015-02-02 21:59:18 -080061 CoordinateLsa
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060062 createCoordinateLsa(const std::string& origin, double radius, std::vector<double> angle)
Jiewen Tana0497d82015-02-02 21:59:18 -080063 {
Davide Pesavento288141a2024-02-13 17:30:35 -050064 return {origin, 1, time::system_clock::now(), radius, angle};
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040065 }
66
67 void
68 processDatasetInterest(std::function<bool(const ndn::Block&)> isSameType)
69 {
70 advanceClocks(30_ms);
71
72 BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
73 ndn::Block parser(face.sentData[0].getContent());
74 parser.parse();
75 face.sentData.clear();
76
77 auto it = parser.elements_begin();
78 BOOST_CHECK(isSameType(*it++));
79 BOOST_CHECK(it == parser.elements_end());
Jiewen Tana0497d82015-02-02 21:59:18 -080080 }
81
Jiewen Tana0497d82015-02-02 21:59:18 -080082public:
Junxiao Shi43f37a02023-08-09 00:09:00 +000083 ndn::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -060084 ConfParameter conf;
85 DummyConfFileProcessor confProcessor;
laqinfand22da512017-05-25 17:29:53 -050086 Nlsr nlsr;
87 Lsdb& lsdb;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050088
89 ndn::security::pib::Identity routerId;
laqinfan35731852017-08-08 06:17:39 -050090 RoutingTable& rt1;
Jiewen Tana0497d82015-02-02 21:59:18 -080091};
92
Davide Pesavento288141a2024-02-13 17:30:35 -050093} // namespace nlsr::tests
dmcoomes9f936662017-03-02 10:33:09 -060094
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040095#endif // NLSR_TESTS_PUBLISHER_FIXTURE_HPP