NetEmulation.PktLagMin
NetEmulation.PktLagMin
#Overview
name: NetEmulation.PktLagMin
This variable is created as a Console Variable (cvar).
- type:
Cmd
- help:
Sets minimum outgoing packet latency
It is referenced in 10
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of NetEmulation.PktLagMin is to set the minimum outgoing packet latency in a network emulation scenario. This setting is part of Unreal Engine’s network simulation system, which allows developers to test their games under various network conditions.
This setting variable is primarily used by the networking subsystem of Unreal Engine, specifically in the network emulation and packet simulation components. It’s referenced in the NetDriver, NetConnection, and related network emulation helper classes.
The value of this variable is typically set through configuration files (.ini), console commands, or programmatically in the engine’s network settings. It can be loaded from config files using the LoadConfig
function of FPacketSimulationSettings
.
NetEmulation.PktLagMin interacts with several other network simulation variables, particularly:
- PktLagMax: Sets the maximum outgoing packet latency.
- PktLag: Used for simulating a fixed network packet lag.
- PktLagVariance: Used to simulate variable network packet lag.
Developers should be aware that:
- PktLagMin is used in conjunction with PktLagMax to create a range of latency for outgoing packets.
- If PktLag is set, it takes precedence over PktLagMin and PktLagMax.
- The engine ensures that PktLagMin is always less than or equal to PktLagMax.
Best practices when using this variable include:
- Use it in combination with PktLagMax to simulate realistic network conditions.
- Ensure values are set appropriately for the network conditions you want to test.
- Be aware of how it interacts with other network simulation settings.
- Use the built-in console commands or configuration settings to adjust these values during runtime for testing.
Regarding the associated variable PktLagMin:
The purpose of PktLagMin is the same as NetEmulation.PktLagMin. It’s used in the same context and represents the minimum outgoing packet latency in the network simulation settings. This variable is typically used within the engine’s internal structures and classes, such as FPacketSimulationSettings and UNetDriver, to store and manage the minimum lag value for outgoing packets in the network simulation.
The same considerations, best practices, and interactions with other variables apply to PktLagMin as they do to NetEmulation.PktLagMin. They are essentially the same setting, just referenced in different contexts within the engine’s codebase.
#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:352
Scope (from outer to inner):
file
namespace UE::Net::Private::NetEmulationHelper
Source code excerpt:
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");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLoss, "Simulates incoming packet loss");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktJitter, "Simulates outgoing packet jitter");
#Associated Variable and Callsites
This variable is associated with another variable named PktLagMin
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Settings/LevelEditorPlayNetworkEmulationSettings.cpp:24
Scope (from outer to inner):
file
namespace NetworkEmulationSettingsHelper
function void ConvertNetDriverSettingsToLevelEditorSettings
Source code excerpt:
if (NetDriverSettings.PktLag > 0)
{
OutgoingTrafficPieSettings.MinLatency = FMath::Max(NetDriverSettings.PktLag - NetDriverSettings.PktLagVariance, 0);
OutgoingTrafficPieSettings.MaxLatency = FMath::Max(OutgoingTrafficPieSettings.MinLatency, NetDriverSettings.PktLag + NetDriverSettings.PktLagVariance); ;
}
else if (NetDriverSettings.PktLagMin > 0 || NetDriverSettings.PktLagMax > 0)
{
OutgoingTrafficPieSettings.MinLatency = NetDriverSettings.PktLagMin;
OutgoingTrafficPieSettings.MaxLatency = NetDriverSettings.PktLagMax;
}
OutgoingTrafficPieSettings.PacketLossPercentage = NetDriverSettings.PktLoss;
IncomingTrafficPieSettings.MinLatency = NetDriverSettings.PktIncomingLagMin;
IncomingTrafficPieSettings.MaxLatency = NetDriverSettings.PktIncomingLagMax;
IncomingTrafficPieSettings.PacketLossPercentage = NetDriverSettings.PktIncomingLoss;
}
FNetworkEmulationPacketSettings* GetPacketSettingsFromHandle(const TSharedPtr<IPropertyHandle>& PropertyHandle)
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Settings/LevelEditorPlayNetworkEmulationSettings.cpp:259
Scope (from outer to inner):
file
function void FLevelEditorPlayNetworkEmulationSettings::ConvertToNetDriverSettings
Source code excerpt:
}
if (IsCustomProfile() || !bProfileFound)
{
// For custom set the settings manually from the PIE variables
OutNetDriverSettings.PktLagMin = OutPackets.MinLatency;
OutNetDriverSettings.PktLagMax = OutPackets.MaxLatency;
OutNetDriverSettings.PktLoss = OutPackets.PacketLossPercentage;
OutNetDriverSettings.PktIncomingLagMin = InPackets.MinLatency;
OutNetDriverSettings.PktIncomingLagMax = InPackets.MaxLatency;
OutNetDriverSettings.PktIncomingLoss = InPackets.PacketLossPercentage;
}
}
FString FLevelEditorPlayNetworkEmulationSettings::BuildPacketSettingsForCmdLine() const
{
// Empty string when disabled
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:521
Scope: file
Source code excerpt:
/**
* If set lag values will randomly fluctuate between Min and Max.
* Ignored if PktLag value is set
*/
UPROPERTY(EditAnywhere, Category = "Simulation Settings")
int32 PktLagMin = 0;
UPROPERTY(EditAnywhere, Category = "Simulation Settings")
int32 PktLagMax = 0;
/**
* Set a value to add a minimum delay in milliseconds to incoming
* packets before they are processed.
*/
UPROPERTY(EditAnywhere, Category = "Simulation Settings")
int32 PktIncomingLagMin = 0;
/**
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:547
Scope: file
Source code excerpt:
*/
UPROPERTY(EditAnywhere, Category = "Simulation Settings")
int32 PktIncomingLoss = 0;
/**
* Causes sent packets to have a variable latency that fluctuates from [PktLagMin] to [PktLagMin+PktJitter]
* Note that this will cause packet loss on the receiving end.
*/
UPROPERTY(EditAnywhere, Category = "Simulation Settings")
int32 PktJitter = 0;
/** reads in settings from the .ini file
* @note: overwrites all previous settings
*/
ENGINE_API void LoadConfig(const TCHAR* OptionalQualifier = nullptr);
/**
* Load a preconfigured emulation profile from the .ini
* Returns true if the given profile existed
*/
#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");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLoss, "Simulates incoming packet loss");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktJitter, "Simulates outgoing packet jitter");
} // end namespace UE::Net::Private::NetEmulationHelper
#endif //#if DO_ENABLE_NET_TEST
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2329
Scope (from outer to inner):
file
function bool UNetConnection::CheckOutgoingPacketEmulation
Source code excerpt:
// In order to cause jitter, send one packet at min latency and the next packet at high latency
bool bIsLowLatency = (OutPacketId % 2) == 0;
if (bIsLowLatency)
{
// ExtraLag goes from [PktLagMin, PktLagMin+PktLagVariance]
const double LagVariance = 2.0f * (FMath::FRand() - 0.5f) * double(PacketSimulationSettings.PktLagVariance);
const double ExtraLag = (double(PacketSimulationSettings.PktLagMin) + LagVariance) / 1000.f;
B.SendTime = FPlatformTime::Seconds() + ExtraLag;
}
else
{
// ExtraLag goes from [PktLagMin+PktJitter, PktLagMin+PktJitter+PktLagVariance]
const double LagVariance = 2.0f * (FMath::FRand() - 0.5f) * double(PacketSimulationSettings.PktLagVariance);
const double ExtraLag = (double(PacketSimulationSettings.PktLagMin + PacketSimulationSettings.PktJitter) + LagVariance) / 1000.f;
B.SendTime = FPlatformTime::Seconds() + ExtraLag;
}
}
else if (PacketSimulationSettings.PktLag)
{
FDelayedPacket& B = *(new(Delayed)FDelayedPacket(SendBuffer.GetData(), SendBuffer.GetNumBits(), Traits));
// ExtraLag goes from PktLag + [-PktLagVariance, PktLagVariance]
const double LagVariance = 2.0f * (FMath::FRand() - 0.5f) * double(PacketSimulationSettings.PktLagVariance);
const double ExtraLag = (double(PacketSimulationSettings.PktLag) + LagVariance) / 1000.f;
B.SendTime = FPlatformTime::Seconds() + ExtraLag;
return true;
}
else if (PacketSimulationSettings.PktLagMin > 0 || PacketSimulationSettings.PktLagMax > 0)
{
FDelayedPacket& B = *(new(Delayed)FDelayedPacket(SendBuffer.GetData(), SendBuffer.GetNumBits(), Traits));
// ExtraLag goes from [PktLagMin, PktLagMax]
const double LagVariance = FMath::FRand() * double(PacketSimulationSettings.PktLagMax - PacketSimulationSettings.PktLagMin);
const double ExtraLag = (double(PacketSimulationSettings.PktLagMin) + LagVariance) / 1000.f;
B.SendTime = FPlatformTime::Seconds() + ExtraLag;
return true;
}
return false;
}
#endif
#if DO_ENABLE_NET_TEST
bool UNetConnection::ShouldDropOutgoingPacketForLossSimulation(int64 NumBits) const
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4462
Scope (from outer to inner):
file
function void FPacketSimulationSettings::LoadConfig
Source code excerpt:
PktOrder = int32(InPktOrder);
ConfigHelperInt(TEXT("PktLag"), PktLag, OptionalQualifier);
ConfigHelperInt(TEXT("PktLagVariance"), PktLagVariance, OptionalQualifier);
ConfigHelperInt(TEXT("PktLagMin"), PktLagMin, OptionalQualifier);
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);
ValidateSettings();
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4536
Scope (from outer to inner):
file
function void FPacketSimulationSettings::ValidateSettings
Source code excerpt:
PktLoss = FMath::Clamp<int32>(PktLoss, 0, 100);
PktOrder = FMath::Clamp<int32>(PktOrder, 0, 1);
PktLagMin = FMath::Max(PktLagMin, 0);
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
}
bool FPacketSimulationSettings::ConfigHelperInt(const TCHAR* Name, int32& Value, const TCHAR* OptionalQualifier)
{
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4639
Scope (from outer to inner):
file
function bool FPacketSimulationSettings::ParseSettings
Source code excerpt:
if (ParseHelper(Cmd, TEXT("PktLagVariance="), PktLagVariance, OptionalQualifier))
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktLagVariance set to %d"), PktLagVariance);
}
if (ParseHelper(Cmd, TEXT("PktLagMin="), PktLagMin, OptionalQualifier))
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktLagMin set to %d"), PktLagMin);
}
if (ParseHelper(Cmd, TEXT("PktLagMax="), PktLagMax, OptionalQualifier))
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktLagMax set to %d"), PktLagMax);
}
if (ParseHelper(Cmd, TEXT("PktIncomingLagMin="), PktIncomingLagMin, OptionalQualifier))
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktIncomingLagMin set to %d"), PktIncomingLagMin);
}