blob: 8ee842b575c9223014cef61c104a7cc930a3e8d8 [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2017, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
#include "publisher/lsa-publisher.hpp"
#include "tlv/adjacency.hpp"
#include "tlv/adjacency-lsa.hpp"
#include "tlv/tlv-nlsr.hpp"
#include "publisher-fixture.hpp"
#include "../boost-test.hpp"
namespace nlsr {
namespace test {
BOOST_FIXTURE_TEST_SUITE(PublisherTestLsaPublisher, PublisherFixture)
BOOST_AUTO_TEST_CASE(AdjacencyLsaPublisherBasic)
{
ndn::Name thisRouter("/RouterA");
// Adjacency LSA for RouterA
AdjLsa routerALsa;
routerALsa.setOrigRouter(thisRouter);
addAdjacency(routerALsa, "/RouterA/adjacency1", "udp://face-1", 10);
lsdb.installAdjLsa(routerALsa);
// Adjacency LSA for RouterB
AdjLsa routerBLsa;
routerBLsa.setOrigRouter("/RouterB");
routerBLsa.setLsSeqNo(5);
addAdjacency(routerBLsa, "/RouterB/adjacency1", "udp://face-1", 10);
addAdjacency(routerBLsa, "/RouterB/adjacency2", "udp://face-2", 20);
addAdjacency(routerBLsa, "/RouterB/adjacency3", "udp://face-3", 30);
lsdb.installAdjLsa(routerBLsa);
AdjacencyLsaPublisher publisher(lsdb, *face, keyChain);
ndn::Name publishingPrefix = ndn::Name(thisRouter);
publishingPrefix.append(Lsdb::NAME_COMPONENT).append(AdjacencyLsaPublisher::DATASET_COMPONENT);
publisher.publish(publishingPrefix);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
ndn::Block parser = face->sentData[0].getContent();
parser.parse();
// Check RouterB LSA
ndn::Block::element_const_iterator it = parser.elements_begin();
checkTlvAdjLsa(*it, routerBLsa);
// Check RouterA LSA
it++;
checkTlvAdjLsa(*it, routerALsa);
}
BOOST_AUTO_TEST_CASE(CoordinateLsaBasic)
{
ndn::Name thisRouter("/RouterA");
CoordinateLsa routerALsa = createCoordinateLsa(thisRouter.toUri(), 10.0, 20.0);
lsdb.installCoordinateLsa(routerALsa);
CoordinateLsa routerBLsa = createCoordinateLsa("/RouterB", 123.45, 543.21);
lsdb.installCoordinateLsa(routerBLsa);
CoordinateLsa routerCLsa = createCoordinateLsa("/RouterC", 0.01, 0.02);
lsdb.installCoordinateLsa(routerCLsa);
CoordinateLsaPublisher publisher(lsdb, *face, keyChain);
ndn::Name publishingPrefix = ndn::Name(thisRouter);
publishingPrefix.append(Lsdb::NAME_COMPONENT).append(CoordinateLsaPublisher::DATASET_COMPONENT);
publisher.publish(publishingPrefix);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
ndn::Block parser = face->sentData[0].getContent();
parser.parse();
// Check RouterC LSA
ndn::Block::element_const_iterator it = parser.elements_begin();
checkTlvCoordinateLsa(*it, routerCLsa);
// Check RouterB LSA
++it;
checkTlvCoordinateLsa(*it, routerBLsa);
// Check RouterA LSA
++it;
checkTlvCoordinateLsa(*it, routerALsa);
}
BOOST_AUTO_TEST_CASE(NameLsaBasic)
{
ndn::Name thisRouter("/RouterA");
// Name LSA for RouterA
NameLsa routerALsa;
routerALsa.setOrigRouter(thisRouter.toUri());
routerALsa.addName(ndn::Name(thisRouter).append("name1"));
lsdb.installNameLsa(routerALsa);
// Name LSA for RouterB
NameLsa routerBLsa;
routerBLsa.setOrigRouter("/RouterB");
routerBLsa.addName("/RouterB/name1");
routerBLsa.addName("/RouterB/name2");
routerBLsa.addName("/RouterB/name3");
lsdb.installNameLsa(routerBLsa);
NameLsaPublisher publisher(lsdb, *face, keyChain);
ndn::Name publishingPrefix = ndn::Name(thisRouter);
publishingPrefix.append(Lsdb::NAME_COMPONENT).append(NameLsaPublisher::DATASET_COMPONENT);
publisher.publish(publishingPrefix);
face->processEvents(ndn::time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentData.size(), 1);
ndn::Block parser = face->sentData[0].getContent();
parser.parse();
// Check RouterB LSA
ndn::Block::element_const_iterator it = parser.elements_begin();
checkTlvNameLsa(*it, routerBLsa);
// Check RouterA LSA
it++;
checkTlvNameLsa(*it, routerALsa);
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace test
} // namespace nlsr