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