Skip to content

Commit

Permalink
Merge pull request #29 from o3de/stabilization/2210
Browse files Browse the repository at this point in the history
Merge stabilization/2210 into main
Signed-off-by: Alex Peterson <[email protected]>
  • Loading branch information
AMZN-alexpete authored Oct 11, 2022
2 parents 13a3e5b + 8cff785 commit 19bcf79
Show file tree
Hide file tree
Showing 25 changed files with 257 additions and 91 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
_savebackup/
_savebackup/
.mayaSwatches/
*.swatches
[Bb]uild/
[Cc]ache/
[Uu]ser/
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ endfunction()

if(NOT PROJECT_NAME)
cmake_minimum_required(VERSION 3.19)
include(cmake/CompilerSettings.cmake)
project(NetSoakTest
LANGUAGES C CXX
VERSION 1.0.0.0
)
include(EngineFinder.cmake OPTIONAL)
include(cmake/EngineFinder.cmake OPTIONAL)
find_package(o3de REQUIRED)
o3de_initialize()
add_vs_debugger_arguments()
Expand Down
53 changes: 0 additions & 53 deletions EngineFinder.cmake

This file was deleted.

58 changes: 42 additions & 16 deletions Gem/Code/Source/NetSoakTestSystemComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#include "NetSoakTestSystemComponent.h"

#include <AzFramework/API/ApplicationAPI.h>
#include <AzFramework/Windowing/WindowBus.h>

