blob: eda0f711b0c533a326d2caa568817b75d4c71cf6 [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, 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/>.
20 **/
21
22#include "nlsr.hpp"
23
24#include "../boost-test.hpp"
25#include "../test-common.hpp"
26
27#include <ndn-cxx/util/dummy-client-face.hpp>
28
29namespace nlsr {
30namespace test {
31
32class PublisherFixture : public BaseFixture
33{
34public:
35 PublisherFixture()
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060036 : face(make_shared<ndn::util::DummyClientFace>())
Jiewen Tana0497d82015-02-02 21:59:18 -080037 , nlsr(g_ioService, g_scheduler, ndn::ref(*face))
38 , lsdb(nlsr, g_scheduler, nlsr.getSyncLogicHandler())
39 {
40 }
41
42 void
43 addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost)
44 {
45 Adjacent adjacency(name, faceUri, cost, Adjacent::STATUS_ACTIVE, 0, 0);
46 lsa.addAdjacent(adjacency);
47 }
48
49 void
50 checkTlvLsaInfo(const tlv::LsaInfo& info, Lsa& lsa)
51 {
52 BOOST_CHECK_EQUAL(info.getOriginRouter(), lsa.getOrigRouter());
53 BOOST_CHECK_EQUAL(info.getSequenceNumber(), lsa.getLsSeqNo());
54 BOOST_CHECK_LE(info.getExpirationPeriod(), ndn::time::milliseconds(0));
55 }
56
57 void
58 checkTlvAdjLsa(const ndn::Block& block, AdjLsa& lsa)
59 {
60 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::AdjacencyLsa);
61
62 tlv::AdjacencyLsa tlvLsa;
63 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
64
65 checkTlvAdjLsa(tlvLsa, lsa);
66 }
67
68 void
69 checkTlvAdjLsa(const tlv::AdjacencyLsa& tlvLsa, AdjLsa& lsa)
70 {
71 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
72
73 std::list<tlv::Adjacency>::const_iterator it = tlvLsa.getAdjacencies().begin();
74
75 for (const Adjacent& adjacency : lsa.getAdl().getAdjList()) {
76 BOOST_CHECK_EQUAL(it->getName(), adjacency.getName());
77 BOOST_CHECK_EQUAL(it->getUri(), adjacency.getConnectingFaceUri());
78 BOOST_CHECK_EQUAL(it->getCost(), adjacency.getLinkCost());
79 ++it;
80 }
81 }
82
83 CoordinateLsa
84 createCoordinateLsa(const std::string& origin, double radius, double angle)
85 {
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060086 CoordinateLsa lsa(origin, 1, ndn::time::system_clock::now(),
Jiewen Tana0497d82015-02-02 21:59:18 -080087 radius, angle);
88
Alexander Afanasyevf9f39102015-12-01 17:43:40 -080089 return lsa;
Jiewen Tana0497d82015-02-02 21:59:18 -080090 }
91
92 void
93 checkTlvCoordinateLsa(const ndn::Block& block, CoordinateLsa& lsa)
94 {
95 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::CoordinateLsa);
96
97 tlv::CoordinateLsa tlvLsa;
98 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
99
100 checkTlvCoordinateLsa(tlvLsa, lsa);
101 }
102
103 void
104 checkTlvCoordinateLsa(const tlv::CoordinateLsa& tlvLsa, CoordinateLsa& lsa)
105 {
106 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
107
108 BOOST_CHECK_EQUAL(tlvLsa.getHyperbolicRadius(), lsa.getCorRadius());
109 BOOST_CHECK_EQUAL(tlvLsa.getHyperbolicAngle(), lsa.getCorTheta());
110 }
111
112 void
113 checkTlvNameLsa(const ndn::Block& block, NameLsa& lsa)
114 {
115 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::NameLsa);
116
117 tlv::NameLsa tlvLsa;
118 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
119
120 checkTlvNameLsa(tlvLsa, lsa);
121 }
122
123 void
124 checkTlvNameLsa(const tlv::NameLsa& tlvLsa, NameLsa& lsa)
125 {
126 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
127
128 std::list<ndn::Name>::const_iterator it = tlvLsa.getNames().begin();
129
130 for (const ndn::Name& name : lsa.getNpl().getNameList()) {
131 BOOST_CHECK_EQUAL(*it, name);
132 ++it;
133 }
134 }
135
136public:
137 shared_ptr<ndn::util::DummyClientFace> face;
138 Nlsr nlsr;
139 Lsdb lsdb;
140 ndn::KeyChain keyChain;
141};
142
143} // namespace test
144} // namespace nlsr