blob: d7e20ec1433c1b07073f2e60998673a6fee862c7 [file] [log] [blame]
Alexander Afanasyev048ae422012-08-17 17:33:02 -07001/* -*- 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 Afanasyevec1e3952012-08-20 13:48:15 -070025#include <list>
Alexander Afanasyev048ae422012-08-17 17:33:02 -070026
27#include "ns3/ptr.h"
Alexander Afanasyeved449cc2012-08-21 11:10:33 -070028#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 Afanasyev048ae422012-08-17 17:33:02 -070033
34namespace ns3 {
35namespace ndn {
36
37class Face;
38namespace pit { class Entry; }
39
Alexander Afanasyev5db92172012-08-21 16:52:07 -070040/**
41 * @ingroup ndn
42 * @brief Queue for PIT entries, interests for which cannot be immediately forwarded
43 */
Alexander Afanasyev048ae422012-08-17 17:33:02 -070044class PitQueue
45{
46public:
Alexander Afanasyev5db92172012-08-21 16:52:07 -070047 /**
48 * @brief Default constructor
49 */
Alexander Afanasyevec1e3952012-08-20 13:48:15 -070050 PitQueue ();
Alexander Afanasyev5db92172012-08-21 16:52:07 -070051
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 Afanasyevec1e3952012-08-20 13:48:15 -070058 void
59 SetMaxQueueSize (uint32_t size);
60
Alexander Afanasyev5db92172012-08-21 16:52:07 -070061 /**
62 * @brief Get current maximum queue size
63 * @returns per-incoming face maximum queue size
64 */
Alexander Afanasyevec1e3952012-08-20 13:48:15 -070065 uint32_t
66 GetMaxQueueSize () const;
67
Alexander Afanasyev5db92172012-08-21 16:52:07 -070068 /**
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 Afanasyev98c16e02012-08-28 00:02:02 -070072 * @param updatedWeight the current value for the inFace weight (stats-based weight)
Alexander Afanasyev5db92172012-08-21 16:52:07 -070073 * return true if successfully enqueued, false if limit is reached or some other reason
74 */
Alexander Afanasyev048ae422012-08-17 17:33:02 -070075 bool
76 Enqueue (Ptr<Face> inFace,
Alexander Afanasyev98c16e02012-08-28 00:02:02 -070077 Ptr<pit::Entry> pitEntry,
78 double updatedWeight);
Alexander Afanasyev048ae422012-08-17 17:33:02 -070079
Alexander Afanasyev5db92172012-08-21 16:52:07 -070080 /**
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 Afanasyev048ae422012-08-17 17:33:02 -070086 Ptr<pit::Entry>
87 Pop ();
88
Alexander Afanasyev5db92172012-08-21 16:52:07 -070089 /**
90 * @brief Remove all references to face from all queues and enqueued PIT entries
91 * @param face smart pointer to face
92 */
Alexander Afanasyev048ae422012-08-17 17:33:02 -070093 void
94 Remove (Ptr<Face> face);
95
Alexander Afanasyev5db92172012-08-21 16:52:07 -070096 /**
97 * @brief Remove all references to PIT entry from queues
98 * @param entry smart pointer to PIT entry
99 */
100 static void
Alexander Afanasyev048ae422012-08-17 17:33:02 -0700101 Remove (Ptr<pit::Entry> entry);
102
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700103 /**
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700104 * @brief Check if all per-in-face queues is empty
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700105 */
106 bool
107 IsEmpty () const;
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700108
109 /**
110 * @brief Check if the specified per-in-face queue is empty
111 */
112 bool
113 IsEmpty (Ptr<Face> inFace) const;
114
115private:
116 void
117 UpdateWeightedRounds ();
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700118
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700119public:
Alexander Afanasyevec1e3952012-08-20 13:48:15 -0700120 typedef std::list< Ptr<pit::Entry> > Queue;
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700121 typedef boost::tuple< Queue, double, uint32_t > WeightedQueue;
122 typedef std::map< Ptr<Face>, boost::shared_ptr<WeightedQueue> > PerInFaceQueue;
Alexander Afanasyevec1e3952012-08-20 13:48:15 -0700123
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700124private:
Alexander Afanasyev372cbab2012-08-22 09:43:53 -0700125 // uint32_t m_maxQueueSize;
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700126 PerInFaceQueue::iterator m_lastQueue; // last queue from which interest was taken
Alexander Afanasyevec1e3952012-08-20 13:48:15 -0700127 PerInFaceQueue m_queues;
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700128
129 uint32_t m_serviceCounter;
130
Alexander Afanasyev048ae422012-08-17 17:33:02 -0700131};
132
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700133namespace fw {
134
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700135/**
136 * @ingroup ndn
137 * @brief Forwarding strategy tag that stores queue-related information in PIT entries
138 */
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700139class PitQueueTag :
140 public Tag
141{
142public:
Alexander Afanasyev38ba9b22012-08-21 13:32:43 -0700143 // map based on addresses, should be good enough
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700144 typedef std::map< boost::shared_ptr<PitQueue::WeightedQueue>, PitQueue::Queue::iterator > MapOfItems;
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700145
Alexander Afanasyev38ba9b22012-08-21 13:32:43 -0700146public:
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700147 /**
148 * @brief Virtual destructor
149 */
Alexander Afanasyev38ba9b22012-08-21 13:32:43 -0700150 virtual
151 ~PitQueueTag () { };
152
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700153 /**
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 Afanasyev38ba9b22012-08-21 13:32:43 -0700158 void
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700159 InsertQueue (boost::shared_ptr<PitQueue::WeightedQueue> item, PitQueue::Queue::iterator iterator);
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700160
161 /**
162 * @brief Remove PIT entry from all queues
163 */
Alexander Afanasyev38ba9b22012-08-21 13:32:43 -0700164 void
165 RemoveFromAllQueues ();
166
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700167 /**
168 * @brief Remove PIT entry from the specified queue
169 * @param queue Queue from which PIT entry should be removed
170 */
Alexander Afanasyev38ba9b22012-08-21 13:32:43 -0700171 void
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700172 RemoveFromQueue (boost::shared_ptr<PitQueue::WeightedQueue> queue);
Alexander Afanasyev6f101fc2012-08-23 16:34:34 -0700173
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 Afanasyev98c16e02012-08-28 00:02:02 -0700179 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 Afanasyev38ba9b22012-08-21 13:32:43 -0700186
187private:
188 MapOfItems m_items;
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700189};
190
191} // namespace fw
192
Alexander Afanasyev048ae422012-08-17 17:33:02 -0700193} // namespace ndn
194} // namespace ns3
195
196#endif // NDN_PIT_QUEUE_H