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

util: Remove hardware specific values from BS router_config #2131

Closed
wants to merge 5 commits into from

Conversation

KrishnaIyer
Copy link
Member

Summary

Closed #2130

Changes

  • Add omitempty to necessary fields and set type-default values to them.
  • Update tests.

Notes for Reviewers

Pending testing on metal.

Checklist

  • Scope: The referenced issue is addressed, there are no unrelated changes.
  • Compatibility: The changes are backwards compatible with existing API, database and configuration, according to the stability commitments in README.md.
  • Testing: The changes are covered with unit tests. The changes are tested manually as well.
  • Documentation: Relevant documentation is added or updated.
  • Changelog: Significant features, behavior changes, deprecations and fixes are added to CHANGELOG.md.
  • Commits: Commit messages follow guidelines in CONTRIBUTING.md, there are no fixup commits left.

@KrishnaIyer KrishnaIyer added bug Something isn't working c/gateway conf server This is related to the Gateway Configuration Server labels Mar 11, 2020
@KrishnaIyer KrishnaIyer added this to the March 2020 milestone Mar 11, 2020
@KrishnaIyer KrishnaIyer self-assigned this Mar 11, 2020
CHANGELOG.md Outdated Show resolved Hide resolved
@@ -33,7 +33,7 @@ import (
// SX1301Config contains the configuration for the SX1301 concentrator.
type SX1301Config struct {
LoRaWANPublic bool
ClockSource uint8
ClockSource uint8 `json:"omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Your json tag now renames this field to omitempty
  2. This has no effect, because SX1301Config has a MarshalJSON implementation. That's where you need to change this.
  3. You need to make this a *uint8 so that we can make a distinction between 0 and "omit"

pkg/pfconfig/shared/shared.go Outdated Show resolved Hide resolved
import "time"

// Bool returns a boolean pointer for the given value.
func Bool(v bool) *bool { return &v }
Copy link
Member

Choose a reason for hiding this comment

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

Let's please not do this

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is a one-time thing you could just oneline this. E.g.

ClassBTimeout: func(v time.Duration) *time.Duration { return &v }(time.Minute),

Otherwise just have a non-exported boolPtr next to the usage.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why not? Then I need to define the same boolPtr and functions for each type in 4 different files.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that is inherent to Go

@@ -116,10 +116,13 @@ func GetRouterConfig(bandID string, fps map[string]*frequencyplans.FrequencyPlan
// These fields are not defined in the v1.5 ref design https://doc.sm.tc/station/gw_v1.5.html#rfconf-object and would cause a parsing error.
sx1301Conf.Radios[0].TxFreqMin = 0
sx1301Conf.Radios[0].TxFreqMax = 0
// Remove hardware specific values that are not necessary.
// Remove hardware specific values that are handled by the gateway itself.
sx1301Conf.ClockSource = nil
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the underlying problem that we have radio specific fields in the frequency plan?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well these fields are valid SX1301_conf fields. Issue is that basic station specifically already has a config file on each hardware and hardware specific fields are already present there.

Copy link
Member

Choose a reason for hiding this comment

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

But isn't that true for other gateways too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Most gateways use what's provided in the global_conf.json right? Some have overrides in local_conf.json but not all of them afaik.

Copy link
Member

Choose a reason for hiding this comment

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

What I understand from #2130 is that we send information too specific about a gateway to a gateway. That makes me think that we have fields in our frequency plans that don't belong there. So removing those from BSLNS as you do here is a fix, but it's a fix for the symptoms. We may need to remove these fields from the frequency plans, pfconfig and GCS.

@@ -285,7 +286,7 @@ func BuildSX1301Config(frequencyPlan *frequencyplans.FrequencyPlan) (*SX1301Conf
conf := new(SX1301Config)

conf.LoRaWANPublic = true
conf.ClockSource = frequencyPlan.ClockSource
conf.ClockSource = pointers.Uint8(frequencyPlan.ClockSource)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
conf.ClockSource = pointers.Uint8(frequencyPlan.ClockSource)
conf.ClockSource = &frequencyPlan.ClockSource

@@ -88,25 +89,24 @@ func TestSX1301Conf(t *testing.T) {
},
SX1301Config{
LoRaWANPublic: true,
ClockSource: 1,
ClockSource: pointers.Uint8(1),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ClockSource: pointers.Uint8(1),
ClockSource: func(v uint8) *uint8 { return &v }(1),

AntennaGain: 0,
Radios: []RFConfig{
{
Enable: true,
Type: "SX1257",
Frequency: 867500000,
TxEnable: true,
TxEnable: pointers.Bool(true),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
TxEnable: pointers.Bool(true),
TxEnable: func(v bool) *bool { return &v }(true),

TxFreqMin: 863000000,
TxFreqMax: 870000000,
RSSIOffset: -166,
RSSIOffset: pointers.Float32(-166),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only place you actually may want to have a helper function, since there are 2 usages.
However, why not just define const defaultRSSIOffset = -166 and use &defaultRSSIOffset here and below?

@KrishnaIyer
Copy link
Member Author

@KrishnaIyer KrishnaIyer closed this Apr 2, 2020
@johanstokking johanstokking deleted the fix/2130-router-config branch April 2, 2020 11:44
@johanstokking johanstokking restored the fix/2130-router-config branch April 2, 2020 11:44
@KrishnaIyer KrishnaIyer deleted the fix/2130-router-config branch July 22, 2020 14:35
rvolosatovs added a commit to rvolosatovs/lorawan-stack-fork that referenced this pull request Sep 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working c/gateway conf server This is related to the Gateway Configuration Server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Basic Station Integration: router_config should not include hardware-specific configuration
4 participants