blob: 58c4eff188c953da17c18787d22bc8ffb700f68d [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, The University of Memphis,
4 * 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
52 // Install coordinate LSAs
53 CoordinateLsa routerACorLsa = createCoordinateLsa("/RouterA", 10.0, 20.0);
54 lsdb.installCoordinateLsa(routerACorLsa);
55
56 CoordinateLsa routerBCorLsa = createCoordinateLsa("/RouterB", 123.45, 543.21);
57 lsdb.installCoordinateLsa(routerBCorLsa);
58
59 CoordinateLsa routerCCorLsa = createCoordinateLsa("/RouterC", 0.01, 0.02);
60 lsdb.installCoordinateLsa(routerCCorLsa);
61
62 // Install Name LSAs
63 // Name LSA for RouterA
64 NameLsa routerANameLsa;
65 routerANameLsa.setOrigRouter("/RouterA");
66 routerANameLsa.addName("/RouterA/name1");
67 lsdb.installNameLsa(routerANameLsa);
68
69 // Name LSA for RouterB
70 NameLsa routerBNameLsa;
71 routerBNameLsa.setOrigRouter("/RouterB");
72 routerBNameLsa.addName("/RouterB/name1");
73 routerBNameLsa.addName("/RouterB/name2");
74 routerBNameLsa.addName("/RouterB/name3");
75 lsdb.installNameLsa(routerBNameLsa);
76
77 ndn::Name thisRouter("/This/Router");
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050078 AdjacencyLsaPublisher adjacencyLsaPublisher(lsdb, *face, keyChain);
79 CoordinateLsaPublisher coordinateLsaPublisher(lsdb, *face, keyChain);
80 NameLsaPublisher nameLsaPublisher(lsdb, *face, keyChain);
Jiewen Tana0497d82015-02-02 21:59:18 -080081
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050082 LsdbStatusPublisher publisher(lsdb, *face, keyChain,
Jiewen Tana0497d82015-02-02 21:59:18 -080083 adjacencyLsaPublisher,
84 coordinateLsaPublisher,
85 nameLsaPublisher);
86
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050087 ndn::Name publishingPrefix = ndn::Name(thisRouter);
88 publishingPrefix.append(Lsdb::NAME_COMPONENT).append(LsdbStatusPublisher::DATASET_COMPONENT);
89
90 publisher.publish(publishingPrefix);
Jiewen Tana0497d82015-02-02 21:59:18 -080091 face->processEvents(ndn::time::milliseconds(1));
92
93 BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
94
95 ndn::Block parser = face->sentDatas[0].getContent();
96 parser.parse();
97
98 ndn::Block::element_const_iterator it = parser.elements_begin();
99
100 BOOST_CHECK_EQUAL(it->type(), ndn::tlv::nlsr::LsdbStatus);
101
102 tlv::LsdbStatus lsdbStatusTlv;
103 BOOST_REQUIRE_NO_THROW(lsdbStatusTlv.wireDecode(*it));
104
105 BOOST_CHECK_EQUAL(lsdbStatusTlv.hasAdjacencyLsas(), true);
106
107 // Check adjacency LSAs
108 std::list<tlv::AdjacencyLsa>::const_iterator adjLsaIt = lsdbStatusTlv.getAdjacencyLsas().begin();
109 checkTlvAdjLsa(*adjLsaIt, routerAAdjLsa);
110
111 ++adjLsaIt;
112 checkTlvAdjLsa(*adjLsaIt, routerBAdjLsa);
113
114 // Check coordinate LSAs
115 std::list<tlv::CoordinateLsa>::const_iterator corLsaIt =
116 lsdbStatusTlv.getCoordinateLsas().begin();
117 checkTlvCoordinateLsa(*corLsaIt, routerACorLsa);
118
119 ++corLsaIt;
120 checkTlvCoordinateLsa(*corLsaIt, routerBCorLsa);
121
122 ++corLsaIt;
123 checkTlvCoordinateLsa(*corLsaIt, routerCCorLsa);
124
125 // Check Name LSAs
126 std::list<tlv::NameLsa>::const_iterator nameLsaIt = lsdbStatusTlv.getNameLsas().begin();
127 checkTlvNameLsa(*nameLsaIt, routerANameLsa);
128
129 ++nameLsaIt;
130 checkTlvNameLsa(*nameLsaIt, routerBNameLsa);
131}
132
133BOOST_AUTO_TEST_SUITE_END()
134
135} // namespace test
136} // namespace nlsr