Skip to content

Commit

Permalink
Merge pull request #7235 from TheThingsNetwork/feature/filter-frequen…
Browse files Browse the repository at this point in the history
…cy-plans

Indicate whether the frequency plan is applicable to gateways
  • Loading branch information
halimi authored Sep 5, 2024
2 parents 28504fc + 28fa03d commit 5caad01
Show file tree
Hide file tree
Showing 16 changed files with 397 additions and 307 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ For details about compatibility between different releases, see the **Commitment

### Added

- Option to filter out non-gateway related frequency plans.
- `ListFrequencyPlans` RPC has a new `gateways-only` flag.

### Changed

### Deprecated
Expand Down
1 change: 1 addition & 0 deletions api/ttn/lorawan/v3/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2793,6 +2793,7 @@ PeerInfo
| ----- | ---- | ----- | ----------- |
| `base_frequency` | [`uint32`](#uint32) | | Optional base frequency in MHz for hardware support (433, 470, 868 or 915) |
| `band_id` | [`string`](#string) | | Optional Band ID to filter the results. |
| `gateways_only` | [`bool`](#bool) | | Optional field to include only gateway related results. |

### <a name="ttn.lorawan.v3.ListFrequencyPlansResponse">Message `ListFrequencyPlansResponse`</a>

Expand Down
7 changes: 7 additions & 0 deletions api/ttn/lorawan/v3/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4730,6 +4730,13 @@
"in": "query",
"required": false,
"type": "string"
},
{
"name": "gateways_only",
"description": "Optional field to include only gateway related results.",
"in": "query",
"required": false,
"type": "boolean"
}
],
"tags": [
Expand Down
2 changes: 2 additions & 0 deletions api/ttn/lorawan/v3/configuration_services.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ message ListFrequencyPlansRequest {
uint32 base_frequency = 1;
// Optional Band ID to filter the results.
string band_id = 2;
// Optional field to include only gateway related results.
bool gateways_only = 3;
}

message FrequencyPlanDescription {
Expand Down
14 changes: 13 additions & 1 deletion cmd/ttn-lw-cli/commands/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ func getGatewayEUI(flagSet *pflag.FlagSet, args []string, requireEUI bool) (*ttn
return ids, nil
}

func listFrequencyPlansFlags() *pflag.FlagSet {
flagSet := &pflag.FlagSet{}
flagSet.Uint32("base-frequency", 0, "Base frequency in MHz for hardware support (433, 470, 868 or 915)")
flagSet.String("band-id", "", "Band ID to filter by")
flagSet.Bool("gateways-only", false, "List only frequency plans that support gateways")
return flagSet
}

var (
gatewaysCommand = &cobra.Command{
Use: "gateways",
Expand All @@ -118,12 +126,16 @@ var (
PersistentPreRunE: preRun(),
RunE: func(cmd *cobra.Command, args []string) error {
baseFrequency, _ := cmd.Flags().GetUint32("base-frequency")
bandID, _ := cmd.Flags().GetString("band-id")
gatewaysOnly, _ := cmd.Flags().GetBool("gateways-only")
gs, err := api.Dial(ctx, config.GatewayServerGRPCAddress)
if err != nil {
return err
}
res, err := ttnpb.NewConfigurationClient(gs).ListFrequencyPlans(ctx, &ttnpb.ListFrequencyPlansRequest{
BaseFrequency: baseFrequency,
BandId: bandID,
GatewaysOnly: gatewaysOnly,
})
if err != nil {
return err
Expand Down Expand Up @@ -610,7 +622,7 @@ If both the parameter and the flag are provided, the flag is ignored.`,

func init() {
ttnpb.AddSelectFlagsForGateway(selectGatewayFlags, "", false)
gatewaysListFrequencyPlans.Flags().Uint32("base-frequency", 0, "Base frequency in MHz for hardware support (433, 470, 868 or 915)")
gatewaysListFrequencyPlans.Flags().AddFlagSet(listFrequencyPlansFlags())
gatewaysCommand.AddCommand(gatewaysListFrequencyPlans)
ttnpb.AddSetFlagsForListGatewaysRequest(gatewaysListCommand.Flags(), "", false)
AddCollaboratorFlagAlias(gatewaysListCommand.Flags(), "collaborator")
Expand Down
2 changes: 1 addition & 1 deletion data/lorawan-frequency-plans
3 changes: 3 additions & 0 deletions pkg/frequencyplans/frequencyplans.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ func (fp FrequencyPlan) Extend(extension FrequencyPlan) FrequencyPlan {
val := *extension.MaxEIRP
extended.MaxEIRP = &val
}

return extended
}

Expand Down Expand Up @@ -527,6 +528,8 @@ type FrequencyPlanDescription struct {
BaseFrequency uint16 `yaml:"base-frequency"`
// File is the file where the frequency plan is defined.
File string `yaml:"file"`
// Gateways is a boolean indicating whether the frequency plan is suitable for gateways.
Gateways *bool `yaml:"gateways,omitempty"`
}

var errFetchFailed = errors.Define("fetch", "fetching failed")
Expand Down
6 changes: 6 additions & 0 deletions pkg/frequencyplans/frequencyplans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,19 @@ func TestStore(t *testing.T) {
description: South East Asia
base-frequency: 915
file: AS_923.yml
gateways: true
- id: JP
base-id: AS_923
description: Japan
base-frequency: 915
file: JP.yml
gateways: true
- id: KR
base-id: AS_923
description: South Korea
base-frequency: 915
file: KR.yml
gateways: true
- id: EU_863_870
description: European Union
file: EU.yml
Expand All @@ -106,16 +109,19 @@ func TestStore(t *testing.T) {
description: United States
file: US_915.yml
base-frequency: 915
gateways: true
- id: SA
base-id: AFRICA
description: South Africa
file: AS_923.yml
base-frequency: 868
gateways: false
- id: CA
base-id: US_915
description: Canada
file: EU.yml
base-frequency: 915
gateways: false
`),
"AS_923.yml": []byte(`band-id: AS_923
uplink-channels:
Expand Down
3 changes: 3 additions & 0 deletions pkg/frequencyplans/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func (s *RPCServer) ListFrequencyPlans(ctx context.Context, req *ttnpb.ListFrequ
if req.BandId != "" && req.BandId != desc.BandID {
continue
}
if req.GatewaysOnly && (desc.Gateways == nil || !*desc.Gateways) {
continue
}
res.FrequencyPlans = append(res.FrequencyPlans, &ttnpb.FrequencyPlanDescription{
Id: desc.ID,
BandId: desc.BandID,
Expand Down
9 changes: 9 additions & 0 deletions pkg/frequencyplans/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ func TestRPCServer(t *testing.T) {
description: Frequency Plan A
base-frequency: 868
file: A.yml
gateways: true
- id: B
band-id: AS_923
base-id: A
description: Frequency Plan B
file: B.yml
gateways: false
- id: C
band-id: US_902_928
description: Frequency Plan C
Expand Down Expand Up @@ -86,4 +88,11 @@ func TestRPCServer(t *testing.T) {
a.So(err, should.BeNil)
a.So(bandAS.FrequencyPlans, should.HaveLength, 1)
a.So(bandAS.FrequencyPlans[0], should.Resemble, expectedAll[1])

gateways, err := server.ListFrequencyPlans(context.Background(), &ttnpb.ListFrequencyPlansRequest{
GatewaysOnly: true,
})
a.So(err, should.BeNil)
a.So(gateways.FrequencyPlans, should.HaveLength, 1)
a.So(gateways.FrequencyPlans[0], should.Resemble, expectedAll[0])
}
Loading

0 comments on commit 5caad01

Please sign in to comment.