Skip to content

Commit 6f14901

Browse files
authored
Merge pull request #7515 from TheThingsNetwork/feature/assign-mac-settings-profile
Associate MAC settings profile
2 parents ab1baae + 34d569f commit 6f14901

32 files changed

+1973
-528
lines changed

api/ttn/lorawan/v3/api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4028,7 +4028,7 @@ SDKs are responsible for combining (if desired) the three.
40284028
| `resets_join_nonces` | [`bool`](#bool) | | Whether the device resets the join and dev nonces (not LoRaWAN compliant). Stored in Join Server. Copied on creation from template identified by version_ids, if any or from the home Network Server device profile, if any. |
40294029
| `root_keys` | [`RootKeys`](#ttn.lorawan.v3.RootKeys) | | Device root keys. Stored in Join Server. |
40304030
| `net_id` | [`bytes`](#bytes) | | Home NetID. Stored in Join Server. |
4031-
| `mac_settings` | [`MACSettings`](#ttn.lorawan.v3.MACSettings) | | Settings for how the Network Server handles MAC layer for this device. Stored in Network Server. |
4031+
| `mac_settings` | [`MACSettings`](#ttn.lorawan.v3.MACSettings) | | Settings for how the Network Server handles MAC layer for this device. Stored in Network Server. Mutually exclusive with MAC settings profile. |
40324032
| `mac_state` | [`MACState`](#ttn.lorawan.v3.MACState) | | MAC state of the device. Stored in Network Server. |
40334033
| `pending_mac_state` | [`MACState`](#ttn.lorawan.v3.MACState) | | Pending MAC state of the device. Stored in Network Server. |
40344034
| `session` | [`Session`](#ttn.lorawan.v3.Session) | | Current session of the device. Stored in Network Server and Application Server. |
@@ -4054,6 +4054,7 @@ SDKs are responsible for combining (if desired) the three.
40544054
| `last_seen_at` | [`google.protobuf.Timestamp`](#google.protobuf.Timestamp) | | Timestamp when a device uplink has been last observed. This field is set by the Application Server and stored in the Identity Server. |
40554055
| `serial_number` | [`string`](#string) | | |
40564056
| `lora_alliance_profile_ids` | [`LoRaAllianceProfileIdentifiers`](#ttn.lorawan.v3.LoRaAllianceProfileIdentifiers) | | |
4057+
| `mac_settings_profile_ids` | [`MACSettingsProfileIdentifiers`](#ttn.lorawan.v3.MACSettingsProfileIdentifiers) | | MAC settings profile identifiers. Mutually exclusive with MAC settings. |
40574058

40584059
#### Field Rules
40594060

api/ttn/lorawan/v3/api.swagger.json

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21865,7 +21865,7 @@
2186521865
},
2186621866
"mac_settings": {
2186721867
"$ref": "#/definitions/v3MACSettings",
21868-
"description": "Settings for how the Network Server handles MAC layer for this device. Stored in Network Server."
21868+
"description": "Settings for how the Network Server handles MAC layer for this device. Stored in Network Server.\nMutually exclusive with MAC settings profile."
2186921869
},
2187021870
"mac_state": {
2187121871
"$ref": "#/definitions/v3MACState",
@@ -21981,6 +21981,10 @@
2198121981
},
2198221982
"lora_alliance_profile_ids": {
2198321983
"$ref": "#/definitions/v3LoRaAllianceProfileIdentifiers"
21984+
},
21985+
"mac_settings_profile_ids": {
21986+
"$ref": "#/definitions/v3MACSettingsProfileIdentifiers",
21987+
"description": "MAC settings profile identifiers.\nMutually exclusive with MAC settings."
2198421988
}
2198521989
},
2198621990
"description": "Defines an End Device registration and its state on the network.\nThe persistence of the EndDevice is divided between the Network Server, Application Server and Join Server.\nSDKs are responsible for combining (if desired) the three."
@@ -23300,7 +23304,7 @@
2330023304
},
2330123305
"mac_settings": {
2330223306
"$ref": "#/definitions/v3MACSettings",
23303-
"description": "Settings for how the Network Server handles MAC layer for this device. Stored in Network Server."
23307+
"description": "Settings for how the Network Server handles MAC layer for this device. Stored in Network Server.\nMutually exclusive with MAC settings profile."
2330423308
},
2330523309
"mac_state": {
2330623310
"$ref": "#/definitions/v3MACState",
@@ -23416,6 +23420,10 @@
2341623420
},
2341723421
"lora_alliance_profile_ids": {
2341823422
"$ref": "#/definitions/v3LoRaAllianceProfileIdentifiers"
23423+
},
23424+
"mac_settings_profile_ids": {
23425+
"$ref": "#/definitions/v3MACSettingsProfileIdentifiers",
23426+
"description": "MAC settings profile identifiers.\nMutually exclusive with MAC settings."
2341923427
}
2342023428
},
2342123429
"description": "Defines an End Device registration and its state on the network.\nThe persistence of the EndDevice is divided between the Network Server, Application Server and Join Server.\nSDKs are responsible for combining (if desired) the three."
@@ -23780,7 +23788,7 @@
2378023788
},
2378123789
"mac_settings": {
2378223790
"$ref": "#/definitions/v3MACSettings",
23783-
"description": "Settings for how the Network Server handles MAC layer for this device. Stored in Network Server."
23791+
"description": "Settings for how the Network Server handles MAC layer for this device. Stored in Network Server.\nMutually exclusive with MAC settings profile."
2378423792
},
2378523793
"mac_state": {
2378623794
"$ref": "#/definitions/v3MACState",
@@ -23896,6 +23904,10 @@
2389623904
},
2389723905
"lora_alliance_profile_ids": {
2389823906
"$ref": "#/definitions/v3LoRaAllianceProfileIdentifiers"
23907+
},
23908+
"mac_settings_profile_ids": {
23909+
"$ref": "#/definitions/v3MACSettingsProfileIdentifiers",
23910+
"description": "MAC settings profile identifiers.\nMutually exclusive with MAC settings."
2389923911
}
2390023912
},
2390123913
"description": "Defines an End Device registration and its state on the network.\nThe persistence of the EndDevice is divided between the Network Server, Application Server and Join Server.\nSDKs are responsible for combining (if desired) the three."
@@ -24083,7 +24095,7 @@
2408324095
},
2408424096
"mac_settings": {
2408524097
"$ref": "#/definitions/v3MACSettings",
24086-
"description": "Settings for how the Network Server handles MAC layer for this device. Stored in Network Server."
24098+
"description": "Settings for how the Network Server handles MAC layer for this device. Stored in Network Server.\nMutually exclusive with MAC settings profile."
2408724099
},
2408824100
"mac_state": {
2408924101
"$ref": "#/definitions/v3MACState",
@@ -24199,6 +24211,10 @@
2419924211
},
2420024212
"lora_alliance_profile_ids": {
2420124213
"$ref": "#/definitions/v3LoRaAllianceProfileIdentifiers"
24214+
},
24215+
"mac_settings_profile_ids": {
24216+
"$ref": "#/definitions/v3MACSettingsProfileIdentifiers",
24217+
"description": "MAC settings profile identifiers.\nMutually exclusive with MAC settings."
2420224218
}
2420324219
},
2420424220
"description": "Defines an End Device registration and its state on the network.\nThe persistence of the EndDevice is divided between the Network Server, Application Server and Join Server.\nSDKs are responsible for combining (if desired) the three."
@@ -25774,7 +25790,7 @@
2577425790
},
2577525791
"mac_settings": {
2577625792
"$ref": "#/definitions/v3MACSettings",
25777-
"description": "Settings for how the Network Server handles MAC layer for this device. Stored in Network Server."
25793+
"description": "Settings for how the Network Server handles MAC layer for this device. Stored in Network Server.\nMutually exclusive with MAC settings profile."
2577825794
},
2577925795
"mac_state": {
2578025796
"$ref": "#/definitions/v3MACState",
@@ -25890,6 +25906,10 @@
2589025906
},
2589125907
"lora_alliance_profile_ids": {
2589225908
"$ref": "#/definitions/v3LoRaAllianceProfileIdentifiers"
25909+
},
25910+
"mac_settings_profile_ids": {
25911+
"$ref": "#/definitions/v3MACSettingsProfileIdentifiers",
25912+
"description": "MAC settings profile identifiers.\nMutually exclusive with MAC settings."
2589325913
}
2589425914
},
2589525915
"description": "Defines an End Device registration and its state on the network.\nThe persistence of the EndDevice is divided between the Network Server, Application Server and Join Server.\nSDKs are responsible for combining (if desired) the three."
@@ -27803,7 +27823,7 @@
2780327823
},
2780427824
"mac_settings": {
2780527825
"$ref": "#/definitions/v3MACSettings",
27806-
"description": "Settings for how the Network Server handles MAC layer for this device. Stored in Network Server."
27826+
"description": "Settings for how the Network Server handles MAC layer for this device. Stored in Network Server.\nMutually exclusive with MAC settings profile."
2780727827
},
2780827828
"mac_state": {
2780927829
"$ref": "#/definitions/v3MACState",
@@ -27919,6 +27939,10 @@
2791927939
},
2792027940
"lora_alliance_profile_ids": {
2792127941
"$ref": "#/definitions/v3LoRaAllianceProfileIdentifiers"
27942+
},
27943+
"mac_settings_profile_ids": {
27944+
"$ref": "#/definitions/v3MACSettingsProfileIdentifiers",
27945+
"description": "MAC settings profile identifiers.\nMutually exclusive with MAC settings."
2792227946
}
2792327947
},
2792427948
"description": "Defines an End Device registration and its state on the network.\nThe persistence of the EndDevice is divided between the Network Server, Application Server and Join Server.\nSDKs are responsible for combining (if desired) the three."

