blob: 993cb8322a76381175b67c06e3f7a1b0ae2e2bd2 [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
72 * return true if successfully enqueued, false if limit is reached or some other reason
73 */
Alexander Afanasyev048ae422012-08-17 17:33:02 -070074 bool
75 Enqueue (Ptr<Face> inFace,
76 Ptr<pit::Entry> pitEntry);
77
Alexander Afanasyev5db92172012-08-21 16:52:07 -070078 /**
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 Afanasyev048ae422012-08-17 17:33:02 -070084 Ptr<pit::Entry>
85 Pop ();
86
Alexander Afanasyev5db92172012-08-21 16:52:07 -070087 /**
88 * @brief Remove all references to face from all queues and enqueued PIT entries
89 * @param face smart pointer to face
90 */
Alexander Afanasyev048ae422012-08-17 17:33:02 -070091 void
92 Remove (Ptr<Face> face);
93
Alexander Afanasyev5db92172012-08-21 16:52:07 -070094 /**
95 * @brief Remove all references to PIT entry from queues
96 * @param entry smart pointer to PIT entry
97 */
98 static void
Alexander Afanasyev048ae422012-08-17 17:33:02 -070099 Remove (Ptr<pit::Entry> entry);
100
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700101 /**
102 * @brief Check if queue is empty
103 */
104 bool
105 IsEmpty () const;
106
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700107public:
Alexander Afanasyevec1e3952012-08-20 13:48:15 -0700108 typedef std::list< Ptr<pit::Entry> > Queue;
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700109 typedef std::map< Ptr<Face>, boost::shared_ptr<Queue> > PerInFaceQueue;
Alexander Afanasyevec1e3952012-08-20 13:48:15 -0700110
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700111private:
Alexander Afanasyev372cbab2012-08-22 09:43:53 -0700112 // uint32_t m_maxQueueSize;
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700113 PerInFaceQueue::iterator m_lastQueue; // last queue from which interest was taken
Alexander Afanasyevec1e3952012-08-20 13:48:15 -0700114 PerInFaceQueue m_queues;
Alexander Afanasyev048ae422012-08-17 17:33:02 -0700115};
116
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700117namespace fw {
118
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700119/**
120 * @ingroup ndn
121 * @brief Forwarding strategy tag that stores queue-related information in PIT entries
122 */
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700123class PitQueueTag :
124 public Tag
125{
126public:
Alexander Afanasyev38ba9b22012-08-21 13:32:43 -0700127 // map based on addresses, should be good enough
128 typedef std::map< boost::shared_ptr<PitQueue::Queue>, PitQueue::Queue::iterator > MapOfItems;
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700129
Alexander Afanasyev38ba9b22012-08-21 13:32:43 -0700130public:
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700131 /**
132 * @brief Virtual destructor
133 */
Alexander Afanasyev38ba9b22012-08-21 13:32:43 -0700134 virtual
135 ~PitQueueTag () { };
136
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700137 /**
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 Afanasyev38ba9b22012-08-21 13:32:43 -0700142 void
143 InsertQueue (boost::shared_ptr<PitQueue::Queue> item, PitQueue::Queue::iterator iterator);
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700144
145 /**
146 * @brief Remove PIT entry from all queues
147 */
Alexander Afanasyev38ba9b22012-08-21 13:32:43 -0700148 void
149 RemoveFromAllQueues ();
150
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700151 /**
152 * @brief Remove PIT entry from the specified queue
153 * @param queue Queue from which PIT entry should be removed
154 */
Alexander Afanasyev38ba9b22012-08-21 13:32:43 -0700155 void
156 RemoveFromQueue (boost::shared_ptr<PitQueue::Queue> queue);
157
158private:
159 MapOfItems m_items;
Alexander Afanasyeved449cc2012-08-21 11:10:33 -0700160};
161
162} // namespace fw
163
Alexander Afanasyev048ae422012-08-17 17:33:02 -0700164} // namespace ndn
165} // namespace ns3
166
167#endif // NDN_PIT_QUEUE_H