Table Of Contents
Table Of Contents

Storing Packets on Behalf of Multiple Queues

The PacketBuffer module stores packets on behalf of multiple queues, acting as a shared buffer for them. Instead of each individual queue having a separate capacity, the whole group of queues has a global, shared capacity, represented by the buffer. The buffer keeps a record of which packets belong to which queue, and also maintains the order of packets.

In this example network, packets are produced at random intervals by two active packet sources (ActivePacketSource). Each packet source pushes packets into its associated queue (PacketQueue). The two queues share a packet buffer module (PacketBuffer). The buffer is configured to have a capacity of 2 packets. Packets are popped from the queues by two active packet sinks (ActivePacketSink). Since the buffer has a limited packet capacity, and the PacketAtCollectionBeginDropper function is used as the dropper function, the buffer drops packets from the beginning of the buffer when it gets overloaded.

../../../_images/Buffer.png
network BufferTutorialStep
{
    submodules:
        buffer: PacketBuffer {
            @display("p=125,350");
        }
        producer1: ActivePacketSource {
            @display("p=125,100");
        }
        producer2: ActivePacketSource {
            @display("p=125,225");
        }
        queue1: PacketQueue {
            @display("p=350,100");
            bufferModule = "^.buffer";
        }
        queue2: PacketQueue {
            @display("p=350,225");
            bufferModule = "^.buffer";
        }
        collector1: ActivePacketSink {
            @display("p=575,100");
        }
        collector2: ActivePacketSink {
            @display("p=575,225");
        }
    connections:
        producer1.out --> queue1.in;
        queue1.out --> collector1.in;
        producer2.out --> queue2.in;
        queue2.out --> collector2.in;
}
[Config Buffer]
network = BufferTutorialStep
sim-time-limit = 10s

*.buffer.dropperClass = "inet::queueing::PacketAtCollectionBeginDropper"
*.producer*.packetLength = 1B
*.producer*.productionInterval = uniform(0s, 1s)
*.collector*.collectionInterval = uniform(0s, 2s)
*.buffer.packetCapacity = 2