NLSR 24.08-21-g73a96d2c
Loading...
Searching...
No Matches
sync-logic-handler.cpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2026, The University of Memphis,
4 * 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
23#include "hello-protocol.hpp"
24#include "logger.hpp"
26
27namespace nlsr {
28
29INIT_LOGGER(SyncLogicHandler);
30
31const std::string LSA_COMPONENT{"LSA"};
32
33SyncLogicHandler::SyncLogicHandler(ndn::Face& face, ndn::KeyChain& keyChain,
34 const SyncLogicOptions& opts)
35 : m_routerPrefix(opts.routerPrefix)
36 , m_hyperbolicState(opts.hyperbolicState)
37 , m_nameLsaUserPrefix(makeLsaUserPrefix(opts.userPrefix, Lsa::Type::NAME))
38 , m_adjLsaUserPrefix(makeLsaUserPrefix(opts.userPrefix, Lsa::Type::ADJACENCY))
39 , m_coorLsaUserPrefix(makeLsaUserPrefix(opts.userPrefix, Lsa::Type::COORDINATE))
40 , m_syncLogic(face, keyChain, opts.syncProtocol, opts.syncPrefix,
41 m_nameLsaUserPrefix, opts.syncInterestLifetime,
42 std::bind(&SyncLogicHandler::processUpdate, this, _1, _2, _3))
43{
44 if (m_hyperbolicState != HYPERBOLIC_STATE_ON) {
45 m_syncLogic.addUserNode(m_adjLsaUserPrefix);
46 }
47
48 if (m_hyperbolicState != HYPERBOLIC_STATE_OFF) {
49 m_syncLogic.addUserNode(m_coorLsaUserPrefix);
50 }
51}
52
53void
54SyncLogicHandler::processUpdate(const ndn::Name& updateName, uint64_t highSeq, uint64_t incomingFaceId)
55{
56 NLSR_LOG_DEBUG("Update Name: " << updateName << " Seq no: " << highSeq);
57
58 int32_t nlsrPosition = util::getNameComponentPosition(updateName, HelloProtocol::NLSR_COMPONENT);
59 int32_t lsaPosition = util::getNameComponentPosition(updateName, LSA_COMPONENT);
60
61 if (nlsrPosition < 0 || lsaPosition < 0) {
62 NLSR_LOG_WARN("Received malformed sync update");
63 return;
64 }
65
66 ndn::Name networkName = updateName.getSubName(1, nlsrPosition - 1);
67 ndn::Name routerName = updateName.getSubName(lsaPosition + 1).getPrefix(-1);
68 ndn::Name originRouter = networkName;
69 originRouter.append(routerName);
70
71 onSyncUpdate(updateName, highSeq, originRouter, incomingFaceId);
72}
73
74void
76{
77 switch (type) {
79 m_syncLogic.publishUpdate(m_adjLsaUserPrefix, seqNo);
80 break;
82 m_syncLogic.publishUpdate(m_coorLsaUserPrefix, seqNo);
83 break;
84 case Lsa::Type::NAME:
85 m_syncLogic.publishUpdate(m_nameLsaUserPrefix, seqNo);
86 break;
87 default:
88 break;
89 }
90}
91
92} // namespace nlsr
static const std::string NLSR_COMPONENT
Represents a Link State Announcement (LSA).
Definition lsa.hpp:48
NLSR-to-sync interaction point.
SyncLogicHandler(ndn::Face &face, ndn::KeyChain &keyChain, const SyncLogicOptions &opts)
void publishRoutingUpdate(Lsa::Type type, uint64_t seqNo)
Instruct ChronoSync to publish an update.
void publishUpdate(const ndn::Name &userPrefix, uint64_t seq)
Publish update to Sync.
void addUserNode(const ndn::Name &userPrefix)
Add user node to Sync.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define NLSR_LOG_DEBUG(x)
Definition logger.hpp:38
#define INIT_LOGGER(name)
Definition logger.hpp:35
#define NLSR_LOG_WARN(x)
Definition logger.hpp:40
int32_t getNameComponentPosition(const ndn::Name &name, const std::string &searchString)
search a name component in ndn::Name and return the position of the component
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
const std::string LSA_COMPONENT
ndn::Name makeLsaUserPrefix(const ndn::Name &userPrefix, Lsa::Type lsaType)
@ HYPERBOLIC_STATE_ON
@ HYPERBOLIC_STATE_OFF