Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #ifndef NDN_PIT_QUEUE_H |
| 22 | #define NDN_PIT_QUEUE_H |
| 23 | |
| 24 | #include <map> |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 25 | #include <list> |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 26 | |
| 27 | #include "ns3/ptr.h" |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 28 | #include "ns3/ndn-fw-tag.h" |
| 29 | |
| 30 | #include <boost/tuple/tuple.hpp> |
| 31 | #include <boost/shared_ptr.hpp> |
| 32 | #include <boost/make_shared.hpp> |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 33 | |
| 34 | namespace ns3 { |
| 35 | namespace ndn { |
| 36 | |
| 37 | class Face; |
| 38 | namespace pit { class Entry; } |
| 39 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 40 | /** |
| 41 | * @ingroup ndn |
| 42 | * @brief Queue for PIT entries, interests for which cannot be immediately forwarded |
| 43 | */ |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 44 | class PitQueue |
| 45 | { |
| 46 | public: |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 47 | /** |
| 48 | * @brief Default constructor |
| 49 | */ |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 50 | PitQueue (); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * @brief Set maximum queue size |
| 54 | * @param size per-incoming face maximum queue size |
| 55 | * |
| 56 | * Each per-incoming-face queue will have this maximum size |
| 57 | */ |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 58 | void |
| 59 | SetMaxQueueSize (uint32_t size); |
| 60 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 61 | /** |
| 62 | * @brief Get current maximum queue size |
| 63 | * @returns per-incoming face maximum queue size |
| 64 | */ |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 65 | uint32_t |
| 66 | GetMaxQueueSize () const; |
| 67 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 68 | /** |
| 69 | * @brief Enqueue PIT entry for delayed processing |
| 70 | * @param inFace incoming face to which queue PIT entry should enqueued |
| 71 | * @param pitEntry smart pointer to PIT entry |
| 72 | * return true if successfully enqueued, false if limit is reached or some other reason |
| 73 | */ |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 74 | bool |
| 75 | Enqueue (Ptr<Face> inFace, |
| 76 | Ptr<pit::Entry> pitEntry); |
| 77 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 78 | /** |
| 79 | * @brief Get next PIT entry |
| 80 | * @returns next PIT entry or 0 if no entries available |
| 81 | * |
| 82 | * This method implement round-robin (in future weighted round-robin) to pick elements from different per-in-face queues |
| 83 | */ |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 84 | Ptr<pit::Entry> |
| 85 | Pop (); |
| 86 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 87 | /** |
| 88 | * @brief Remove all references to face from all queues and enqueued PIT entries |
| 89 | * @param face smart pointer to face |
| 90 | */ |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 91 | void |
| 92 | Remove (Ptr<Face> face); |
| 93 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 94 | /** |
| 95 | * @brief Remove all references to PIT entry from queues |
| 96 | * @param entry smart pointer to PIT entry |
| 97 | */ |
| 98 | static void |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 99 | Remove (Ptr<pit::Entry> entry); |
| 100 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 101 | /** |
| 102 | * @brief Check if queue is empty |
| 103 | */ |
| 104 | bool |
| 105 | IsEmpty () const; |
| 106 | |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 107 | public: |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 108 | typedef std::list< Ptr<pit::Entry> > Queue; |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 109 | typedef std::map< Ptr<Face>, boost::shared_ptr<Queue> > PerInFaceQueue; |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 110 | |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 111 | private: |
Alexander Afanasyev | 372cbab | 2012-08-22 09:43:53 -0700 | [diff] [blame] | 112 | // uint32_t m_maxQueueSize; |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 113 | PerInFaceQueue::iterator m_lastQueue; // last queue from which interest was taken |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 114 | PerInFaceQueue m_queues; |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 117 | namespace fw { |
| 118 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 119 | /** |
| 120 | * @ingroup ndn |
| 121 | * @brief Forwarding strategy tag that stores queue-related information in PIT entries |
| 122 | */ |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 123 | class PitQueueTag : |
| 124 | public Tag |
| 125 | { |
| 126 | public: |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 127 | // map based on addresses, should be good enough |
| 128 | typedef std::map< boost::shared_ptr<PitQueue::Queue>, PitQueue::Queue::iterator > MapOfItems; |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 129 | |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 130 | public: |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 131 | /** |
| 132 | * @brief Virtual destructor |
| 133 | */ |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 134 | virtual |
| 135 | ~PitQueueTag () { }; |
| 136 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 137 | /** |
| 138 | * @brief Remember in which queue at which position PIT entry is enqueued |
| 139 | * @brief item smart pointer to Queue |
| 140 | * @brief iterator queue's iterator |
| 141 | */ |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 142 | void |
| 143 | InsertQueue (boost::shared_ptr<PitQueue::Queue> item, PitQueue::Queue::iterator iterator); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 144 | |
| 145 | /** |
| 146 | * @brief Remove PIT entry from all queues |
| 147 | */ |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 148 | void |
| 149 | RemoveFromAllQueues (); |
| 150 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 151 | /** |
| 152 | * @brief Remove PIT entry from the specified queue |
| 153 | * @param queue Queue from which PIT entry should be removed |
| 154 | */ |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 155 | void |
| 156 | RemoveFromQueue (boost::shared_ptr<PitQueue::Queue> queue); |
| 157 | |
| 158 | private: |
| 159 | MapOfItems m_items; |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | } // namespace fw |
| 163 | |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 164 | } // namespace ndn |
| 165 | } // namespace ns3 |
| 166 | |
| 167 | #endif // NDN_PIT_QUEUE_H |