10% packet loss · ACK-based retransmission · Timeout handling
Network LayerData Link LayerPDU EncapsulationRetransmissionOMNeT++ Simulation
Overview
This post presents the corrected solution for the OMNeT++ Layered Architecture Lab — implementing a two-layer (Network Layer + Data Link Layer) simulation with 10% packet loss, ACK-based retransmission, and timeout handling.
Task Summary
a
Network Layer: Define number of packets as a state variable using par()
b
Data Link Layer: Simulate 10% packet loss at the destination
c
Data Link Layer: Retransmit on timeout; reset timeout after each transmission; cancel on ACK
Bugs Fixed — Summary
✓ 10% loss fix✓ decapsulate() memory leak✓ ACK leak on drop✓ copy_message nullptr✓ old copy_message deleted✓ self-event leak fixed✓ unused cGate* in removed
#
Bug
Wrong Code
Fixed Code
1
Packet loss % wrong
uniform(0,1) <= 0.8 → 80% drop
uniform(0,1) < 0.1 → 10% drop
2
decapsulate() memory leak
Return value ignored; outer wrapper sent
inner = decapsulate(); send inner; delete outer
3
ACK leak in drop case
ACK created but never deleted on drop
ACK created only when packet is accepted
4
copy_message garbage init
copy_message = new Dll_pkt() — empty packet
copy_message = nullptr with null-check guard
5
Old copy_message not deleted
Memory leak on every new packet
delete copy_message before storing new one
6
Self-event not deleted (NL)
cMessage event leaked after use
delete msg after every self-message
7
Unused variable cGate* in
Declared in nl_node.h but never used
Removed from header and .cc file
How to Run in OMNeT++
1
Create a new OMNeT++ project and add all files above.
2
Compile packets.msg first — it auto-generates nl_pkt_m.h and dll_pkt_m.h.
3
Build the project and run with omnetpp.ini.
4
Open the Event Log to see packet flow, ACKs, timeouts, and retransmissions.
No comments: