5.8. Debug Support - Packet Loss Emulation

Description

PiaTransport comes with a packet loss emulation feature. The packet loss emulation feature creates a pseudo-environment mimicking a poor network environment by intentionally generating packet loss that occurs in communication.

Internal Operation

When the packet loss emulation feature is enabled, the PiaTransport send and receive threads drop packets based on random values. On the thread for sending, the dropped packet will not be delivered on the network and will be destroyed. On the thread for receiving, the dropped packet will not be delivered to the receive function of each communication protocol and will be destroyed.

Packet Loss Settings

Specify packet loss emulation behavior by setting the member variables of the transport::Transport::DebugSetting structure, and then call the transport::Transport::SetDebugSetting() function.

Code 5-32. Enabling the Packet Loss Emulation Feature
// Set the parameters to the member variables of the Transport::DebugSetting structure.
nn::pia::transport::Transport::DebugSetting debugSetting;
debugSetting.sendThreadLatencyEmulationPacketNum = 0; // The latency emulation feature is not used here.
debugSetting.receiveThreadLatencyEmulationPacketNum = 0; // The latency emulation feature is not used here.
debugSetting.bPacketLossEmulation = true; // Enable the packet loss emulation feature.


// When you use the Transport::SetDebugSetting() function for its debugging features, you must call it before calling the Transport::CreateInstance() function.
nn::pia::transport::Transport::SetDebugSetting(debugSetting);

 
// Set the appropriate values in each of the setting member variables.
nn::pia::transport::Transport::Setting setting;
...
...
 
// Create a Transport class instance.
nn::pia::transport::Transport::GetInstance()->CreateInstance(setting);

In the packet loss emulation feature, the sending end and receiving end are independent, and the respective packet loss rates can be set.

Code 5-33. Packet Loss Rate Settings
nn::pia::transport::ThreadStreamManager* pMgr = nn::pia::transport::ThreadStreamManager::GetInstance();
PIA_SAMPLE_ASSERT(PIA_IS_VALID_POINTER(pMgr));
pMgr->SetSendThreadPacketLossRatio(5); // Set the packet loss rate to 5% on the sending end.
pMgr->SetReceiveThreadPacketLossRatio(5); // Set the packet loss rate to 5% on the receiving end.