Skip to content

Commit 73a96d2

Browse files
committed
lsdb: recover lost LSA seqNo from network via sync
refs: #5386 Change-Id: I35167fa0ba4ab5821ccbb4b95e537a645de10799
1 parent 3592483 commit 73a96d2

10 files changed

Lines changed: 304 additions & 108 deletions

File tree

.mailmap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
A K M Mahmudul Hoque <akmhoque@gmail.com>
22
<aa@cs.fiu.edu> <alexander.afanasyev@ucla.edu>
3-
<agawande@memphis.edu> <ashu2493@gmail.com>
3+
Ashlesh Gawande <git@ashlesh.me> <ashu2493@gmail.com>
4+
Ashlesh Gawande <git@ashlesh.me> <agawande@memphis.edu>
45
Alexander Lane <awlane@memphis.edu>
56
<davidepesa@gmail.com> <davide.pesavento@lip6.fr>
67
<enewberry@email.arizona.edu> <enewberry@cs.arizona.edu>

src/communication/sync-logic-handler.cpp

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2014-2024, The University of Memphis,
3+
* Copyright (c) 2014-2026, The University of Memphis,
44
* Regents of the University of California,
55
* Arizona Board of Regents.
66
*
@@ -31,9 +31,8 @@ INIT_LOGGER(SyncLogicHandler);
3131
const std::string LSA_COMPONENT{"LSA"};
3232

3333
SyncLogicHandler::SyncLogicHandler(ndn::Face& face, ndn::KeyChain& keyChain,
34-
IsLsaNew isLsaNew, const SyncLogicOptions& opts)
35-
: m_isLsaNew(std::move(isLsaNew))
36-
, m_routerPrefix(opts.routerPrefix)
34+
const SyncLogicOptions& opts)
35+
: m_routerPrefix(opts.routerPrefix)
3736
, m_hyperbolicState(opts.hyperbolicState)
3837
, m_nameLsaUserPrefix(makeLsaUserPrefix(opts.userPrefix, Lsa::Type::NAME))
3938
, m_adjLsaUserPrefix(makeLsaUserPrefix(opts.userPrefix, Lsa::Type::ADJACENCY))
@@ -69,42 +68,7 @@ SyncLogicHandler::processUpdate(const ndn::Name& updateName, uint64_t highSeq, u
6968
ndn::Name originRouter = networkName;
7069
originRouter.append(routerName);
7170

72-
processUpdateFromSync(originRouter, updateName, highSeq, incomingFaceId);
73-
}
74-
75-
void
76-
SyncLogicHandler::processUpdateFromSync(const ndn::Name& originRouter,
77-
const ndn::Name& updateName, uint64_t seqNo,
78-
uint64_t incomingFaceId)
79-
{
80-
NLSR_LOG_DEBUG("Origin Router of update: " << originRouter);
81-
82-
if (originRouter == m_routerPrefix) {
83-
// A router should not try to fetch its own LSA
84-
return;
85-
}
86-
87-
auto lsaType = boost::lexical_cast<Lsa::Type>(updateName.get(-1).toUri());
88-
NLSR_LOG_DEBUG("Received sync update with higher " << lsaType <<
89-
" sequence number than entry in LSDB");
90-
91-
if (m_isLsaNew(originRouter, lsaType, seqNo, incomingFaceId)) {
92-
if (lsaType == Lsa::Type::ADJACENCY && seqNo != 0 &&
93-
m_hyperbolicState == HYPERBOLIC_STATE_ON) {
94-
NLSR_LOG_ERROR("Got an update for adjacency LSA when hyperbolic routing "
95-
"is enabled. Not going to fetch.");
96-
return;
97-
}
98-
99-
if (lsaType == Lsa::Type::COORDINATE && seqNo != 0 &&
100-
m_hyperbolicState == HYPERBOLIC_STATE_OFF) {
101-
NLSR_LOG_ERROR("Got an update for coordinate LSA when link-state "
102-
"is enabled. Not going to fetch.");
103-
return;
104-
}
105-
106-
onNewLsa(updateName, seqNo, originRouter, incomingFaceId);
107-
}
71+
onSyncUpdate(updateName, highSeq, originRouter, incomingFaceId);
10872
}
10973

11074
void

src/communication/sync-logic-handler.hpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2014-2024, The University of Memphis,
3+
* Copyright (c) 2014-2026, The University of Memphis,
44
* Regents of the University of California,
55
* Arizona Board of Regents.
66
*
@@ -62,12 +62,8 @@ class SyncLogicHandler
6262
using std::runtime_error::runtime_error;
6363
};
6464

65-
using IsLsaNew = std::function<
66-
bool (const ndn::Name& routerName, Lsa::Type lsaType, uint64_t seqNo, uint64_t inFace)
67-
>;
68-
6965
SyncLogicHandler(ndn::Face& face, ndn::KeyChain& keyChain,
70-
IsLsaNew isLsaNew, const SyncLogicOptions& opts);
66+
const SyncLogicOptions& opts);
7167

7268
/*! \brief Instruct ChronoSync to publish an update.
7369
*
@@ -91,23 +87,10 @@ class SyncLogicHandler
9187
void
9288
processUpdate(const ndn::Name& updateName, uint64_t highSeq, uint64_t incomingFaceId);
9389

94-
/*! \brief Determine which kind of LSA was updated and fetch it.
95-
*
96-
* Checks that the received update is not from us, which can happen,
97-
* and then inspects the update to determine which kind of LSA the
98-
* update is for. Finally, it expresses interest for the correct LSA
99-
* type.
100-
* \throws SyncUpdate::Error If the sync update doesn't look like a sync LSA update.
101-
*/
102-
void
103-
processUpdateFromSync(const ndn::Name& originRouter,
104-
const ndn::Name& updateName, uint64_t seqNo, uint64_t incomingFaceId);
105-
10690
public:
107-
OnNewLsa onNewLsa;
91+
OnSyncUpdate onSyncUpdate;
10892

10993
private:
110-
IsLsaNew m_isLsaNew;
11194
ndn::Name m_routerPrefix;
11295
HyperbolicState m_hyperbolicState;
11396

src/lsdb.cpp

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2014-2024, The University of Memphis,
3+
* Copyright (c) 2014-2026, The University of Memphis,
44
* Regents of the University of California,
55
* Arizona Board of Regents.
66
*
@@ -36,9 +36,6 @@ Lsdb::Lsdb(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
3636
, m_scheduler(face.getIoContext())
3737
, m_confParam(confParam)
3838
, m_sync(m_face, keyChain,
39-
[this] (const auto& routerName, Lsa::Type lsaType, uint64_t seqNo, uint64_t) {
40-
return isLsaNew(routerName, lsaType, seqNo);
41-
},
4239
SyncLogicOptions{
4340
confParam.getSyncProtocol(),
4441
confParam.getSyncPrefix(),
@@ -51,12 +48,10 @@ Lsdb::Lsdb(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
5148
, m_adjLsaBuildInterval(m_confParam.getAdjLsaBuildInterval())
5249
, m_thisRouterPrefix(m_confParam.getRouterPrefix())
5350
, m_sequencingManager(m_confParam.getStateFileDir(), m_confParam.getHyperbolicState())
54-
, m_onNewLsaConnection(m_sync.onNewLsa.connect(
51+
, m_onSyncUpdate(m_sync.onSyncUpdate.connect(
5552
[this] (const ndn::Name& updateName, uint64_t sequenceNumber,
5653
const ndn::Name& originRouter, uint64_t incomingFaceId) {
57-
ndn::Name lsaInterest{updateName};
58-
lsaInterest.appendNumber(sequenceNumber);
59-
expressInterest(lsaInterest, 0, incomingFaceId);
54+
processUpdateFromSync(updateName, sequenceNumber, originRouter, incomingFaceId);
6055
}))
6156
, m_segmenter(keyChain, m_confParam.getSigningInfo())
6257
, m_segmentFifo(100)
@@ -89,6 +84,63 @@ Lsdb::~Lsdb()
8984
}
9085
}
9186

87+
void
88+
Lsdb::processUpdateFromSync(const ndn::Name& updateName, uint64_t seqNo,
89+
const ndn::Name& originRouter, uint64_t incomingFaceId)
90+
{
91+
NLSR_LOG_DEBUG("Origin Router of update: " << originRouter << " seq: " << seqNo);
92+
auto lsaType = boost::lexical_cast<Lsa::Type>(updateName.get(-1).toUri());
93+
94+
if (originRouter == m_thisRouterPrefix) {
95+
NLSR_LOG_TRACE("Received sync update for own router");
96+
// Other routers might be telling us that they have higher sequence number
97+
// than what we started with because of our sequence file corruption
98+
// So we adapt that sequence number
99+
if (isLsaNew(originRouter, lsaType, seqNo)) {
100+
if (lsaType == Lsa::Type::NAME) {
101+
m_sequencingManager.setNameLsaSeq(seqNo);
102+
buildAndInstallOwnNameLsa();
103+
}
104+
if (lsaType == Lsa::Type::ADJACENCY &&
105+
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
106+
m_sequencingManager.setAdjLsaSeq(seqNo);
107+
buildAndInstallOwnAdjLsa();
108+
}
109+
if (lsaType == Lsa::Type::COORDINATE &&
110+
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
111+
m_sequencingManager.setCorLsaSeq(seqNo);
112+
buildAndInstallOwnCoordinateLsa();
113+
}
114+
}
115+
// A router should not try to fetch its own LSA
116+
return;
117+
}
118+
119+
NLSR_LOG_DEBUG("Received sync update with higher " << lsaType << " sequence number than entry in LSDB");
120+
121+
if (isLsaNew(originRouter, lsaType, seqNo)) {
122+
if (lsaType == Lsa::Type::ADJACENCY && seqNo != 0 &&
123+
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
124+
NLSR_LOG_ERROR("Got an update for adjacency LSA when hyperbolic routing "
125+
"is enabled. Not going to fetch.");
126+
return;
127+
}
128+
129+
if (lsaType == Lsa::Type::COORDINATE && seqNo != 0 &&
130+
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
131+
NLSR_LOG_ERROR("Got an update for coordinate LSA when link-state "
132+
"is enabled. Not going to fetch.");
133+
return;
134+
}
135+
136+
onNewLsa(updateName, seqNo, originRouter, incomingFaceId);
137+
138+
ndn::Name lsaInterest{updateName};
139+
lsaInterest.appendNumber(seqNo);
140+
expressInterest(lsaInterest, 0, incomingFaceId);
141+
}
142+
}
143+
92144
void
93145
Lsdb::buildAndInstallOwnNameLsa()
94146
{

src/lsdb.hpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2014-2025, The University of Memphis,
3+
* Copyright (c) 2014-2026, The University of Memphis,
44
* Regents of the University of California,
55
* Arizona Board of Regents.
66
*
@@ -29,6 +29,7 @@
2929
#include "lsa/coordinate-lsa.hpp"
3030
#include "lsa/adj-lsa.hpp"
3131
#include "sequencing-manager.hpp"
32+
#include "signals.hpp"
3233
#include "statistics.hpp"
3334
#include "test-access-control.hpp"
3435

@@ -82,6 +83,21 @@ class Lsdb
8283
void
8384
buildAndInstallOwnCoordinateLsa();
8485

86+
/*! \brief Determine which kind of LSA was updated and fetch it.
87+
*
88+
* If the received update is for our own router then the network
89+
* is telling us that we are recovering from a sequence file corruption.
90+
* So we use the sequence number provided in this update as a base
91+
* and publish a new update.
92+
*
93+
* Otherwise if the update is for another router we inspect the update to determine
94+
* which kind of LSA the update is for and expresses interest for the correct LSA
95+
* type.
96+
*/
97+
void
98+
processUpdateFromSync(const ndn::Name& updateName, uint64_t seqNo,
99+
const ndn::Name& originRouter, uint64_t incomingFaceId);
100+
85101
public:
86102
/*! \brief Schedules a build of this router's LSA. */
87103
void
@@ -337,6 +353,7 @@ class Lsdb
337353
using AfterLsdbModified = ndn::signal::Signal<Lsdb, std::shared_ptr<Lsa>, LsdbUpdate,
338354
std::list<nlsr::PrefixInfo>, std::list<nlsr::PrefixInfo>>;
339355
AfterLsdbModified onLsdbModified;
356+
OnLsaUpdate onNewLsa;
340357

341358
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
342359
ndn::Face& m_face;
@@ -357,7 +374,7 @@ class Lsdb
357374

358375
SequencingManager m_sequencingManager;
359376

360-
ndn::signal::ScopedConnection m_onNewLsaConnection;
377+
ndn::signal::ScopedConnection m_onSyncUpdate;
361378

362379
std::set<std::shared_ptr<ndn::SegmentFetcher>> m_fetchers;
363380
ndn::Segmenter m_segmenter;

src/nlsr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2014-2025, The University of Memphis,
3+
* Copyright (c) 2014-2026, The University of Memphis,
44
* Regents of the University of California,
55
* Arizona Board of Regents.
66
*
@@ -47,7 +47,7 @@ Nlsr::Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
4747
, m_namePrefixTable(confParam.getRouterPrefix(), m_fib, m_routingTable,
4848
m_routingTable.afterRoutingChange, m_lsdb.onLsdbModified)
4949
, m_helloProtocol(m_face, keyChain, confParam, m_routingTable, m_lsdb)
50-
, m_onNewLsaConnection(m_lsdb.getSync().onNewLsa.connect(
50+
, m_onNewLsaConnection(m_lsdb.onNewLsa.connect(
5151
[this] (const ndn::Name& updateName, uint64_t sequenceNumber,
5252
const ndn::Name& originRouter, uint64_t incomingFaceId) {
5353
registerStrategyForCerts(originRouter);

src/signals.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2014-2023, The University of Memphis,
3+
* Copyright (c) 2014-2026, The University of Memphis,
44
* Regents of the University of California,
55
* Arizona Board of Regents.
66
*
@@ -31,9 +31,11 @@ namespace nlsr {
3131
class RoutingTable;
3232
class RoutingTableEntry;
3333
class SyncLogicHandler;
34+
class Lsdb;
3435

3536
using AfterRoutingChange = ndn::signal::Signal<RoutingTable, std::list<RoutingTableEntry>>;
36-
using OnNewLsa = ndn::signal::Signal<SyncLogicHandler, ndn::Name, uint64_t, ndn::Name, uint64_t>;
37+
using OnSyncUpdate = ndn::signal::Signal<SyncLogicHandler, ndn::Name, uint64_t, ndn::Name, uint64_t>;
38+
using OnLsaUpdate = ndn::signal::Signal<Lsdb, ndn::Name, uint64_t, ndn::Name, uint64_t>;
3739

3840
} // namespace nlsr
3941

0 commit comments

Comments
 (0)