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 | #include "ndn-pit-queue.h" |
| 22 | |
| 23 | #include "ns3/ndn-face.h" |
| 24 | #include "ns3/ndn-pit-entry.h" |
Alexander Afanasyev | 0ffa716 | 2012-08-21 22:39:22 -0700 | [diff] [blame] | 25 | #include "ns3/log.h" |
Alexander Afanasyev | c23a3e3 | 2012-08-28 00:16:23 -0700 | [diff] [blame] | 26 | #include "ns3/simulator.h" |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 27 | |
| 28 | #include "ns3/assert.h" |
| 29 | |
| 30 | using namespace std; |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 31 | using namespace boost; |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | 0ffa716 | 2012-08-21 22:39:22 -0700 | [diff] [blame] | 33 | NS_LOG_COMPONENT_DEFINE ("ndn.PitQueue"); |
| 34 | |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 35 | namespace ns3 { |
| 36 | namespace ndn { |
| 37 | |
Alexander Afanasyev | caeade2 | 2012-09-04 16:31:12 -0700 | [diff] [blame] | 38 | const double MIN_WEIGHT = 0.01; |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 39 | |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 40 | PitQueue::PitQueue () |
Alexander Afanasyev | 372cbab | 2012-08-22 09:43:53 -0700 | [diff] [blame] | 41 | // : m_maxQueueSize (20) |
| 42 | : m_lastQueue (m_queues.end ()) |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 43 | { |
| 44 | } |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 45 | |
Alexander Afanasyev | 372cbab | 2012-08-22 09:43:53 -0700 | [diff] [blame] | 46 | // void |
| 47 | // PitQueue::SetMaxQueueSize (uint32_t size) |
| 48 | // { |
| 49 | // m_maxQueueSize = size; |
| 50 | // } |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 51 | |
Alexander Afanasyev | 372cbab | 2012-08-22 09:43:53 -0700 | [diff] [blame] | 52 | // uint32_t |
| 53 | // PitQueue::GetMaxQueueSize () const |
| 54 | // { |
| 55 | // return m_maxQueueSize; |
| 56 | // } |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 57 | |
| 58 | |
| 59 | bool |
| 60 | PitQueue::Enqueue (Ptr<Face> inFace, |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 61 | Ptr<pit::Entry> pitEntry, |
| 62 | double updatedWeight) |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 63 | { |
Alexander Afanasyev | 187cba2 | 2012-08-28 11:16:52 -0700 | [diff] [blame] | 64 | if (updatedWeight < 0) updatedWeight = 0.5; |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 65 | if (updatedWeight < MIN_WEIGHT) updatedWeight = MIN_WEIGHT; |
| 66 | |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 67 | PerInFaceQueue::iterator queue = m_queues.find (inFace); |
| 68 | if (queue == m_queues.end ()) |
| 69 | { |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 70 | pair<PerInFaceQueue::iterator, bool> itemPair = |
| 71 | m_queues.insert (make_pair (inFace, boost::make_shared< WeightedQueue > (make_tuple (Queue (), updatedWeight, 0)))); |
Alexander Afanasyev | 0ffa716 | 2012-08-21 22:39:22 -0700 | [diff] [blame] | 72 | m_lastQueue = m_queues.end (); // for some reason end() iterator is invalidated when new item is inserted |
Alexander Afanasyev | ed449cc | 2012-08-21 11:10:33 -0700 | [diff] [blame] | 73 | NS_ASSERT (itemPair.second == true); |
| 74 | |
| 75 | queue = itemPair.first; |
| 76 | } |
Alexander Afanasyev | caeade2 | 2012-09-04 16:31:12 -0700 | [diff] [blame] | 77 | else |
| 78 | { |
| 79 | queue->second->get<1> () = updatedWeight; |
| 80 | } |
Alexander Afanasyev | ff03395 | 2012-08-23 15:45:52 -0700 | [diff] [blame] | 81 | |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 82 | if ((inFace->GetLimits ().GetMaxLimit () == 0 && queue->second->get<0> ().size () > 100) || |
| 83 | (inFace->GetLimits ().GetMaxLimit () != 0 && queue->second->get<0> ().size () >= 0.5 * inFace->GetLimits ().GetMaxLimit ())) |
Alexander Afanasyev | ff03395 | 2012-08-23 15:45:52 -0700 | [diff] [blame] | 84 | { |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 85 | return false; |
Alexander Afanasyev | ff03395 | 2012-08-23 15:45:52 -0700 | [diff] [blame] | 86 | } |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 88 | Queue::iterator itemIterator = queue->second->get<0> ().insert (queue->second->get<0> ().end (), pitEntry); |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 89 | |
| 90 | shared_ptr<fw::PitQueueTag> tag = pitEntry->GetFwTag<fw::PitQueueTag> (); |
| 91 | if (tag == shared_ptr<fw::PitQueueTag> ()) |
| 92 | { |
| 93 | tag = make_shared<fw::PitQueueTag> (); |
| 94 | pitEntry->AddFwTag (tag); |
| 95 | } |
| 96 | tag->InsertQueue (queue->second, itemIterator); |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 97 | |
Alexander Afanasyev | caeade2 | 2012-09-04 16:31:12 -0700 | [diff] [blame] | 98 | // if (Simulator::GetContext () == 4) |
| 99 | // { |
| 100 | // cout << "====== " << Simulator::Now ().ToDouble (Time::S) << "s " << *queue->first << endl; |
| 101 | // cout << " " << m_serviceCounter << " / " << queue->second->get<1> () << " / " << queue->second->get<2> () << "\n"; |
| 102 | // for (PerInFaceQueue::const_iterator somequeue = m_queues.begin (); |
| 103 | // somequeue != m_queues.end (); |
| 104 | // somequeue ++) |
| 105 | // { |
| 106 | // if (somequeue == queue) cout << "*"; |
| 107 | // cout << somequeue->second->get<0> ().size () << " "; |
| 108 | // } |
| 109 | // cout << endl; |
| 110 | // } |
| 111 | |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 112 | UpdateWeightedRounds (); |
Alexander Afanasyev | caeade2 | 2012-09-04 16:31:12 -0700 | [diff] [blame] | 113 | |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 114 | return true; |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 117 | |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 118 | Ptr<pit::Entry> |
| 119 | PitQueue::Pop () |
| 120 | { |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 121 | PerInFaceQueue::iterator queue = m_lastQueue; |
| 122 | |
Alexander Afanasyev | c23a3e3 | 2012-08-28 00:16:23 -0700 | [diff] [blame] | 123 | if (queue != m_queues.end () && |
Alexander Afanasyev | 187cba2 | 2012-08-28 11:16:52 -0700 | [diff] [blame] | 124 | m_serviceCounter >= queue->second->get<2> ()) |
Alexander Afanasyev | c23a3e3 | 2012-08-28 00:16:23 -0700 | [diff] [blame] | 125 | { |
Alexander Afanasyev | 187cba2 | 2012-08-28 11:16:52 -0700 | [diff] [blame] | 126 | queue ++; // actually implement weighted round robin... |
| 127 | m_serviceCounter = 0; |
Alexander Afanasyev | c23a3e3 | 2012-08-28 00:16:23 -0700 | [diff] [blame] | 128 | } |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 129 | |
| 130 | while (queue != m_queues.end () && queue->second->get<0> ().size () == 0) // advance iterator |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 131 | { |
| 132 | queue ++; |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 133 | m_serviceCounter = 0; |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | if (queue == m_queues.end ()) |
Alexander Afanasyev | 0ffa716 | 2012-08-21 22:39:22 -0700 | [diff] [blame] | 137 | { |
| 138 | queue = m_queues.begin (); // circle to the beginning |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 139 | m_serviceCounter = 0; |
Alexander Afanasyev | 0ffa716 | 2012-08-21 22:39:22 -0700 | [diff] [blame] | 140 | } |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 141 | |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 142 | while (queue != m_queues.end () && queue->second->get<0> ().size () == 0) // advance iterator |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 143 | { |
| 144 | queue ++; |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 145 | m_serviceCounter = 0; |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Alexander Afanasyev | 187cba2 | 2012-08-28 11:16:52 -0700 | [diff] [blame] | 148 | m_serviceCounter ++; |
| 149 | |
| 150 | // if (Simulator::GetContext () == 4) |
Alexander Afanasyev | c23a3e3 | 2012-08-28 00:16:23 -0700 | [diff] [blame] | 151 | // { |
Alexander Afanasyev | 187cba2 | 2012-08-28 11:16:52 -0700 | [diff] [blame] | 152 | // cout << "====== " << Simulator::Now ().ToDouble (Time::S) << "s " << *queue->first << endl; |
Alexander Afanasyev | caeade2 | 2012-09-04 16:31:12 -0700 | [diff] [blame] | 153 | // cout << " " << m_serviceCounter << " / " << queue->second->get<1> () << " / " << queue->second->get<2> () << "\n"; |
Alexander Afanasyev | c23a3e3 | 2012-08-28 00:16:23 -0700 | [diff] [blame] | 154 | // for (PerInFaceQueue::const_iterator somequeue = m_queues.begin (); |
| 155 | // somequeue != m_queues.end (); |
| 156 | // somequeue ++) |
| 157 | // { |
| 158 | // if (somequeue == queue) cout << "*"; |
| 159 | // cout << somequeue->second->get<0> ().size () << " "; |
| 160 | // } |
| 161 | // cout << endl; |
| 162 | // } |
| 163 | |
Alexander Afanasyev | 187cba2 | 2012-08-28 11:16:52 -0700 | [diff] [blame] | 164 | if (queue == m_queues.end () || queue->second->get<0> ().size () == 0) |
| 165 | return 0; |
| 166 | |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 167 | NS_ASSERT_MSG (queue->second->get<0> ().size () != 0, "Logic error"); |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 168 | |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 169 | Ptr<pit::Entry> entry = *queue->second->get<0> ().begin (); |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 170 | shared_ptr<fw::PitQueueTag> tag = entry->GetFwTag<fw::PitQueueTag> (); |
| 171 | NS_ASSERT (tag != shared_ptr<fw::PitQueueTag> ()); |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 172 | |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 173 | #ifdef NS3_LOG_ENABLE |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 174 | size_t queueSize = queue->second->get<0> ().size (); |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 175 | #endif |
| 176 | tag->RemoveFromQueue (queue->second); |
| 177 | #ifdef NS3_LOG_ENABLE |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 178 | NS_ASSERT_MSG (queue->second->get<0> ().size () == queueSize-1, "Queue size should be reduced by one"); |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 179 | #endif |
Alexander Afanasyev | 187cba2 | 2012-08-28 11:16:52 -0700 | [diff] [blame] | 180 | |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 181 | m_lastQueue = queue; |
| 182 | return entry; |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | void |
| 186 | PitQueue::Remove (Ptr<Face> face) |
| 187 | { |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 188 | if (m_lastQueue->first == face) |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 189 | { |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 190 | m_lastQueue++; |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 191 | } |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 192 | |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 193 | PerInFaceQueue::iterator queue = m_queues.find (face); |
| 194 | if (queue == m_queues.end ()) |
| 195 | return; |
| 196 | |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 197 | for (Queue::iterator pitEntry = queue->second->get<0> ().begin (); |
| 198 | pitEntry != queue->second->get<0> ().end (); |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 199 | pitEntry ++) |
| 200 | { |
| 201 | shared_ptr<fw::PitQueueTag> tag = (*pitEntry)->GetFwTag<fw::PitQueueTag> (); |
| 202 | NS_ASSERT (tag != shared_ptr<fw::PitQueueTag> ()); |
| 203 | |
Alexander Afanasyev | 6f101fc | 2012-08-23 16:34:34 -0700 | [diff] [blame] | 204 | tag->RemoveFromQueuesExcept (queue->second); |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 207 | NS_ASSERT_MSG (queue->second->get<0> ().size () == 0, "Queue size should be 0 by now"); |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 208 | m_queues.erase (queue); |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void |
| 212 | PitQueue::Remove (Ptr<pit::Entry> entry) |
| 213 | { |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 214 | shared_ptr<fw::PitQueueTag> tag = entry->GetFwTag<fw::PitQueueTag> (); |
| 215 | if (tag == shared_ptr<fw::PitQueueTag> ()) |
| 216 | return; |
| 217 | |
| 218 | tag->RemoveFromAllQueues (); |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 221 | bool |
| 222 | PitQueue::IsEmpty () const |
| 223 | { |
Alexander Afanasyev | 0ffa716 | 2012-08-21 22:39:22 -0700 | [diff] [blame] | 224 | bool isEmpty = true; |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 225 | |
| 226 | for (PerInFaceQueue::const_iterator queue = m_queues.begin (); |
| 227 | queue != m_queues.end (); |
| 228 | queue ++) |
| 229 | { |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 230 | isEmpty &= (queue->second->get<0> ().size () == 0); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | return isEmpty; |
| 234 | } |
| 235 | |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 236 | bool |
| 237 | PitQueue::IsEmpty (Ptr<Face> inFace) const |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 238 | { |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 239 | PerInFaceQueue::const_iterator queue = m_queues.find (inFace); |
| 240 | if (queue == m_queues.end ()) |
| 241 | return true; |
| 242 | |
| 243 | return queue->second->get<0> ().size () == 0; |
| 244 | } |
| 245 | |
| 246 | |
| 247 | void |
| 248 | PitQueue::UpdateWeightedRounds () |
| 249 | { |
| 250 | double minWeight = 100.0; |
| 251 | for (PerInFaceQueue::const_iterator queue = m_queues.begin (); |
| 252 | queue != m_queues.end (); |
| 253 | queue ++) |
| 254 | { |
| 255 | if (queue->second->get<1> () < minWeight) |
| 256 | minWeight = queue->second->get<1> (); |
| 257 | } |
| 258 | |
| 259 | for (PerInFaceQueue::const_iterator queue = m_queues.begin (); |
| 260 | queue != m_queues.end (); |
| 261 | queue ++) |
| 262 | { |
Alexander Afanasyev | caeade2 | 2012-09-04 16:31:12 -0700 | [diff] [blame] | 263 | queue->second->get<2> () = static_cast<uint32_t>((queue->second->get<1> () / minWeight) + 0.5); |
Alexander Afanasyev | 187cba2 | 2012-08-28 11:16:52 -0700 | [diff] [blame] | 264 | if (queue->second->get<2> () < 1) |
| 265 | queue->second->get<2> () = 1; |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 266 | } |
Alexander Afanasyev | 187cba2 | 2012-08-28 11:16:52 -0700 | [diff] [blame] | 267 | |
| 268 | // if (m_queues.size () > 1) |
| 269 | // { |
| 270 | // cout << "Node " << Simulator::GetContext () << " (min = " << minWeight << "): "; |
| 271 | // for (PerInFaceQueue::const_iterator queue = m_queues.begin (); |
| 272 | // queue != m_queues.end (); |
| 273 | // queue ++) |
| 274 | // { |
| 275 | // cout << queue->second->get<1> () << "/" << queue->second->get<2> () << " "; |
| 276 | // } |
| 277 | // cout << endl; |
| 278 | // } |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | |
| 282 | //////////////////////////////////////////////////////////////////////////////// |
| 283 | |
| 284 | void |
| 285 | fw::PitQueueTag::InsertQueue (boost::shared_ptr<PitQueue::WeightedQueue> queue, PitQueue::Queue::iterator iterator) |
| 286 | { |
| 287 | // std::cerr << "size before: " << m_items.size () << " item: " << (*iterator)->GetPrefix (); |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 288 | pair<MapOfItems::iterator, bool> item = m_items.insert (make_pair (queue, iterator)); |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 289 | // std::cerr << " and after: " << m_items.size () << std::endl; |
| 290 | NS_ASSERT_MSG (item.second == true, "Should be a new tag for PIT entry, but something is wrong"); |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | void |
| 294 | fw::PitQueueTag::RemoveFromAllQueues () |
| 295 | { |
| 296 | for (MapOfItems::iterator item = m_items.begin (); |
| 297 | item != m_items.end (); |
| 298 | item ++) |
| 299 | { |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 300 | item->first->get<0> ().erase (item->second); |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 301 | } |
| 302 | m_items.clear (); |
| 303 | } |
| 304 | |
| 305 | void |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 306 | fw::PitQueueTag::RemoveFromQueue (boost::shared_ptr<PitQueue::WeightedQueue> queue) |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 307 | { |
| 308 | MapOfItems::iterator item = m_items.find (queue); |
| 309 | if (item == m_items.end ()) |
| 310 | return; |
| 311 | |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 312 | item->first->get<0> ().erase (item->second); |
Alexander Afanasyev | 38ba9b2 | 2012-08-21 13:32:43 -0700 | [diff] [blame] | 313 | m_items.erase (item); |
| 314 | } |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 315 | |
Alexander Afanasyev | 6f101fc | 2012-08-23 16:34:34 -0700 | [diff] [blame] | 316 | void |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 317 | fw::PitQueueTag::RemoveFromQueuesExcept (boost::shared_ptr<PitQueue::WeightedQueue> queue) |
Alexander Afanasyev | 6f101fc | 2012-08-23 16:34:34 -0700 | [diff] [blame] | 318 | { |
| 319 | for (MapOfItems::iterator item = m_items.begin (); |
| 320 | item != m_items.end (); ) |
| 321 | { |
| 322 | if (item->first == queue) |
| 323 | { |
| 324 | item ++; |
| 325 | continue; |
| 326 | } |
| 327 | |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 328 | item->first->get<0> ().erase (item->second); |
Alexander Afanasyev | 6f101fc | 2012-08-23 16:34:34 -0700 | [diff] [blame] | 329 | |
| 330 | MapOfItems::iterator itemToDelete = item; |
| 331 | item ++; |
| 332 | m_items.erase (itemToDelete); |
| 333 | } |
| 334 | } |
| 335 | |
Alexander Afanasyev | 98c16e0 | 2012-08-28 00:02:02 -0700 | [diff] [blame] | 336 | bool |
| 337 | fw::PitQueueTag::IsLastOneInQueues () const |
| 338 | { |
| 339 | bool lastOne = true; |
| 340 | |
| 341 | for (MapOfItems::const_iterator item = m_items.begin (); |
| 342 | item != m_items.end (); |
| 343 | item ++) |
| 344 | { |
| 345 | lastOne &= (item->first->get<0> ().size () == 1); |
| 346 | } |
| 347 | |
| 348 | return lastOne; |
| 349 | } |
| 350 | |
Alexander Afanasyev | 6f101fc | 2012-08-23 16:34:34 -0700 | [diff] [blame] | 351 | |
Alexander Afanasyev | 048ae42 | 2012-08-17 17:33:02 -0700 | [diff] [blame] | 352 | } // namespace ndn |
| 353 | } // namespace ns3 |