EMANE  1.2.1
bitpool.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater, New
3  * Jersey
4  * Copyright (c) 2009-2010 - DRS CenGen, LLC, Columbia, Maryland
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of DRS CenGen, LLC nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef BITPOOL_HEADER_
36 #define BITPOOL_HEADER_
37 
38 #include "emane/types.h"
40 
41 namespace EMANE
42 {
43  namespace Utils
44  {
52  class BitPool
53  {
54  public:
58  BitPool(PlatformServiceProvider * pPlatformService, NEMId id);
59 
63  ~BitPool();
64 
73  std::uint64_t get(std::uint64_t u64Request, bool bFullFill = true);
74 
81  std::uint64_t getCurrentSize();
82 
89  void setMaxSize(std::uint64_t u64NewSize);
90 
91  private:
92  EMANE::PlatformServiceProvider * pPlatformService_;
93 
94  NEMId id_;
95 
96  std::uint64_t u64MaxSize_;
97 
98  std::uint64_t u64CurrentSize_;
99 
100  TimePoint lastRequestTime_;
101 
102  float fFillRemainder_;
103 
104  std::mutex mutex_;
105 
111  void doFillPool(const TimePoint & requestTime);
112 
123  std::uint64_t doDrainPool(std::uint64_t u64Request,
124  const TimePoint & requestTime,
125  Microseconds & intervalMicroseconds);
126  };
127  }
128 }
129 
130 #include "emane/utils/bitpool.inl"
131 
132 #endif // BITPOOL_HEADER_
Implementation of a rate limiting bit pool.
Definition: bitpool.h:52
BitPool(PlatformServiceProvider *pPlatformService, NEMId id)
Definition: bitpool.inl:47
void setMaxSize(std::uint64_t u64NewSize)
Definition: bitpool.inl:65
The PlatformServiceProvider interface provides access to emulator services.
std::chrono::microseconds Microseconds
Definition: types.h:45
std::uint16_t NEMId
Definition: types.h:52
std::uint64_t getCurrentSize()
Definition: bitpool.inl:164
Clock::time_point TimePoint
Definition: types.h:50
Definition: agent.h:43