REDQueue.cc
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 
17 #include "REDQueue.hh"
18 
19 // Custom includes
24 
25 #define prefix_
26 
29 {
30  return ppi::QueueingAlgorithm::ptr(new REDQueue(16384, 25));
31 }
32 
33 prefix_ senf::emu::REDQueue::REDQueue(boost::uint32_t _limit, boost::uint8_t lowThreshPrecentage)
34  : queueLimit_ (0), lowThresh_ (0), lowThreshPrecentage_ (lowThreshPrecentage), frontPktSize_(0)
35 {
36  clear();
37  limit( _limit, lowThreshPrecentage_);
38 
39  namespace fty = console::factory;
40  consoleDir().add( "limit", fty::Command(
41  SENF_MEMBINDFNP( void, REDQueue, limit, (boost::uint32_t, boost::uint8_t)))
42  .doc( "set the RED queue size bytes and low threshold in percent"));
43  consoleDir().add( "limit", fty::Command(
44  SENF_MEMBINDFNP( limit_t, REDQueue, limit, () const))
45  .doc( "get the RED queue size in bytes and low threshold in percent"));
46  consoleDir().add( "dropped", fty::Command( &REDQueue::dropped, this)
47  .doc( "get the number of dropped packets since the last call."));
48  consoleDir().add( "size", fty::Command( &REDQueue::size, this)
49  .doc( "return the current RED queue size (usage) in bytes"));
50  consoleDir().add( "droppedTotal", fty::Variable( boost::cref(REDQueue::packetsDroppedTotal_))
51  .doc( "Get the total number of dropped packets."));
52 }
53 
54 
55 prefix_ void senf::emu::REDQueue::v_clear()
56 {
57  queueSize_ = 0;
58  packetsDroppedLast_ = 0;
59  packetsDroppedTotal_ = 0;
60  while (!queue_.empty())
61  queue_.pop();
62  frontPktSize_ = 0;
63 }
64 
65 
66 prefix_ void senf::emu::REDQueue::limit(boost::uint32_t bytes, boost::uint8_t lowThreshPrecentage)
67 {
68  if (lowThreshPrecentage > 100)
69  lowThreshPrecentage = 100;
70 
71  // 2GByte limit
72  if (bytes > 0x7fffffff)
73  bytes = 0x7fffffff;
74 
75  queueLimit_ = bytes;
76  lowThreshPrecentage_ = lowThreshPrecentage;
77 
78  lowThresh_ = (queueLimit_ * lowThreshPrecentage_) / 100;
79 
80  clear();
81 }
82 
84  const
85 {
86  return std::make_pair(queueLimit_, lowThreshPrecentage_);
87 }
88 
90  const
91 {
92  return packetsDroppedTotal_ - packetsDroppedLast_;
93 }
94 
96 {
97  packetsDroppedLast_ = packetsDroppedTotal_;
98 }
99 
101 #undef prefix_
std::pair< std::uint32_t, std::uint8_t > limit_t
Definition: REDQueue.hh:36
#define SENF_MEMBINDFNP(ret, cls, fn, args)
std::uint32_t dropped() const
Definition: REDQueue.cc:89
REDQueue(std::uint32_t _limit=16384, std::uint8_t lowThreshPrecentage=25)
Definition: REDQueue.cc:33
PacketParserBase::size_type bytes(Parser const &p)
std::unique_ptr< QueueingAlgorithm > ptr
limit_t limit() const
Definition: REDQueue.cc:83
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)
#define prefix_
Definition: REDQueue.cc:25
REDQueue public header.
console::DirectoryNode & consoleDir()
static ppi::QueueingAlgorithm::ptr create()
Definition: REDQueue.cc:28