akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 2 | /* |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2024, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 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/>. |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 20 | */ |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 21 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 22 | #include "sync-logic-handler.hpp" |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 23 | #include "hello-protocol.hpp" |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 24 | #include "logger.hpp" |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 25 | #include "utility/name-helper.hpp" |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 26 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 27 | namespace nlsr { |
| 28 | |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 29 | INIT_LOGGER(SyncLogicHandler); |
| 30 | |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 31 | const std::string LSA_COMPONENT{"LSA"}; |
| 32 | |
| 33 | SyncLogicHandler::SyncLogicHandler(ndn::Face& face, ndn::KeyChain& keyChain, |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame^] | 34 | IsLsaNew isLsaNew, const SyncLogicOptions& opts) |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 35 | : m_isLsaNew(std::move(isLsaNew)) |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame^] | 36 | , m_routerPrefix(opts.routerPrefix) |
| 37 | , m_hyperbolicState(opts.hyperbolicState) |
| 38 | , m_nameLsaUserPrefix(makeLsaUserPrefix(opts.userPrefix, Lsa::Type::NAME)) |
| 39 | , m_adjLsaUserPrefix(makeLsaUserPrefix(opts.userPrefix, Lsa::Type::ADJACENCY)) |
| 40 | , m_coorLsaUserPrefix(makeLsaUserPrefix(opts.userPrefix, Lsa::Type::COORDINATE)) |
| 41 | , m_syncLogic(face, keyChain, opts.syncProtocol, opts.syncPrefix, |
| 42 | m_nameLsaUserPrefix, opts.syncInterestLifetime, |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 43 | std::bind(&SyncLogicHandler::processUpdate, this, _1, _2, _3)) |
Vince Lehman | 0bcf9a3 | 2014-12-10 11:24:45 -0600 | [diff] [blame] | 44 | { |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame^] | 45 | if (m_hyperbolicState != HYPERBOLIC_STATE_ON) { |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 46 | m_syncLogic.addUserNode(m_adjLsaUserPrefix); |
Vince Lehman | 9d09780 | 2015-03-16 17:55:59 -0500 | [diff] [blame] | 47 | } |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 48 | |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame^] | 49 | if (m_hyperbolicState != HYPERBOLIC_STATE_OFF) { |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 50 | m_syncLogic.addUserNode(m_coorLsaUserPrefix); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 51 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 55 | SyncLogicHandler::processUpdate(const ndn::Name& updateName, uint64_t highSeq, uint64_t incomingFaceId) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 56 | { |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 57 | NLSR_LOG_DEBUG("Update Name: " << updateName << " Seq no: " << highSeq); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 58 | |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 59 | int32_t nlsrPosition = util::getNameComponentPosition(updateName, HelloProtocol::NLSR_COMPONENT); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 60 | int32_t lsaPosition = util::getNameComponentPosition(updateName, LSA_COMPONENT); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 61 | |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 62 | if (nlsrPosition < 0 || lsaPosition < 0) { |
| 63 | NLSR_LOG_WARN("Received malformed sync update"); |
| 64 | return; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 65 | } |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 66 | |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 67 | ndn::Name networkName = updateName.getSubName(1, nlsrPosition - 1); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 68 | ndn::Name routerName = updateName.getSubName(lsaPosition + 1).getPrefix(-1); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 69 | ndn::Name originRouter = networkName; |
| 70 | originRouter.append(routerName); |
| 71 | |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 72 | processUpdateFromSync(originRouter, updateName, highSeq, incomingFaceId); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 76 | SyncLogicHandler::processUpdateFromSync(const ndn::Name& originRouter, |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 77 | const ndn::Name& updateName, uint64_t seqNo, |
| 78 | uint64_t incomingFaceId) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 79 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 80 | NLSR_LOG_DEBUG("Origin Router of update: " << originRouter); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 81 | |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame^] | 82 | if (originRouter == m_routerPrefix) { |
| 83 | // A router should not try to fetch its own LSA |
| 84 | return; |
| 85 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 86 | |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame^] | 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"); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 90 | |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame^] | 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; |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 97 | } |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame^] | 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); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 110 | void |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame^] | 111 | SyncLogicHandler::publishRoutingUpdate(Lsa::Type type, uint64_t seqNo) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 112 | { |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 113 | switch (type) { |
| 114 | case Lsa::Type::ADJACENCY: |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 115 | m_syncLogic.publishUpdate(m_adjLsaUserPrefix, seqNo); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 116 | break; |
| 117 | case Lsa::Type::COORDINATE: |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 118 | m_syncLogic.publishUpdate(m_coorLsaUserPrefix, seqNo); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 119 | break; |
| 120 | case Lsa::Type::NAME: |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 121 | m_syncLogic.publishUpdate(m_nameLsaUserPrefix, seqNo); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 122 | break; |
| 123 | default: |
| 124 | break; |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 125 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 126 | } |
| 127 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 128 | } // namespace nlsr |