Table Of Contents
Table Of Contents

Generating Tokens after Received Packets

The PacketBasedTokenGenerator is a passive packet sink, and generates a configurable number of tokens into a token-based server when receiving a packet.

Packets are generated by an active packet source (ActivePacketSource), and pushed into the token generator (PacketBasedTokenGenerator). The generator generates tokens into a token-based server (TokenBasedServer). When the server has tokens, it pops packets from the connected packet provider (PassivePacketSource), and pushes them into a packet consumer (PassivePacketSink).

network PacketBasedTokenGeneratorTutorialStep
{
    @display("bgb=1000,250");
    submodules:
        producer: ActivePacketSource {
            @display("p=100,125");
        }
        provider: PassivePacketSource {
            @display("p=500,125");
        }
        server: TokenBasedServer {
            @display("p=700,125");
        }
        consumer: PassivePacketSink {
            @display("p=900,125");
        }
        tokenGenerator: PacketBasedTokenGenerator {
            @display("p=300,125");
            serverModule = "^.server";
        }
    connections allowunconnected:
        producer.out --> tokenGenerator.in;
        provider.out --> server.in;
        server.out --> consumer.in;
}
[Config PacketBasedTokenGenerator]
network = PacketBasedTokenGeneratorTutorialStep
sim-time-limit = 10s

*.provider.packetLength = 1B
*.producer.packetLength = 1B
*.producer.productionInterval = 1s