Table Of Contents
Table Of Contents

Generating Tokens Periodically

The TimeBasedTokenGenerator generates tokens periodically into a token-based server, with a configurable generation interval.

In this step, packets are generated by a passive packet source (PassivePacketSource). A TokenBasedServer pops packets from the connected packet source when it has enough tokens, and pushes them onto a passive packet sink (PassivePacketSink). Tokens are generated at random intervals by a TimeBasedTokenGenerator.

../../../_images/TimeBasedTokenGenerator.png
network TimeBasedTokenGeneratorTutorialStep
{
    @display("bgb=600,350");
    submodules:
        provider: PassivePacketSource {
            @display("p=100,125");
        }
        server: TokenBasedServer {
            @display("p=300,125");
        }
        consumer: PassivePacketSink {
            @display("p=500,125");
        }
        tokenGenerator: TimeBasedTokenGenerator {
            @display("p=100,250");
            storageModule = "^.server";
        }
    connections allowunconnected:
        provider.out --> server.in;
        server.out --> consumer.in;
}
[Config TimeBasedTokenGenerator]
network = TimeBasedTokenGeneratorTutorialStep
sim-time-limit = 10s

*.provider.packetLength = 1B
*.tokenGenerator.generationInterval = intuniform(1s,2s)
*.tokenGenerator.numTokens = intuniform(1,2)
*.server.tokenConsumptionPerPacket = intuniform(1,2)