blob: b187ffbf70ab7c08589e7b2fc004754d88fb7ed8 [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/*
Junxiao Shi43f37a02023-08-09 00:09:00 +00003 * Copyright (c) 2014-2023, 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
Jiewen Tana0497d82015-02-02 21:59:18 -080031namespace nlsr {
32namespace test {
33
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040034class PublisherFixture : public IoKeyChainFixture
Jiewen Tana0497d82015-02-02 21:59:18 -080035{
36public:
37 PublisherFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040038 : face(m_io, m_keyChain, {true, true})
Saurab Dulal427e0122019-11-28 11:58:02 -060039 , conf(face, m_keyChain)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060040 , confProcessor(conf)
41 , nlsr(face, m_keyChain, conf)
42 , lsdb(nlsr.m_lsdb)
43 , rt1(nlsr.m_routingTable)
Jiewen Tana0497d82015-02-02 21:59:18 -080044 {
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040045 routerId = m_keyChain.createIdentity(conf.getRouterPrefix());
46 advanceClocks(100_ms);
Jiewen Tana0497d82015-02-02 21:59:18 -080047 }
48
49 void
50 addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost)
51 {
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050052 Adjacent adjacency(name, ndn::FaceUri(faceUri), cost, Adjacent::STATUS_ACTIVE, 0, 0);
Nick Gordone9733ed2017-04-26 10:48:39 -050053 lsa.addAdjacent(std::move(adjacency));
Jiewen Tana0497d82015-02-02 21:59:18 -080054 }
55
laqinfan35731852017-08-08 06:17:39 -050056 NextHop
57 createNextHop(const std::string& faceUri, double cost)
58 {
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040059 return {faceUri, cost};
laqinfan35731852017-08-08 06:17:39 -050060 }
61
Jiewen Tana0497d82015-02-02 21:59:18 -080062 CoordinateLsa
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060063 createCoordinateLsa(const std::string& origin, double radius, std::vector<double> angle)
Jiewen Tana0497d82015-02-02 21:59:18 -080064 {
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040065 return {origin, 1, ndn::time::system_clock::now(), radius, angle};
66 }
67
68 void
69 processDatasetInterest(std::function<bool(const ndn::Block&)> isSameType)
70 {
71 advanceClocks(30_ms);
72
73 BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
74 ndn::Block parser(face.sentData[0].getContent());
75 parser.parse();
76 face.sentData.clear();
77
78 auto it = parser.elements_begin();
79 BOOST_CHECK(isSameType(*it++));
80 BOOST_CHECK(it == parser.elements_end());
Jiewen Tana0497d82015-02-02 21:59:18 -080081 }
82
Jiewen Tana0497d82015-02-02 21:59:18 -080083public:
Junxiao Shi43f37a02023-08-09 00:09:00 +000084 ndn::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -060085 ConfParameter conf;
86 DummyConfFileProcessor confProcessor;
laqinfand22da512017-05-25 17:29:53 -050087 Nlsr nlsr;
88 Lsdb& lsdb;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050089
90 ndn::security::pib::Identity routerId;
laqinfan35731852017-08-08 06:17:39 -050091 RoutingTable& rt1;
Jiewen Tana0497d82015-02-02 21:59:18 -080092};
93
94} // namespace test
95} // namespace nlsr
dmcoomes9f936662017-03-02 10:33:09 -060096
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040097#endif // NLSR_TESTS_PUBLISHER_FIXTURE_HPP