blob: c9412adf7b3a3b3515fa60c6dc46ece253b8e4fb [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonfeae5572017-01-13 12:06:26 -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 "publisher/lsdb-status-publisher.hpp"
23#include "tlv/lsdb-status.hpp"
24#include "tlv/tlv-nlsr.hpp"
25
26#include "publisher-fixture.hpp"
27#include "../boost-test.hpp"
28
29namespace nlsr {
30namespace test {
31
32BOOST_FIXTURE_TEST_SUITE(PublisherTestLsdbStatusPublisher, PublisherFixture)
33
34BOOST_AUTO_TEST_CASE(Basic)
35{
36 // Install adjacency LSAs
37 // Adjacency LSA for RouterA
38 AdjLsa routerAAdjLsa;
39 routerAAdjLsa.setOrigRouter("/RouterA");
40 addAdjacency(routerAAdjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
41 lsdb.installAdjLsa(routerAAdjLsa);
42
43 // Adjacency LSA for RouterB
44 AdjLsa routerBAdjLsa;
45 routerBAdjLsa.setOrigRouter("/RouterB");
46 routerBAdjLsa.setLsSeqNo(5);
47 addAdjacency(routerBAdjLsa, "/RouterB/adjacency1", "udp://face-1", 10);
48 addAdjacency(routerBAdjLsa, "/RouterB/adjacency2", "udp://face-2", 20);
49 addAdjacency(routerBAdjLsa, "/RouterB/adjacency3", "udp://face-3", 30);
50 lsdb.installAdjLsa(routerBAdjLsa);
51
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060052 std::vector<double> anglesA = {20.00},
53 anglesB = {543.21},
54 anglesC = {0.02, 2.25};
55
Jiewen Tana0497d82015-02-02 21:59:18 -080056 // Install coordinate LSAs
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060057 CoordinateLsa routerACorLsa = createCoordinateLsa("/RouterA", 10.0, anglesA);
Jiewen Tana0497d82015-02-02 21:59:18 -080058 lsdb.installCoordinateLsa(routerACorLsa);
59
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060060 CoordinateLsa routerBCorLsa = createCoordinateLsa("/RouterB", 123.45, anglesB);
Jiewen Tana0497d82015-02-02 21:59:18 -080061 lsdb.installCoordinateLsa(routerBCorLsa);
62
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060063 CoordinateLsa routerCCorLsa = createCoordinateLsa("/RouterC", 0.01, anglesC);
Jiewen Tana0497d82015-02-02 21:59:18 -080064 lsdb.installCoordinateLsa(routerCCorLsa);
65
66 // Install Name LSAs
67 // Name LSA for RouterA
68 NameLsa routerANameLsa;
69 routerANameLsa.setOrigRouter("/RouterA");
70 routerANameLsa.addName("/RouterA/name1");
71 lsdb.installNameLsa(routerANameLsa);
72
73 // Name LSA for RouterB
74 NameLsa routerBNameLsa;
75 routerBNameLsa.setOrigRouter("/RouterB");
76 routerBNameLsa.addName("/RouterB/name1");
77 routerBNameLsa.addName("/RouterB/name2");
78 routerBNameLsa.addName("/RouterB/name3");
79 lsdb.installNameLsa(routerBNameLsa);
80
81 ndn::Name thisRouter("/This/Router");
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050082 AdjacencyLsaPublisher adjacencyLsaPublisher(lsdb, *face, keyChain);
83 CoordinateLsaPublisher coordinateLsaPublisher(lsdb, *face, keyChain);
84 NameLsaPublisher nameLsaPublisher(lsdb, *face, keyChain);
Jiewen Tana0497d82015-02-02 21:59:18 -080085
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050086 LsdbStatusPublisher publisher(lsdb, *face, keyChain,
Jiewen Tana0497d82015-02-02 21:59:18 -080087 adjacencyLsaPublisher,
88 coordinateLsaPublisher,
89 nameLsaPublisher);
90
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050091 ndn::Name publishingPrefix = ndn::Name(thisRouter);
92 publishingPrefix.append(Lsdb::NAME_COMPONENT).append(LsdbStatusPublisher::DATASET_COMPONENT);
93
94 publisher.publish(publishingPrefix);
Jiewen Tana0497d82015-02-02 21:59:18 -080095 face->processEvents(ndn::time::milliseconds(1));
96
Junxiao Shic778e812016-07-14 15:44:26 +000097 BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
Jiewen Tana0497d82015-02-02 21:59:18 -080098
Junxiao Shic778e812016-07-14 15:44:26 +000099 ndn::Block parser = face->sentData[0].getContent();
Jiewen Tana0497d82015-02-02 21:59:18 -0800100 parser.parse();
101
102 ndn::Block::element_const_iterator it = parser.elements_begin();
103
104 BOOST_CHECK_EQUAL(it->type(), ndn::tlv::nlsr::LsdbStatus);
105
106 tlv::LsdbStatus lsdbStatusTlv;
107 BOOST_REQUIRE_NO_THROW(lsdbStatusTlv.wireDecode(*it));
108
109 BOOST_CHECK_EQUAL(lsdbStatusTlv.hasAdjacencyLsas(), true);
110
111 // Check adjacency LSAs
112 std::list<tlv::AdjacencyLsa>::const_iterator adjLsaIt = lsdbStatusTlv.getAdjacencyLsas().begin();
113 checkTlvAdjLsa(*adjLsaIt, routerAAdjLsa);
114
115 ++adjLsaIt;
116 checkTlvAdjLsa(*adjLsaIt, routerBAdjLsa);
117
118 // Check coordinate LSAs
119 std::list<tlv::CoordinateLsa>::const_iterator corLsaIt =
120 lsdbStatusTlv.getCoordinateLsas().begin();
121 checkTlvCoordinateLsa(*corLsaIt, routerACorLsa);
122
123 ++corLsaIt;
124 checkTlvCoordinateLsa(*corLsaIt, routerBCorLsa);
125
126 ++corLsaIt;
127 checkTlvCoordinateLsa(*corLsaIt, routerCCorLsa);
128
129 // Check Name LSAs
130 std::list<tlv::NameLsa>::const_iterator nameLsaIt = lsdbStatusTlv.getNameLsas().begin();
131 checkTlvNameLsa(*nameLsaIt, routerANameLsa);
132
133 ++nameLsaIt;
134 checkTlvNameLsa(*nameLsaIt, routerBNameLsa);
135}
136
137BOOST_AUTO_TEST_SUITE_END()
138
139} // namespace test
140} // namespace nlsr