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 | |
| 14 | namespace fw { |
| 15 | class Strategy; |
| 16 | } |
| 17 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 18 | namespace fib { |
| 19 | |
| 20 | /** \class NextHopList |
| 21 | * \brief represents a collection of nexthops |
| 22 | * This type has these methods: |
| 23 | * iterator<NextHop> begin() |
| 24 | * iterator<NextHop> end() |
| 25 | * size_t size() |
| 26 | */ |
| 27 | typedef std::vector<fib::NextHop> NextHopList; |
| 28 | |
| 29 | /** \class Entry |
| 30 | * \brief represents a FIB entry |
| 31 | */ |
Junxiao Shi | 408a700 | 2014-02-12 17:53:47 -0700 | [diff] [blame] | 32 | class Entry : public StrategyInfoHost, noncopyable |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 33 | { |
| 34 | public: |
Junxiao Shi | 408a700 | 2014-02-12 17:53:47 -0700 | [diff] [blame] | 35 | explicit |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 36 | Entry(const Name& prefix); |
| 37 | |
| 38 | const Name& |
| 39 | getPrefix() const; |
| 40 | |
| 41 | /** \brief gives the nexthops explicitly defined on this entry |
| 42 | * This list does not include inherited nexthops. |
| 43 | */ |
| 44 | const NextHopList& |
| 45 | getNextHops() const; |
| 46 | |
| 47 | /// adds a nexthop |
| 48 | void |
| 49 | addNextHop(shared_ptr<Face> face, int32_t cost); |
| 50 | |
| 51 | /// removes a nexthop |
| 52 | void |
| 53 | removeNextHop(shared_ptr<Face> face); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 54 | |
| 55 | const fw::Strategy& |
| 56 | getStrategy() const; |
| 57 | |
| 58 | void |
| 59 | setStrategy(shared_ptr<fw::Strategy> strategy); |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 60 | |
| 61 | private: |
| 62 | /// sorts the nexthop list |
| 63 | void |
| 64 | sortNextHops(); |
| 65 | |
| 66 | private: |
| 67 | Name m_prefix; |
| 68 | NextHopList m_nextHops; |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 69 | shared_ptr<fw::Strategy> m_strategy; |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | |
| 73 | inline const Name& |
| 74 | Entry::getPrefix() const |
| 75 | { |
| 76 | return m_prefix; |
| 77 | } |
| 78 | |
| 79 | inline const NextHopList& |
| 80 | Entry::getNextHops() const |
| 81 | { |
| 82 | return m_nextHops; |
| 83 | } |
| 84 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 85 | inline const fw::Strategy& |
| 86 | Entry::getStrategy() const |
| 87 | { |
| 88 | BOOST_ASSERT(static_cast<bool>(m_strategy)); |
| 89 | return *m_strategy; |
| 90 | } |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 91 | |
| 92 | } // namespace fib |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 93 | } // namespace nfd |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 94 | |
| 95 | #endif // NFD_TABLE_FIB_ENTRY_HPP |