blob: d8a3bc1f65f47a0925cef508f37add5bb3199da0 [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
akmhoquefdbddb12014-05-02 18:35:19 -050022#ifndef NLSR_NAME_PREFIX_TABLE_HPP
23#define NLSR_NAME_PREFIX_TABLE_HPP
akmhoque53353462014-04-22 08:43:45 -050024
akmhoquec8a10f72014-04-25 18:42:55 -050025#include "name-prefix-table-entry.hpp"
akmhoque53353462014-04-22 08:43:45 -050026#include "routing-table-entry.hpp"
27
Vince Lehmancae33b62015-06-05 09:21:30 -050028#include <list>
29
akmhoque53353462014-04-22 08:43:45 -050030namespace nlsr {
31class Nlsr;
32
akmhoquec8a10f72014-04-25 18:42:55 -050033class NamePrefixTable
akmhoque53353462014-04-22 08:43:45 -050034{
35public:
Vince Lehmancae33b62015-06-05 09:21:30 -050036
37 typedef std::list<NamePrefixTableEntry> NptEntryList;
38 typedef NptEntryList::const_iterator const_iterator;
39
akmhoque31d1d4b2014-05-05 22:08:14 -050040 NamePrefixTable(Nlsr& nlsr)
41 : m_nlsr(nlsr)
akmhoque53353462014-04-22 08:43:45 -050042 {
43 }
akmhoque53353462014-04-22 08:43:45 -050044
Nick G97e34942016-07-11 14:46:27 -050045 /*! \brief Adds an entry to the NPT.
46 \param name The name prefix that is being advertised.
47 \param destRouter The destination router that is advertising the prefix.
48
49 Adds a destination router to the name prefix. If there isn't
50 currently an entry present for the prefix, one is made and
51 added. If there is no routing table entry available for the
52 destination router, a placeholder routing table entry without next
53 hops will be made. Since this function can be called when a
54 routing table entry has been updated to have no hops (i.e. is
55 unreachable), this function will check for the number of next hops
56 an entry has. If it is found to have no next hops, the NPT will
57 inform the FIB to remove that prefix.
58 */
akmhoque53353462014-04-22 08:43:45 -050059 void
akmhoque31d1d4b2014-05-05 22:08:14 -050060 addEntry(const ndn::Name& name, const ndn::Name& destRouter);
akmhoquefdbddb12014-05-02 18:35:19 -050061
62 void
akmhoque31d1d4b2014-05-05 22:08:14 -050063 removeEntry(const ndn::Name& name, const ndn::Name& destRouter);
akmhoque53353462014-04-22 08:43:45 -050064
65 void
akmhoque31d1d4b2014-05-05 22:08:14 -050066 updateWithNewRoute();
akmhoque53353462014-04-22 08:43:45 -050067
68 void
akmhoque674b0b12014-05-20 14:33:28 -050069 writeLog();
70
Vince Lehmancae33b62015-06-05 09:21:30 -050071 const_iterator
72 begin() const;
73
74 const_iterator
75 end() const;
76
akmhoque53353462014-04-22 08:43:45 -050077private:
Nick G97e34942016-07-11 14:46:27 -050078 /*! \brief Adds an entry to the NPT table.
79 \param name The name prefix to add to the table.
80 \param rte The routing table entry with the next hop information to
81 reach the prefix.
82 */
akmhoque53353462014-04-22 08:43:45 -050083 void
akmhoque31d1d4b2014-05-05 22:08:14 -050084 addEntry(const ndn::Name& name, RoutingTableEntry& rte);
akmhoque53353462014-04-22 08:43:45 -050085
86 void
akmhoque31d1d4b2014-05-05 22:08:14 -050087 removeEntry(const ndn::Name& name, RoutingTableEntry& rte);
akmhoque53353462014-04-22 08:43:45 -050088
89private:
akmhoque31d1d4b2014-05-05 22:08:14 -050090 Nlsr& m_nlsr;
akmhoquefdbddb12014-05-02 18:35:19 -050091 std::list<NamePrefixTableEntry> m_table;
akmhoque53353462014-04-22 08:43:45 -050092};
93
Vince Lehmancae33b62015-06-05 09:21:30 -050094inline NamePrefixTable::const_iterator
95NamePrefixTable::begin() const
96{
97 return m_table.begin();
98}
akmhoque53353462014-04-22 08:43:45 -050099
Vince Lehmancae33b62015-06-05 09:21:30 -0500100inline NamePrefixTable::const_iterator
101NamePrefixTable::end() const
102{
103 return m_table.end();
104}
105
106std::ostream&
107operator<<(std::ostream& os, const NamePrefixTable& table);
108
109} // namespace nlsr
110
111#endif // NLSR_NAME_PREFIX_TABLE_HPP