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
Closed
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
34 changes: 12 additions & 22 deletions pkg/gatewayserver/io/basicstationlns/basicstationlns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,22 +491,17 @@ func TestVersion(t *testing.T) {
SX1301Config: []shared.SX1301Config{
{
LoRaWANPublic: true,
ClockSource: 1,
AntennaGain: 0,
Radios: []shared.RFConfig{
{
Enable: true,
Frequency: 867500000,
TxEnable: true,
RSSIOffset: -166,
Enable: true,
Frequency: 867500000,
},
{
Enable: true,
Frequency: 868500000,
TxEnable: false,
TxFreqMin: 0,
TxFreqMax: 0,
RSSIOffset: -166,
Enable: true,
Frequency: 868500000,
TxFreqMin: 0,
TxFreqMax: 0,
},
},
Channels: []shared.IFConfig{
Expand Down Expand Up @@ -573,22 +568,17 @@ func TestVersion(t *testing.T) {
SX1301Config: []shared.SX1301Config{
{
LoRaWANPublic: true,
ClockSource: 1,
AntennaGain: 0,
Radios: []shared.RFConfig{
{
Enable: true,
Frequency: 867500000,
TxEnable: true,
RSSIOffset: -166,
Enable: true,
Frequency: 867500000,
},
{
Enable: true,
Frequency: 868500000,
TxEnable: false,
TxFreqMin: 0,
TxFreqMax: 0,
RSSIOffset: -166,
Enable: true,
Frequency: 868500000,
TxFreqMin: 0,
TxFreqMax: 0,
},
},
Channels: []shared.IFConfig{
Expand Down
5 changes: 4 additions & 1 deletion pkg/pfconfig/basicstationlns/basicstationlns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

sx1301Conf.TxLUTConfigs = nil
for i := range sx1301Conf.Radios {
sx1301Conf.Radios[i].Type = ""
sx1301Conf.Radios[i].TxEnable = nil
sx1301Conf.Radios[i].RSSIOffset = nil
}
if err != nil {
return RouterConfig{}, err
Expand Down
15 changes: 2 additions & 13 deletions pkg/pfconfig/basicstationlns/basicstationlns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,15 @@ func TestGetRouterConfig(t *testing.T) {
SX1301Config: []shared.SX1301Config{
{
LoRaWANPublic: true,
ClockSource: 0,
AntennaGain: 0,
Radios: []shared.RFConfig{
{
Enable: true,
Frequency: 922300000,
TxEnable: true,
},
{
Enable: false,
Frequency: 923000000,
TxEnable: false,
},
},
Channels: []shared.IFConfig{
Expand Down Expand Up @@ -178,18 +175,15 @@ func TestGetRouterConfig(t *testing.T) {
SX1301Config: []shared.SX1301Config{
{
LoRaWANPublic: true,
ClockSource: 0,
AntennaGain: 0,
Radios: []shared.RFConfig{
{
Enable: true,
Frequency: 922300000,
TxEnable: true,
},
{
Enable: false,
Frequency: 923000000,
TxEnable: false,
},
},
Channels: []shared.IFConfig{
Expand Down Expand Up @@ -243,7 +237,8 @@ func TestGetRouterConfigWithMultipleFP(t *testing.T) {
Name: "ValidFrequencyPlan",
BandID: "US_902_928",
FrequencyPlans: map[string]*frequencyplans.FrequencyPlan{test.USFrequencyPlanID: {
BandID: "US_902_928",
ClockSource: 0,
BandID: "US_902_928",
Radios: []frequencyplans.Radio{
{
Enable: true,
Expand Down Expand Up @@ -306,18 +301,15 @@ func TestGetRouterConfigWithMultipleFP(t *testing.T) {
SX1301Config: []shared.SX1301Config{
{
LoRaWANPublic: true,
ClockSource: 0,
AntennaGain: 0,
Radios: []shared.RFConfig{
{
Enable: true,
Frequency: 924300000,
TxEnable: true,
},
{
Enable: false,
Frequency: 925000000,
TxEnable: false,
},
},
Channels: []shared.IFConfig{
Expand All @@ -335,18 +327,15 @@ func TestGetRouterConfigWithMultipleFP(t *testing.T) {
},
{
LoRaWANPublic: true,
ClockSource: 0,
AntennaGain: 0,
Radios: []shared.RFConfig{
{
Enable: true,
Frequency: 924300000,
TxEnable: true,
},
{
Enable: false,
Frequency: 925000000,
TxEnable: false,
},
},
Channels: []shared.IFConfig{
Expand Down
27 changes: 14 additions & 13 deletions pkg/pfconfig/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import (
"go.thethings.network/lorawan-stack/pkg/errors"
"go.thethings.network/lorawan-stack/pkg/frequencyplans"
"go.thethings.network/lorawan-stack/pkg/ttnpb"
"go.thethings.network/lorawan-stack/pkg/util/pointers"
)

// SX1301Config contains the configuration for the SX1301 concentrator.
type SX1301Config struct {
LoRaWANPublic bool
ClockSource uint8
ClockSource *uint8
AntennaGain float32
LBTConfig *LBTConfig
Radios []RFConfig
Expand Down Expand Up @@ -85,7 +86,7 @@ func (m orderedMap) MarshalJSON() ([]byte, error) {
func (c SX1301Config) MarshalJSON() ([]byte, error) {
var m orderedMap
m.add("lorawan_public", c.LoRaWANPublic)
m.add("clksrc", c.ClockSource)
m.add("clksrc,omitempty", c.ClockSource)
m.add("antenna_gain", c.AntennaGain)
if c.LBTConfig != nil {
m.add("lbt_cfg", *c.LBTConfig)
Expand Down Expand Up @@ -206,14 +207,14 @@ type LBTChannelConfig struct {

// RFConfig contains the configuration for one of the radios.
type RFConfig struct {
Enable bool `json:"enable"`
Type string `json:"type,omitempty"`
Frequency uint64 `json:"freq"`
RSSIOffset float32 `json:"rssi_offset"`
TxEnable bool `json:"tx_enable"`
TxFreqMin uint64 `json:"tx_freq_min,omitempty"`
TxFreqMax uint64 `json:"tx_freq_max,omitempty"`
TxNotchFreq uint64 `json:"tx_notch_freq,omitempty"`
Enable bool `json:"enable"`
Type string `json:"type,omitempty"`
Frequency uint64 `json:"freq"`
RSSIOffset *float32 `json:"rssi_offset,omitempty"`
TxEnable *bool `json:"tx_enable,omitempty"`
TxFreqMin uint64 `json:"tx_freq_min,omitempty"`
TxFreqMax uint64 `json:"tx_freq_max,omitempty"`
TxNotchFreq uint64 `json:"tx_notch_freq,omitempty"`
}

// IFConfig contains the configuration for one of the channels.
Expand Down Expand Up @@ -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


if frequencyPlan.LBT != nil {
lbtConfig := &LBTConfig{
Expand All @@ -311,10 +312,10 @@ func BuildSX1301Config(frequencyPlan *frequencyplans.FrequencyPlan) (*SX1301Conf
Enable: radio.Enable,
Type: radio.ChipType,
Frequency: radio.Frequency,
RSSIOffset: radio.RSSIOffset,
RSSIOffset: &radio.RSSIOffset,
}
if radio.TxConfiguration != nil {
rfConfig.TxEnable = true
rfConfig.TxEnable = pointers.Bool(true)
rfConfig.TxFreqMin = radio.TxConfiguration.MinFrequency
rfConfig.TxFreqMax = radio.TxConfiguration.MaxFrequency
if radio.TxConfiguration.NotchFrequency != nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/pfconfig/shared/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"go.thethings.network/lorawan-stack/pkg/errors"
"go.thethings.network/lorawan-stack/pkg/frequencyplans"
. "go.thethings.network/lorawan-stack/pkg/pfconfig/shared"
"go.thethings.network/lorawan-stack/pkg/util/pointers"
)

func TestSX1301Conf(t *testing.T) {
Expand Down Expand Up @@ -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?

},
{
Enable: true, Type: "SX1257",
Frequency: 868500000,
TxEnable: false,
TxFreqMin: 0,
TxFreqMax: 0,
RSSIOffset: -166,
RSSIOffset: pointers.Float32(-166),
},
},
Channels: []IFConfig{
Expand Down
32 changes: 32 additions & 0 deletions pkg/util/pointers/pointers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright © 2020 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package pointers

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


// Duration returns a duration pointer for the given value.
func Duration(d time.Duration) *time.Duration { return &d }

// Time returns a time.Time pointer for the given value.
func Time(t time.Time) *time.Time { return &t }

// Float32 returns a float32 pointer for the given value.
func Float32(v float32) *float32 { return &v }

// Uint8 returns a uint8 pointer for the given value.
func Uint8(v uint8) *uint8 { return &v }