Hi,
you don't "solve" this, you "cope with it".
Let me explain. UDP is based on IP, and IP doesn't provide any guarantee on anything. In particular it's not guaranteed:
- The packet delivery (IP does its best and that's it)
- The packet duplication (packets may arrive duplicated)
- Packet ordering (packets may arrive out of order)
UDP offers little or nothing more than raw IP, just the port demultiplexing and a (weak) data protection through a checksum.
As a consequence, you have to assume that packets may be lost, duplicated and disordered.
About why ns-3 disorder them... it's simple: nothing is done to prevent this. In the specific case, the disordering may be due to a number of reasons, including the NetDevice and its internal buffers.
How to "cope with it". That's not simple. You can use the same method VoIP uses, as is add a header providing sequence numbers. In the application you'll have to reorder the chunks, trash the duplicates and (eventually) request the retransmission of lost chunks.
Mind that this is perfectly normal, VoIP does it, NFS does it... basically all the protocols based on UDP do that.
Hope this helps,
T.