Table Of Contents
Table Of Contents

Ordering the Packets in the Queue

The PacketQueue module can order the packets it contains using a packet comparator function, which makes it suitable for implementing priority queueing. (Other ways of implementing priority queueing, for example using PriorityScheduler, will be covered in later steps.)

In this example network, an active packet source (ActivePacketSource) creates 1-byte packets every second with a random byte as content. The packets are pushed into a queue (PacketQueue). The queue is configured to use the PacketDataComparator function, which orders packets by data. The packets are popped from the queue by an active packet sink (ActivePacketSink) every 2 seconds.

During simulation, the producer creates packets more frequently than the collector pops them from the queue, so packets accumulate in the queue. When this happens, packets will be ordered in the queue, so the collector will receive a series of ordered sequences.

../../../_images/Comparator.png
network ComparatorTutorialStep
{
    @display("bgb=600,200");
    submodules:
        producer: ActivePacketSource {
            @display("p=100,100");
        }
        queue: PacketQueue {
            @display("p=300,100");
        }
        collector: ActivePacketSink {
            @display("p=500,100");
        }
    connections allowunconnected:
        producer.out --> queue.in;
        queue.out --> collector.in;
}
[Config Comparator]
network = ComparatorTutorialStep
sim-time-limit = 10s

*.producer.packetLength = 1B
*.producer.packetData = intuniform(0,255)
*.producer.productionInterval = 1s
*.collector.collectionInterval = 2s
*.queue.comparatorClass = "inet::queueing::PacketDataComparator"

The following screenshot demonstrates the queue’s contents at the end of the simulation without the comparator function:

../../../_images/nocomparator.png

And this one using the comparator function (head at the top, tail at the bottom):

../../../_images/withcomparator.png