EMANE  1.2.1
rfpipe/downstreamqueue.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2010 - DRS CenGen, LLC, Columbia, Maryland
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of DRS CenGen, LLC nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 
35 #include "downstreamqueue.h"
36 
37 namespace
38 {
39  const std::uint16_t QUEUE_SIZE_DEFAULT{0xFF};
40 }
41 
43  maxQueueSize_{QUEUE_SIZE_DEFAULT},
44  numDiscards_{},
45  pNumHighWaterMark_{}
46 {}
47 
48 
50 {}
51 
52 
54 {
55  pNumHighWaterMark_ =
56  statisticRegistrar.registerNumeric<std::uint32_t>("numHighWaterMark",
58 }
59 
60 
61 
62 size_t
64 {
65  size_t result{numDiscards_};
66 
67  if(bClear)
68  {
69  numDiscards_ = 0;
70  }
71 
72  return result;
73 }
74 
75 
76 size_t
78 {
79  return queue_.size();
80 }
81 
82 
83 size_t
85 {
86  return maxQueueSize_;
87 }
88 
89 
90 std::pair<EMANE::Models::RFPipe::DownstreamQueueEntry,bool>
92 {
93  if(queue_.empty())
94  {
95  return {{},false};
96  }
97 
98  DownstreamQueueEntry entry{queue_.front()};
99 
100  queue_.pop();
101 
102  return {entry,true};
103 }
104 
105 
106 std::vector<EMANE::Models::RFPipe::DownstreamQueueEntry>
108 {
109  std::vector<DownstreamQueueEntry> result;
110 
111  // check for queue overflow
112  while(queue_.size() >= maxQueueSize_)
113  {
114  ++numDiscards_;
115 
116  result.push_back(std::move(queue_.front()));
117 
118  queue_.pop();
119  }
120 
121  queue_.push(std::move(entry));
122 
123  if(queue_.size() > pNumHighWaterMark_->get())
124  {
125  *pNumHighWaterMark_ = queue_.size();
126  }
127 
128  return result;
129 }
130 
131 
132 
135 {
136  return queue_.front();
137 }
138 
std::pair< DownstreamQueueEntry, bool > dequeue()
removes an element from the queue
std::vector< DownstreamQueueEntry > enqueue(DownstreamQueueEntry &entry)
Adds an element to the queue.
RFPipe MAC downstream queue entry definition.
size_t getNumDiscards(bool bClear)
Returns the number of discards.
The StatisticRegistrar allows NEM layers to register statistics and statistic tables. Statistics and Statistic tables are owned by the emulator framework and a borrowed reference is returned to the registering NEM layer.
void registerStatistics(StatisticRegistrar &statisticRegistrar)
StatisticNumeric< T > * registerNumeric(const std::string &sName, const StatisticProperties &properties=StatisticProperties::NONE, const std::string &sDescription="")
const std::uint8_t QUEUE_SIZE_DEFAULT
Definition: macconfig.h:65
size_t getMaxCapacity()
Returns the max size of the queue.
size_t getCurrentDepth()
Returns the current size of the queue.
const DownstreamQueueEntry & peek()
Returns a reference to the element to be pop&#39;d next.