blob: 48b09d616b7dcdc321551122bb0a6dfe62825850 [file] [log] [blame]
Junxiao Shic1e12362014-01-24 20:03:26 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NFD_TABLE_FIB_ENTRY_HPP
8#define NFD_TABLE_FIB_ENTRY_HPP
9
10#include "fib-nexthop.hpp"
11
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080012namespace nfd {
Junxiao Shidbe71732014-02-21 22:23:28 -070013
Junxiao Shiefceadc2014-03-09 18:52:57 -070014class NameTree;
15namespace name_tree {
16class Entry;
17}
18
Junxiao Shic1e12362014-01-24 20:03:26 -070019namespace fib {
20
21/** \class NextHopList
22 * \brief represents a collection of nexthops
23 * This type has these methods:
24 * iterator<NextHop> begin()
25 * iterator<NextHop> end()
26 * size_t size()
27 */
28typedef std::vector<fib::NextHop> NextHopList;
29
30/** \class Entry
31 * \brief represents a FIB entry
32 */
Junxiao Shi408a7002014-02-12 17:53:47 -070033class Entry : public StrategyInfoHost, noncopyable
Junxiao Shic1e12362014-01-24 20:03:26 -070034{
35public:
Junxiao Shi408a7002014-02-12 17:53:47 -070036 explicit
Junxiao Shic1e12362014-01-24 20:03:26 -070037 Entry(const Name& prefix);
Junxiao Shi7bb01512014-03-05 21:34:09 -070038
Junxiao Shic1e12362014-01-24 20:03:26 -070039 const Name&
40 getPrefix() const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070041
Junxiao Shic1e12362014-01-24 20:03:26 -070042 const NextHopList&
43 getNextHops() const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070044
Junxiao Shiefceadc2014-03-09 18:52:57 -070045 /// whether this Entry has any nexthop
46 bool
47 hasNextHops() const;
48
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070049 bool
50 hasNextHop(shared_ptr<Face> face) const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070051
Junxiao Shic1e12362014-01-24 20:03:26 -070052 /// adds a nexthop
53 void
54 addNextHop(shared_ptr<Face> face, int32_t cost);
Junxiao Shi7bb01512014-03-05 21:34:09 -070055
Junxiao Shic1e12362014-01-24 20:03:26 -070056 /// removes a nexthop
57 void
58 removeNextHop(shared_ptr<Face> face);
59
60private:
61 /// sorts the nexthop list
62 void
63 sortNextHops();
64
65private:
66 Name m_prefix;
67 NextHopList m_nextHops;
Junxiao Shiefceadc2014-03-09 18:52:57 -070068
69 shared_ptr<name_tree::Entry> m_nameTreeEntry;
70 friend class nfd::NameTree;
71 friend class nfd::name_tree::Entry;
Junxiao Shic1e12362014-01-24 20:03:26 -070072};
73
74
75inline const Name&
76Entry::getPrefix() const
77{
78 return m_prefix;
79}
80
81inline const NextHopList&
82Entry::getNextHops() const
83{
84 return m_nextHops;
85}
86
Junxiao Shiefceadc2014-03-09 18:52:57 -070087inline bool
88Entry::hasNextHops() const
89{
90 return !m_nextHops.empty();
91}
92
Junxiao Shic1e12362014-01-24 20:03:26 -070093} // namespace fib
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080094} // namespace nfd
Junxiao Shic1e12362014-01-24 20:03:26 -070095
96#endif // NFD_TABLE_FIB_ENTRY_HPP