Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused DevEUI that breaks deserialization #1711

Merged
merged 3 commits into from
May 19, 2022
Merged
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 @@ -101,7 +101,7 @@ private async Task<PreferredGatewayResult> ComputePreferredGateway(IPipelineExec
{
if (preferredGateway.FcntUp >= fcntUp)
{
return new PreferredGatewayResult(devEUI, fcntUp, preferredGateway);
return new PreferredGatewayResult(fcntUp, preferredGateway);
}
}

Expand All @@ -126,7 +126,7 @@ private async Task<PreferredGatewayResult> ComputePreferredGateway(IPipelineExec
{
this.log.LogError("Could not resolve closest gateway in {devEUI} and {fcntUp}", devEUI, fcntUp);

return new PreferredGatewayResult(devEUI, fcntUp, "Could not resolve closest gateway");
return new PreferredGatewayResult(fcntUp, "Could not resolve closest gateway");
}

preferredGateway = new LoRaDevicePreferredGateway(winner.GatewayID, fcntUp);
Expand Down Expand Up @@ -155,13 +155,13 @@ private async Task<PreferredGatewayResult> ComputePreferredGateway(IPipelineExec
{
if (preferredGateway.FcntUp >= fcntUp)
{
return new PreferredGatewayResult(devEUI, fcntUp, preferredGateway);
return new PreferredGatewayResult(fcntUp, preferredGateway);
}
}
}

this.log.LogError("Could not resolve closest gateway in {devEUI} and {fcntUp}", devEUI, fcntUp);
return new PreferredGatewayResult(devEUI, fcntUp, "Could not resolve closest gateway");
return new PreferredGatewayResult(fcntUp, "Could not resolve closest gateway");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace LoraKeysManagerFacade
{
using LoRaWan;
using Newtonsoft.Json;
using System;

Expand All @@ -12,8 +11,6 @@ namespace LoraKeysManagerFacade
/// </summary>
public class PreferredGatewayResult
{
public DevEui DevEUI { get; }

public uint RequestFcntUp { get; }

[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
Expand All @@ -38,20 +35,18 @@ public PreferredGatewayResult()
{
}

public PreferredGatewayResult(DevEui devEUI, uint fcntUp, LoRaDevicePreferredGateway preferredGateway)
public PreferredGatewayResult(uint fcntUp, LoRaDevicePreferredGateway preferredGateway)
{
if (preferredGateway is null) throw new ArgumentNullException(nameof(preferredGateway));

DevEUI = devEUI;
RequestFcntUp = fcntUp;
CurrentFcntUp = preferredGateway.FcntUp;
PreferredGatewayID = preferredGateway.GatewayID;
Conflict = fcntUp != preferredGateway.FcntUp;
}

public PreferredGatewayResult(DevEui devEUI, uint fcntUp, string errorMessage)
public PreferredGatewayResult(uint fcntUp, string errorMessage)
{
DevEUI = devEUI;
RequestFcntUp = fcntUp;
ErrorMessage = errorMessage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public async Task<bool> SendAsync(IReceivedLoRaCloudToDeviceMessage message, Can
return false;
}

var fcntDown = await frameCounterStrategy.NextFcntDown(loRaDevice, 0);
var fcntDown = await frameCounterStrategy.NextFcntDown(loRaDevice, loRaDevice.FCntUp);
if (fcntDown <= 0)
{
this.logger.LogError("[class-c] could not obtain fcnt down for class C device");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ namespace LoRaWan.NetworkServer
/// </summary>
public class PreferredGatewayResult
{
[JsonIgnore]
public DevEui DevEUI { get; set; }

[JsonProperty("DevEUI")]
public string DevEuiString
{
get => DevEUI.ToString();
set => DevEUI = DevEui.Parse(value);
}

public uint RequestFcntUp { get; set; }

[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
Expand Down
6 changes: 2 additions & 4 deletions Tests/Integration/ClassCIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public async Task When_ABP_Sends_Upstream_Followed_By_DirectMethod_Should_Send_U

if (string.IsNullOrEmpty(deviceGatewayID))
{
LoRaDeviceApi.Setup(x => x.NextFCntDownAsync(simDevice.DevEUI, fcntDownFromTwin + fcntDelta, 0, ServerConfiguration.GatewayID))
LoRaDeviceApi.Setup(x => x.NextFCntDownAsync(simDevice.DevEUI, fcntDownFromTwin + fcntDelta, simDevice.FrmCntUp, ServerConfiguration.GatewayID))
.ReturnsAsync((ushort)expectedFcntDown);
}

Expand Down Expand Up @@ -234,7 +234,7 @@ public async Task When_OTAA_Join_Then_Sends_Upstream_DirectMethod_Should_Send_Do

if (string.IsNullOrEmpty(deviceGatewayID))
{
LoRaDeviceApi.Setup(x => x.NextFCntDownAsync(simDevice.DevEUI, simDevice.FrmCntDown, 0, ServerConfiguration.GatewayID))
LoRaDeviceApi.Setup(x => x.NextFCntDownAsync(simDevice.DevEUI, simDevice.FrmCntDown, simDevice.FrmCntUp, ServerConfiguration.GatewayID))
.ReturnsAsync((ushort)(simDevice.FrmCntDown + 1));
}

Expand Down Expand Up @@ -451,7 +451,6 @@ public async Task When_Processing_Data_Request_Should_Compute_Preferred_Gateway_
{
PreferredGatewayResult = new PreferredGatewayResult()
{
DevEUI = simulatedDevice.DevEUI,
PreferredGatewayID = preferredGatewayID,
CurrentFcntUp = PayloadFcnt,
RequestFcntUp = PayloadFcnt,
Expand Down Expand Up @@ -547,7 +546,6 @@ public async Task When_Updating_PreferredGateway_And_FcntUp_Should_Save_Twin_Onc
{
PreferredGatewayResult = new PreferredGatewayResult()
{
DevEUI = simulatedDevice.DevEUI,
PreferredGatewayID = ServerGatewayID,
CurrentFcntUp = PayloadFcnt,
RequestFcntUp = PayloadFcnt,
Expand Down
30 changes: 30 additions & 0 deletions Tests/Unit/NetworkServer/PreferredGatewayResultTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable enable

namespace LoRaWan.Tests.Unit.NetworkServer
{
using Newtonsoft.Json;
using Xunit;

public sealed class PreferredGatewayResultTests
{
[Fact]
public void Can_Deserialize()
{
// arrange
var input = new global::LoraKeysManagerFacade.PreferredGatewayResult(12, new global::LoraKeysManagerFacade.LoRaDevicePreferredGateway("gateway", 13));

// act
var result = JsonConvert.DeserializeObject<LoRaWan.NetworkServer.PreferredGatewayResult>(JsonConvert.SerializeObject(input));

// assert
Assert.Equal(input.RequestFcntUp, result!.RequestFcntUp);
Assert.Equal(input.PreferredGatewayID, result.PreferredGatewayID);
Assert.Equal(input.Conflict, result.Conflict);
Assert.Equal(input.CurrentFcntUp, result.CurrentFcntUp);
Assert.Equal(input.ErrorMessage, result.ErrorMessage);
}
}
}