MCPcopy Create free account
hub / github.com/ValveSoftware/GameNetworkingSockets / TestNetworkConditions

Function TestNetworkConditions

tests/test_connection.cpp:366–496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364}
365
366static void TestNetworkConditions( int rate, float loss, int lag, float reorderPct, int reorderLag, bool bActLikeGame, ETestConnectionMode eMode )
367{
368 ISteamNetworkingSockets *pSteamSocketNetworking = SteamNetworkingSockets();
369
370 #ifdef _DEBUG
371 rate = std::min( 750000, rate*2/3 );
372 #endif
373
374 TEST_Printf( "---------------------------------------------------\n" );
375 TEST_Printf( "NETWORK CONDITIONS\n" );
376 TEST_Printf( "Rate . . . . . . : %d Bps\n", rate );
377 TEST_Printf( "Loss . . . . . . : %g%%\n", loss );
378 TEST_Printf( "Ping . . . . . . : %d\n", lag*2 );
379 TEST_Printf( "Reorder. . . . . : %g%% @ %dms\n", reorderPct, reorderLag );
380 TEST_Printf( "Act like game. . : %d\n", (int)bActLikeGame );
381 TEST_Printf( "---------------------------------------------------\n" );
382
383 SteamNetworkingUtils()->SetGlobalConfigValueInt32( k_ESteamNetworkingConfig_SendRateMin, rate );
384 SteamNetworkingUtils()->SetGlobalConfigValueInt32( k_ESteamNetworkingConfig_SendRateMax, rate );
385
386 SteamNetworkingUtils()->SetGlobalConfigValueFloat( k_ESteamNetworkingConfig_FakePacketLoss_Send, loss );
387 SteamNetworkingUtils()->SetGlobalConfigValueFloat( k_ESteamNetworkingConfig_FakePacketLoss_Recv, 0 );
388 SteamNetworkingUtils()->SetGlobalConfigValueInt32( k_ESteamNetworkingConfig_FakePacketLag_Send, lag );
389 SteamNetworkingUtils()->SetGlobalConfigValueInt32( k_ESteamNetworkingConfig_FakePacketLag_Recv, 0 );
390 SteamNetworkingUtils()->SetGlobalConfigValueFloat( k_ESteamNetworkingConfig_FakePacketReorder_Send, reorderPct );
391 SteamNetworkingUtils()->SetGlobalConfigValueInt32( k_ESteamNetworkingConfig_FakePacketReorder_Time, reorderLag );
392
393 SteamNetworkingMicroseconds usecWhenStarted = SteamNetworkingUtils()->GetLocalTimestamp();
394
395 struct Timing { double flQuietSec; double flActiveSec; float flPrintIntervalSec; int nIterations; };
396 static const Timing k_timing[] = {
397 { 0.5, 2.0, 1.0f, 1 }, // Cursory
398 { 1.0, 5.0, 2.0f, 2 }, // Normal
399 { 8.0, 25.0, 5.0f, 4 }, // Soak
400 };
401 const Timing &timing = k_timing[ (int)eMode ];
402
403 SteamNetworkingMicroseconds usecQuietDuration = SteamNetworkingMicroseconds( timing.flQuietSec * 1e6 );
404 SteamNetworkingMicroseconds usecActiveDuration = SteamNetworkingMicroseconds( timing.flActiveSec * 1e6 );
405 float flWaitBetweenPrints = timing.flPrintIntervalSec;
406 int nIterations = timing.nIterations;
407
408 bool bQuiet = true;
409 SteamNetworkingMicroseconds usecWhenStateEnd = 0;
410 SteamNetworkingMicroseconds usecLastPrint = SteamNetworkingUtils()->GetLocalTimestamp();
411
412 while ( true )
413 {
414 SteamNetworkingMicroseconds now = SteamNetworkingUtils()->GetLocalTimestamp();
415 g_usecTestElapsed = now - usecWhenStarted;
416 // If flElapsed > 1.0 when in debug, just slamp it
417 //if ( Plat_IsInDebugSession() && now - flLastNow > 1.0f )
418 //{
419 // flStartTime += now - flLastNow - 1.0f;
420 // flElapsed = now - flStartTime;
421 //}
422 //usecLastNow = now;
423

Callers 2

Test_ConnectionFunction · 0.85
Test_pipeFunction · 0.85

Calls 14

SteamNetworkingSocketsFunction · 0.85
TEST_PrintfFunction · 0.85
SteamNetworkingUtilsFunction · 0.85
PrintStatusFunction · 0.85
RecvFunction · 0.85
GetLocalTimestampMethod · 0.80
UpdateStatsMethod · 0.80
GetQueuedSendBytesMethod · 0.80
SendRandomMessageMethod · 0.80

Tested by

no test coverage detected