Table Of Contents
Table Of Contents

Token-Based Server

The TokenBasedServer module pops packets from a passive source and processes them when it has enough tokens. A configured amount of tokens is lost when a packet is processed. The module processes packets in zero simulation time, and pushes them onto the packet consumer connected to its output. The module acquires tokens from token generator modules.

In this step, packets are generated by a passive packet source (PassivePacketSource). The packets are popped by the TokenBasedServer module. There are no token generators in this network, but the server has 10 initial tokens to process packets; the tokens eventually run out. Packets are consumed by a passive packet sink (PassivePacketSink).

network TokenBasedServerTutorialStep
{
    @display("bgb=600,200");
    submodules:
        provider: PassivePacketSource {
            @display("p=100,100");
        }
        server: TokenBasedServer {
            @display("p=300,100");
        }
        consumer: PassivePacketSink {
            @display("p=500,100");
        }
    connections allowunconnected:
        provider.out --> server.in;
        server.out --> consumer.in;
}
[Config TokenBasedServer]
network = TokenBasedServerTutorialStep
sim-time-limit = 10s

*.provider.packetLength = 1B
*.server.initialNumTokens = 10