Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#nullable enable

namespace LoRaWan.NetworkServer
namespace LoRaWan.NetworkServer.Extensions
{
using LoRaWan;
using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -53,8 +54,8 @@ private async Task<TResult> InvokeAsync<T1, T2, TResult>(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#nullable enable

namespace LoRaWan.NetworkServer
namespace LoRaWan.NetworkServer.Extensions
{
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ToUpstreamProtocol(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 ToTransportType(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")
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace LoRaWan.NetworkServer
{
using LoRaTools.LoRaMessage;
using LoRaWan.NetworkServer.Extensions;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace LoRaWan.NetworkServer
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using LoRaTools;
using LoRaWan.NetworkServer.Extensions;

/// <summary>
/// Manages <see cref="ILoRaDeviceClient"/> connections for <see cref="LoRaDevice"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -146,12 +147,16 @@ public class NetworkServerConfiguration
/// </summary>
public bool IsLocalDevelopment { get; set; }


/// <summary>
/// Specifies the Processing Delay in Milliseconds
/// </summary>
public int ProcessingDelayInMilliseconds { get; set; } = Constants.DefaultProcessingDelayInMilliseconds;

/// <summary>
/// Specifies the protocol to use for communication from the Azure IoT Device to Azure
/// </summary>
public TransportType UpstreamProtocol { get; set; }

// Creates a new instance of NetworkServerConfiguration by reading values from environment variables
public static NetworkServerConfiguration CreateFromEnvironmentVariables()
{
Expand Down Expand Up @@ -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", "Amqp")
.ToUpstreamProtocol()
.ToTransportType();

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.");
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace LoRaWan.NetworkServer
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using LoRaWan.NetworkServer.Extensions;

/// <summary>
/// A <see cref="IWebSocketWriter{T}"/> implementation for text messages that uses a queue to
Expand Down
1 change: 1 addition & 0 deletions Tests/Common/SimulatedBasicsStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace LoRaWan.Tests.Unit.NetworkServer
{
using System;
using System.Threading;
using LoRaWan.NetworkServer;
using LoRaWan.NetworkServer.Extensions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to revert this change to have it compiled

using Xunit;

public class CancellationTokenExtensionsTest
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/NetworkServer/DisposableExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to revert this change to have it compiled

using Moq;
using Xunit;

Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/NetworkServer/HexadecimalExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/NetworkServer/TaskExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down