Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * 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 | * The University of Memphis |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | **/ |
| 25 | |
| 26 | #ifndef NFD_RIB_RIB_HPP |
| 27 | #define NFD_RIB_RIB_HPP |
| 28 | |
| 29 | #include "common.hpp" |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 30 | #include <ndn-cxx/management/nfd-control-command.hpp> |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | namespace rib { |
| 34 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 35 | class RibEntry |
| 36 | { |
| 37 | public: |
| 38 | RibEntry() |
| 39 | : faceId(0) |
| 40 | , origin(0) |
| 41 | , flags(0) |
| 42 | , cost(0) |
| 43 | , expires(time::steady_clock::TimePoint::min()) |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | public: |
| 48 | Name name; |
| 49 | uint64_t faceId; |
| 50 | uint64_t origin; |
| 51 | uint64_t flags; |
| 52 | uint64_t cost; |
| 53 | time::steady_clock::TimePoint expires; |
| 54 | }; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 55 | |
| 56 | /** \brief represents the RIB |
| 57 | */ |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 58 | class Rib : noncopyable |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 59 | { |
| 60 | public: |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 61 | typedef std::list<RibEntry> RibTable; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 62 | typedef RibTable::const_iterator const_iterator; |
| 63 | |
| 64 | Rib(); |
| 65 | |
| 66 | ~Rib(); |
| 67 | |
| 68 | const_iterator |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 69 | find(const RibEntry& entry) const; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 70 | |
| 71 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 72 | insert(const RibEntry& entry); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 73 | |
| 74 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 75 | erase(const RibEntry& entry); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 76 | |
| 77 | void |
| 78 | erase(uint64_t faceId); |
| 79 | |
| 80 | const_iterator |
| 81 | begin() const; |
| 82 | |
| 83 | const_iterator |
| 84 | end() const; |
| 85 | |
| 86 | size_t |
| 87 | size() const; |
| 88 | |
| 89 | size_t |
| 90 | empty() const; |
| 91 | |
| 92 | private: |
| 93 | // Note: Taking a list right now. A Trie will be used later to store |
| 94 | // prefixes |
| 95 | RibTable m_rib; |
| 96 | }; |
| 97 | |
| 98 | inline Rib::const_iterator |
| 99 | Rib::begin() const |
| 100 | { |
| 101 | return m_rib.begin(); |
| 102 | } |
| 103 | |
| 104 | inline Rib::const_iterator |
| 105 | Rib::end() const |
| 106 | { |
| 107 | return m_rib.end(); |
| 108 | } |
| 109 | |
| 110 | inline size_t |
| 111 | Rib::size() const |
| 112 | { |
| 113 | return m_rib.size(); |
| 114 | } |
| 115 | |
| 116 | inline size_t |
| 117 | Rib::empty() const |
| 118 | { |
| 119 | return m_rib.empty(); |
| 120 | } |
| 121 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 122 | std::ostream& |
| 123 | operator<<(std::ostream& os, const RibEntry& entry); |
| 124 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 125 | } // namespace rib |
| 126 | } // namespace nfd |
| 127 | |
| 128 | #endif // NFD_RIB_RIB_HPP |