REDQueue.cci
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief REDQueue inline non-template implementation */
16 
17 //#include "REDQueue.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 prefix_ bool senf::emu::REDQueue::v_enqueue(senf::Packet const & packet, bool force)
24 {
25  if (!force and (queueSize_ > lowThresh_)) {
26  if ( (boost::uint32_t(rand()) % (queueLimit_ - lowThresh_ + 1)) <= (queueSize_ - lowThresh_) ) {
27  packetsDroppedTotal_++;
28  return false; // no additional packet added to queue
29  }
30  }
31 
32  queue_.emplace(packet);
33  queueSize_ += packet.size();
34  return true;
35 }
36 
37 prefix_ void senf::emu::REDQueue::v_pop()
38 {
39  if (SENF_LIKELY(frontPktSize_ > 0)) {
40  queueSize_ -= frontPktSize_;
41  queue_.pop();
42  frontPktSize_ = 0;
43  }
44 }
45 
46 prefix_ unsigned senf::emu::REDQueue::v_peek(unsigned maxSize)
47  const
48 {
49  if (!queue_.empty() and (queue_.front().size() <= maxSize))
50  return frontPktSize_ = queue_.front().size();
51  return 0;
52 }
53 
54 prefix_ senf::Packet const & senf::emu::REDQueue::v_front()
55  const
56 {
57  return queue_.front();
58 }
59 
60 prefix_ bool senf::emu::REDQueue::v_empty()
61  const
62 {
63  return queue_.empty();
64 }
65 
66 prefix_ unsigned senf::emu::REDQueue::v_size()
67  const
68 {
69  return queueSize_;
70 }
71 
72 prefix_ void senf::emu::REDQueue::incrDropped()
73 {
74  packetsDroppedTotal_++;
75 }
76 
77 //-/////////////////////////////////////////////////////////////////////////////////////////////////
78 #undef prefix_
79 
80 
81 // Local Variables:
82 // mode: c++
83 // fill-column: 100
84 // comment-column: 40
85 // c-file-style: "senf"
86 // indent-tabs-mode: nil
87 // ispell-local-dictionary: "american"
88 // compile-command: "scons -u test"
89 // End: