blob: 8ee842b575c9223014cef61c104a7cc930a3e8d8 [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/lsa-publisher.hpp"
23#include "tlv/adjacency.hpp"
24#include "tlv/adjacency-lsa.hpp"
25#include "tlv/tlv-nlsr.hpp"
26
27#include "publisher-fixture.hpp"
28#include "../boost-test.hpp"
29
30namespace nlsr {
31namespace test {
32
33BOOST_FIXTURE_TEST_SUITE(PublisherTestLsaPublisher, PublisherFixture)
34
35BOOST_AUTO_TEST_CASE(AdjacencyLsaPublisherBasic)
36{
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050037 ndn::Name thisRouter("/RouterA");
38
Jiewen Tana0497d82015-02-02 21:59:18 -080039 // Adjacency LSA for RouterA
40 AdjLsa routerALsa;
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050041 routerALsa.setOrigRouter(thisRouter);
Jiewen Tana0497d82015-02-02 21:59:18 -080042 addAdjacency(routerALsa, "/RouterA/adjacency1", "udp://face-1", 10);
43 lsdb.installAdjLsa(routerALsa);
44
45 // Adjacency LSA for RouterB
46 AdjLsa routerBLsa;
47 routerBLsa.setOrigRouter("/RouterB");
48 routerBLsa.setLsSeqNo(5);
49 addAdjacency(routerBLsa, "/RouterB/adjacency1", "udp://face-1", 10);
50 addAdjacency(routerBLsa, "/RouterB/adjacency2", "udp://face-2", 20);
51 addAdjacency(routerBLsa, "/RouterB/adjacency3", "udp://face-3", 30);
52 lsdb.installAdjLsa(routerBLsa);
53
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050054 AdjacencyLsaPublisher publisher(lsdb, *face, keyChain);
Jiewen Tana0497d82015-02-02 21:59:18 -080055
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050056 ndn::Name publishingPrefix = ndn::Name(thisRouter);
57 publishingPrefix.append(Lsdb::NAME_COMPONENT).append(AdjacencyLsaPublisher::DATASET_COMPONENT);
58
59 publisher.publish(publishingPrefix);
Jiewen Tana0497d82015-02-02 21:59:18 -080060 face->processEvents(ndn::time::milliseconds(1));
61
Junxiao Shic778e812016-07-14 15:44:26 +000062 BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
63 ndn::Block parser = face->sentData[0].getContent();
Jiewen Tana0497d82015-02-02 21:59:18 -080064 parser.parse();
65
66 // Check RouterB LSA
67 ndn::Block::element_const_iterator it = parser.elements_begin();
68 checkTlvAdjLsa(*it, routerBLsa);
69
70 // Check RouterA LSA
71 it++;
72 checkTlvAdjLsa(*it, routerALsa);
73}
74
75BOOST_AUTO_TEST_CASE(CoordinateLsaBasic)
76{
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050077 ndn::Name thisRouter("/RouterA");
78
79 CoordinateLsa routerALsa = createCoordinateLsa(thisRouter.toUri(), 10.0, 20.0);
Jiewen Tana0497d82015-02-02 21:59:18 -080080 lsdb.installCoordinateLsa(routerALsa);
81
82 CoordinateLsa routerBLsa = createCoordinateLsa("/RouterB", 123.45, 543.21);
83 lsdb.installCoordinateLsa(routerBLsa);
84
85 CoordinateLsa routerCLsa = createCoordinateLsa("/RouterC", 0.01, 0.02);
86 lsdb.installCoordinateLsa(routerCLsa);
87
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050088 CoordinateLsaPublisher publisher(lsdb, *face, keyChain);
Jiewen Tana0497d82015-02-02 21:59:18 -080089
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050090 ndn::Name publishingPrefix = ndn::Name(thisRouter);
91 publishingPrefix.append(Lsdb::NAME_COMPONENT).append(CoordinateLsaPublisher::DATASET_COMPONENT);
92
93 publisher.publish(publishingPrefix);
Jiewen Tana0497d82015-02-02 21:59:18 -080094 face->processEvents(ndn::time::milliseconds(1));
95
Junxiao Shic778e812016-07-14 15:44:26 +000096 BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
97 ndn::Block parser = face->sentData[0].getContent();
Jiewen Tana0497d82015-02-02 21:59:18 -080098 parser.parse();
99
100 // Check RouterC LSA
101 ndn::Block::element_const_iterator it = parser.elements_begin();
102 checkTlvCoordinateLsa(*it, routerCLsa);
103
104 // Check RouterB LSA
105 ++it;
106 checkTlvCoordinateLsa(*it, routerBLsa);
107
108 // Check RouterA LSA
109 ++it;
110 checkTlvCoordinateLsa(*it, routerALsa);
111}
112
113BOOST_AUTO_TEST_CASE(NameLsaBasic)
114{
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500115 ndn::Name thisRouter("/RouterA");
116
Jiewen Tana0497d82015-02-02 21:59:18 -0800117 // Name LSA for RouterA
118 NameLsa routerALsa;
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500119 routerALsa.setOrigRouter(thisRouter.toUri());
120 routerALsa.addName(ndn::Name(thisRouter).append("name1"));
Jiewen Tana0497d82015-02-02 21:59:18 -0800121 lsdb.installNameLsa(routerALsa);
122
123 // Name LSA for RouterB
124 NameLsa routerBLsa;
125 routerBLsa.setOrigRouter("/RouterB");
126 routerBLsa.addName("/RouterB/name1");
127 routerBLsa.addName("/RouterB/name2");
128 routerBLsa.addName("/RouterB/name3");
129 lsdb.installNameLsa(routerBLsa);
130
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500131 NameLsaPublisher publisher(lsdb, *face, keyChain);
Jiewen Tana0497d82015-02-02 21:59:18 -0800132
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500133 ndn::Name publishingPrefix = ndn::Name(thisRouter);
134 publishingPrefix.append(Lsdb::NAME_COMPONENT).append(NameLsaPublisher::DATASET_COMPONENT);
135
136 publisher.publish(publishingPrefix);
Jiewen Tana0497d82015-02-02 21:59:18 -0800137 face->processEvents(ndn::time::milliseconds(1));
138
Junxiao Shic778e812016-07-14 15:44:26 +0000139 BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
140 ndn::Block parser = face->sentData[0].getContent();
Jiewen Tana0497d82015-02-02 21:59:18 -0800141 parser.parse();
142
143 // Check RouterB LSA
144 ndn::Block::element_const_iterator it = parser.elements_begin();
145 checkTlvNameLsa(*it, routerBLsa);
146
147 // Check RouterA LSA
148 it++;
149 checkTlvNameLsa(*it, routerALsa);
150}
151
152BOOST_AUTO_TEST_SUITE_END()
153
154} // namespace test
155} // namespace nlsr