blob: e30f9d7d34ec155abd2530552543f8bc2e481fcf [file] [log] [blame]
Junxiao Shic1e12362014-01-24 20:03:26 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology
9 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shic1e12362014-01-24 20:03:26 -070024
25#ifndef NFD_TABLE_FIB_ENTRY_HPP
26#define NFD_TABLE_FIB_ENTRY_HPP
27
28#include "fib-nexthop.hpp"
29
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080030namespace nfd {
Junxiao Shidbe71732014-02-21 22:23:28 -070031
Junxiao Shiefceadc2014-03-09 18:52:57 -070032class NameTree;
33namespace name_tree {
34class Entry;
35}
36
Junxiao Shic1e12362014-01-24 20:03:26 -070037namespace fib {
38
39/** \class NextHopList
40 * \brief represents a collection of nexthops
41 * This type has these methods:
42 * iterator<NextHop> begin()
43 * iterator<NextHop> end()
44 * size_t size()
45 */
46typedef std::vector<fib::NextHop> NextHopList;
47
48/** \class Entry
49 * \brief represents a FIB entry
50 */
Junxiao Shie349ea12014-03-12 01:32:42 -070051class Entry : noncopyable
Junxiao Shic1e12362014-01-24 20:03:26 -070052{
53public:
Junxiao Shi408a7002014-02-12 17:53:47 -070054 explicit
Junxiao Shic1e12362014-01-24 20:03:26 -070055 Entry(const Name& prefix);
Junxiao Shi7bb01512014-03-05 21:34:09 -070056
Junxiao Shic1e12362014-01-24 20:03:26 -070057 const Name&
58 getPrefix() const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070059
Junxiao Shic1e12362014-01-24 20:03:26 -070060 const NextHopList&
61 getNextHops() const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070062
Junxiao Shiefceadc2014-03-09 18:52:57 -070063 /// whether this Entry has any nexthop
64 bool
65 hasNextHops() const;
66
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070067 bool
68 hasNextHop(shared_ptr<Face> face) const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070069
Junxiao Shic1e12362014-01-24 20:03:26 -070070 /// adds a nexthop
71 void
Alexander Afanasyev11b9f3f2014-04-10 00:01:15 -070072 addNextHop(shared_ptr<Face> face, uint64_t cost);
Junxiao Shi7bb01512014-03-05 21:34:09 -070073
Junxiao Shic1e12362014-01-24 20:03:26 -070074 /// removes a nexthop
75 void
76 removeNextHop(shared_ptr<Face> face);
77
78private:
79 /// sorts the nexthop list
80 void
81 sortNextHops();
82
83private:
84 Name m_prefix;
85 NextHopList m_nextHops;
Junxiao Shiefceadc2014-03-09 18:52:57 -070086
87 shared_ptr<name_tree::Entry> m_nameTreeEntry;
88 friend class nfd::NameTree;
89 friend class nfd::name_tree::Entry;
Junxiao Shic1e12362014-01-24 20:03:26 -070090};
91
92
93inline const Name&
94Entry::getPrefix() const
95{
96 return m_prefix;
97}
98
99inline const NextHopList&
100Entry::getNextHops() const
101{
102 return m_nextHops;
103}
104
Junxiao Shiefceadc2014-03-09 18:52:57 -0700105inline bool
106Entry::hasNextHops() const
107{
108 return !m_nextHops.empty();
109}
110
Junxiao Shic1e12362014-01-24 20:03:26 -0700111} // namespace fib
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800112} // namespace nfd
Junxiao Shic1e12362014-01-24 20:03:26 -0700113
114#endif // NFD_TABLE_FIB_ENTRY_HPP