Skip to content

Commit

Permalink
all: Extract relay uplink forwarding rule message
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansmares committed Dec 8, 2023
1 parent d6c4cff commit 3e607c7
Show file tree
Hide file tree
Showing 16 changed files with 2,227 additions and 2,142 deletions.
34 changes: 17 additions & 17 deletions api/ttn/lorawan/v3/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@
- [Message `MACState.UplinkMessage.RxMetadata.RelayMetadata`](#ttn.lorawan.v3.MACState.UplinkMessage.RxMetadata.RelayMetadata)
- [Message `MACState.UplinkMessage.TxSettings`](#ttn.lorawan.v3.MACState.UplinkMessage.TxSettings)
- [Message `RelayParameters`](#ttn.lorawan.v3.RelayParameters)
- [Message `RelayUplinkForwardingRule`](#ttn.lorawan.v3.RelayUplinkForwardingRule)
- [Message `ResetAndGetEndDeviceRequest`](#ttn.lorawan.v3.ResetAndGetEndDeviceRequest)
- [Message `ServedRelayParameters`](#ttn.lorawan.v3.ServedRelayParameters)
- [Message `ServingRelayForwardingLimits`](#ttn.lorawan.v3.ServingRelayForwardingLimits)
- [Message `ServingRelayParameters`](#ttn.lorawan.v3.ServingRelayParameters)
- [Message `ServingRelayParameters.UplinkForwardingRule`](#ttn.lorawan.v3.ServingRelayParameters.UplinkForwardingRule)
- [Message `Session`](#ttn.lorawan.v3.Session)
- [Message `SetEndDeviceRequest`](#ttn.lorawan.v3.SetEndDeviceRequest)
- [Message `UpdateEndDeviceRequest`](#ttn.lorawan.v3.UpdateEndDeviceRequest)
Expand Down Expand Up @@ -4373,6 +4373,21 @@ This is used internally by the Network Server.
| `serving` | [`ServingRelayParameters`](#ttn.lorawan.v3.ServingRelayParameters) | | Parameters related to a relay which is serving end devices. |
| `served` | [`ServedRelayParameters`](#ttn.lorawan.v3.ServedRelayParameters) | | Parameters related to an end device served by a relay. |

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

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `limits` | [`RelayUplinkForwardLimits`](#ttn.lorawan.v3.RelayUplinkForwardLimits) | | Bucket configuration for the served end device. If unset, no individual limits will apply to the end device, but the relay global limitations will apply. |
| `last_w_f_cnt` | [`uint32`](#uint32) | | Last wake on radio frame counter used by the served end device. |
| `device_id` | [`string`](#string) | | End device identifier of the served end device. |
| `session_key_id` | [`bytes`](#bytes) | | Session key ID of the session keys used to derive the root relay session key. |

#### Field Rules

| Field | Validations |
| ----- | ----------- |
| `device_id` | <p>`string.max_len`: `36`</p><p>`string.pattern`: `^[a-z0-9](?:[-]?[a-z0-9]){2,}$`</p> |

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

| Field | Type | Label | Description |
Expand Down Expand Up @@ -4421,7 +4436,7 @@ This is used internally by the Network Server.
| `second_channel` | [`RelaySecondChannel`](#ttn.lorawan.v3.RelaySecondChannel) | | Second wake on radio channel configuration. |
| `default_channel_index` | [`uint32`](#uint32) | | Index of the default wake on radio channel. |
| `cad_periodicity` | [`RelayCADPeriodicity`](#ttn.lorawan.v3.RelayCADPeriodicity) | | Channel activity detection periodicity. |
| `uplink_forwarding_rules` | [`ServingRelayParameters.UplinkForwardingRule`](#ttn.lorawan.v3.ServingRelayParameters.UplinkForwardingRule) | repeated | Configured uplink forwarding rules. |
| `uplink_forwarding_rules` | [`RelayUplinkForwardingRule`](#ttn.lorawan.v3.RelayUplinkForwardingRule) | repeated | Configured uplink forwarding rules. |
| `limits` | [`ServingRelayForwardingLimits`](#ttn.lorawan.v3.ServingRelayForwardingLimits) | | Configured forwarding limits. If unset, the default value from Network Server configuration will be used. |

#### Field Rules
Expand All @@ -4432,21 +4447,6 @@ This is used internally by the Network Server.
| `cad_periodicity` | <p>`enum.defined_only`: `true`</p> |
| `uplink_forwarding_rules` | <p>`repeated.max_items`: `16`</p> |

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

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `limits` | [`RelayUplinkForwardLimits`](#ttn.lorawan.v3.RelayUplinkForwardLimits) | | Bucket configuration for the served end device. If unset, no individual limits will apply to the end device, but the relay global limitations will apply. |
| `last_w_f_cnt` | [`uint32`](#uint32) | | Last wake on radio frame counter used by the served end device. |
| `device_id` | [`string`](#string) | | End device identifier of the served end device. |
| `session_key_id` | [`bytes`](#bytes) | | Session key ID of the session keys used to derive the root relay session key. |

#### Field Rules

| Field | Validations |
| ----- | ----------- |
| `device_id` | <p>`string.max_len`: `36`</p><p>`string.pattern`: `^[a-z0-9](?:[-]?[a-z0-9]){2,}$`</p> |

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

| Field | Type | Label | Description |
Expand Down
48 changes: 24 additions & 24 deletions api/ttn/lorawan/v3/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -19323,29 +19323,6 @@
"default": "ENABLED",
"description": " - ENABLED: No restrictions are in place.\n - WARNING: Warnings are being emitted that the provider will be deprecated in the future.\n - DISABLED: New integrations cannot be set up, and old ones do not start."
},
"ServingRelayParametersUplinkForwardingRule": {
"type": "object",
"properties": {
"limits": {
"$ref": "#/definitions/v3RelayUplinkForwardLimits",
"description": "Bucket configuration for the served end device.\nIf unset, no individual limits will apply to the end device, but the relay global limitations will apply."
},
"last_w_f_cnt": {
"type": "integer",
"format": "int64",
"description": "Last wake on radio frame counter used by the served end device."
},
"device_id": {
"type": "string",
"description": "End device identifier of the served end device."
},
"session_key_id": {
"type": "string",
"format": "byte",
"description": "Session key ID of the session keys used to derive the root relay session key."
}
}
},
"TxAcknowledgmentResult": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -25668,6 +25645,29 @@
}
}
},
"v3RelayUplinkForwardingRule": {
"type": "object",
"properties": {
"limits": {
"$ref": "#/definitions/v3RelayUplinkForwardLimits",
"description": "Bucket configuration for the served end device.\nIf unset, no individual limits will apply to the end device, but the relay global limitations will apply."
},
"last_w_f_cnt": {
"type": "integer",
"format": "int64",
"description": "Last wake on radio frame counter used by the served end device."
},
"device_id": {
"type": "string",
"description": "End device identifier of the served end device."
},
"session_key_id": {
"type": "string",
"format": "byte",
"description": "Session key ID of the session keys used to derive the root relay session key."
}
}
},
"v3Right": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -25929,7 +25929,7 @@
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/ServingRelayParametersUplinkForwardingRule"
"$ref": "#/definitions/v3RelayUplinkForwardingRule"
},
"description": "Configured uplink forwarding rules."
},
Expand Down
40 changes: 23 additions & 17 deletions api/ttn/lorawan/v3/end_device.proto
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ message ServingRelayForwardingLimits {
RelayForwardLimits overall = 5;
}

message RelayUplinkForwardingRule {
option (thethings.flags.message) = {
select: true,
set: true
};

// Bucket configuration for the served end device.
// If unset, no individual limits will apply to the end device, but the relay global limitations will apply.
RelayUplinkForwardLimits limits = 1;
// Last wake on radio frame counter used by the served end device.
uint32 last_w_f_cnt = 2;

// End device identifier of the served end device.
string device_id = 3 [(validate.rules).string = {
pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$",
max_len: 36,
ignore_empty: true
}];
// Session key ID of the session keys used to derive the root relay session key.
bytes session_key_id = 4;
}

message ServingRelayParameters {
option (thethings.flags.message) = {
select: true,
Expand All @@ -124,24 +146,8 @@ message ServingRelayParameters {
uint32 default_channel_index = 2 [(validate.rules).uint32.lte = 255];
// Channel activity detection periodicity.
RelayCADPeriodicity cad_periodicity = 3 [(validate.rules).enum.defined_only = true];
message UplinkForwardingRule {
// Bucket configuration for the served end device.
// If unset, no individual limits will apply to the end device, but the relay global limitations will apply.
RelayUplinkForwardLimits limits = 1;
// Last wake on radio frame counter used by the served end device.
uint32 last_w_f_cnt = 2;

// End device identifier of the served end device.
string device_id = 3 [(validate.rules).string = {
pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$",
max_len: 36,
ignore_empty: true
}];
// Session key ID of the session keys used to derive the root relay session key.
bytes session_key_id = 4;
}
// Configured uplink forwarding rules.
repeated UplinkForwardingRule uplink_forwarding_rules = 4 [(validate.rules).repeated.max_items = 16];
repeated RelayUplinkForwardingRule uplink_forwarding_rules = 4 [(validate.rules).repeated.max_items = 16];
// Configured forwarding limits.
// If unset, the default value from Network Server configuration will be used.
ServingRelayForwardingLimits limits = 5;
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkserver/mac/relay_ctrl_uplink_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func HandleRelayCtrlUplinkListAns(
switch req.Action {
case ttnpb.RelayCtrlUplinkListAction_RELAY_CTRL_UPLINK_LIST_ACTION_READ_W_F_CNT:
case ttnpb.RelayCtrlUplinkListAction_RELAY_CTRL_UPLINK_LIST_ACTION_REMOVE_TRUSTED_END_DEVICE:
currentServing.UplinkForwardingRules[req.RuleIndex] = &ttnpb.ServingRelayParameters_UplinkForwardingRule{}
currentServing.UplinkForwardingRules[req.RuleIndex] = &ttnpb.RelayUplinkForwardingRule{}
default:
panic("unreachable")
}
Expand Down
26 changes: 13 additions & 13 deletions pkg/networkserver/mac/relay_ctrl_uplink_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestDeviceNeedsRelayCtrlUplinkListReq(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{
LastWFCnt: 42,

Expand All @@ -78,7 +78,7 @@ func TestDeviceNeedsRelayCtrlUplinkListReq(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{
LastWFCnt: 12,

Expand All @@ -94,7 +94,7 @@ func TestDeviceNeedsRelayCtrlUplinkListReq(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{
Limits: &ttnpb.RelayUplinkForwardLimits{
BucketSize: ttnpb.RelayLimitBucketSize_RELAY_LIMIT_BUCKET_SIZE_12,
Expand All @@ -121,7 +121,7 @@ func TestDeviceNeedsRelayCtrlUplinkListReq(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{
LastWFCnt: 12,

Expand All @@ -143,7 +143,7 @@ func TestDeviceNeedsRelayCtrlUplinkListReq(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{},
{
LastWFCnt: 12,
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestEnqueueRelayCtrlUplinkListReq(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{
LastWFCnt: 42,

Expand All @@ -220,7 +220,7 @@ func TestEnqueueRelayCtrlUplinkListReq(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{},
{
LastWFCnt: 42,
Expand All @@ -242,7 +242,7 @@ func TestEnqueueRelayCtrlUplinkListReq(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{
LastWFCnt: 42,

Expand All @@ -264,7 +264,7 @@ func TestEnqueueRelayCtrlUplinkListReq(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{},
{
LastWFCnt: 42,
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestHandleRelayCtrlUplinkListAns(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{
LastWFCnt: 42,

Expand All @@ -358,7 +358,7 @@ func TestHandleRelayCtrlUplinkListAns(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{},
{
LastWFCnt: 42,
Expand All @@ -385,7 +385,7 @@ func TestHandleRelayCtrlUplinkListAns(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{},
{
LastWFCnt: 42,
Expand All @@ -402,7 +402,7 @@ func TestHandleRelayCtrlUplinkListAns(t *testing.T) {
Relay: &ttnpb.RelayParameters{
Mode: &ttnpb.RelayParameters_Serving{
Serving: &ttnpb.ServingRelayParameters{
UplinkForwardingRules: []*ttnpb.ServingRelayParameters_UplinkForwardingRule{
UplinkForwardingRules: []*ttnpb.RelayUplinkForwardingRule{
{},
{
LastWFCnt: 42,
Expand Down
6 changes: 3 additions & 3 deletions pkg/networkserver/mac/relay_update_uplink_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

var (
emptyRelayUplinkForwardingRule = &ttnpb.ServingRelayParameters_UplinkForwardingRule{}
emptyRelayUplinkForwardingRule = &ttnpb.RelayUplinkForwardingRule{}

// EvtEnqueueRelayUpdateUplinkListRequest is emitted when a relay update uplink list request is enqueued.
EvtEnqueueRelayUpdateUplinkListRequest = defineEnqueueMACRequestEvent(
Expand Down Expand Up @@ -178,12 +178,12 @@ func HandleRelayUpdateUplinkListAns(
currentServing.UplinkForwardingRules = append(
currentServing.UplinkForwardingRules,
make(
[]*ttnpb.ServingRelayParameters_UplinkForwardingRule,
[]*ttnpb.RelayUplinkForwardingRule,
1+int(req.RuleIndex-uint32(n)),
)...,
)
for i := n; i < len(currentServing.UplinkForwardingRules); i++ {
currentServing.UplinkForwardingRules[i] = &ttnpb.ServingRelayParameters_UplinkForwardingRule{}
currentServing.UplinkForwardingRules[i] = &ttnpb.RelayUplinkForwardingRule{}
}
}
rule := currentServing.UplinkForwardingRules[req.RuleIndex]
Expand Down
Loading

0 comments on commit 3e607c7

Please sign in to comment.