Token Bucket¶
The TokenBucket compound module implements the token bucket algorithm. By default, the module contains a DropTailQueue and a TokenBasedServer. The queue capacity and the token consumption of the token-based server can be used to parameterize the token bucket algorithm. The module uses an external token generator for the token-based server.
In this example network, packets are produced periodically by an active packet source (ActivePacketSource). The packets are pushed into a token bucket (TokenBucket), which pushes them into a passive packet sink (PassivePacketSink). A token generator (TimeBasedTokenGenerator) generates tokens periodically into the token bucket module.
network TokenBucketTutorialStep
{
submodules:
producer: ActivePacketSource {
@display("p=100,100");
}
bucket: TokenBucket {
@display("p=200,100");
}
consumer: PassivePacketSink {
@display("p=300,100");
}
tokenGenerator: TimeBasedTokenGenerator {
@display("p=100,200");
storageModule = "^.bucket.server";
}
connections allowunconnected:
producer.out --> bucket.in;
bucket.out --> consumer.in;
}
[Config TokenBucket]
network = TokenBucketTutorialStep
sim-time-limit = 10s
*.producer.packetLength = 1B
*.producer.productionInterval = uniform(0s, 2s)
*.bucket.server.maxNumTokens = 10
*.tokenGenerator.generationInterval = uniform(0s, 2s)