Skip to content

Commit be9a65e

Browse files
author
Vinod Patmanathan
committed
feat: add HasUserLocationInformationNRExtension helper
Add a small NGAP-aware helper that reports whether a given UserLocationInformationNR carries a protocol extension with the specified ProtocolIE-ID inside its IEExtensions container. Generic over the extension ID, so callers can compose it with any existing or future ProtocolIEID* constant (NRNTN-TAI-Information being the immediate use case from omec-project/amf#684). Keeping NGAP-aware inspection helpers in this repo makes the eventual N2 release uplift easier to scope: all NGAP-touching code lives here. Signed-off-by: Vinod Patmanathan <vinod.patmanathan@forsway.com>
1 parent 7b7a658 commit be9a65e

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

extensions.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2026 Forsway Solutions AB
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package ngap
6+
7+
import "github.com/omec-project/ngap/ngapType"
8+
9+
// HasUserLocationInformationNRExtension reports whether the given
10+
// UserLocationInformationNR carries a protocol extension with the
11+
// specified ProtocolIE-ID inside its IEExtensions container.
12+
//
13+
// A nil UserLocationInformationNR or a nil IEExtensions container both
14+
// yield false.
15+
func HasUserLocationInformationNRExtension(loc *ngapType.UserLocationInformationNR, id int64) bool {
16+
if loc == nil || loc.IEExtensions == nil {
17+
return false
18+
}
19+
for _, ext := range loc.IEExtensions.List {
20+
if ext.Id.Value == id {
21+
return true
22+
}
23+
}
24+
return false
25+
}

extensions_test.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2026 Forsway Solutions AB
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package ngap_test
6+
7+
import (
8+
"testing"
9+
10+
"github.com/omec-project/ngap"
11+
"github.com/omec-project/ngap/ngapType"
12+
)
13+
14+
func TestHasUserLocationInformationNRExtension(t *testing.T) {
15+
tests := []struct {
16+
name string
17+
loc *ngapType.UserLocationInformationNR
18+
id int64
19+
want bool
20+
}{
21+
{
22+
name: "nil location",
23+
loc: nil,
24+
id: ngapType.ProtocolIEIDNRNTNTAIInformation,
25+
want: false,
26+
},
27+
{
28+
name: "nil extensions",
29+
loc: &ngapType.UserLocationInformationNR{},
30+
id: ngapType.ProtocolIEIDNRNTNTAIInformation,
31+
want: false,
32+
},
33+
{
34+
name: "empty extension list",
35+
loc: &ngapType.UserLocationInformationNR{
36+
IEExtensions: &ngapType.ProtocolExtensionContainerUserLocationInformationNRExtIEs{},
37+
},
38+
id: ngapType.ProtocolIEIDNRNTNTAIInformation,
39+
want: false,
40+
},
41+
{
42+
name: "unrelated extension only",
43+
loc: newNRLocationWithExtensionIDs(42),
44+
id: ngapType.ProtocolIEIDNRNTNTAIInformation,
45+
want: false,
46+
},
47+
{
48+
name: "matching extension present",
49+
loc: newNRLocationWithExtensionIDs(ngapType.ProtocolIEIDNRNTNTAIInformation),
50+
id: ngapType.ProtocolIEIDNRNTNTAIInformation,
51+
want: true,
52+
},
53+
{
54+
name: "matching extension among several",
55+
loc: newNRLocationWithExtensionIDs(42, 99, ngapType.ProtocolIEIDNRNTNTAIInformation, 150),
56+
id: ngapType.ProtocolIEIDNRNTNTAIInformation,
57+
want: true,
58+
},
59+
}
60+
for _, tc := range tests {
61+
t.Run(tc.name, func(t *testing.T) {
62+
if got := ngap.HasUserLocationInformationNRExtension(tc.loc, tc.id); got != tc.want {
63+
t.Errorf("HasUserLocationInformationNRExtension = %v, want %v", got, tc.want)
64+
}
65+
})
66+
}
67+
}
68+
69+
func newNRLocationWithExtensionIDs(ids ...int64) *ngapType.UserLocationInformationNR {
70+
list := make([]ngapType.UserLocationInformationNRExtIEs, 0, len(ids))
71+
for _, id := range ids {
72+
list = append(list, ngapType.UserLocationInformationNRExtIEs{
73+
Id: ngapType.ProtocolExtensionID{Value: id},
74+
})
75+
}
76+
return &ngapType.UserLocationInformationNR{
77+
IEExtensions: &ngapType.ProtocolExtensionContainerUserLocationInformationNRExtIEs{
78+
List: list,
79+
},
80+
}
81+
}

0 commit comments

Comments
 (0)