lsa: define AdjLsa operator==
Delete noLink field that is not used anywhere.
refs #4094
Change-Id: I646eb2dc828935c1f75ec2c036ba4fd60e907706
diff --git a/src/lsa/adj-lsa.cpp b/src/lsa/adj-lsa.cpp
index 38edb63..ac583e4 100644
--- a/src/lsa/adj-lsa.cpp
+++ b/src/lsa/adj-lsa.cpp
@@ -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.
*
@@ -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) {
@@ -42,12 +40,6 @@
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
@@ -143,7 +135,7 @@
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);
diff --git a/src/lsa/adj-lsa.hpp b/src/lsa/adj-lsa.hpp
index 5aad4c0..133e95c 100644
--- a/src/lsa/adj-lsa.hpp
+++ b/src/lsa/adj-lsa.hpp
@@ -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.
*
@@ -26,6 +26,8 @@
#include "adjacent.hpp"
#include "adjacency-list.hpp"
+#include <boost/operators.hpp>
+
namespace nlsr {
/*!
@@ -35,7 +37,7 @@
Adjacency*
*/
-class AdjLsa : public Lsa
+class AdjLsa : public Lsa, private boost::equality_comparable<AdjLsa>
{
public:
typedef AdjacencyList::const_iterator const_iterator;
@@ -43,8 +45,7 @@
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);
@@ -74,21 +75,12 @@
}
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
{
@@ -117,8 +109,16 @@
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;
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index f672a41..608b575 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -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.
*
@@ -343,7 +343,6 @@
{
AdjLsa adjLsa(m_thisRouterPrefix, m_sequencingManager.getAdjLsaSeq() + 1,
getLsaExpirationTimePoint(),
- m_confParam.getAdjacencyList().getNumOfActiveNeighbor(),
m_confParam.getAdjacencyList());
m_sequencingManager.increaseAdjLsaSeq();
m_sequencingManager.writeSeqNoToFile();
diff --git a/tests/lsa/test-adj-lsa.cpp b/tests/lsa/test-adj-lsa.cpp
index 3effb97..91610bd 100644
--- a/tests/lsa/test-adj-lsa.cpp
+++ b/tests/lsa/test-adj-lsa.cpp
@@ -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.
*
@@ -84,13 +84,11 @@
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
@@ -99,17 +97,15 @@
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());
@@ -144,7 +140,7 @@
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;
@@ -181,9 +177,9 @@
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()
diff --git a/tests/route/test-hyperbolic-calculator.cpp b/tests/route/test-hyperbolic-calculator.cpp
index 0d4dd5e..bbb7930 100644
--- a/tests/route/test-hyperbolic-calculator.cpp
+++ b/tests/route/test-hyperbolic-calculator.cpp
@@ -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.
*
@@ -69,7 +69,7 @@
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);
@@ -83,7 +83,7 @@
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);
@@ -97,7 +97,7 @@
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);
diff --git a/tests/route/test-link-state-calculator.cpp b/tests/route/test-link-state-calculator.cpp
index 73421b0..366aa7e 100644
--- a/tests/route/test-link-state-calculator.cpp
+++ b/tests/route/test-link-state-calculator.cpp
@@ -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.
*
@@ -74,7 +74,7 @@
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
@@ -85,7 +85,7 @@
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
@@ -96,7 +96,7 @@
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>();
diff --git a/tests/route/test-name-prefix-table.cpp b/tests/route/test-name-prefix-table.cpp
index 6181296..adeaa6d 100644
--- a/tests/route/test-name-prefix-table.cpp
+++ b/tests/route/test-name-prefix-table.cpp
@@ -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.
*
@@ -78,7 +78,6 @@
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));
@@ -88,7 +87,7 @@
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));
@@ -121,7 +120,7 @@
// 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));
@@ -350,7 +349,7 @@
// 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, {}, {});
diff --git a/tests/route/test-routing-table.cpp b/tests/route/test-routing-table.cpp
index a6ce36d..de91bea 100644
--- a/tests/route/test-routing-table.cpp
+++ b/tests/route/test-routing-table.cpp
@@ -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).
@@ -124,7 +124,7 @@
{
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);
@@ -147,7 +147,7 @@
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);
diff --git a/tests/test-lsdb.cpp b/tests/test-lsdb.cpp
index 0db16e6..323db04 100644
--- a/tests/test-lsdb.cpp
+++ b/tests/test-lsdb.cpp
@@ -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.
*
@@ -403,7 +403,7 @@
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, {}, {});
diff --git a/tests/test-nlsr.cpp b/tests/test-nlsr.cpp
index ed8ce66..adb321b 100644
--- a/tests/test-nlsr.cpp
+++ b/tests/test-nlsr.cpp
@@ -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.
*
@@ -344,7 +344,7 @@
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
@@ -353,7 +353,7 @@
AdjLsa failAdjLsa("/ndn/neighborA", 10,
ndn::time::system_clock::now() + ndn::time::seconds(3600),
- 1, failAdjacencies);
+ failAdjacencies);
lsdb.installLsa(std::make_shared<AdjLsa>(failAdjLsa));
@@ -363,7 +363,7 @@
AdjLsa otherAdjLsa("/ndn/neighborB", 10,
ndn::time::system_clock::now() + ndn::time::seconds(3600),
- 1, otherAdjacencies);
+ otherAdjacencies);
lsdb.installLsa(std::make_shared<AdjLsa>(otherAdjLsa));
diff --git a/tests/test-statistics.cpp b/tests/test-statistics.cpp
index 641d55b..887112a 100644
--- a/tests/test-statistics.cpp
+++ b/tests/test-statistics.cpp
@@ -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.
*
@@ -298,7 +298,7 @@
// adjacency lsa
ndn::Name adjInterest("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/ADJACENCY/");
adjInterest.appendNumber(seqNo);
- AdjLsa aLsa(routerName, seqNo, MAX_TIME, 1, conf.getAdjacencyList());
+ AdjLsa aLsa(routerName, seqNo, MAX_TIME, conf.getAdjacencyList());
lsdb.installLsa(std::make_shared<AdjLsa>(aLsa));
lsdb.afterFetchLsa(aLsa.wireEncode().getBuffer(), adjInterest);