Skip to content

Commit

Permalink
lsa: define AdjLsa operator==
Browse files Browse the repository at this point in the history
Delete noLink field that is not used anywhere.

refs #4094

Change-Id: I646eb2dc828935c1f75ec2c036ba4fd60e907706
  • Loading branch information
yoursunny committed Jan 8, 2024
1 parent e988b73 commit b875293
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 66 deletions.
14 changes: 3 additions & 11 deletions src/lsa/adj-lsa.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Copyright (c) 2014-2024, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand All @@ -25,10 +25,8 @@
namespace nlsr {

AdjLsa::AdjLsa(const ndn::Name& originRouter, uint64_t seqNo,
const ndn::time::system_clock::time_point& timepoint,
uint32_t noLink, AdjacencyList& adl)
const ndn::time::system_clock::time_point& timepoint, AdjacencyList& adl)
: Lsa(originRouter, seqNo, timepoint)
, m_noLink(noLink)
{
for (const auto& adjacent : adl.getAdjList()) {
if (adjacent.getStatus() == Adjacent::STATUS_ACTIVE) {
Expand All @@ -42,12 +40,6 @@ AdjLsa::AdjLsa(const ndn::Block& block)
wireDecode(block);
}

bool
AdjLsa::isEqualContent(const AdjLsa& alsa) const
{
return m_adl == alsa.getAdl();
}

template<ndn::encoding::Tag TAG>
size_t
AdjLsa::wireEncode(ndn::EncodingImpl<TAG>& block) const
Expand Down Expand Up @@ -143,7 +135,7 @@ std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>>
AdjLsa::update(const std::shared_ptr<Lsa>& lsa)
{
auto alsa = std::static_pointer_cast<AdjLsa>(lsa);
if (!isEqualContent(*alsa)) {
if (*this != *alsa) {
resetAdl();
for (const auto& adjacent : alsa->getAdl()) {
addAdjacent(adjacent);
Expand Down
32 changes: 16 additions & 16 deletions src/lsa/adj-lsa.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Copyright (c) 2014-2024, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand All @@ -26,6 +26,8 @@
#include "adjacent.hpp"
#include "adjacency-list.hpp"

#include <boost/operators.hpp>

namespace nlsr {

/*!
Expand All @@ -35,16 +37,15 @@ namespace nlsr {
Adjacency*
*/
class AdjLsa : public Lsa
class AdjLsa : public Lsa, private boost::equality_comparable<AdjLsa>
{
public:
typedef AdjacencyList::const_iterator const_iterator;

AdjLsa() = default;

AdjLsa(const ndn::Name& originR, uint64_t seqNo,
const ndn::time::system_clock::time_point& timepoint,
uint32_t noLink, AdjacencyList& adl);
const ndn::time::system_clock::time_point& timepoint, AdjacencyList& adl);

AdjLsa(const ndn::Block& block);

Expand Down Expand Up @@ -74,21 +75,12 @@ class AdjLsa : public Lsa
}

void
addAdjacent(Adjacent adj)
addAdjacent(const Adjacent& adj)
{
m_wire.reset();
m_adl.insert(adj);
}

uint32_t
getNoLink()
{
return m_noLink;
}

bool
isEqualContent(const AdjLsa& alsa) const;

const_iterator
begin() const
{
Expand Down Expand Up @@ -117,8 +109,16 @@ class AdjLsa : public Lsa
std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>>
update(const std::shared_ptr<Lsa>& lsa) override;

private:
uint32_t m_noLink;
private: // non-member operators
// NOTE: the following "hidden friend" operators are available via
// argument-dependent lookup only and must be defined inline.
// boost::equality_comparable provides != operator.

friend bool
operator==(const AdjLsa& lhs, const AdjLsa& rhs)
{
return lhs.m_adl == rhs.m_adl;
}

PUBLIC_WITH_TESTS_ELSE_PRIVATE:
AdjacencyList m_adl;
Expand Down
3 changes: 1 addition & 2 deletions src/lsdb.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Copyright (c) 2014-2024, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand Down Expand Up @@ -343,7 +343,6 @@ Lsdb::buildAndInstallOwnAdjLsa()
{
AdjLsa adjLsa(m_thisRouterPrefix, m_sequencingManager.getAdjLsaSeq() + 1,
getLsaExpirationTimePoint(),
m_confParam.getAdjacencyList().getNumOfActiveNeighbor(),
m_confParam.getAdjacencyList());
m_sequencingManager.increaseAdjLsaSeq();
m_sequencingManager.writeSeqNoToFile();
Expand Down
22 changes: 9 additions & 13 deletions tests/lsa/test-adj-lsa.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Copyright (c) 2014-2024, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand Down Expand Up @@ -84,13 +84,11 @@ BOOST_AUTO_TEST_CASE(Basic)
activeAdjacency.setStatus(Adjacent::STATUS_ACTIVE);
activeAdjacencies.insert(activeAdjacency);

AdjLsa alsa1(routerName, seqNo, testTimePoint,
activeAdjacencies.size(), activeAdjacencies);
AdjLsa alsa1(routerName, seqNo, testTimePoint, activeAdjacencies);
BOOST_CHECK_EQUAL(alsa1.getAdl().size(), 1);
BOOST_CHECK_EQUAL(alsa1.getType(), Lsa::Type::ADJACENCY);
BOOST_CHECK_EQUAL(alsa1.getSeqNo(), seqNo);
BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint);
BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1);
BOOST_CHECK(alsa1.getAdl().isNeighbor(activeAdjacency.getName()));

// An AdjLsa initialized with INACTIVE adjacencies should not copy the adjacencies
Expand All @@ -99,17 +97,15 @@ BOOST_AUTO_TEST_CASE(Basic)
inactiveAdjacency.setStatus(Adjacent::STATUS_INACTIVE);
inactiveAdjacencies.insert(inactiveAdjacency);

AdjLsa alsa2(routerName, seqNo, testTimePoint,
inactiveAdjacencies.size(), inactiveAdjacencies);
AdjLsa alsa2(routerName, seqNo, testTimePoint, inactiveAdjacencies);
BOOST_CHECK_EQUAL(alsa2.getAdl().size(), 0);

// Thus, the two LSAs should not have equal content
BOOST_CHECK_EQUAL(alsa1.isEqualContent(alsa2), false);
BOOST_CHECK_NE(alsa1, alsa2);

// Create a duplicate of alsa1 which should have equal content
AdjLsa alsa3(routerName, seqNo, testTimePoint,
activeAdjacencies.size(), activeAdjacencies);
BOOST_CHECK(alsa1.isEqualContent(alsa3));
AdjLsa alsa3(routerName, seqNo, testTimePoint, activeAdjacencies);
BOOST_CHECK_EQUAL(alsa1, alsa3);

auto wire = alsa1.wireEncode();
BOOST_TEST(wire == ADJ_LSA1, boost::test_tools::per_element());
Expand Down Expand Up @@ -144,7 +140,7 @@ BOOST_AUTO_TEST_CASE(IncrementAdjacentNumber)

auto testTimePoint = ndn::time::system_clock::now() + ndn::time::seconds(3600);

AdjLsa lsa("router1", 12, testTimePoint, adjList.size(), adjList);
AdjLsa lsa("router1", 12, testTimePoint, adjList);

std::ostringstream os;
os << lsa;
Expand Down Expand Up @@ -181,9 +177,9 @@ BOOST_AUTO_TEST_CASE(InitializeFromContent)

auto testTimePoint = ndn::time::system_clock::now();

AdjLsa adjlsa1("router1", 1, testTimePoint, adjList.size(), adjList);
AdjLsa adjlsa1("router1", 1, testTimePoint, adjList);
AdjLsa adjlsa2(adjlsa1.wireEncode());
BOOST_CHECK(adjlsa1.isEqualContent(adjlsa2));
BOOST_CHECK_EQUAL(adjlsa1, adjlsa2);
}

BOOST_AUTO_TEST_SUITE_END()
Expand Down
8 changes: 4 additions & 4 deletions tests/route/test-hyperbolic-calculator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Copyright (c) 2014-2024, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand Down Expand Up @@ -69,7 +69,7 @@ class HyperbolicCalculatorFixture : public IoKeyChainFixture
adjacencies.insert(b);
adjacencies.insert(c);

AdjLsa adjA(a.getName(), 1, MAX_TIME, 2, adjacencies);
AdjLsa adjA(a.getName(), 1, MAX_TIME, adjacencies);
lsdb.installLsa(std::make_shared<AdjLsa>(adjA));

CoordinateLsa coordA(adjA.getOriginRouter(), 1, MAX_TIME, 16.23, anglesA);
Expand All @@ -83,7 +83,7 @@ class HyperbolicCalculatorFixture : public IoKeyChainFixture
adjacencyListB.insert(a);
adjacencyListB.insert(c);

AdjLsa adjB(b.getName(), 1, MAX_TIME, 2, adjacencyListB);
AdjLsa adjB(b.getName(), 1, MAX_TIME, adjacencyListB);
lsdb.installLsa(std::make_shared<AdjLsa>(adjB));

CoordinateLsa coordB(adjB.getOriginRouter(), 1, MAX_TIME, 16.59, anglesB);
Expand All @@ -97,7 +97,7 @@ class HyperbolicCalculatorFixture : public IoKeyChainFixture
adjacencyListC.insert(a);
adjacencyListC.insert(b);

AdjLsa adjC(c.getName(), 1, MAX_TIME, 2, adjacencyListC);
AdjLsa adjC(c.getName(), 1, MAX_TIME, adjacencyListC);
lsdb.installLsa(std::make_shared<AdjLsa>(adjC));

CoordinateLsa coordC(adjC.getOriginRouter(), 1, MAX_TIME, 14.11, anglesC);
Expand Down
8 changes: 4 additions & 4 deletions tests/route/test-link-state-calculator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Copyright (c) 2014-2024, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand Down Expand Up @@ -74,7 +74,7 @@ class LinkStateCalculatorFixture : public IoKeyChainFixture
adjacencyListA.insert(b);
adjacencyListA.insert(c);

AdjLsa adjA(a.getName(), 1, MAX_TIME, 2, adjacencyListA);
AdjLsa adjA(a.getName(), 1, MAX_TIME, adjacencyListA);
lsdb.installLsa(std::make_shared<AdjLsa>(adjA));

// Router B
Expand All @@ -85,7 +85,7 @@ class LinkStateCalculatorFixture : public IoKeyChainFixture
adjacencyListB.insert(a);
adjacencyListB.insert(c);

AdjLsa adjB(b.getName(), 1, MAX_TIME, 2, adjacencyListB);
AdjLsa adjB(b.getName(), 1, MAX_TIME, adjacencyListB);
lsdb.installLsa(std::make_shared<AdjLsa>(adjB));

// Router C
Expand All @@ -96,7 +96,7 @@ class LinkStateCalculatorFixture : public IoKeyChainFixture
adjacencyListC.insert(a);
adjacencyListC.insert(b);

AdjLsa adjC(c.getName(), 1, MAX_TIME, 2, adjacencyListC);
AdjLsa adjC(c.getName(), 1, MAX_TIME, adjacencyListC);
lsdb.installLsa(std::make_shared<AdjLsa>(adjC));

auto lsaRange = lsdb.getLsdbIterator<AdjLsa>();
Expand Down
9 changes: 4 additions & 5 deletions tests/route/test-name-prefix-table.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Copyright (c) 2014-2024, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand Down Expand Up @@ -78,7 +78,6 @@ BOOST_FIXTURE_TEST_CASE(Bupt, NamePrefixTableFixture)
conf.getAdjacencyList().insert(bupt);
AdjLsa thisRouterAdjLsa(thisRouter.getName(), 1,
ndn::time::system_clock::now() + 3600_s,
2,
conf.getAdjacencyList());

lsdb.installLsa(std::make_shared<AdjLsa>(thisRouterAdjLsa));
Expand All @@ -88,7 +87,7 @@ BOOST_FIXTURE_TEST_CASE(Bupt, NamePrefixTableFixture)
buptAdjacencies.insert(thisRouter);
AdjLsa buptAdjLsa(buptRouterName, 1,
ndn::time::system_clock::now() + ndn::time::seconds(5),
0 , buptAdjacencies);
buptAdjacencies);

lsdb.installLsa(std::make_shared<AdjLsa>(buptAdjLsa));

Expand Down Expand Up @@ -121,7 +120,7 @@ BOOST_FIXTURE_TEST_CASE(Bupt, NamePrefixTableFixture)
// Install new adjacency LSA
AdjLsa buptNewAdjLsa(buptRouterName, 12,
ndn::time::system_clock::now() + ndn::time::seconds(3600),
0, buptAdjacencies);
buptAdjacencies);
lsdb.installLsa(std::make_shared<AdjLsa>(buptNewAdjLsa));

this->advanceClocks(ndn::time::seconds(1));
Expand Down Expand Up @@ -350,7 +349,7 @@ BOOST_FIXTURE_TEST_CASE(UpdateFromLsdb, NamePrefixTableFixture)

// Adj and Coordinate LSAs router
ndn::Name router2("/router2/2");
AdjLsa adjLsa(router2, 12, testTimePoint, 2, conf.getAdjacencyList());
AdjLsa adjLsa(router2, 12, testTimePoint, conf.getAdjacencyList());
lsaPtr = std::make_shared<AdjLsa>(adjLsa);
BOOST_CHECK(npt.begin() == npt.end());
npt.updateFromLsdb(lsaPtr, LsdbUpdate::INSTALLED, {}, {});
Expand Down
6 changes: 3 additions & 3 deletions tests/route/test-routing-table.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Copyright (c) 2014-2024, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
Expand Down Expand Up @@ -124,7 +124,7 @@ BOOST_FIXTURE_TEST_CASE(UpdateFromLsdb, RoutingTableFixture)
{
auto testTimePoint = ndn::time::system_clock::now() + 3600_s;
ndn::Name router2("/router2");
AdjLsa adjLsa(router2, 12, testTimePoint, 2, conf.getAdjacencyList());
AdjLsa adjLsa(router2, 12, testTimePoint, conf.getAdjacencyList());
std::shared_ptr<Lsa> lsaPtr = std::make_shared<AdjLsa>(adjLsa);
BOOST_CHECK(!rt.m_isRouteCalculationScheduled);
lsdb.installLsa(lsaPtr);
Expand All @@ -147,7 +147,7 @@ BOOST_FIXTURE_TEST_CASE(UpdateFromLsdb, RoutingTableFixture)
Adjacent ownAdj(conf.getRouterPrefix());
ownAdj.setStatus(Adjacent::STATUS_ACTIVE);
adjl.insert(ownAdj);
AdjLsa adjLsa4("/router4", 12, testTimePoint, 2, adjl);
AdjLsa adjLsa4("/router4", 12, testTimePoint, adjl);
lsaPtr = std::make_shared<AdjLsa>(adjLsa4);
lsdb.installLsa(lsaPtr);

Expand Down
4 changes: 2 additions & 2 deletions tests/test-lsdb.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Copyright (c) 2014-2024, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand Down Expand Up @@ -403,7 +403,7 @@ BOOST_AUTO_TEST_CASE(LsdbSignals)
connectSignal();
auto testTimePoint = ndn::time::system_clock::now() + 3600_s;
ndn::Name router2("/router2");
AdjLsa adjLsa(router2, 12, testTimePoint, 2, conf.getAdjacencyList());
AdjLsa adjLsa(router2, 12, testTimePoint, conf.getAdjacencyList());
std::shared_ptr<Lsa> lsaPtr = std::make_shared<AdjLsa>(adjLsa);
lsdb.installLsa(lsaPtr);
checkSignalResult(LsdbUpdate::INSTALLED, lsaPtr, {}, {});
Expand Down
8 changes: 4 additions & 4 deletions tests/test-nlsr.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Copyright (c) 2014-2024, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand Down Expand Up @@ -344,7 +344,7 @@ BOOST_AUTO_TEST_CASE(FaceDestroyEvent)
10, Adjacent::STATUS_ACTIVE, 0, 256);

AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10,
ndn::time::system_clock::now(), 1, neighbors);
ndn::time::system_clock::now(), neighbors);
lsdb.installLsa(std::make_shared<AdjLsa>(ownAdjLsa));

// Router that will fail
Expand All @@ -353,7 +353,7 @@ BOOST_AUTO_TEST_CASE(FaceDestroyEvent)

AdjLsa failAdjLsa("/ndn/neighborA", 10,
ndn::time::system_clock::now() + ndn::time::seconds(3600),
1, failAdjacencies);
failAdjacencies);

lsdb.installLsa(std::make_shared<AdjLsa>(failAdjLsa));

Expand All @@ -363,7 +363,7 @@ BOOST_AUTO_TEST_CASE(FaceDestroyEvent)

AdjLsa otherAdjLsa("/ndn/neighborB", 10,
ndn::time::system_clock::now() + ndn::time::seconds(3600),
1, otherAdjacencies);
otherAdjacencies);

lsdb.installLsa(std::make_shared<AdjLsa>(otherAdjLsa));

Expand Down
Loading

0 comments on commit b875293

Please sign in to comment.