blob: 0aab84f5fec5356f23ad436308950552f9d1323a [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande0421bc62020-05-08 20:42:19 -07002/*
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/>.
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070019 */
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{
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070035 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>();
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070051 auto it = mappingNumberView.find(mn);
52 return it == mappingNumberView.end() ? ndn::nullopt : ndn::optional<ndn::Name>(it->router);
akmhoque53353462014-04-22 08:43:45 -050053}
54
Nick Gordone40377d2017-08-11 15:10:02 -050055ndn::optional<int32_t>
akmhoque31d1d4b2014-05-05 22:08:14 -050056Map::getMappingNoByRouterName(const ndn::Name& rName)
akmhoque53353462014-04-22 08:43:45 -050057{
Nick Gordone40377d2017-08-11 15:10:02 -050058 auto&& routerNameView = m_entries.get<detail::byRouterName>();
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070059 auto it = routerNameView.find(rName);
60 return it == routerNameView.end() ? ndn::nullopt : ndn::optional<int32_t>(it->mappingNumber);
akmhoque53353462014-04-22 08:43:45 -050061}
62
akmhoque2f423352014-06-03 11:49:35 -050063void
64Map::writeLog()
akmhoque53353462014-04-22 08:43:45 -050065{
dmcoomes5bcb39e2017-10-31 15:07:55 -050066 NLSR_LOG_DEBUG("---------------Map----------------------");
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070067 for (const auto& entry : m_entries.get<detail::byRouterName>()) {
68 NLSR_LOG_DEBUG("MapEntry: ( Router: " << entry.router << " Mapping No: " <<
69 entry.mappingNumber << " )");
akmhoque53353462014-04-22 08:43:45 -050070 }
akmhoque53353462014-04-22 08:43:45 -050071}
72
Nick Gordonfad8e252016-08-11 14:21:38 -050073} // namespace nlsr