namespace AzNetworking
{
enum class SoakMode
Expand All @@ -26,14 +29,12 @@ namespace AzNetworking

namespace AZ::ConsoleTypeHelpers
{
template <>
inline CVarFixedString ValueToString(const AzNetworking::ProtocolType& value)
{
return (value == AzNetworking::ProtocolType::Tcp) ? "tcp" : "udp";
}

template <>
inline bool StringSetToValue<AzNetworking::ProtocolType>(AzNetworking::ProtocolType& outValue, const ConsoleCommandContainer& arguments)
inline bool StringSetToValue(AzNetworking::ProtocolType& outValue, const ConsoleCommandContainer& arguments)
{
if (!arguments.empty())
{
Expand All @@ -51,7 +52,6 @@ namespace AZ::ConsoleTypeHelpers
return false;
}

template <>
inline CVarFixedString ValueToString(const AzNetworking::SoakMode& value)
{
if (value == AzNetworking::SoakMode::Client)
Expand All @@ -65,8 +65,7 @@ namespace AZ::ConsoleTypeHelpers
return "loopback";
}

template <>
inline bool StringSetToValue<AzNetworking::SoakMode>(AzNetworking::SoakMode& outValue, const ConsoleCommandContainer& arguments)
inline bool StringSetToValue(AzNetworking::SoakMode& outValue, const ConsoleCommandContainer& arguments)
{
if (!arguments.empty())
{
Expand All @@ -93,17 +92,18 @@ namespace NetSoakTest
static const AZStd::string_view s_networkInterfaceName("NetSoakNetworkInterface");
static const AZStd::string_view s_loopbackInterfaceName("NetSoakLoopbackInterface");

AZ_CVAR(AZ::TimeMs, soak_latencyms, AZ::TimeMs(0), nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Simulated connection quality latency");
AZ_CVAR(AZ::TimeMs, soak_variancems, AZ::TimeMs(0), nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Simulated connection quality variance");
AZ_CVAR(AZ::TimeMs, soak_latencyms, AZ::Time::ZeroTimeMs, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Simulated connection quality latency");
AZ_CVAR(AZ::TimeMs, soak_variancems, AZ::Time::ZeroTimeMs, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Simulated connection quality variance");
AZ_CVAR(uint16_t, soak_losspercentage, 0, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Simulated connection quality packet drop rate");
AZ_CVAR(AZ::CVarFixedString, soak_serveraddr, AZ::CVarFixedString("127.0.0.1"), nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "The address of the server or host to connect to");
AZ_CVAR(uint16_t, soak_port, 33450, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "The port that this soak test will bind to for game traffic");
AZ_CVAR(ProtocolType, soak_protocol, ProtocolType::Udp, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Soak test protocol");
AZ_CVAR(SoakMode, soak_mode, SoakMode::Loopback, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Soak test mode");
AZ_CVAR(AZ::TimeMs, soak_runtimems, AZ::Time::ZeroTimeMs, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "How long to run (milliseconds) the soak test for before dumping stats. Defaults to running forever.");

void NetSoakTestSystemComponent::Reflect(AZ::ReflectContext* context)
{
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
if (auto serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<NetSoakTestSystemComponent, AZ::Component>()
->Version(0)
Expand Down Expand Up @@ -169,23 +169,51 @@ namespace NetSoakTest
{
AZ::TickBus::Handler::BusDisconnect();
NetSoakTestRequestBus::Handler::BusDisconnect();

AZ::Interface<INetworking>::Get()->DestroyNetworkInterface(AZ::Name(s_loopbackInterfaceName));
AZ::Interface<INetworking>::Get()->DestroyNetworkInterface(AZ::Name(s_networkInterfaceName));
}

void NetSoakTestSystemComponent::OnTick(float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
bool NetSoakTestSystemComponent::CheckforTimedTermination()
{
[[maybe_unused]] AZ::TimeMs elapsedMs = aznumeric_cast<AZ::TimeMs>(aznumeric_cast<int64_t>(deltaTime / 1000.0f));
// Check to see if test should terminate early if running in timed mode
if (soak_runtimems != AZ::Time::ZeroTimeMs)
{
if (m_soakEndTimepointMs == AZ::Time::ZeroTimeMs)
{
m_soakEndTimepointMs = AZ::GetRealElapsedTimeMs() + soak_runtimems;
}
else if (AZ::GetRealElapsedTimeMs() >= m_soakEndTimepointMs)
{
return true;
}

}
return false;
}

void NetSoakTestSystemComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
{
if (CheckforTimedTermination())
{
AZLOG_INFO("Completed timed run for %.2f seconds", AZ::TimeMsToSeconds(soak_runtimems));
AZ::Interface<AZ::IConsole>::Get()->PerformCommand("DumpSoakStats");

AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::ExitMainLoop);
return;
}

NetSoakTestPackets::Small packet;

auto visitor = [&packet](IConnection& connection)
{
connection.SendReliablePacket(packet);

uint32_t rand_int = rand();
const uint32_t rand_int = rand();
if (rand_int % 10 == 1)
{
NetSoakTest::TestNetworkBuffer buffer = NetSoakTest::TestNetworkBuffer(NetSoakTest::MassiveBuffer);
NetSoakTestPackets::Large* large = new NetSoakTestPackets::Large(buffer);
const NetSoakTestPackets::Large* large = new NetSoakTestPackets::Large(buffer);
connection.SendReliablePacket(*large);
delete large;
}
Expand All @@ -196,7 +224,6 @@ namespace NetSoakTest
unreliable.SetSmallDatum(2);
connection.SendUnreliablePacket(unreliable);
}

};

m_networkInterface->GetConnectionSet().VisitConnections(visitor);
Expand Down Expand Up @@ -256,7 +283,6 @@ namespace NetSoakTest

void NetSoakTestSystemComponent::OnPacketLost([[maybe_unused]] IConnection* connection, [[maybe_unused]] PacketId packetId)
{
;
}

void NetSoakTestSystemComponent::OnDisconnect(IConnection* connection, [[maybe_unused]] DisconnectReason reason, [[maybe_unused]] AzNetworking::TerminationEndpoint endpoint)
Expand All @@ -270,7 +296,7 @@ namespace NetSoakTest
networkInterfaces.push_back(AZ::Interface<INetworking>::Get()->RetrieveNetworkInterface(AZ::Name(s_networkInterfaceName)));
networkInterfaces.push_back(AZ::Interface<INetworking>::Get()->RetrieveNetworkInterface(AZ::Name(s_loopbackInterfaceName)));

for (auto& networkInterface : networkInterfaces)
for (const auto& networkInterface : networkInterfaces)
{
const char* protocol = networkInterface->GetType() == ProtocolType::Tcp ? "Tcp" : "Udp";
const char* trustZone = networkInterface->GetTrustZone() == TrustZone::ExternalClientToServer ? "ExternalClientToServer" : "InternalServerToServer";
Expand Down
3 changes: 3 additions & 0 deletions Gem/Code/Source/NetSoakTestSystemComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ namespace NetSoakTest
////////////////////////////////////////////////////////////////////////

private:
bool CheckforTimedTermination();

AzNetworking::INetworkInterface* m_networkInterface = nullptr;
AzNetworking::INetworkInterface* m_loopbackInterface = nullptr;
AZ::TimeMs m_soakEndTimepointMs = AZ::Time::ZeroTimeMs;
};
}
2 changes: 1 addition & 1 deletion Gem/Code/Source/NetSoakTestTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace NetSoakTest
constexpr char hexchar[] = "0123456789ABCDEF";

TestNetworkBuffer rBuffer;
for (int i = 0; i < TestSize; ++i)
for (size_t i = 0; i < TestSize; ++i)
{
rBuffer.append(1, hexchar[i % (sizeof(hexchar) - 1)]);
}
Expand Down
3 changes: 0 additions & 3 deletions Gem/Resources/CryEngineLogoLauncher.bmp

This file was deleted.

4 changes: 2 additions & 2 deletions Gem/Resources/GameSDK.ico
Git LFS file not shown
3 changes: 3 additions & 0 deletions Gem/Resources/LegacyLogoLauncher.bmp
Git LFS file not shown
6 changes: 6 additions & 0 deletions Platform/Android/android_project.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#

9 changes: 9 additions & 0 deletions Platform/Android/android_project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Tags": ["Android"],
"android_settings" : {
"package_name" : "org.o3de.NetSoakTest",
"version_number" : 1,
"version_name" : "1.0.0.0",
"orientation" : "landscape"
}
}
6 changes: 6 additions & 0 deletions Platform/Linux/linux_project.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#

3 changes: 3 additions & 0 deletions Platform/Linux/linux_project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Tags": ["Linux"]
}
6 changes: 6 additions & 0 deletions Platform/Mac/mac_project.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#

3 changes: 3 additions & 0 deletions Platform/Mac/mac_project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Tags": ["Mac"]
}
6 changes: 6 additions & 0 deletions Platform/Windows/windows_project.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#

3 changes: 3 additions & 0 deletions Platform/Windows/windows_project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Tags": ["Windows"]
}
6 changes: 6 additions & 0 deletions Platform/iOS/ios_project.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#

3 changes: 3 additions & 0 deletions Platform/iOS/ios_project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Tags": ["iOS"]
}
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ If you have a Git credential helper configured, you should not be prompted for y

## Running the Project

Run the netsoak ServerLauncher with the relevant options (see below). It is strongly recommended to use --rhi=null when launching NetSoakTest.ServerLauncher

To pass command line values when launching the executable the format is ```--<command>=<value>```
Run the netsoak ServerLauncher with the relevant comand line values, using the nformat is ```--<command>=<value>```. See the full list of options below.

For example, the following params will run the loopback test for 2 minutes before dumping stats and exiting:
```
NetSoakTest.ServerLauncher --soak_mode=loopback --rhi=null
NetSoakTest.ServerLauncher --soak_mode=loopback --soak_runtime=2000
```

When running tests, you can use the [debug console](https://www.o3de.org/docs/user-guide/appendix/cvars/debugging/#using-console-debug-views) and the `DumpSoakStats` command to see point-in-time stats from the test. The test will run indefinitely unless `soak_runtime` is set.

Note: All O3DE projects generate a GameLauncher and a ServerLauncher. NetSoakTest does not utilize its GameLauncher by design.

### Options
Expand All @@ -118,6 +119,8 @@ Note: All O3DE projects generate a GameLauncher and a ServerLauncher. NetSoakTes
| soak_port | The port that this soak test will bind to for game traffic | 33450 |
| soak_protocol | Soak test protocol (TCP or UDP) | udp |
| soak_mode | The operating mode for the soak test, options are loopback, client or host. `Loopback` has two connection within the application feed traffic to each other in a loop. `Client` expects to connect to a server hosted at soak_serveraddr. `Host` hosts a server for clients to connect to | Loopback |
| soak_runtimems | How long to run the test for in milliseconds. Will automatically dump stats at the end of the test period. | 0 (run indefinitely) |
| DumpSoakStats | Dump snapshot of soak test networking stats to console and log. | N/A |

Other networking features such as Compression or DTLS/TLS can be enabled/disabled in the same way they would be in a production environment. For example:

Expand Down
13 changes: 13 additions & 0 deletions cmake/CompilerSettings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#

# File to tweak compiler settings before compiler detection happens (before project() is called)
# We dont have PAL enabled at this point, so we can only use pure-CMake variables
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
include(cmake/Platform/Linux/CompilerSettings_linux.cmake)
endif()
Loading

0 comments on commit 19bcf79

Please sign in to comment.