Skip to content

Commit

Permalink
dcs,api: Return whether the gateway is a managed gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
johanstokking committed Jul 31, 2024
1 parent 5974120 commit 3e73593
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 136 deletions.
1 change: 1 addition & 0 deletions api/ttn/lorawan/v3/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3100,6 +3100,7 @@ DEPRECATED: This message is deprecated and will be removed in a future version o
| ----- | ---- | ----- | ----------- |
| `eui` | [`bytes`](#bytes) | | |
| `supports_claiming` | [`bool`](#bool) | | |
| `is_managed` | [`bool`](#bool) | | Indicates whether the gateway is a managed gateway. If true, when the gateway is successfully claimed, it can be managed with ManagedGatewayConfigurationService. |

#### Field Rules

Expand Down
4 changes: 4 additions & 0 deletions api/ttn/lorawan/v3/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -24696,6 +24696,10 @@
},
"supports_claiming": {
"type": "boolean"
},
"is_managed": {
"type": "boolean",
"description": "Indicates whether the gateway is a managed gateway.\nIf true, when the gateway is successfully claimed, it can be managed with ManagedGatewayConfigurationService."
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions api/ttn/lorawan/v3/deviceclaimingserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ message GetInfoByGatewayEUIResponse {
}
];
bool supports_claiming = 2;
// Indicates whether the gateway is a managed gateway.
// If true, when the gateway is successfully claimed, it can be managed with ManagedGatewayConfigurationService.
bool is_managed = 3;
}

// The GatewayClaimingServer service support claiming and managing gateway claims.
Expand Down
2 changes: 2 additions & 0 deletions pkg/deviceclaimingserver/gateways/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type Claimer interface {
Claim(ctx context.Context, eui types.EUI64, ownerToken string, clusterAddress string) error
// Unclaim unclaims a gateway.
Unclaim(ctx context.Context, eui types.EUI64) error
// IsManagedGateway returns true if the gateway is a managed gateway.
IsManagedGateway(ctx context.Context, eui types.EUI64) (bool, error)
}

// rangeClaimer supports claiming a range of EUIs.
Expand Down
6 changes: 6 additions & 0 deletions pkg/deviceclaimingserver/gateways/ttgc/ttgc.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,9 @@ func (u *Upstream) Unclaim(ctx context.Context, eui types.EUI64) error {
}
return nil
}

// IsManagedGateway implements gateways.GatewayClaimer.
// This method always returns true.
func (*Upstream) IsManagedGateway(context.Context, types.EUI64) (bool, error) {
return true, nil
}
17 changes: 15 additions & 2 deletions pkg/deviceclaimingserver/grpc_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,24 @@ func (gcls gatewayClaimingServer) GetInfoByGatewayEUI(
if err != nil {
return nil, err
}
eui := types.MustEUI64(in.Eui).OrZero()
var (
eui = types.MustEUI64(in.Eui).OrZero()
claimer = gcls.upstream.Claimer(eui)
supportsClaiming = claimer != nil
isManaged bool
)
if supportsClaiming {
var err error
isManaged, err = claimer.IsManagedGateway(ctx, eui)
if err != nil {
return nil, err
}
}

return &ttnpb.GetInfoByGatewayEUIResponse{
Eui: in.Eui,
SupportsClaiming: gcls.upstream.Claimer(eui) != nil,
SupportsClaiming: supportsClaiming,
IsManaged: isManaged,
}, nil
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/deviceclaimingserver/grpc_gateways_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ func TestGatewayClaimingServer(t *testing.T) { // nolint:paralleltest
},
})

mockGatewayclaimer := &MockGatewayClaimer{}
mockGatewayclaimer := &MockGatewayClaimer{
IsManagedGatewayFunc: func(_ context.Context, e types.EUI64) (bool, error) {
return e.Equal(supportedEUI), nil
},
}
mockUpstream, err := gateways.NewUpstream(
ctx,
c,
Expand Down Expand Up @@ -157,6 +161,7 @@ func TestGatewayClaimingServer(t *testing.T) { // nolint:paralleltest
a.So(err, should.BeNil)
a.So(resp.Eui, should.Resemble, unsupportedEUI.Bytes())
a.So(resp.SupportsClaiming, should.BeFalse)
a.So(resp.IsManaged, should.BeFalse)

resp, err = gclsClient.GetInfoByGatewayEUI(
ctx,
Expand All @@ -168,6 +173,7 @@ func TestGatewayClaimingServer(t *testing.T) { // nolint:paralleltest
a.So(err, should.BeNil)
a.So(resp.Eui, should.Resemble, supportedEUI.Bytes())
a.So(resp.SupportsClaiming, should.BeTrue)
a.So(resp.IsManaged, should.BeTrue)

// Test claiming
for _, tc := range []struct {
Expand Down
10 changes: 8 additions & 2 deletions pkg/deviceclaimingserver/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ func (m MockEndDeviceClaimer) BatchUnclaim(
type MockGatewayClaimer struct {
EUIs []types.EUI64

ClaimFunc func(context.Context, types.EUI64, string, string) error
UnclaimFunc func(context.Context, types.EUI64) error
ClaimFunc func(context.Context, types.EUI64, string, string) error
UnclaimFunc func(context.Context, types.EUI64) error
IsManagedGatewayFunc func(context.Context, types.EUI64) (bool, error)
}

// Claim implements gateways.Claimer.
Expand All @@ -99,6 +100,11 @@ func (claimer MockGatewayClaimer) Unclaim(ctx context.Context, eui types.EUI64)
return claimer.UnclaimFunc(ctx, eui)
}

// IsManagedGateway implements gateways.Claimer.
func (claimer MockGatewayClaimer) IsManagedGateway(ctx context.Context, eui types.EUI64) (bool, error) {
return claimer.IsManagedGatewayFunc(ctx, eui)
}

type mockGatewayRegistry struct {
gateways []*ttnpb.Gateway
authorizedMD rpcmetadata.MD
Expand Down
Loading

0 comments on commit 3e73593

Please sign in to comment.