Table Of Contents
Table Of Contents

Generating Tokens When a Queue Becomes Empty

The QueueBasedTokenGenerator module generates tokens into a token-based server when an observed queue becomes empty. The module can be used by applications to create traffic that completely utilizes a network interface, for example.

In this example network, packets are generated by a passive packet source (PassivePacketSource). A token-based server (TokenBasedServer) pops packets from the source when it has enough tokens. Then it pushes packets into the connected queue (PacketQueue). Packets are collected from the queue by an active packet sink (ActivePacketSink). Tokens are generated by a QueueBasedTokenGenerator, which observes the queue, and generates a token whenever the queue is empty.

../../../_images/QueueBasedTokenGenerator.png
network QueueBasedTokenGeneratorTutorialStep
{
    @display("bgb=875,350");
    submodules:
        provider: PassivePacketSource {
            @display("p=100,125");
        }
        server: TokenBasedServer {
            @display("p=325,125");
        }
        queue: PacketQueue {
            @display("p=550,125");
        }
        collector: ActivePacketSink {
            @display("p=775,125");
        }
        tokenGenerator: QueueBasedTokenGenerator {
            @display("p=100,250");
            storageModule = "^.server";
            queueModule = "^.queue";
        }
    connections allowunconnected:
        provider.out --> server.in;
        server.out --> queue.in;
        queue.out --> collector.in;
}
[Config QueueBasedTokenGenerator]
network = QueueBasedTokenGeneratorTutorialStep
sim-time-limit = 10s

*.provider.packetLength = 1B
*.collector.collectionInterval = 1s