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

Set MAC state for devices with active session #14

Merged
merged 1 commit into from
Feb 12, 2021

Conversation

neoaggelos
Copy link
Contributor

@neoaggelos neoaggelos commented Dec 23, 2020

Summary

References https://github.com/TheThingsIndustries/lorawan-stack/issues/2417

Changes

  • For OTAA devices with a session, set current parameters instead of MAC state. This is only relevant for the Rx1 Delay for devices exported from TTNv2

Testing

Test with devices from TTN

OTAA device, without a session -> Sets mac_settings.rx1_delay
OTAA device with session -> Sets mac_state.current_parameters.rx1_delay
ABP devices -> Sets mac_settings.rx1_delay

Checklist

  • Scope: The referenced issue is addressed, there are no unrelated changes.
  • Documentation: Relevant documentation is added or updated.
  • Changelog: Significant features, behavior changes, deprecations and fixes are added to CHANGELOG.md.

@neoaggelos neoaggelos added this to the December 2020 milestone Dec 23, 2020
@neoaggelos neoaggelos self-assigned this Dec 23, 2020
Comment on lines 172 to 194
if deviceHasSession && deviceSupportsJoin {
v3dev.MACState = &ttnpb.MACState{
DeviceClass: ttnpb.CLASS_A,
LoRaWANVersion: ttnpb.MAC_V1_0_2,
CurrentParameters: ttnpb.MACParameters{
Rx1Delay: ttnpb.RX_DELAY_1,
},
}
} else {
v3dev.MACSettings.Rx1Delay = &ttnpb.RxDelayValue{
Value: ttnpb.RX_DELAY_1,
}
}

Choose a reason for hiding this comment

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

Suggested change
if deviceHasSession && deviceSupportsJoin {
v3dev.MACState = &ttnpb.MACState{
DeviceClass: ttnpb.CLASS_A,
LoRaWANVersion: ttnpb.MAC_V1_0_2,
CurrentParameters: ttnpb.MACParameters{
Rx1Delay: ttnpb.RX_DELAY_1,
},
}
} else {
v3dev.MACSettings.Rx1Delay = &ttnpb.RxDelayValue{
Value: ttnpb.RX_DELAY_1,
}
}
if deviceHasSession {
v3dev.MACState = &ttnpb.MACState{
DeviceClass: ttnpb.CLASS_A,
LoRaWANVersion: ttnpb.MAC_V1_0_2,
CurrentParameters: ttnpb.MACParameters{
Rx1Delay: ttnpb.RX_DELAY_1,
},
}
}
if !deviceSupportsJoin {
v3dev.MACSettings.Rx1Delay = &ttnpb.RxDelayValue{
Value: ttnpb.RX_DELAY_1,
}
}

@rvolosatovs rvolosatovs changed the title Set current parameters instead of MAC settings for active OTAA devices Set MAC state for devices with active session Dec 24, 2020
@rvolosatovs
Copy link

rvolosatovs commented Dec 24, 2020

If session is set, then a complete mac-state should be set as well, Network Server should not allow setting just session, for example, and not setting mac-state as well.

In fact, I think the best approach is CLI using https://github.com/TheThingsNetwork/lorawan-stack/blob/b4c8dcda48ba9b43e383a7e09e909c4607cbd565/pkg/networkserver/mac/utils.go#L548-L601 to generate a MAC state, doing all the adjustments for v2 and then setting that

@neoaggelos neoaggelos force-pushed the feature/otaa-mac-state branch from 4f739fe to e5caad0 Compare December 24, 2020 14:50
@neoaggelos neoaggelos requested review from rvolosatovs and removed request for rvolosatovs December 24, 2020 14:50
Copy link

@rvolosatovs rvolosatovs left a comment

Choose a reason for hiding this comment

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

This looks good, but the tool should be careful with the field paths sent to NS - if the tool sends top-level mac_state, then the created device will end up with a corrupted MAC state and will be unusable

@rvolosatovs
Copy link

And, to reiterate, I think the cleanest approach would be:

  1. Generate new MAC state
  2. Apply all modifications to it according to v2 specifics
  3. Send the whole mac_state with top-level mac_state field path specified

Copy link
Contributor

@htdvisser htdvisser left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@rvolosatovs rvolosatovs left a comment

Choose a reason for hiding this comment

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

A possible improvement is to not set mac-state.desired-parameters, such that v3 NS would compute that by itself and modify the state accordingly, but I'm not sure we should do that.
For example, that would mean that immediately after migration v3 NS would try to reconfigure device to use RX1 Delay of 5 seconds(v3 default) via MAC commands, @johanstokking @htdvisser - what do you think?
IMO it's safest not to do that and just let the device stay with exact same configuration as v2 to minimize chance of potential issues. Users can set mac-state.desired-parameters.rx1-delay if necessary

pkg/source/ttnv2/config.go Show resolved Hide resolved
@johanstokking
Copy link
Member

For example, that would mean that immediately after migration v3 NS would try to reconfigure device to use RX1 Delay of 5 seconds(v3 default) via MAC commands, @johanstokking @htdvisser - what do you think?

Yeah good point.

What are the other settings that we should consider, besides RX1 delay?

As for this particular instance, I do think that we should reconfigure the RX1 delay to TTS' default.

@neoaggelos
Copy link
Contributor Author

Updated according to our discussion with @rvolosatovs. Will proceed with testing after NS supports importing device sessions.

@@ -210,5 +209,8 @@ func (s *Source) RangeDevices(appID string, f func(source.Source, string) error)

// Close implements the Source interface.
func (s *Source) Close() error {
return s.client.Close()
if s.client != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I don't really like the fact that we lazy-initialize client with the first application ID that is seen by Source. Is there a good reason for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lazy initialization is removed as part of #13

@rvolosatovs
Copy link

rvolosatovs commented Jan 4, 2021

Blocked by TheThingsNetwork/lorawan-stack#2472

@rvolosatovs
Copy link

v3dev.MACState.DeviceClass = ttnpb.CLASS_A
v3dev.MACState.LoRaWANVersion = ttnpb.MAC_V1_0_2
v3dev.MACState.CurrentParameters.Rx1Delay = ttnpb.RX_DELAY_1
v3dev.MACState.DesiredParameters = ttnpb.MACParameters{}

Choose a reason for hiding this comment

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

You should not need to be doing this. Instead, this should be covered by the field mask.
Only relevant fields in mac_state.current_parameters and in top-level mac_state should be specified

@neoaggelos neoaggelos force-pushed the feature/otaa-mac-state branch from 7f3518e to e3988a4 Compare January 21, 2021 00:50
@johanstokking
Copy link
Member

@neoaggelos if this is ready for review, request them.

@neoaggelos
Copy link
Contributor Author

I am currently testing against the changes in TheThingsNetwork/lorawan-stack#3680, will request review when ready.

Copy link

@rvolosatovs rvolosatovs left a comment

Choose a reason for hiding this comment

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

I don't see the fieldmask in the diff and don't know where to find it, but I assume that is correct

@neoaggelos neoaggelos force-pushed the feature/otaa-mac-state branch from e3988a4 to 5aa1a1a Compare February 12, 2021 14:26
@neoaggelos neoaggelos merged commit 7418528 into master Feb 12, 2021
@rvolosatovs rvolosatovs deleted the feature/otaa-mac-state branch February 16, 2021 17:04
@rvolosatovs
Copy link

FYI, TheThingsNetwork/lorawan-stack#3680 is still not merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants