NetEmulation.PktDup
NetEmulation.PktDup
#Overview
name: NetEmulation.PktDup
This variable is created as a Console Variable (cvar).
- type:
Cmd
- help:
Simulates sending/receiving duplicate network packets
It is referenced in 7
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of NetEmulation.PktDup is to simulate network packet duplication in Unreal Engine’s networking system. This setting is used for network emulation and testing purposes, allowing developers to simulate real-world network conditions where packets may be duplicated during transmission.
NetEmulation.PktDup is primarily used by the networking subsystem of Unreal Engine, specifically within the NetDriver and NetConnection modules. These modules are responsible for managing network connections and packet handling in multiplayer games and networked applications.
The value of this variable is set in several ways:
- It can be configured through the engine’s configuration files.
- It can be modified at runtime using console commands.
- It can be set programmatically through the FPacketSimulationSettings struct.
The associated variable PktDup interacts directly with NetEmulation.PktDup. They share the same value and purpose. PktDup is the actual property within the FPacketSimulationSettings struct that controls packet duplication.
Developers must be aware of the following when using this variable:
- The value is clamped between 0 and 100, representing a percentage of packets to be duplicated.
- It cannot be used simultaneously with PktOrder or PktLag settings.
- Using this setting will impact network performance and should only be used for testing and debugging purposes.
Best practices when using this variable include:
- Use it only in development or testing environments, never in production.
- Start with low values and gradually increase to observe the impact on your application.
- Always reset the value to 0 after testing to ensure normal network behavior.
- Use in conjunction with other network emulation settings to simulate complex network conditions.
Regarding the associated variable PktDup: The purpose of PktDup is identical to NetEmulation.PktDup. It’s the actual property within the FPacketSimulationSettings struct that controls packet duplication.
PktDup is used directly in the networking subsystem, particularly in the NetConnection and NetDriver classes. It’s checked during packet sending to determine if a packet should be duplicated.
The value of PktDup can be set through configuration files, console commands, or programmatically. It’s loaded from config files in the LoadConfig function and can be modified at runtime.
PktDup interacts with other network simulation settings but takes precedence over PktLag. However, it cannot be used with PktOrder.
Developers should be aware that PktDup is clamped between 0 and 100 in the ValidateSettings function, ensuring it always represents a valid percentage.
Best practices for PktDup are the same as for NetEmulation.PktDup, focusing on careful use in testing environments and resetting to 0 when not actively testing network conditions.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetEmulationHelper.cpp:349
Scope (from outer to inner):
file
namespace UE::Net::Private::NetEmulationHelper
Source code excerpt:
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLoss, "Simulates network packet loss");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktOrder, "Simulates network packets received out of order");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktDup, "Simulates sending/receiving duplicate network packets");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLag, "Simulates network packet lag");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLagVariance, "Simulates variable network packet lag");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLagMin, "Sets minimum outgoing packet latency");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLagMax, "Sets maximum outgoing packet latency)");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLagMin, "Sets minimum incoming packet latency");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLagMax, "Sets maximum incoming packet latency");
#Associated Variable and Callsites
This variable is associated with another variable named PktDup
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:485
Scope: file
Source code excerpt:
* This works by randomly selecting packets to be delayed until a subsequent call to FlushNet.
*
* Takes precedence over PktDup and PktLag.
*/
UPROPERTY(EditAnywhere, Category="Simulation Settings")
int32 PktOrder = 0;
/**
* When set, will cause calls to FlushNet to duplicate packets.
* Value is treated as % of packets duplicated (i.e. 0 = None, 100 = All).
* No general pattern / ordering is guaranteed.
* Clamped between 0 and 100.
*
* Cannot be used with PktOrder or PktLag.
*/
UPROPERTY(EditAnywhere, Category="Simulation Settings")
int32 PktDup = 0;
/**
* When set, will cause calls to FlushNet to delay packets.
* Value is treated as millisecond lag.
*
* Cannot be used with PktOrder.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetEmulationHelper.cpp:349
Scope (from outer to inner):
file
namespace UE::Net::Private::NetEmulationHelper
Source code excerpt:
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLoss, "Simulates network packet loss");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktOrder, "Simulates network packets received out of order");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktDup, "Simulates sending/receiving duplicate network packets");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLag, "Simulates network packet lag");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLagVariance, "Simulates variable network packet lag");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLagMin, "Sets minimum outgoing packet latency");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLagMax, "Sets maximum outgoing packet latency)");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLagMin, "Sets minimum incoming packet latency");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLagMax, "Sets maximum incoming packet latency");
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2214
Scope: file
Source code excerpt:
}
#if DO_ENABLE_NET_TEST
if (PacketSimulationSettings.PktDup && FMath::FRand() * 100.f < PacketSimulationSettings.PktDup)
{
// Checked in FlushNet() so each child class doesn't have to implement this
if (Driver->IsNetResourceValid())
{
LowLevelSend((char*) SendBuffer.GetData(), SendBuffer.GetNumBits(), Traits);
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4468
Scope (from outer to inner):
file
function void FPacketSimulationSettings::LoadConfig
Source code excerpt:
ConfigHelperInt(TEXT("PktLagMax"), PktLagMax, OptionalQualifier);
ConfigHelperInt(TEXT("PktDup"), PktDup, OptionalQualifier);
ConfigHelperInt(TEXT("PktIncomingLagMin"), PktIncomingLagMin, OptionalQualifier);
ConfigHelperInt(TEXT("PktIncomingLagMax"), PktIncomingLagMax, OptionalQualifier);
ConfigHelperInt(TEXT("PktIncomingLoss"), PktIncomingLoss, OptionalQualifier);
ConfigHelperInt(TEXT("PktJitter"), PktJitter, OptionalQualifier);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4542
Scope (from outer to inner):
file
function void FPacketSimulationSettings::ValidateSettings
Source code excerpt:
PktLagMax = FMath::Max(PktLagMin, PktLagMax);
PktDup = FMath::Clamp<int32>(PktDup, 0, 100);
PktIncomingLagMin = FMath::Max(PktIncomingLagMin, 0);
PktIncomingLagMax = FMath::Max(PktIncomingLagMin, PktIncomingLagMax);
PktIncomingLoss = FMath::Clamp<int32>(PktIncomingLoss, 0, 100);
#endif
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4632
Scope (from outer to inner):
file
function bool FPacketSimulationSettings::ParseSettings
Source code excerpt:
UE_LOG(LogNet, Log, TEXT("PktLag set to %d"), PktLag);
}
if( ParseHelper(Cmd, TEXT("PktDup="), PktDup, OptionalQualifier) )
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktDup set to %d"), PktDup);
}
if (ParseHelper(Cmd, TEXT("PktLagVariance="), PktLagVariance, OptionalQualifier))
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktLagVariance set to %d"), PktLagVariance);
}