Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 12 | namespace nfd { |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 13 | |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 14 | class NameTree; |
| 15 | namespace name_tree { |
| 16 | class Entry; |
| 17 | } |
| 18 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 19 | namespace 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 | */ |
| 28 | typedef std::vector<fib::NextHop> NextHopList; |
| 29 | |
| 30 | /** \class Entry |
| 31 | * \brief represents a FIB entry |
| 32 | */ |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 33 | class Entry : noncopyable |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 34 | { |
| 35 | public: |
Junxiao Shi | 408a700 | 2014-02-12 17:53:47 -0700 | [diff] [blame] | 36 | explicit |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 37 | Entry(const Name& prefix); |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 38 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 39 | const Name& |
| 40 | getPrefix() const; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 41 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 42 | const NextHopList& |
| 43 | getNextHops() const; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 44 | |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 45 | /// whether this Entry has any nexthop |
| 46 | bool |
| 47 | hasNextHops() const; |
| 48 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 49 | bool |
| 50 | hasNextHop(shared_ptr<Face> face) const; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 51 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 52 | /// adds a nexthop |
| 53 | void |
| 54 | addNextHop(shared_ptr<Face> face, int32_t cost); |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 55 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 56 | /// removes a nexthop |
| 57 | void |
| 58 | removeNextHop(shared_ptr<Face> face); |
| 59 | |
| 60 | private: |
| 61 | /// sorts the nexthop list |
| 62 | void |
| 63 | sortNextHops(); |
| 64 | |
| 65 | private: |
| 66 | Name m_prefix; |
| 67 | NextHopList m_nextHops; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 68 | |
| 69 | shared_ptr<name_tree::Entry> m_nameTreeEntry; |
| 70 | friend class nfd::NameTree; |
| 71 | friend class nfd::name_tree::Entry; |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | |
| 75 | inline const Name& |
| 76 | Entry::getPrefix() const |
| 77 | { |
| 78 | return m_prefix; |
| 79 | } |
| 80 | |
| 81 | inline const NextHopList& |
| 82 | Entry::getNextHops() const |
| 83 | { |
| 84 | return m_nextHops; |
| 85 | } |
| 86 | |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 87 | inline bool |
| 88 | Entry::hasNextHops() const |
| 89 | { |
| 90 | return !m_nextHops.empty(); |
| 91 | } |
| 92 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 93 | } // namespace fib |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 94 | } // namespace nfd |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 95 | |
| 96 | #endif // NFD_TABLE_FIB_ENTRY_HPP |