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

#include <MultiTokenBucketMixin.h>

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

Public Member Functions

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 finish () override
 
virtual ITokenStoragegetExcessTokenStorage (const char *designator)
 
const virtual char * resolveDirective (char directive) const override
 

Protected Attributes

std::vector< TokenBuckettokenBuckets
 

Additional Inherited Members

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

Member Function Documentation

◆ addTokenProductionRate()

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

Implements inet::queueing::ITokenStorage.

129  {
130  Enter_Method("addTokenProductionRate");
131  auto &tokenBucket = tokenBuckets[0];
132  EV_INFO << "Adding token production rate" << EV_FIELD(tokenRate) << EV_FIELD(tokenBucket) << EV_ENDL;
133  tokenBucket.addTokenProductionRate(tokenRate);
134  }

◆ addTokens()

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

Implements inet::queueing::ITokenStorage.

111  {
112  Enter_Method("addTokens");
113  EV_INFO << "Adding tokens" << EV_FIELD(numTokens) << EV_FIELD(tokenBuckets) << EV_ENDL;
114  T::emit(tokensChangedSignal, getNumTokens());
115  tokenBuckets[0].addTokens(numTokens);
116  T::emit(tokensChangedSignal, getNumTokens());
117  }

◆ finish()

template<typename T >
virtual void inet::queueing::MultiTokenBucketMixin< T >::finish ( )
inlineoverrideprotectedvirtual
59  {
61  }

◆ getExcessTokenStorage()

template<typename T >
virtual ITokenStorage* inet::queueing::MultiTokenBucketMixin< T >::getExcessTokenStorage ( const char *  designator)
inlineprotectedvirtual
64  {
65  try {
66  return &tokenBuckets[std::stoi(designator)];
67  }
68  catch (...) {
69  const char *colon = strchr(designator, ':');
70  if (colon == nullptr)
71  return check_and_cast<ITokenStorage*>(T::getModuleByPath(designator));
72  else {
73  auto multiTokenBucketMixin = check_and_cast<MultiTokenBucketMixin<T>*>(T::getModuleByPath(designator));
74  int tokenBucketIndex = std::stoi(colon + 1);
75  return &multiTokenBucketMixin->tokenBuckets[tokenBucketIndex];
76  }
77  }
78  }

◆ getNumTokens()

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

Implements inet::queueing::ITokenStorage.

103  {
104  double numTokens = 0;
105  for (auto &tokenBucket : tokenBuckets)
106  numTokens += tokenBucket.getNumTokens();
107  return numTokens;
108  }

◆ initialize()

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

Reimplemented in inet::queueing::TokenBucketMeterMixin< MultiTokenBucketMixin< PacketMeterBase > >, inet::queueing::MultiTokenBucketMeter, inet::queueing::TokenBucketClassifierMixin< MultiTokenBucketMixin< PacketClassifierBase > >, and inet::queueing::MultiTokenBucketClassifier.

39  {
40  T::initialize(stage);
41  if (stage == INITSTAGE_LOCAL) {
42  cValueArray *bucketConfigurations = check_and_cast<cValueArray*>(T::par("buckets").objectValue());
43  tokenBuckets.resize(bucketConfigurations->size());
44  for (int i = bucketConfigurations->size() - 1; i >= 0; i--) {
45  cValueMap *bucketConfiguration = check_and_cast<cValueMap*>(bucketConfigurations->get(i).objectValue());
46  double numTokens = bucketConfiguration->containsKey("initialNumTokens") ? bucketConfiguration->get("initialNumTokens").doubleValue() : 0;
47  double maxNumTokens = bucketConfiguration->containsKey("maxNumTokens") ? bucketConfiguration->get("maxNumTokens").doubleValue() : -1;
48  double tokenProductionRate = bucketConfiguration->get("tokenProductionRate");
49  auto excessTokenStorage = bucketConfiguration->containsKey("excessTokenModule") ? getExcessTokenStorage(bucketConfiguration->get("excessTokenModule")) : (i < bucketConfigurations->size() - 1 ? &tokenBuckets[i + 1] : nullptr);
50  tokenBuckets[i] = (TokenBucket(numTokens, maxNumTokens, tokenProductionRate, excessTokenStorage));
51  }
52  WATCH_VECTOR(tokenBuckets);
53  }
54  else if (stage == INITSTAGE_QUEUEING)
56  }

◆ removeTokenProductionRate()

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

Implements inet::queueing::ITokenStorage.

137  {
138  Enter_Method("removeTokenProductionRate");
139  auto &tokenBucket = tokenBuckets[0];
140  EV_INFO << "Removing token production rate" << EV_FIELD(tokenRate) << EV_FIELD(tokenBucket) << EV_ENDL;
141  tokenBucket.removeTokenProductionRate(tokenRate);
142  }

◆ removeTokens()

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

Implements inet::queueing::ITokenStorage.

120  {
121  Enter_Method("removeTokens");
122  EV_INFO << "Removing tokens" << EV_FIELD(numTokens) << EV_ENDL;
123  T::emit(tokensChangedSignal, getNumTokens());
124  tokenBuckets[0].removeTokens(numTokens);
125  T::emit(tokensChangedSignal, getNumTokens());
126  }

◆ resolveDirective()

template<typename T >
const virtual char* inet::queueing::MultiTokenBucketMixin< T >::resolveDirective ( char  directive) const
inlineoverrideprotectedvirtual
81  {
82  static std::string result;
83  switch (directive) {
84  case 'n': {
85  std::stringstream stream;
86  for (int i = 0; i < tokenBuckets.size(); i++) {
87  auto &tokenBucket = tokenBuckets[i];
88  if (i != 0)
89  stream << ", ";
90  stream << tokenBucket.getNumTokens();
91  }
92  result = stream.str();
93  break;
94  }
95  default:
96  return T::resolveDirective(directive);
97  }
98  return result.c_str();
99  }

Member Data Documentation

◆ tokenBuckets

template<typename T >
std::vector<TokenBucket> inet::queueing::MultiTokenBucketMixin< T >::tokenBuckets
protected

The documentation for this class was generated from the following file:
inet::tokensChangedSignal
simsignal_t tokensChangedSignal
Definition: Simsignals.cc:121
inet::INITSTAGE_QUEUEING
INET_API InitStage INITSTAGE_QUEUEING
Initialization of queueing modules.
inet::queueing::MultiTokenBucketMixin::getNumTokens
virtual double getNumTokens() const override
Definition: MultiTokenBucketMixin.h:102
inet::queueing::MultiTokenBucketMixin::tokenBuckets
std::vector< TokenBucket > tokenBuckets
Definition: MultiTokenBucketMixin.h:35
EV_FIELD
#define EV_FIELD(...)
Definition: INETDefs.h:112
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::queueing::MultiTokenBucketMixin::getExcessTokenStorage
virtual ITokenStorage * getExcessTokenStorage(const char *designator)
Definition: MultiTokenBucketMixin.h:63
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
EV_ENDL
#define EV_ENDL
Definition: INETDefs.h:114