From 00b649f92f54449ed258cce90887d7e3cac39b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nora=20Emma=20=C2=ABMetal-Mighty=C2=BB=20Barlow?= <5247527+Metal-Mighty@users.noreply.github.com> Date: Thu, 30 May 2024 15:03:54 +0200 Subject: [PATCH 1/3] Add Azure device clients protocol configuration Currently supports Amqp or AmqpWs --- .../BasicsStation/DownstreamMessageSender.cs | 1 + .../DefaultLoRaDataRequestHandler.cs | 1 + .../DownlinkMessageBuilder.cs | 1 + .../CancellationTokenExtensions.cs | 0 .../{ => Extensions}/DisposableExtensions.cs | 0 .../{ => Extensions}/HexadecimalExtensions.cs | 2 +- .../LoRaDeviceClientExtensions.cs | 7 +++-- .../{ => Extensions}/TaskExtensions.cs | 2 +- .../Extensions/UpstreamProtocolExtensions.cs | 29 +++++++++++++++++++ .../LoRaWan.NetworkServer/LoRaDeviceCache.cs | 1 + .../LoRaDeviceClientConnectionManager.cs | 1 + .../LoRaDeviceFactory.cs | 3 +- .../LoRaPayloadDecoder.cs | 1 + .../NetworkServerConfiguration.cs | 11 ++++++- .../LoRaWan.NetworkServer/UpstreamProtocol.cs | 10 +++++++ .../WebSocketTextChannel.cs | 1 + Tests/Common/SimulatedBasicsStation.cs | 1 + .../CancellationTokenExtensionsTest.cs | 2 +- .../DisposableExtensionsTests.cs | 2 +- .../HexadecimalExtensionsTests.cs | 2 +- .../LoRaDeviceClientResiliencyTests.cs | 1 + .../Unit/NetworkServer/TaskExtensionTests.cs | 2 +- 22 files changed, 70 insertions(+), 11 deletions(-) rename LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/{ => Extensions}/CancellationTokenExtensions.cs (100%) rename LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/{ => Extensions}/DisposableExtensions.cs (100%) rename LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/{ => Extensions}/HexadecimalExtensions.cs (95%) rename LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/{ => Extensions}/LoRaDeviceClientExtensions.cs (96%) rename LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/{ => Extensions}/TaskExtensions.cs (97%) create mode 100644 LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/UpstreamProtocolExtensions.cs create mode 100644 LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/UpstreamProtocol.cs diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/BasicsStation/DownstreamMessageSender.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/BasicsStation/DownstreamMessageSender.cs index 8a8754516e..7d109deaeb 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/BasicsStation/DownstreamMessageSender.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/BasicsStation/DownstreamMessageSender.cs @@ -11,6 +11,7 @@ namespace LoRaWan.NetworkServer.BasicsStation using System.Threading; using System.Threading.Tasks; using LoRaTools.LoRaPhysical; + using LoRaWan.NetworkServer.Extensions; using Microsoft.Extensions.Logging; internal class DownstreamMessageSender : IDownstreamMessageSender diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/DefaultLoRaDataRequestHandler.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/DefaultLoRaDataRequestHandler.cs index 72e6bd5451..6ddbfbb451 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/DefaultLoRaDataRequestHandler.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/DefaultLoRaDataRequestHandler.cs @@ -15,6 +15,7 @@ namespace LoRaWan.NetworkServer using LoRaTools.Mac; using LoRaTools.Regions; using LoRaWan.NetworkServer.ADR; + using LoRaWan.NetworkServer.Extensions; using Microsoft.Extensions.Logging; using Newtonsoft.Json; diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/DownlinkMessageBuilder.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/DownlinkMessageBuilder.cs index 08356f9897..e390b2f61e 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/DownlinkMessageBuilder.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/DownlinkMessageBuilder.cs @@ -14,6 +14,7 @@ namespace LoRaWan.NetworkServer using LoRaTools.Mac; using LoRaTools.Regions; using LoRaTools.Utils; + using LoRaWan.NetworkServer.Extensions; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using static ReceiveWindowNumber; diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/CancellationTokenExtensions.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/CancellationTokenExtensions.cs similarity index 100% rename from LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/CancellationTokenExtensions.cs rename to LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/CancellationTokenExtensions.cs diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/DisposableExtensions.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/DisposableExtensions.cs similarity index 100% rename from LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/DisposableExtensions.cs rename to LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/DisposableExtensions.cs diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/HexadecimalExtensions.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/HexadecimalExtensions.cs similarity index 95% rename from LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/HexadecimalExtensions.cs rename to LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/HexadecimalExtensions.cs index 14dd1d9d66..3f6fd3fb3c 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/HexadecimalExtensions.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/HexadecimalExtensions.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace LoRaWan.NetworkServer +namespace LoRaWan.NetworkServer.Extensions { using System; diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceClientExtensions.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/LoRaDeviceClientExtensions.cs similarity index 96% rename from LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceClientExtensions.cs rename to LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/LoRaDeviceClientExtensions.cs index 4b46b014ce..4d47b46dc1 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceClientExtensions.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/LoRaDeviceClientExtensions.cs @@ -3,8 +3,9 @@ #nullable enable -namespace LoRaWan.NetworkServer +namespace LoRaWan.NetworkServer.Extensions { + using LoRaWan; using System; using System.Collections.Generic; using System.Globalization; @@ -53,8 +54,8 @@ private async Task InvokeAsync(T1 arg1, T2 arg2, Func< } catch (Exception ex) when ((ex is ObjectDisposedException - || (ex is InvalidOperationException ioe - && ioe.Message.StartsWith("This operation is only allowed using a successfully authenticated context.", StringComparison.OrdinalIgnoreCase))) + || ex is InvalidOperationException ioe + && ioe.Message.StartsWith("This operation is only allowed using a successfully authenticated context.", StringComparison.OrdinalIgnoreCase)) && ExceptionFilterUtility.True(() => this.logger?.LogDebug(ex, @"Device client operation ""{Operation}"" (attempt {Attempt}/" + MaxAttempts.ToString(CultureInfo.InvariantCulture) diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/TaskExtensions.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/TaskExtensions.cs similarity index 97% rename from LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/TaskExtensions.cs rename to LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/TaskExtensions.cs index 6b72fda984..81c31294cc 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/TaskExtensions.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/TaskExtensions.cs @@ -3,7 +3,7 @@ #nullable enable -namespace LoRaWan.NetworkServer +namespace LoRaWan.NetworkServer.Extensions { using System; using System.Collections.Generic; diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/UpstreamProtocolExtensions.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/UpstreamProtocolExtensions.cs new file mode 100644 index 0000000000..7afb353c31 --- /dev/null +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/UpstreamProtocolExtensions.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace LoRaWan.NetworkServer.Extensions; + +using System; +using Microsoft.Azure.Devices.Client; + +public static class UpstreamProtocolExtensions +{ + public static UpstreamProtocol StringToUpstreamProtocol(this string value) + { + return Enum.TryParse(value, true, out UpstreamProtocol upstreamProtocol) + ? throw new ArgumentOutOfRangeException(nameof(value), value, + $"Invalid value '{value}' for UpstreamProtocol") + : upstreamProtocol; + } + + public static TransportType UpstreamProtocolToTransportType(this UpstreamProtocol value) + { + return value switch + { + UpstreamProtocol.Amqp => TransportType.Amqp_Tcp_Only, + UpstreamProtocol.AmqpWs => TransportType.Amqp_WebSocket_Only, + _ => throw new ArgumentOutOfRangeException(nameof(value), value, + "Value '{value}' cannot be associated to a TransportType") + }; + } +} diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceCache.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceCache.cs index c366f49a29..d4027f6308 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceCache.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceCache.cs @@ -6,6 +6,7 @@ namespace LoRaWan.NetworkServer { using LoRaTools.LoRaMessage; + using LoRaWan.NetworkServer.Extensions; using Microsoft.Extensions.Logging; using System; using System.Collections.Concurrent; diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceClientConnectionManager.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceClientConnectionManager.cs index 805fc0cb74..e9965805c2 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceClientConnectionManager.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceClientConnectionManager.cs @@ -17,6 +17,7 @@ namespace LoRaWan.NetworkServer using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using LoRaTools; + using LoRaWan.NetworkServer.Extensions; /// /// Manages connections for . diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceFactory.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceFactory.cs index 1915246e6b..69e2db8f4f 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceFactory.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaDeviceFactory.cs @@ -9,6 +9,7 @@ namespace LoRaWan.NetworkServer using System.Diagnostics.Metrics; using Microsoft.Azure.Devices.Client; using Microsoft.Extensions.Logging; + using LoRaWan.NetworkServer.Extensions; public class LoRaDeviceFactory : ILoRaDeviceFactory { @@ -152,7 +153,7 @@ public virtual ILoRaDeviceClient CreateDeviceClient(string deviceId, string prim // Enabling AMQP multiplexing var transportSettings = new ITransportSettings[] { - new AmqpTransportSettings(TransportType.Amqp_Tcp_Only) + new AmqpTransportSettings(this.configuration.UpstreamProtocol) { AmqpConnectionPoolSettings = new AmqpConnectionPoolSettings() { diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaPayloadDecoder.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaPayloadDecoder.cs index ea737e534a..eb1bc6c94a 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaPayloadDecoder.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/LoRaPayloadDecoder.cs @@ -11,6 +11,7 @@ namespace LoRaWan.NetworkServer using System.Text; using System.Threading.Tasks; using System.Web; + using LoRaWan.NetworkServer.Extensions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Newtonsoft.Json; diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/NetworkServerConfiguration.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/NetworkServerConfiguration.cs index c3789468be..ec19a21958 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/NetworkServerConfiguration.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/NetworkServerConfiguration.cs @@ -6,6 +6,7 @@ namespace LoRaWan.NetworkServer using System; using System.Collections.Generic; using System.Linq; + using Extensions; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.Azure.Devices.Client; @@ -146,12 +147,16 @@ public class NetworkServerConfiguration /// public bool IsLocalDevelopment { get; set; } - /// /// Specifies the Processing Delay in Milliseconds /// public int ProcessingDelayInMilliseconds { get; set; } = Constants.DefaultProcessingDelayInMilliseconds; + /// + /// Specifies the protocol to use for communication from the Azure IoT Device to Azure + /// + public TransportType UpstreamProtocol { get; set; } + // Creates a new instance of NetworkServerConfiguration by reading values from environment variables public static NetworkServerConfiguration CreateFromEnvironmentVariables() { @@ -210,6 +215,10 @@ public static NetworkServerConfiguration CreateFromEnvironmentVariables() ? size : throw new NotSupportedException($"'IOTHUB_CONNECTION_POOL_SIZE' needs to be between 1 and {AmqpConnectionPoolSettings.AbsoluteMaxPoolSize}."); + config.UpstreamProtocol = envVars.GetEnvVar("UPSTREAM_PROTOCOL", string.Empty) + .StringToUpstreamProtocol() + .UpstreamProtocolToTransportType(); + config.RedisConnectionString = envVars.GetEnvVar("REDIS_CONNECTION_STRING", string.Empty); if (!config.RunningAsIoTEdgeModule && !config.IsLocalDevelopment && string.IsNullOrEmpty(config.RedisConnectionString)) throw new InvalidOperationException("'REDIS_CONNECTION_STRING' can't be empty if running network server as part of a cloud only deployment."); diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/UpstreamProtocol.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/UpstreamProtocol.cs new file mode 100644 index 0000000000..b7cca9299c --- /dev/null +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/UpstreamProtocol.cs @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace LoRaWan.NetworkServer; + +public enum UpstreamProtocol +{ + Amqp, + AmqpWs, +} diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/WebSocketTextChannel.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/WebSocketTextChannel.cs index b00f1fc47f..de26b51e46 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/WebSocketTextChannel.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/WebSocketTextChannel.cs @@ -11,6 +11,7 @@ namespace LoRaWan.NetworkServer using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; + using LoRaWan.NetworkServer.Extensions; /// /// A implementation for text messages that uses a queue to diff --git a/Tests/Common/SimulatedBasicsStation.cs b/Tests/Common/SimulatedBasicsStation.cs index 3594bb90d0..f48cda9937 100644 --- a/Tests/Common/SimulatedBasicsStation.cs +++ b/Tests/Common/SimulatedBasicsStation.cs @@ -16,6 +16,7 @@ namespace LoRaWan.Tests.Common using LoRaTools.LoRaMessage; using System.Text.Json.Serialization; using LoRaTools; + using LoRaWan.NetworkServer.Extensions; public sealed class SimulatedBasicsStation : IDisposable { diff --git a/Tests/Unit/NetworkServer/CancellationTokenExtensionsTest.cs b/Tests/Unit/NetworkServer/CancellationTokenExtensionsTest.cs index 365deff4fa..2700347257 100644 --- a/Tests/Unit/NetworkServer/CancellationTokenExtensionsTest.cs +++ b/Tests/Unit/NetworkServer/CancellationTokenExtensionsTest.cs @@ -5,7 +5,7 @@ namespace LoRaWan.Tests.Unit.NetworkServer { using System; using System.Threading; - using LoRaWan.NetworkServer; + using LoRaWan.NetworkServer.Extensions; using Xunit; public class CancellationTokenExtensionsTest diff --git a/Tests/Unit/NetworkServer/DisposableExtensionsTests.cs b/Tests/Unit/NetworkServer/DisposableExtensionsTests.cs index 1ce13d2747..fefc9f7aff 100644 --- a/Tests/Unit/NetworkServer/DisposableExtensionsTests.cs +++ b/Tests/Unit/NetworkServer/DisposableExtensionsTests.cs @@ -10,7 +10,7 @@ namespace LoRaWan.Tests.Unit.NetworkServer using System.Linq; using System.Threading; using System.Threading.Tasks; - using LoRaWan.NetworkServer; + using LoRaWan.NetworkServer.Extensions; using Moq; using Xunit; diff --git a/Tests/Unit/NetworkServer/HexadecimalExtensionsTests.cs b/Tests/Unit/NetworkServer/HexadecimalExtensionsTests.cs index 60a5119935..395bf5cadc 100644 --- a/Tests/Unit/NetworkServer/HexadecimalExtensionsTests.cs +++ b/Tests/Unit/NetworkServer/HexadecimalExtensionsTests.cs @@ -5,7 +5,7 @@ namespace LoRaWan.Tests.Unit.NetworkServer { using System; using Common; - using LoRaWan.NetworkServer; + using LoRaWan.NetworkServer.Extensions; using Xunit; public class HexadecimalExtensionsTests diff --git a/Tests/Unit/NetworkServer/LoRaDeviceClientResiliencyTests.cs b/Tests/Unit/NetworkServer/LoRaDeviceClientResiliencyTests.cs index 94193e1649..fed91da9da 100644 --- a/Tests/Unit/NetworkServer/LoRaDeviceClientResiliencyTests.cs +++ b/Tests/Unit/NetworkServer/LoRaDeviceClientResiliencyTests.cs @@ -13,6 +13,7 @@ namespace LoRaWan.Tests.Unit.NetworkServer using System.Threading.Tasks; using Common; using LoRaWan.NetworkServer; + using LoRaWan.NetworkServer.Extensions; using Microsoft.Azure.Devices.Client; using Microsoft.Azure.Devices.Shared; using Microsoft.Extensions.Logging; diff --git a/Tests/Unit/NetworkServer/TaskExtensionTests.cs b/Tests/Unit/NetworkServer/TaskExtensionTests.cs index 87a69afd02..5132b328f3 100644 --- a/Tests/Unit/NetworkServer/TaskExtensionTests.cs +++ b/Tests/Unit/NetworkServer/TaskExtensionTests.cs @@ -8,7 +8,7 @@ namespace LoRaWan.Tests.Unit.NetworkServer using System; using System.Linq; using System.Threading.Tasks; - using LoRaWan.NetworkServer; + using LoRaWan.NetworkServer.Extensions; using LoRaWan.Tests.Common; using Xunit; From fd6f671817b14fb2c656411cf41c178a7197f0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nora=20Emma=20=C2=ABMetal-Mighty=C2=BB=20Barlow?= <5247527+Metal-Mighty@users.noreply.github.com> Date: Thu, 30 May 2024 15:04:12 +0200 Subject: [PATCH 2/3] Set default value to Amqp Amqp was the default protocol in cloud-based mode before, keeping it the same for compatibility --- .../LoRaWan.NetworkServer/NetworkServerConfiguration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/NetworkServerConfiguration.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/NetworkServerConfiguration.cs index ec19a21958..b1905cf8f8 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/NetworkServerConfiguration.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/NetworkServerConfiguration.cs @@ -215,7 +215,7 @@ public static NetworkServerConfiguration CreateFromEnvironmentVariables() ? size : throw new NotSupportedException($"'IOTHUB_CONNECTION_POOL_SIZE' needs to be between 1 and {AmqpConnectionPoolSettings.AbsoluteMaxPoolSize}."); - config.UpstreamProtocol = envVars.GetEnvVar("UPSTREAM_PROTOCOL", string.Empty) + config.UpstreamProtocol = envVars.GetEnvVar("UPSTREAM_PROTOCOL", "Amqp") .StringToUpstreamProtocol() .UpstreamProtocolToTransportType(); From c013efd06b304787292d7777c4645a838550d7e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nora=20Emma=20=C2=ABMetal-Mighty=C2=BB=20Barlow?= <5247527+Metal-Mighty@users.noreply.github.com> Date: Thu, 30 May 2024 15:04:24 +0200 Subject: [PATCH 3/3] Rename extension methods --- .../Extensions/UpstreamProtocolExtensions.cs | 4 ++-- .../LoRaWan.NetworkServer/NetworkServerConfiguration.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/UpstreamProtocolExtensions.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/UpstreamProtocolExtensions.cs index 7afb353c31..5011575853 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/UpstreamProtocolExtensions.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/Extensions/UpstreamProtocolExtensions.cs @@ -8,7 +8,7 @@ namespace LoRaWan.NetworkServer.Extensions; public static class UpstreamProtocolExtensions { - public static UpstreamProtocol StringToUpstreamProtocol(this string value) + public static UpstreamProtocol ToUpstreamProtocol(this string value) { return Enum.TryParse(value, true, out UpstreamProtocol upstreamProtocol) ? throw new ArgumentOutOfRangeException(nameof(value), value, @@ -16,7 +16,7 @@ public static UpstreamProtocol StringToUpstreamProtocol(this string value) : upstreamProtocol; } - public static TransportType UpstreamProtocolToTransportType(this UpstreamProtocol value) + public static TransportType ToTransportType(this UpstreamProtocol value) { return value switch { diff --git a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/NetworkServerConfiguration.cs b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/NetworkServerConfiguration.cs index b1905cf8f8..9daaea03eb 100644 --- a/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/NetworkServerConfiguration.cs +++ b/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWan.NetworkServer/NetworkServerConfiguration.cs @@ -216,8 +216,8 @@ public static NetworkServerConfiguration CreateFromEnvironmentVariables() : throw new NotSupportedException($"'IOTHUB_CONNECTION_POOL_SIZE' needs to be between 1 and {AmqpConnectionPoolSettings.AbsoluteMaxPoolSize}."); config.UpstreamProtocol = envVars.GetEnvVar("UPSTREAM_PROTOCOL", "Amqp") - .StringToUpstreamProtocol() - .UpstreamProtocolToTransportType(); + .ToUpstreamProtocol() + .ToTransportType(); config.RedisConnectionString = envVars.GetEnvVar("REDIS_CONNECTION_STRING", string.Empty); if (!config.RunningAsIoTEdgeModule && !config.IsLocalDevelopment && string.IsNullOrEmpty(config.RedisConnectionString))