INET Framework for OMNeT++/OMNEST
inet::queueing::TokenBucketMixin< T > Class Template Reference

#include <TokenBucketMixin.h>

Inheritance diagram for inet::queueing::TokenBucketMixin< T >:
inet::units::value< Value, Units > inet::queueing::ITokenStorage

Public Member Functions

virtual ~TokenBucketMixin ()
 
virtual double getNumTokens () const override
 
virtual void addTokens (double numTokens) override
 
virtual void removeTokens (double numTokens) override
 
virtual void addTokenProductionRate (double tokenRate) override
 
virtual void removeTokenProductionRate (double tokenRate) override
 
- Public Member Functions inherited from inet::units::value< Value, Units >
 value ()
 
 value (const value_type &v)
 
template<typename OtherValue , typename OtherUnits >
 value (const value< OtherValue, OtherUnits > &v)
 
std::string str () const
 
const value_typeget () const
 
void set (const value_type &v)
 
template<typename OtherValue , typename OtherUnits >
valueoperator= (const value< OtherValue, OtherUnits > &other)
 
template<typename OtherValue , typename OtherUnits , typename ResultValue = typename std::remove_cv<decltype(Value() + OtherValue())>::type>
value< ResultValue, Units > operator+ (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue , typename OtherUnits >
valueoperator+= (const value< OtherValue, OtherUnits > &other)
 
template<typename OtherValue , typename OtherUnits >
valueoperator-= (const value< OtherValue, OtherUnits > &other)
 
template<typename OtherValue , typename OtherUnits , typename ResultValue = typename std::remove_cv<decltype(Value() - OtherValue())>::type>
value< ResultValue, Units > operator- (const value< OtherValue, OtherUnits > &other) const
 
value operator- () const
 
template<typename OtherValue , typename OtherUnits , typename ResultValue = typename std::remove_cv<decltype(Value() * OtherValue())>::type>
value< ResultValue, compose< Units, OtherUnits > > operator* (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue >
value operator* (OtherValue v) const
 
valueoperator*= (const value_type &v)
 
template<typename OtherValue , typename OtherUnits , typename ResultValue = typename std::remove_cv<decltype(Value() / OtherValue())>::type>
value< ResultValue, compose< Units, pow< OtherUnits, -1 > > > operator/ (const value< OtherValue, OtherUnits > &other) const
 
value operator/ (const value_type &v) const
 
valueoperator/= (const value_type &v)
 
template<typename OtherValue , typename OtherUnits >
bool operator== (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue , typename OtherUnits >
bool operator!= (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue , typename OtherUnits >
bool operator< (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue , typename OtherUnits >
bool operator<= (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue , typename OtherUnits >
bool operator> (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue , typename OtherUnits >
bool operator>= (const value< OtherValue, OtherUnits > &other) const
 
valueoperator++ ()
 
value operator++ (int)
 
valueoperator-- ()
 
value operator-- (int)
 
- Public Member Functions inherited from inet::queueing::ITokenStorage
virtual ~ITokenStorage ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *message) override
 
virtual void finish () override
 
const virtual char * resolveDirective (char directive) const override
 
virtual void rescheduleOverflowTimer ()
 

Protected Attributes

TokenBucket tokenBucket
 
cMessage * overflowTimer = nullptr
 

Additional Inherited Members

- Public Types inherited from inet::units::value< Value, Units >
typedef Value value_type
 
typedef Units unit
 

Constructor & Destructor Documentation

◆ ~TokenBucketMixin()

template<typename T >
virtual inet::queueing::TokenBucketMixin< T >::~TokenBucketMixin ( )
inlinevirtual
82 { T::cancelAndDelete(overflowTimer); }

Member Function Documentation

◆ addTokenProductionRate()

template<typename T >
virtual void inet::queueing::TokenBucketMixin< T >::addTokenProductionRate ( double  tokenRate)
inlineoverridevirtual

Implements inet::queueing::ITokenStorage.

110  {
111  Enter_Method("addTokenProductionRate");
112  EV_INFO << "Adding token production rate" << EV_FIELD(tokenRate) << EV_FIELD(tokenBucket) << EV_ENDL;
115  }

◆ addTokens()

template<typename T >
virtual void inet::queueing::TokenBucketMixin< T >::addTokens ( double  numTokens)
inlineoverridevirtual

Implements inet::queueing::ITokenStorage.

90  {
91  Enter_Method("addTokens");
92  EV_INFO << "Adding tokens" << EV_FIELD(numTokens) << EV_FIELD(tokenBucket) << EV_ENDL;
94  tokenBucket.addTokens(numTokens);
97  }

◆ finish()

template<typename T >
virtual void inet::queueing::TokenBucketMixin< T >::finish ( )
inlineoverrideprotectedvirtual
56  {
58  }

◆ getNumTokens()

template<typename T >
virtual double inet::queueing::TokenBucketMixin< T >::getNumTokens ( ) const
inlineoverridevirtual

Implements inet::queueing::ITokenStorage.

85  {
86  return tokenBucket.getNumTokens();
87  }

◆ handleMessage()

template<typename T >
virtual void inet::queueing::TokenBucketMixin< T >::handleMessage ( cMessage *  message)
inlineoverrideprotectedvirtual
47  {
48  if (message == overflowTimer)
49  // initiate overflow
51  else
52  throw cRuntimeError("Unknown message");
53  }

◆ initialize()

template<typename T >
virtual void inet::queueing::TokenBucketMixin< T >::initialize ( int  stage)
inlineoverrideprotectedvirtual

Reimplemented in inet::queueing::TokenBucketMeterMixin< TokenBucketMixin< PacketMeterBase > >, inet::queueing::TokenBucketMeter, inet::queueing::TokenBucketClassifierMixin< TokenBucketMixin< PacketClassifierBase > >, and inet::queueing::TokenBucketClassifier.

29  {
30  T::initialize(stage);
31  if (stage == INITSTAGE_LOCAL) {
32  double numTokens = T::par("initialNumTokens");
33  double maxNumTokens = T::par("maxNumTokens");
34  double tokenProductionRate = T::par("tokenProductionRate");
35  auto excessTokenModule = findModuleFromPar<ITokenStorage>(T::par("excessTokenModule"), this);
36  tokenBucket = TokenBucket(numTokens, maxNumTokens, tokenProductionRate, excessTokenModule);
37  overflowTimer = new cMessage("OverflowTimer");
38  WATCH(tokenBucket);
39  }
40  else if (stage == INITSTAGE_QUEUEING) {
43  }
44  }

◆ removeTokenProductionRate()

template<typename T >
virtual void inet::queueing::TokenBucketMixin< T >::removeTokenProductionRate ( double  tokenRate)
inlineoverridevirtual

Implements inet::queueing::ITokenStorage.

118  {
119  Enter_Method("removeTokenProductionRate");
120  EV_INFO << "Removing token production rate" << EV_FIELD(tokenRate) << EV_FIELD(tokenBucket) << EV_ENDL;
123  }

◆ removeTokens()

template<typename T >
virtual void inet::queueing::TokenBucketMixin< T >::removeTokens ( double  numTokens)
inlineoverridevirtual

Implements inet::queueing::ITokenStorage.

100  {
101  Enter_Method("removeTokens");
102  EV_INFO << "Removing tokens" << EV_FIELD(numTokens) << EV_FIELD(tokenBucket) << EV_ENDL;
103  T::emit(tokensChangedSignal, getNumTokens());
104  tokenBucket.removeTokens(numTokens);
107  }

◆ rescheduleOverflowTimer()

template<typename T >
virtual void inet::queueing::TokenBucketMixin< T >::rescheduleOverflowTimer ( )
inlineprotectedvirtual
76  {
77  if (tokenBucket.getExcessTokenStorage() != nullptr && tokenBucket.getOverflowTime() > simTime())
78  T::rescheduleAt(tokenBucket.getOverflowTime(), overflowTimer);
79  }

◆ resolveDirective()

template<typename T >
const virtual char* inet::queueing::TokenBucketMixin< T >::resolveDirective ( char  directive) const
inlineoverrideprotectedvirtual
61  {
62  static std::string result;
63  switch (directive) {
64  case 'n': {
65  std::stringstream stream;
66  stream << tokenBucket.getNumTokens();
67  result = stream.str();
68  break;
69  }
70  default:
71  return T::resolveDirective(directive);
72  }
73  return result.c_str();
74  }

Member Data Documentation

◆ overflowTimer

template<typename T >
cMessage* inet::queueing::TokenBucketMixin< T >::overflowTimer = nullptr
protected

◆ tokenBucket

template<typename T >
TokenBucket inet::queueing::TokenBucketMixin< T >::tokenBucket
protected

The documentation for this class was generated from the following file:
inet::queueing::TokenBucket::getOverflowTime
virtual simtime_t getOverflowTime()
Returns the simulation time when the token bucket becomes full with the current rate of token product...
Definition: TokenBucket.cc:98
inet::tokensChangedSignal
simsignal_t tokensChangedSignal
Definition: Simsignals.cc:121
inet::INITSTAGE_QUEUEING
INET_API InitStage INITSTAGE_QUEUEING
Initialization of queueing modules.
inet::queueing::TokenBucket::removeTokens
virtual void removeTokens(double numTokens) override
Definition: TokenBucket.cc:45
inet::queueing::TokenBucketMixin::overflowTimer
cMessage * overflowTimer
Definition: TokenBucketMixin.h:25
inet::queueing::TokenBucketMixin::getNumTokens
virtual double getNumTokens() const override
Definition: TokenBucketMixin.h:84
inet::queueing::TokenBucket::addTokens
virtual void addTokens(double numTokens) override
Definition: TokenBucket.cc:27
inet::queueing::TokenBucket::removeTokenProductionRate
virtual void removeTokenProductionRate(double tokenRate) override
Definition: TokenBucket.cc:80
EV_FIELD
#define EV_FIELD(...)
Definition: INETDefs.h:112
inet::queueing::TokenBucketMixin::tokenBucket
TokenBucket tokenBucket
Definition: TokenBucketMixin.h:23
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::queueing::TokenBucket::addTokenProductionRate
virtual void addTokenProductionRate(double tokenRate) override
Definition: TokenBucket.cc:62
inet::queueing::TokenBucket::getExcessTokenStorage
virtual ITokenStorage * getExcessTokenStorage() const
Definition: TokenBucket.h:35
inet::queueing::TokenBucketMixin::rescheduleOverflowTimer
virtual void rescheduleOverflowTimer()
Definition: TokenBucketMixin.h:76
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::queueing::TokenBucket::getNumTokens
virtual double getNumTokens() const override
Definition: TokenBucket.cc:21
EV_ENDL
#define EV_ENDL
Definition: INETDefs.h:114