blob: 3bc9de5fae540bdf3bb4d083002d52380ced22b7 [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/*
Junxiao Shid6922b52024-01-14 19:50:34 +00003 * Copyright (c) 2014-2024, 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
Junxiao Shi4eb4eae2024-02-14 12:36:57 +000021#include "name-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"
Nick Gordon22b5c952017-08-10 17:48:15 -050026
akmhoque53353462014-04-22 08:43:45 -050027namespace nlsr {
28
akmhoque53353462014-04-22 08:43:45 -050029void
Junxiao Shi4eb4eae2024-02-14 12:36:57 +000030NameMap::addEntry(const ndn::Name& rtrName)
akmhoque53353462014-04-22 08:43:45 -050031{
Junxiao Shid6922b52024-01-14 19:50:34 +000032 int32_t mappingNo = static_cast<int32_t>(m_bimap.size());
33 m_bimap.by<ndn::Name>().insert({rtrName, mappingNo});
akmhoque53353462014-04-22 08:43:45 -050034}
35
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040036std::optional<ndn::Name>
Junxiao Shi4eb4eae2024-02-14 12:36:57 +000037NameMap::getRouterNameByMappingNo(int32_t mn) const
akmhoque53353462014-04-22 08:43:45 -050038{
Junxiao Shid6922b52024-01-14 19:50:34 +000039 auto it = m_bimap.by<MappingNo>().find(mn);
40 if (it == m_bimap.by<MappingNo>().end()) {
41 return std::nullopt;
42 }
43 return it->get<ndn::Name>();
akmhoque53353462014-04-22 08:43:45 -050044}
45
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040046std::optional<int32_t>
Junxiao Shi4eb4eae2024-02-14 12:36:57 +000047NameMap::getMappingNoByRouterName(const ndn::Name& rtrName) const
akmhoque53353462014-04-22 08:43:45 -050048{
Junxiao Shi4eb4eae2024-02-14 12:36:57 +000049 auto it = m_bimap.by<ndn::Name>().find(rtrName);
Junxiao Shid6922b52024-01-14 19:50:34 +000050 if (it == m_bimap.by<ndn::Name>().end()) {
51 return std::nullopt;
52 }
Junxiao Shi4eb4eae2024-02-14 12:36:57 +000053 return it->get<MappingNo>();
akmhoque53353462014-04-22 08:43:45 -050054}
55
Junxiao Shid6922b52024-01-14 19:50:34 +000056std::ostream&
Junxiao Shi4eb4eae2024-02-14 12:36:57 +000057operator<<(std::ostream& os, const NameMap& map)
akmhoque53353462014-04-22 08:43:45 -050058{
Junxiao Shi4eb4eae2024-02-14 12:36:57 +000059 os << "---------------NameMap---------------";
Junxiao Shid6922b52024-01-14 19:50:34 +000060 for (const auto& entry : map.m_bimap) {
61 os << "\nMapEntry: ( Router: " << entry.get<ndn::Name>()
Junxiao Shi4eb4eae2024-02-14 12:36:57 +000062 << " Mapping No: " << entry.get<NameMap::MappingNo>() << " )";
akmhoque53353462014-04-22 08:43:45 -050063 }
Junxiao Shid6922b52024-01-14 19:50:34 +000064 return os;
akmhoque53353462014-04-22 08:43:45 -050065}
66
Nick Gordonfad8e252016-08-11 14:21:38 -050067} // namespace nlsr