Skip to content

Commit

Permalink
ns: Add more test to verifiy the logic
Browse files Browse the repository at this point in the history
  • Loading branch information
halimi committed Jan 2, 2025
1 parent 779bffb commit b618ff3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/networkserver/mac/link_adr.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func HandleLinkADRAns(
// rejected. This behavior differs from when the uplink ADR bit is set, in which case the end-
// device accepts or rejects the entire command.
if macspec.UseADRBit(macState.LorawanVersion) {
rejected = (!adrEnabled && !pld.ChannelMaskAck) ||
rejected = !pld.ChannelMaskAck ||
(adrEnabled && !pld.DataRateIndexAck) ||
(adrEnabled && !pld.TxPowerIndexAck)
} else {
Expand Down
62 changes: 62 additions & 0 deletions pkg/networkserver/mac/link_adr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,37 @@ func TestHandleLinkADRAns(t *testing.T) {
Error: ErrRequestNotFound.WithAttributes("cid", ttnpb.MACCommandIdentifier_CID_LINK_ADR),
AdrEnabled: false,
},
{
Name: "1.0.4/channel mask off/adr disabled/rejected",
Device: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP002_V1_0_4,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_0_4,
},
},
Expected: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP002_V1_0_4,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_0_4,
},
},
Payload: &ttnpb.MACCommand_LinkADRAns{
ChannelMaskAck: false,
DataRateIndexAck: false,
TxPowerIndexAck: false,
},
Events: events.Builders{
EvtReceiveLinkADRReject.With(events.WithData(&ttnpb.MACCommand_LinkADRAns{
ChannelMaskAck: false,
DataRateIndexAck: false,
TxPowerIndexAck: false,
})),
},
Error: ErrRequestNotFound.WithAttributes("cid", ttnpb.MACCommandIdentifier_CID_LINK_ADR),
AdrEnabled: false,
},
{
Name: "1.0.4/channel mask on/adr enabled/rejected",
Device: &ttnpb.EndDevice{
Expand Down Expand Up @@ -579,6 +610,37 @@ func TestHandleLinkADRAns(t *testing.T) {
Error: ErrRequestNotFound.WithAttributes("cid", ttnpb.MACCommandIdentifier_CID_LINK_ADR),
AdrEnabled: true,
},
{
Name: "1.0.4/channel mask off/adr enabled/rejected",
Device: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP002_V1_0_4,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_0_4,
},
},
Expected: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP002_V1_0_4,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_0_4,
},
},
Payload: &ttnpb.MACCommand_LinkADRAns{
ChannelMaskAck: false,
DataRateIndexAck: false,
TxPowerIndexAck: false,
},
Events: events.Builders{
EvtReceiveLinkADRReject.With(events.WithData(&ttnpb.MACCommand_LinkADRAns{
ChannelMaskAck: false,
DataRateIndexAck: false,
TxPowerIndexAck: false,
})),
},
Error: ErrRequestNotFound.WithAttributes("cid", ttnpb.MACCommandIdentifier_CID_LINK_ADR),
AdrEnabled: true,
},
{
Name: "1 request/all ack",
Device: &ttnpb.EndDevice{
Expand Down

0 comments on commit b618ff3

Please sign in to comment.