NetEmulation.PktLagVariance

NetEmulation.PktLagVariance

#Overview

name: NetEmulation.PktLagVariance

This variable is created as a Console Variable (cvar).

It is referenced in 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of NetEmulation.PktLagVariance is to simulate variable network packet lag in Unreal Engine’s networking system. This setting is part of the network emulation features used for testing and debugging network-related issues in game development.

NetEmulation.PktLagVariance is primarily used by the networking subsystem of Unreal Engine, specifically within the NetDriver and NetConnection modules. These modules handle network communication and packet management.

The value of this variable is typically set through configuration files, console commands, or programmatically. It can be loaded from config files using the LoadConfig function in the FPacketSimulationSettings class, or set via console commands as seen in the NetEmulationHelper namespace.

This variable interacts closely with other network emulation settings, such as PktLag, PktLagMin, and PktLagMax. It’s used to calculate the variance in packet lag, adding randomness to the simulated network conditions.

Developers must be aware that this setting is for testing and debugging purposes only and should not be used in production builds. It’s important to understand that adjusting this value will affect the simulated network performance and may not accurately represent real-world conditions.

Best practices when using this variable include:

  1. Use it in conjunction with other network emulation settings for comprehensive testing.
  2. Test with various values to simulate different network conditions.
  3. Remember to disable or reset this setting before building for production.
  4. Document the values used during testing for reproducibility.

Regarding the associated variable PktLagVariance, it appears to be the same variable used in different contexts within the engine. It serves the same purpose as NetEmulation.PktLagVariance, being used to calculate packet lag variance in network simulations. The usage and best practices remain the same as described above.

#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:351

Scope (from outer to inner):

file
namespace    UE::Net::Private::NetEmulationHelper

Source code excerpt:

	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");

#Associated Variable and Callsites

This variable is associated with another variable named PktLagVariance. 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;
		}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:517

Scope: file

Source code excerpt:

	 */
	UPROPERTY(EditAnywhere, Category="Simulation Settings")
	int32	PktLagVariance = 0;

	/**
	 * If set lag values will randomly fluctuate between Min and Max.
	 * Ignored if PktLag value is set
	 */
	UPROPERTY(EditAnywhere, Category = "Simulation Settings")

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetEmulationHelper.cpp:351

Scope (from outer to inner):

file
namespace    UE::Net::Private::NetEmulationHelper

Source code excerpt:

	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");

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2332

Scope (from outer to inner):

file
function     bool UNetConnection::CheckOutgoingPacketEmulation

Source code excerpt:

		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;

	}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4463

Scope (from outer to inner):

file
function     void FPacketSimulationSettings::LoadConfig

Source code excerpt:

	
	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);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4637

Scope (from outer to inner):

file
function     bool FPacketSimulationSettings::ParseSettings

Source code excerpt:

		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);
	}
	if (ParseHelper(Cmd, TEXT("PktLagMin="), PktLagMin, OptionalQualifier))
	{
		bParsed = true;
		UE_LOG(LogNet, Log, TEXT("PktLagMin set to %d"), PktLagMin);
	}