blob: 12367779a63386803c095eb60132eda0c7478d36 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Muktadir R Chowdhury800833b2016-07-29 13:43:59 -05003 * Copyright (c) 2014-2016, The University of Memphis,
Vince Lehmancae33b62015-06-05 09:21:30 -05004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
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/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehmancae33b62015-06-05 09:21:30 -050021
22#include "name-prefix-table-entry.hpp"
Vince Lehman0a7da612014-10-29 14:39:29 -050023
24#include "common.hpp"
akmhoque53353462014-04-22 08:43:45 -050025#include "nexthop.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050026#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -050027
28namespace nlsr {
29
akmhoque674b0b12014-05-20 14:33:28 -050030INIT_LOGGER("NamePrefixTableEntry");
31
akmhoque53353462014-04-22 08:43:45 -050032void
akmhoquec8a10f72014-04-25 18:42:55 -050033NamePrefixTableEntry::generateNhlfromRteList()
akmhoque53353462014-04-22 08:43:45 -050034{
akmhoquefdbddb12014-05-02 18:35:19 -050035 m_nexthopList.reset();
akmhoque53353462014-04-22 08:43:45 -050036 for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin();
37 it != m_rteList.end(); ++it)
38 {
39 for (std::list<NextHop>::iterator nhit =
akmhoquefdbddb12014-05-02 18:35:19 -050040 (*it).getNexthopList().getNextHops().begin();
41 nhit != (*it).getNexthopList().getNextHops().end(); ++nhit)
akmhoque53353462014-04-22 08:43:45 -050042 {
akmhoquefdbddb12014-05-02 18:35:19 -050043 m_nexthopList.addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -050044 }
45 }
46}
47
48
49
50static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050051rteCompare(RoutingTableEntry& rte, ndn::Name& destRouter)
akmhoque53353462014-04-22 08:43:45 -050052{
53 return rte.getDestination() == destRouter;
54}
55
56void
akmhoquec8a10f72014-04-25 18:42:55 -050057NamePrefixTableEntry::removeRoutingTableEntry(RoutingTableEntry& rte)
akmhoque53353462014-04-22 08:43:45 -050058{
59 std::list<RoutingTableEntry>::iterator it = std::find_if(m_rteList.begin(),
60 m_rteList.end(),
61 bind(&rteCompare, _1, rte.getDestination()));
62 if (it != m_rteList.end())
63 {
64 m_rteList.erase(it);
65 }
66}
67
68void
akmhoquec8a10f72014-04-25 18:42:55 -050069NamePrefixTableEntry::addRoutingTableEntry(RoutingTableEntry& rte)
akmhoque53353462014-04-22 08:43:45 -050070{
71 std::list<RoutingTableEntry>::iterator it = std::find_if(m_rteList.begin(),
72 m_rteList.end(),
73 bind(&rteCompare, _1, rte.getDestination()));
74 if (it == m_rteList.end())
75 {
76 m_rteList.push_back(rte);
77 }
78 else
79 {
akmhoquefdbddb12014-05-02 18:35:19 -050080 (*it).getNexthopList().reset(); // reseting existing routing table's next hop
akmhoque31d1d4b2014-05-05 22:08:14 -050081 for (std::list<NextHop>::iterator nhit =
82 rte.getNexthopList().getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -050083 nhit != rte.getNexthopList().getNextHops().end(); ++nhit) {
akmhoquefdbddb12014-05-02 18:35:19 -050084 (*it).getNexthopList().addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -050085 }
86 }
87}
88
akmhoque674b0b12014-05-20 14:33:28 -050089void
90NamePrefixTableEntry::writeLog()
91{
92 _LOG_DEBUG("Name: " << m_namePrefix);
93 for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin();
94 it != m_rteList.end(); ++it) {
95 _LOG_DEBUG("Destination: " << (*it).getDestination());
96 _LOG_DEBUG("Nexthops: ");
97 (*it).getNexthopList().writeLog();
98 }
99 m_nexthopList.writeLog();
100}
101
Vince Lehmancae33b62015-06-05 09:21:30 -0500102std::ostream&
103operator<<(std::ostream& os, const NamePrefixTableEntry& entry)
104{
105 os << "Name: " << entry.getNamePrefix() << "\n";
106
107 for (const RoutingTableEntry& rte : entry.getRteList()) {
108 os << "Destination: " << rte.getDestination() << "\n";
109 }
110
111 return os;
112}
113
114} // namespace nlsr