blob: 50d48da43816ba3823dde93a5558aa93d51cc75b [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");
78 AdjacencyLsaPublisher adjacencyLsaPublisher(lsdb, *face, thisRouter, keyChain);
79 CoordinateLsaPublisher coordinateLsaPublisher(lsdb, *face, thisRouter, keyChain);
80 NameLsaPublisher nameLsaPublisher(lsdb, *face, thisRouter, keyChain);
81
82 LsdbStatusPublisher publisher(lsdb, *face, thisRouter, keyChain,
83 adjacencyLsaPublisher,
84 coordinateLsaPublisher,
85 nameLsaPublisher);
86
87 publisher.publish();
88 face->processEvents(ndn::time::milliseconds(1));
89
90 BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
91
92 ndn::Block parser = face->sentDatas[0].getContent();
93 parser.parse();
94
95 ndn::Block::element_const_iterator it = parser.elements_begin();
96
97 BOOST_CHECK_EQUAL(it->type(), ndn::tlv::nlsr::LsdbStatus);
98
99 tlv::LsdbStatus lsdbStatusTlv;
100 BOOST_REQUIRE_NO_THROW(lsdbStatusTlv.wireDecode(*it));
101
102 BOOST_CHECK_EQUAL(lsdbStatusTlv.hasAdjacencyLsas(), true);
103
104 // Check adjacency LSAs
105 std::list<tlv::AdjacencyLsa>::const_iterator adjLsaIt = lsdbStatusTlv.getAdjacencyLsas().begin();
106 checkTlvAdjLsa(*adjLsaIt, routerAAdjLsa);
107
108 ++adjLsaIt;
109 checkTlvAdjLsa(*adjLsaIt, routerBAdjLsa);
110
111 // Check coordinate LSAs
112 std::list<tlv::CoordinateLsa>::const_iterator corLsaIt =
113 lsdbStatusTlv.getCoordinateLsas().begin();
114 checkTlvCoordinateLsa(*corLsaIt, routerACorLsa);
115
116 ++corLsaIt;
117 checkTlvCoordinateLsa(*corLsaIt, routerBCorLsa);
118
119 ++corLsaIt;
120 checkTlvCoordinateLsa(*corLsaIt, routerCCorLsa);
121
122 // Check Name LSAs
123 std::list<tlv::NameLsa>::const_iterator nameLsaIt = lsdbStatusTlv.getNameLsas().begin();
124 checkTlvNameLsa(*nameLsaIt, routerANameLsa);
125
126 ++nameLsaIt;
127 checkTlvNameLsa(*nameLsaIt, routerBNameLsa);
128}
129
130BOOST_AUTO_TEST_SUITE_END()
131
132} // namespace test
133} // namespace nlsr