From b3768071e97ac024f1b60edc325be7e3d2c5ee59 Mon Sep 17 00:00:00 2001 From: "Arrobo, Gabriel" Date: Thu, 6 Aug 2026 18:30:09 -0700 Subject: [PATCH 1/2] Use accessors (new, get, set) instead of direct field access Signed-off-by: Arrobo, Gabriel --- .../api_search_nf_instances_request_compat.go | 4 + nrfcache/match_filters.go | 100 ++++++++++-------- nrfcache/nrfcache.go | 30 +++--- nrfcache/nrfcache_test.go | 58 +++++----- 4 files changed, 105 insertions(+), 87 deletions(-) diff --git a/Nnrf_NFDiscovery/api_search_nf_instances_request_compat.go b/Nnrf_NFDiscovery/api_search_nf_instances_request_compat.go index 0ecd80bc..4207971f 100644 --- a/Nnrf_NFDiscovery/api_search_nf_instances_request_compat.go +++ b/Nnrf_NFDiscovery/api_search_nf_instances_request_compat.go @@ -40,3 +40,7 @@ func (r ApiSearchNFInstancesRequest) GetAmfSetId() *string { func (r ApiSearchNFInstancesRequest) GetSupi() *string { return r.supi } + +func (r ApiSearchNFInstancesRequest) GetTai() *models.Tai { + return r.tai +} diff --git a/nrfcache/match_filters.go b/nrfcache/match_filters.go index f4d7a62f..6e730c4f 100644 --- a/nrfcache/match_filters.go +++ b/nrfcache/match_filters.go @@ -43,8 +43,8 @@ func MatchSmfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A if serviceNames != nil && len(*serviceNames) > 0 { found := false for _, requiredService := range *serviceNames { - for _, nfService := range profile.NfServices { - if nfService.ServiceName == requiredService { + for _, nfService := range profile.GetNfServices() { + if nfService.GetServiceName() == requiredService { found = true break } @@ -55,7 +55,7 @@ func MatchSmfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A } if !found { - logger.NrfcacheLog.Debugf("smf match failed: no service match for %s", profile.NfInstanceId) + logger.NrfcacheLog.Debugf("smf match failed: no service match for %s", profile.GetNfInstanceId()) return false, nil } } @@ -63,17 +63,19 @@ func MatchSmfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A snssais := opts.GetSnssais() if snssais != nil { matchCount := 0 + smfInfo, hasSmfInfo := profile.GetSmfInfoOk() for _, reqSnssai := range *snssais { // Snssai in the smfInfo has priority - if profile.SmfInfo != nil && profile.SmfInfo.SNssaiSmfInfoList != nil { - for _, s := range profile.SmfInfo.SNssaiSmfInfoList { - if (s.SNssai.GetSst() == reqSnssai.GetSst()) && (s.SNssai.GetSd() == reqSnssai.GetSd()) { + if hasSmfInfo && len(smfInfo.GetSNssaiSmfInfoList()) > 0 { + for _, s := range smfInfo.GetSNssaiSmfInfoList() { + snssai := s.GetSNssai() + if snssai.GetSst() == reqSnssai.GetSst() && snssai.GetSd() == reqSnssai.GetSd() { matchCount++ } } - } else if profile.AllowedNssais != nil { - for _, s := range profile.AllowedNssais { - if (s.GetSst() == reqSnssai.GetSst()) && (s.GetSd() == reqSnssai.GetSd()) { + } else { + for _, s := range profile.GetAllowedNssais() { + if s.GetSst() == reqSnssai.GetSst() && s.GetSd() == reqSnssai.GetSd() { matchCount++ } } @@ -93,15 +95,14 @@ func MatchSmfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A // or wild card match dnnMatched := false - if profile.SmfInfo != nil && profile.SmfInfo.SNssaiSmfInfoList != nil { + smfInfo, hasSmfInfo := profile.GetSmfInfoOk() + if hasSmfInfo { matchDnnLoop: - for _, s := range profile.SmfInfo.SNssaiSmfInfoList { - if s.DnnSmfInfoList != nil { - for _, d := range s.DnnSmfInfoList { - if d.GetDnn() == *dnn || d.GetDnn() == "*" { - dnnMatched = true - break matchDnnLoop - } + for _, s := range smfInfo.GetSNssaiSmfInfoList() { + for _, d := range s.GetDnnSmfInfoList() { + if d.GetDnn() == *dnn || d.GetDnn() == "*" { + dnnMatched = true + break matchDnnLoop } } } @@ -111,7 +112,7 @@ func MatchSmfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A return false, nil } } - logger.NrfcacheLog.Infof("smf match found, nfInstance Id %v", profile.NfInstanceId) + logger.NrfcacheLog.Infof("smf match found, nfInstance Id %v", profile.GetNfInstanceId()) return true, nil } @@ -189,21 +190,22 @@ func MatchAusfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery. supi := opts.GetSupi() if supi != nil { // Unrestricted when no SUPI ranges are declared; see MatchPcfProfile. - if profile.AusfInfo == nil || len(profile.AusfInfo.SupiRanges) == 0 { - logger.NrfcacheLog.Debugf("ausf match successful (unrestricted: no SUPI ranges) for %s", profile.NfInstanceId) + ausfInfo, ok := profile.GetAusfInfoOk() + if !ok || len(ausfInfo.GetSupiRanges()) == 0 { + logger.NrfcacheLog.Debugf("ausf match successful (unrestricted: no SUPI ranges) for %s", profile.GetNfInstanceId()) return true, nil } - matchFound := matchSupiRange(*supi, profile.AusfInfo.SupiRanges) + matchFound := matchSupiRange(*supi, ausfInfo.GetSupiRanges()) if matchFound { - logger.NrfcacheLog.Debugf("ausf match successful for %s", profile.NfInstanceId) + logger.NrfcacheLog.Debugf("ausf match successful for %s", profile.GetNfInstanceId()) } else { - logger.NrfcacheLog.Debugf("ausf match failed: SUPI range mismatch for %s", profile.NfInstanceId) + logger.NrfcacheLog.Debugf("ausf match failed: SUPI range mismatch for %s", profile.GetNfInstanceId()) } return matchFound, nil } - logger.NrfcacheLog.Debugf("ausf match successful (no SUPI filter) for %s", profile.NfInstanceId) + logger.NrfcacheLog.Debugf("ausf match successful (no SUPI filter) for %s", profile.GetNfInstanceId()) return true, nil } @@ -217,14 +219,14 @@ func MatchAmfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A return false, fmt.Errorf("profile cannot be nil") } - if profile.NfType != models.NFTYPE_AMF { - return false, fmt.Errorf("profile is not AMF type: %v", profile.NfType) + if profile.GetNfType() != models.NFTYPE_AMF { + return false, fmt.Errorf("profile is not AMF type: %v", profile.GetNfType()) } targetPlmnList := opts.GetTargetPlmnList() if targetPlmnList != nil && len(*targetPlmnList) > 0 { profilePlmnList := profile.GetPlmnList() if len(profilePlmnList) == 0 { - logger.NrfcacheLog.Debugf("amf match failed: no profile PLMNs for %s", profile.NfInstanceId) + logger.NrfcacheLog.Debugf("amf match failed: no profile PLMNs for %s", profile.GetNfInstanceId()) return false, nil } @@ -237,44 +239,45 @@ func MatchAmfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A } if !found { - logger.NrfcacheLog.Debugf("amf match failed: no PLMN match for %s", profile.NfInstanceId) + logger.NrfcacheLog.Debugf("amf match failed: no PLMN match for %s", profile.GetNfInstanceId()) return false, nil } } targetNfInstanceId := opts.GetTargetNfInstanceId() if targetNfInstanceId != nil && profile.GetNfInstanceId() != *targetNfInstanceId { - logger.NrfcacheLog.Debugf("amf match failed: NF instance ID mismatch for %s", profile.NfInstanceId) + logger.NrfcacheLog.Debugf("amf match failed: NF instance ID mismatch for %s", profile.GetNfInstanceId()) return false, nil } - if profile.AmfInfo != nil { + amfInfo, hasAmfInfo := profile.GetAmfInfoOk() + if hasAmfInfo { guamiOpt := opts.GetGuami() - if guamiOpt != nil && (profile.AmfInfo.GuamiList == nil || !slices.Contains(profile.AmfInfo.GuamiList, *guamiOpt)) { - logger.NrfcacheLog.Debugf("amf match failed: GUAMI mismatch for %s", profile.NfInstanceId) + if guamiOpt != nil && !slices.Contains(amfInfo.GetGuamiList(), *guamiOpt) { + logger.NrfcacheLog.Debugf("amf match failed: GUAMI mismatch for %s", profile.GetNfInstanceId()) return false, nil } amfRegionId := opts.GetAmfRegionId() - if amfRegionId != nil && profile.AmfInfo.GetAmfRegionId() != *amfRegionId { - logger.NrfcacheLog.Debugf("amf match failed: AMF region ID mismatch for %s", profile.NfInstanceId) + if amfRegionId != nil && amfInfo.GetAmfRegionId() != *amfRegionId { + logger.NrfcacheLog.Debugf("amf match failed: AMF region ID mismatch for %s", profile.GetNfInstanceId()) return false, nil } amfSetId := opts.GetAmfSetId() - if amfSetId != nil && profile.AmfInfo.GetAmfSetId() != *amfSetId { - logger.NrfcacheLog.Debugf("amf match failed: AMF set ID mismatch for %s", profile.NfInstanceId) + if amfSetId != nil && amfInfo.GetAmfSetId() != *amfSetId { + logger.NrfcacheLog.Debugf("amf match failed: AMF set ID mismatch for %s", profile.GetNfInstanceId()) return false, nil } } else { // Handle case where AMF-specific filters are provided but AmfInfo is nil if opts.GetGuami() != nil || opts.GetAmfRegionId() != nil || opts.GetAmfSetId() != nil { - logger.NrfcacheLog.Debugf("amf match failed: AMF filters provided but no AmfInfo for %s", profile.NfInstanceId) + logger.NrfcacheLog.Debugf("amf match failed: AMF filters provided but no AmfInfo for %s", profile.GetNfInstanceId()) return false, nil } } - logger.NrfcacheLog.Infof("amf match found = %v", profile.NfInstanceId) + logger.NrfcacheLog.Infof("amf match found = %v", profile.GetNfInstanceId()) return true, nil } @@ -287,12 +290,13 @@ func MatchPcfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A // absent" (nrf producer/nf_discovery.go, [Query-18] supi). Rationale: // the cache must select the same profiles as the NRF it caches, // otherwise a cached lookup and a live discovery disagree. - if profile.PcfInfo == nil || len(profile.PcfInfo.SupiRanges) == 0 { + pcfInfo, ok := profile.GetPcfInfoOk() + if !ok || len(pcfInfo.GetSupiRanges()) == 0 { logger.NrfcacheLog.Debugf("pcf match found = true (unrestricted: no SUPI ranges)") return true, nil } - matchFound := matchSupiRange(*supi, profile.PcfInfo.SupiRanges) + matchFound := matchSupiRange(*supi, pcfInfo.GetSupiRanges()) logger.NrfcacheLog.Infof("pcf match found = %v", matchFound) return matchFound, nil } @@ -306,12 +310,13 @@ func MatchUdmProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A supi := opts.GetSupi() if supi != nil { // Unrestricted when no SUPI ranges are declared; see MatchPcfProfile. - if profile.UdmInfo == nil || len(profile.UdmInfo.GetSupiRanges()) == 0 { + udmInfo, ok := profile.GetUdmInfoOk() + if !ok || len(udmInfo.GetSupiRanges()) == 0 { logger.NrfcacheLog.Debugf("udm match found = true (unrestricted: no SUPI ranges)") return true, nil } - matchFound := matchSupiRange(*supi, profile.UdmInfo.GetSupiRanges()) + matchFound := matchSupiRange(*supi, udmInfo.GetSupiRanges()) logger.NrfcacheLog.Infof("udm match found = %v", matchFound) return matchFound, nil } @@ -330,17 +335,18 @@ func MatchUdmProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A func MatchUdrProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.ApiSearchNFInstancesRequest) (bool, error) { supi := opts.GetSupi() if supi == nil { - logger.NrfcacheLog.Debugf("udr match successful (no SUPI filter) for %s", profile.NfInstanceId) + logger.NrfcacheLog.Debugf("udr match successful (no SUPI filter) for %s", profile.GetNfInstanceId()) return true, nil } // Unrestricted when no SUPI ranges are declared; see MatchPcfProfile. - if profile.UdrInfo == nil || len(profile.UdrInfo.GetSupiRanges()) == 0 { - logger.NrfcacheLog.Debugf("udr match successful (unrestricted: no SUPI ranges) for %s", profile.NfInstanceId) + udrInfo, ok := profile.GetUdrInfoOk() + if !ok || len(udrInfo.GetSupiRanges()) == 0 { + logger.NrfcacheLog.Debugf("udr match successful (unrestricted: no SUPI ranges) for %s", profile.GetNfInstanceId()) return true, nil } - matchFound := matchSupiRange(*supi, profile.UdrInfo.GetSupiRanges()) - logger.NrfcacheLog.Debugf("udr match found = %v for %s", matchFound, profile.NfInstanceId) + matchFound := matchSupiRange(*supi, udrInfo.GetSupiRanges()) + logger.NrfcacheLog.Debugf("udr match found = %v for %s", matchFound, profile.GetNfInstanceId()) return matchFound, nil } diff --git a/nrfcache/nrfcache.go b/nrfcache/nrfcache.go index 4c6cd8e8..964bd0ae 100644 --- a/nrfcache/nrfcache.go +++ b/nrfcache/nrfcache.go @@ -152,7 +152,9 @@ func (c *NrfCache) handleLookup(ctx context.Context, nrfUri string, targetNfType c.mutex.RUnlock() if len(nfInstances) > 0 { - return models.SearchResult{NfInstances: nfInstances}, nil + var result models.SearchResult + result.SetNfInstances(nfInstances) + return result, nil } // discoveryMutex serializes NRF round-trips without blocking concurrent cache hits. @@ -165,7 +167,9 @@ func (c *NrfCache) handleLookup(ctx context.Context, nrfUri string, targetNfType c.mutex.RUnlock() if len(nfInstances) > 0 { - return models.SearchResult{NfInstances: nfInstances}, nil + var result models.SearchResult + result.SetNfInstances(nfInstances) + return result, nil } logger.NrfcacheLog.Warnf("cache miss for nftype %s", targetNfType) @@ -178,11 +182,11 @@ func (c *NrfCache) handleLookup(ctx context.Context, nrfUri string, targetNfType return models.SearchResult{}, fmt.Errorf("NRF discovery returned nil result") } - ttl := time.Duration(searchResult.ValidityPeriod) * time.Second - + ttl := time.Duration(searchResult.GetValidityPeriod()) * time.Second c.mutex.Lock() - for i := range searchResult.NfInstances { - c.set(&searchResult.NfInstances[i], ttl) + nfInstances = searchResult.GetNfInstances() + for i := range nfInstances { + c.set(&nfInstances[i], ttl) } c.mutex.Unlock() @@ -200,13 +204,13 @@ func (c *NrfCache) set(nfProfile *models.NFProfileDiscovery, ttl time.Duration) ttl = ttl * time.Second } - item, exists := c.cache[nfProfile.NfInstanceId] + item, exists := c.cache[nfProfile.GetNfInstanceId()] if exists { // if item.isExpired() c.priorityQ.update(item, nfProfile, ttl) } else { newItem := newNfProfileItem(nfProfile, ttl) - c.cache[nfProfile.NfInstanceId] = newItem + c.cache[nfProfile.GetNfInstanceId()] = newItem c.priorityQ.push(newItem) } } @@ -240,9 +244,9 @@ func (c *NrfCache) get(opts Nnrf_NFDiscovery.ApiSearchNFInstancesRequest) []mode continue } - if cb, ok := matchFilters[element.nfProfile.NfType]; ok { + if cb, ok := matchFilters[element.nfProfile.GetNfType()]; ok { if matchFound, err := cb(element.nfProfile, opts); err != nil { - logger.NrfcacheLog.Errorf("match filter error for %s: %v", element.nfProfile.NfInstanceId, err) + logger.NrfcacheLog.Errorf("match filter error for %s: %v", element.nfProfile.GetNfInstanceId(), err) } else if matchFound { nfProfiles = append(nfProfiles, *element.nfProfile) } @@ -267,7 +271,7 @@ func (c *NrfCache) removeByNfInstanceId(nfInstanceId string) bool { // remove - func (c *NrfCache) remove(item *NfProfileItem) { c.priorityQ.remove(item) - delete(c.cache, item.nfProfile.NfInstanceId) + delete(c.cache, item.nfProfile.GetNfInstanceId()) } // cleanupExpiredItems - removes the profiles with expired TTLs @@ -279,7 +283,7 @@ func (c *NrfCache) cleanupExpiredItems() { break } - logger.NrfcacheLog.Debugf("evicted nf instance %s", item.nfProfile.NfInstanceId) + logger.NrfcacheLog.Debugf("evicted nf instance %s", item.nfProfile.GetNfInstanceId()) c.remove(item) } } @@ -460,7 +464,7 @@ func SearchNFInstances(ctx context.Context, nrfUri string, targetNfType, request logger.NrfcacheLog.With("nfType", targetNfType, "param", param).Errorln("handleLookup failed:", err) return nil, fmt.Errorf("handleLookup for nfType %v failed: %w", targetNfType, err) } - for _, np := range searchResult.NfInstances { + for _, np := range searchResult.GetNfInstances() { logger.NrfcacheLog.Infof("%+v", np) } return &searchResult, err diff --git a/nrfcache/nrfcache_test.go b/nrfcache/nrfcache_test.go index caa61d12..7d5a5de5 100644 --- a/nrfcache/nrfcache_test.go +++ b/nrfcache/nrfcache_test.go @@ -484,11 +484,11 @@ func (tc *testContext) nrfDbCallback(ctx context.Context, nrfUri string, targetN logger.NrfcacheLog.Infoln("nrfDbCallback Entry") - var searchResult models.SearchResult + searchResult := models.NewSearchResultWithDefaults() var nfProfile models.NFProfileDiscovery var err error - searchResult.ValidityPeriod = tc.validityPeriod + searchResult.SetValidityPeriod(tc.validityPeriod) switch targetNfType { case models.NFTYPE_SMF: @@ -506,19 +506,23 @@ func (tc *testContext) nrfDbCallback(ctx context.Context, nrfUri string, targetN } nfProfile, err = tc.getNfProfile(key) if err != nil { - return &searchResult, err + return searchResult, err } - searchResult.NfInstances = append(searchResult.NfInstances, nfProfile) + searchResult.SetNfInstances(append(searchResult.GetNfInstances(), nfProfile)) } else { - searchResult.NfInstances, err = tc.getNfProfiles(targetNfType) + var profiles []models.NFProfileDiscovery + profiles, err = tc.getNfProfiles(targetNfType) + searchResult.SetNfInstances(profiles) } case models.NFTYPE_AUSF, models.NFTYPE_AMF: - searchResult.NfInstances, err = tc.getNfProfiles(targetNfType) + var profiles []models.NFProfileDiscovery + profiles, err = tc.getNfProfiles(targetNfType) + searchResult.SetNfInstances(profiles) default: - return &searchResult, fmt.Errorf("unsupported NFType: %s", targetNfType) + return searchResult, fmt.Errorf("unsupported NFType: %s", targetNfType) } - return &searchResult, err + return searchResult, err } func setupTest(t *testing.T) (*testContext, func()) { @@ -1242,7 +1246,7 @@ func TestMatchProfileWithoutSupiRangesIsUnrestricted(t *testing.T) { } if !match { t.Errorf("profile %s declares no SUPI ranges and must match SUPI %s, got no match", - tc.profile.NfInstanceId, supi) + tc.profile.GetNfInstanceId(), supi) } }) } @@ -1251,15 +1255,17 @@ func TestMatchProfileWithoutSupiRangesIsUnrestricted(t *testing.T) { // TestMatchProfileWithSupiRangesStillFiltersOut guards the complementary case: // once a profile declares ranges, a SUPI outside them must not match. func TestMatchProfileWithSupiRangesStillFiltersOut(t *testing.T) { - ranges := []models.SupiRange{{Start: openapi.PtrString("100000000000000"), End: openapi.PtrString("100000000000009")}} + sr := models.NewSupiRange() + sr.SetStart("100000000000000") + sr.SetEnd("100000000000009") + ranges := []models.SupiRange{*sr} param := Nnrf_NFDiscovery.ApiSearchNFInstancesRequest{}.Supi("imsi-208930100007500") - profile := models.NFProfileDiscovery{ - NfInstanceId: "UDM-ranged", - NfType: models.NFTYPE_UDM, - UdmInfo: &models.UdmInfo{SupiRanges: ranges}, - } - match, err := MatchUdmProfile(&profile, param) + udmInfo := models.NewUdmInfo() + udmInfo.SetSupiRanges(ranges) + profile := models.NewNFProfileDiscovery("UDM-ranged", models.NFTYPE_UDM, models.NFSTATUS_REGISTERED) + profile.SetUdmInfo(*udmInfo) + match, err := MatchUdmProfile(profile, param) if err != nil { t.Fatalf("MatchUdmProfile returned error: %v", err) } @@ -1277,18 +1283,16 @@ func TestUdrProfileIsSelectableFromCache(t *testing.T) { t.Fatal("UDR has no entry in matchFilters, so cached UDR discovery can never return a profile") } - profile := models.NFProfileDiscovery{ - NfInstanceId: "UDR-1", - NfType: models.NFTYPE_UDR, - UdrInfo: &models.UdrInfo{ - SupiRanges: []models.SupiRange{ - {Start: openapi.PtrString("208930100007500"), End: openapi.PtrString("208930100007599")}, - }, - }, - } + srUdr := models.NewSupiRange() + srUdr.SetStart("208930100007500") + srUdr.SetEnd("208930100007599") + udrInfo := models.NewUdrInfo() + udrInfo.SetSupiRanges([]models.SupiRange{*srUdr}) + profile := models.NewNFProfileDiscovery("UDR-1", models.NFTYPE_UDR, models.NFSTATUS_REGISTERED) + profile.SetUdrInfo(*udrInfo) inRange := Nnrf_NFDiscovery.ApiSearchNFInstancesRequest{}.Supi("imsi-208930100007550") - match, err := MatchUdrProfile(&profile, inRange) + match, err := MatchUdrProfile(profile, inRange) if err != nil { t.Fatalf("MatchUdrProfile returned error: %v", err) } @@ -1297,7 +1301,7 @@ func TestUdrProfileIsSelectableFromCache(t *testing.T) { } outOfRange := Nnrf_NFDiscovery.ApiSearchNFInstancesRequest{}.Supi("imsi-208930100009999") - match, err = MatchUdrProfile(&profile, outOfRange) + match, err = MatchUdrProfile(profile, outOfRange) if err != nil { t.Fatalf("MatchUdrProfile returned error: %v", err) } From bf1108e140d3b00b6dfdce3efbc6030d014a21f7 Mon Sep 17 00:00:00 2001 From: "Arrobo, Gabriel" Date: Thu, 6 Aug 2026 18:38:47 -0700 Subject: [PATCH 2/2] Address Copilot's comment Signed-off-by: Arrobo, Gabriel --- nrfcache/match_filters.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/nrfcache/match_filters.go b/nrfcache/match_filters.go index 6e730c4f..442c3194 100644 --- a/nrfcache/match_filters.go +++ b/nrfcache/match_filters.go @@ -39,6 +39,9 @@ var matchFilters = MatchFilters{ } func MatchSmfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.ApiSearchNFInstancesRequest) (bool, error) { + if profile == nil { + return false, fmt.Errorf("profile cannot be nil") + } serviceNames := opts.GetServiceNames() if serviceNames != nil && len(*serviceNames) > 0 { found := false @@ -187,6 +190,9 @@ func extractSupiNumber(supi string) string { } func MatchAusfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.ApiSearchNFInstancesRequest) (bool, error) { + if profile == nil { + return false, fmt.Errorf("profile cannot be nil") + } supi := opts.GetSupi() if supi != nil { // Unrestricted when no SUPI ranges are declared; see MatchPcfProfile. @@ -210,6 +216,9 @@ func MatchAusfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery. } func MatchNssfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.ApiSearchNFInstancesRequest) (bool, error) { + if profile == nil { + return false, fmt.Errorf("profile cannot be nil") + } logger.NrfcacheLog.Infoln("nssf match found") return true, nil } @@ -282,6 +291,9 @@ func MatchAmfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A } func MatchPcfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.ApiSearchNFInstancesRequest) (bool, error) { + if profile == nil { + return false, fmt.Errorf("profile cannot be nil") + } supi := opts.GetSupi() if supi != nil { // A profile declaring no SUPI ranges is unrestricted and serves every @@ -307,6 +319,9 @@ func MatchPcfProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A } func MatchUdmProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.ApiSearchNFInstancesRequest) (bool, error) { + if profile == nil { + return false, fmt.Errorf("profile cannot be nil") + } supi := opts.GetSupi() if supi != nil { // Unrestricted when no SUPI ranges are declared; see MatchPcfProfile. @@ -333,6 +348,9 @@ func MatchUdmProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.A // through to a live NRF query. Rationale: UDR is resolved on every subscriber // data access, which makes it the most frequently discovered NF in the core. func MatchUdrProfile(profile *models.NFProfileDiscovery, opts Nnrf_NFDiscovery.ApiSearchNFInstancesRequest) (bool, error) { + if profile == nil { + return false, fmt.Errorf("profile cannot be nil") + } supi := opts.GetSupi() if supi == nil { logger.NrfcacheLog.Debugf("udr match successful (no SUPI filter) for %s", profile.GetNfInstanceId())