blob: 3f6513c53d853f8d6a6205b7b11bdf62baaadc87 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08003 * Copyright (c) 2014-2020, The University of Memphis,
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05004 * Regents of the University of California
akmhoque3d06e792014-05-27 16:23:20 -05005 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
akmhoque3d06e792014-05-27 16:23:20 -050019 **/
akmhoque53353462014-04-22 08:43:45 -050020
Nick Gordon22b5c952017-08-10 17:48:15 -050021#include "map.hpp"
akmhoque53353462014-04-22 08:43:45 -050022#include "nlsr.hpp"
23#include "adjacent.hpp"
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080024#include "lsa/lsa.hpp"
akmhoque53353462014-04-22 08:43:45 -050025#include "lsdb.hpp"
akmhoque2f423352014-06-03 11:49:35 -050026#include "logger.hpp"
Nick Gordon22b5c952017-08-10 17:48:15 -050027
akmhoque53353462014-04-22 08:43:45 -050028namespace nlsr {
29
dmcoomescf8d0ed2017-02-21 11:39:01 -060030INIT_LOGGER(route.Map);
akmhoque2f423352014-06-03 11:49:35 -050031
akmhoque53353462014-04-22 08:43:45 -050032void
akmhoque31d1d4b2014-05-05 22:08:14 -050033Map::addEntry(const ndn::Name& rtrName)
akmhoque53353462014-04-22 08:43:45 -050034{
35 MapEntry me(rtrName, m_mappingIndex);
akmhoque157b0a42014-05-13 00:26:37 -050036 if (addEntry(me)) {
akmhoque53353462014-04-22 08:43:45 -050037 m_mappingIndex++;
38 }
39}
40
41bool
akmhoquefdbddb12014-05-02 18:35:19 -050042Map::addEntry(MapEntry& mpe)
akmhoque53353462014-04-22 08:43:45 -050043{
Nick Gordone40377d2017-08-11 15:10:02 -050044 return m_entries.insert(mpe).second;
akmhoque53353462014-04-22 08:43:45 -050045}
46
Nick Gordone40377d2017-08-11 15:10:02 -050047ndn::optional<ndn::Name>
Saurab Dulal9da6aa72018-01-12 17:25:51 +000048Map::getRouterNameByMappingNo(int32_t mn) const
akmhoque53353462014-04-22 08:43:45 -050049{
Nick Gordone40377d2017-08-11 15:10:02 -050050 auto&& mappingNumberView = m_entries.get<detail::byMappingNumber>();
51 auto iterator = mappingNumberView.find(mn);
52 if (iterator == mappingNumberView.end()) {
53 return {};
akmhoque53353462014-04-22 08:43:45 -050054 }
Nick Gordone40377d2017-08-11 15:10:02 -050055 else {
56 return {iterator->getRouter()};
57 }
akmhoque53353462014-04-22 08:43:45 -050058}
59
Nick Gordone40377d2017-08-11 15:10:02 -050060ndn::optional<int32_t>
akmhoque31d1d4b2014-05-05 22:08:14 -050061Map::getMappingNoByRouterName(const ndn::Name& rName)
akmhoque53353462014-04-22 08:43:45 -050062{
Nick Gordone40377d2017-08-11 15:10:02 -050063 auto&& routerNameView = m_entries.get<detail::byRouterName>();
64 auto iterator = routerNameView.find(rName);
65 if (iterator == routerNameView.end()) {
66 return {};
akmhoque53353462014-04-22 08:43:45 -050067 }
Nick Gordone40377d2017-08-11 15:10:02 -050068 else {
69 return {iterator->getMappingNumber()};
70 }
akmhoque53353462014-04-22 08:43:45 -050071}
72
73void
akmhoque53353462014-04-22 08:43:45 -050074Map::reset()
75{
Nick Gordone40377d2017-08-11 15:10:02 -050076 m_entries = detail::entryContainer{};
akmhoque53353462014-04-22 08:43:45 -050077 m_mappingIndex = 0;
78}
79
akmhoque2f423352014-06-03 11:49:35 -050080void
81Map::writeLog()
akmhoque53353462014-04-22 08:43:45 -050082{
dmcoomes5bcb39e2017-10-31 15:07:55 -050083 NLSR_LOG_DEBUG("---------------Map----------------------");
Nick Gordone40377d2017-08-11 15:10:02 -050084 auto&& routerNameView = m_entries.get<detail::byRouterName>();
85 for (auto entry = routerNameView.begin(); entry != routerNameView.end(); entry++) {
dmcoomes5bcb39e2017-10-31 15:07:55 -050086 NLSR_LOG_DEBUG("MapEntry: ( Router: " << entry->getRouter() << " Mapping No: "
Nick Gordone40377d2017-08-11 15:10:02 -050087 << entry->getMappingNumber() << " )");
akmhoque53353462014-04-22 08:43:45 -050088 }
akmhoque53353462014-04-22 08:43:45 -050089}
90
Nick Gordonfad8e252016-08-11 14:21:38 -050091} // namespace nlsr