api/ttn/lorawan/v3/end_device.proto

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,7 @@ message EndDevice {
11011101
}
11021102
];
11031103
// Settings for how the Network Server handles MAC layer for this device. Stored in Network Server.
1104+
// Mutually exclusive with MAC settings profile.
11041105
MACSettings mac_settings = 24;
11051106
// MAC state of the device. Stored in Network Server.
11061107
MACState mac_state = 25;
@@ -1211,7 +1212,11 @@ message EndDevice {
12111212
reserved 57;
12121213
reserved "label_ids";
12131214

1214-
// next: 58;
1215+
// MAC settings profile identifiers.
1216+
// Mutually exclusive with MAC settings.
1217+
MACSettingsProfileIdentifiers mac_settings_profile_ids = 58;
1218+
1219+
// next: 59;
12151220
}
12161221

12171222
message EndDevices {

pkg/networkserver/downlink.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,15 @@ func (ns *NetworkServer) nextDataDownlinkTaskAt(ctx context.Context, dev *ttnpb.
135135
log.FromContext(ctx).WithError(err).Warn("Failed to determine device band")
136136
return time.Time{}, nil
137137
}
138-
slot, ok := nextDataDownlinkSlot(ctx, dev, phy, ns.defaultMACSettings, earliestAt)
138+
var profile *ttnpb.MACSettingsProfile
139+
if dev.MacSettingsProfileIds != nil {
140+
profile, err = ns.macSettingsProfiles.Get(ctx, dev.GetMacSettingsProfileIds(), []string{"mac_settings"})
141+
if err != nil {
142+
log.FromContext(ctx).WithError(err).Warn("Failed to get MAC settings profile")
143+
return time.Time{}, nil
144+
}
145+
}
146+
slot, ok := nextDataDownlinkSlot(ctx, dev, phy, ns.defaultMACSettings, earliestAt, profile.GetMacSettings())
139147
if !ok {
140148
return time.Time{}, nil
141149
}
@@ -597,8 +605,26 @@ func (ns *NetworkServer) generateDataDownlink(ctx context.Context, dev *ttnpb.En
597605
logger = logger.WithField("f_pending", pld.FHdr.FCtrl.FPending)
598606
ctx = log.NewContext(ctx, logger)
599607

608+
var (
609+
err error
610+
profile *ttnpb.MACSettingsProfile
611+
)
612+
if dev.MacSettingsProfileIds != nil {
613+
profile, err = ns.macSettingsProfiles.Get(ctx, dev.GetMacSettingsProfileIds(), []string{"mac_settings"})
614+
if err != nil {
615+
logger.WithError(err).Warn("Failed to get MAC settings profile")
616+
return nil, genState, err
617+
}
618+
}
619+
600620
if mType == ttnpb.MType_CONFIRMED_DOWN && class != ttnpb.Class_CLASS_A {
601-
confirmedAt, ok := nextConfirmedNetworkInitiatedDownlinkAt(ctx, dev, phy, ns.defaultMACSettings)
621+
confirmedAt, ok := nextConfirmedNetworkInitiatedDownlinkAt(
622+
ctx,
623+
dev,
624+
phy,
625+
ns.defaultMACSettings,
626+
profile.GetMacSettings(),
627+
)
602628
if !ok {
603629
return nil, genState, ErrCorruptedMACState.
604630
WithCause(ErrNetworkDownlinkSlot)
@@ -1931,7 +1957,19 @@ func (ns *NetworkServer) processDownlinkTask(ctx context.Context, consumerID str
19311957
return nil, nil, nil
19321958
}
19331959

1934-
if !mac.DeviceScheduleDownlinks(dev, ns.defaultMACSettings) {
1960+
var (
1961+
err error
1962+
profile *ttnpb.MACSettingsProfile
1963+
)
1964+
if dev.MacSettingsProfileIds != nil {
1965+
profile, err = ns.macSettingsProfiles.Get(ctx, dev.GetMacSettingsProfileIds(), []string{"mac_settings"})
1966+
if err != nil {
1967+
logger.WithError(err).Warn("Failed to get MAC settings profile")
1968+
return dev, nil, err
1969+
}
1970+
}
1971+
1972+
if !mac.DeviceScheduleDownlinks(dev, ns.defaultMACSettings, profile.GetMacSettings()) {
19351973
logger.Debug("Downlink slot skipped since scheduling is disabled")
19361974
return dev, nil, nil
19371975
}
@@ -2154,7 +2192,7 @@ func (ns *NetworkServer) processDownlinkTask(ctx context.Context, consumerID str
21542192
}
21552193
var earliestAt time.Time
21562194
for {
2157-
v, ok := nextDataDownlinkSlot(ctx, dev, phy, ns.defaultMACSettings, earliestAt)
2195+
v, ok := nextDataDownlinkSlot(ctx, dev, phy, ns.defaultMACSettings, earliestAt, profile.GetMacSettings())
21582196
if !ok {
21592197
return dev, nil, nil
21602198
}

0 commit comments

Comments
 (0)