Generating Tokens Based on Received Signals¶
The SignalBasedTokenGenerator module generates tokens into a token-based server when receiving signals.
In this example network, packets are generated by a passive packet source (PassivePacketSource).
A token-based server (TokenBasedServer) pops packet from a passive packet source
(PassivePacketSource) when it has tokens, and pushes them into a passive packet sink (PassivePacketSink).
The token generator is subscribed to the packetDropped
signal of the consumer,
and generates a token whenever the signal is emitted. The provider has a configured providing interval of 1s.
Setting a providing interval is necessary because otherwise (if the provider could generate packets any time),
an infinite amount of packets would be generated and dropped in zero simulation time, resulting in an error.
network SignalBasedTokenGeneratorTutorialStep
{
@display("bgb=600,350");
submodules:
provider: PassivePacketSource {
@display("p=100,125");
}
server: TokenBasedServer {
@display("p=300,125");
}
consumer: PassivePacketSink {
@display("p=500,125");
}
tokenGenerator: SignalBasedTokenGenerator {
@display("p=100,250");
signals = "packetDropped";
subscriptionModule = "^.consumer";
storageModule = "^.server";
}
connections allowunconnected:
provider.out --> server.in;
server.out --> consumer.in;
}
[Config SignalBasedTokenGenerator]
network = SignalBasedTokenGeneratorTutorialStep
sim-time-limit = 10s
*.provider.packetLength = 1B
*.provider.providingInterval = 1s
*.server.initialNumTokens = 1