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 |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 72 | * @param updatedWeight the current value for the inFace weight (stats-based weight) |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 73 | * return true if successfully enqueued, false if limit is reached or some other reason |
| 74 | */ |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 75 | bool |
| 76 | Enqueue (Ptr<Face> inFace, |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 77 | Ptr<pit::Entry> pitEntry, |
| 78 | double updatedWeight); |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 79 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 80 | /** |
| 81 | * @brief Get next PIT entry |
| 82 | * @returns next PIT entry or 0 if no entries available |
| 83 | * |
| 84 | * This method implement round-robin (in future weighted round-robin) to pick elements from different per-in-face queues |
| 85 | */ |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 86 | Ptr<pit::Entry> |
| 87 | Pop (); |
| 88 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 89 | /** |
| 90 | * @brief Remove all references to face from all queues and enqueued PIT entries |
| 91 | * @param face smart pointer to face |
| 92 | */ |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 93 | void |
| 94 | Remove (Ptr<Face> face); |
| 95 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 96 | /** |
| 97 | * @brief Remove all references to PIT entry from queues |
| 98 | * @param entry smart pointer to PIT entry |
| 99 | */ |
| 100 | static void |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 101 | Remove (Ptr<pit::Entry> entry); |
| 102 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 103 | /** |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 104 | * @brief Check if all per-in-face queues is empty |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 105 | */ |
| 106 | bool |
| 107 | IsEmpty () const; |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * @brief Check if the specified per-in-face queue is empty |
| 111 | */ |
| 112 | bool |
| 113 | IsEmpty (Ptr<Face> inFace) const; |
| 114 | |
| 115 | private: |
| 116 | void |
| 117 | UpdateWeightedRounds (); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 118 | |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 119 | public: |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 120 | typedef std::list< Ptr<pit::Entry> > Queue; |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 121 | typedef boost::tuple< Queue, double, uint32_t > WeightedQueue; |
| 122 | typedef std::map< Ptr<Face>, boost::shared_ptr<WeightedQueue> > PerInFaceQueue; |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 123 | |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 124 | private: |
Alexander Afanasyev | 372cbab | 2012-08-22 09:43:53 -0700 | [diff] [blame] | 125 | // uint32_t m_maxQueueSize; |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 126 | PerInFaceQueue::iterator m_lastQueue; // last queue from which interest was taken |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 127 | PerInFaceQueue m_queues; |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 128 | |
| 129 | uint32_t m_serviceCounter; |
| 130 | |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 133 | namespace fw { |
| 134 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 135 | /** |
| 136 | * @ingroup ndn |
| 137 | * @brief Forwarding strategy tag that stores queue-related information in PIT entries |
| 138 | */ |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 139 | class PitQueueTag : |
| 140 | public Tag |
| 141 | { |
| 142 | public: |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 143 | // map based on addresses, should be good enough |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 144 | typedef std::map< boost::shared_ptr<PitQueue::WeightedQueue>, PitQueue::Queue::iterator > MapOfItems; |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 145 | |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 146 | public: |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 147 | /** |
| 148 | * @brief Virtual destructor |
| 149 | */ |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 150 | virtual |
| 151 | ~PitQueueTag () { }; |
| 152 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 153 | /** |
| 154 | * @brief Remember in which queue at which position PIT entry is enqueued |
| 155 | * @brief item smart pointer to Queue |
| 156 | * @brief iterator queue's iterator |
| 157 | */ |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 158 | void |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 159 | InsertQueue (boost::shared_ptr<PitQueue::WeightedQueue> item, PitQueue::Queue::iterator iterator); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * @brief Remove PIT entry from all queues |
| 163 | */ |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 164 | void |
| 165 | RemoveFromAllQueues (); |
| 166 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 167 | /** |
| 168 | * @brief Remove PIT entry from the specified queue |
| 169 | * @param queue Queue from which PIT entry should be removed |
| 170 | */ |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 171 | void |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 172 | RemoveFromQueue (boost::shared_ptr<PitQueue::WeightedQueue> queue); |
Alexander Afanasyev | 6f101fc | 2012-08-23 16:34:34 -0700 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * @brief Remove reference to PIT from queues except the queue in parameter |
| 176 | * @param queue Queue from which PIT entry should not be removed (to preserve iterator) |
| 177 | */ |
| 178 | void |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 179 | RemoveFromQueuesExcept (boost::shared_ptr<PitQueue::WeightedQueue> queue); |
| 180 | |
| 181 | /** |
| 182 | * @brief Check if removal of the entry will empty all the queues |
| 183 | */ |
| 184 | bool |
| 185 | IsLastOneInQueues () const; |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 186 | |
| 187 | private: |
| 188 | MapOfItems m_items; |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | } // namespace fw |
| 192 | |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 193 | } // namespace ndn |
| 194 | } // namespace ns3 |
| 195 | |
| 196 | #endif // NDN_PIT_QUEUE_H |