Skip to content

Commit

Permalink
fix: Ignore NRF URI containing a specific IP on registration (#26)
Browse files Browse the repository at this point in the history
* fix: Ignore NRF URI containing a specific IP on registration

* Add copyright and license to example configuration file

* Update factory/config.example.yaml

Co-authored-by: gab-arrobo <[email protected]>

---------

Co-authored-by: gab-arrobo <[email protected]>
  • Loading branch information
ghislainbourgeois and gab-arrobo committed Dec 12, 2023
1 parent eb2cc23 commit 653cefd
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
22 changes: 22 additions & 0 deletions factory/config.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## SPDX-FileCopyrightText: 2023 Open Networking Foundation <[email protected]>
##
## SPDX-License-Identifier: Apache-2.0
##
info:
version: 1.0.0
description: UDR initial local configuration

configuration:
sbi: # Service Based Interface
scheme: https
registerIPv4: 127.0.0.4
bindingIPv4: 0.0.0.0
port: 8000
plmnSupportList:
- plmnId:
mcc: "208"
mnc: "93"
snssaiList:
- sst: 1
sd: "010203"

2 changes: 1 addition & 1 deletion factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
package factory

import (
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
"github.com/omec-project/logger_util"
"github.com/omec-project/openapi/models"
"github.com/omec-project/udr/logger"
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
)

const (
Expand Down
8 changes: 3 additions & 5 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (udr *UDR) configUpdateDb() {
if err == nil {
initLog.Infof("added entry to sm policy table success")
} else {
initLog.Errorln("entry add failed ", err)
initLog.Errorf("entry add failed %+v", err)
}
}
}
Expand Down Expand Up @@ -386,15 +386,13 @@ func (udr *UDR) registerNF() {
initLog.Infof("Minimum configuration from config pod available %v", msg)
self := udr_context.UDR_Self()
profile := consumer.BuildNFInstance(self)
var newNrfUri string
var err error
var prof models.NfProfile
// send registration with updated PLMN Ids.
prof, newNrfUri, self.NfId, err = consumer.SendRegisterNFInstance(self.NrfUri, profile.NfInstanceId, profile)
prof, _, self.NfId, err = consumer.SendRegisterNFInstance(self.NrfUri, profile.NfInstanceId, profile)
if err == nil {
udr.StartKeepAliveTimer(prof)
logger.CfgLog.Infof("Sent Register NF Instance with updated profile")
self.NrfUri = newNrfUri
logger.CfgLog.Infoln("Sent Register NF Instance with updated profile")
} else {
initLog.Errorf("Send Register NFInstance Error[%s]", err.Error())
}
Expand Down
39 changes: 39 additions & 0 deletions service/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Open Networking Foundation <[email protected]>
//

package service

import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/omec-project/udr/context"
"github.com/omec-project/udr/factory"
)

func Test_nrf_url_is_not_overwritten_when_registering(t *testing.T) {
svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "banana")
}))
svr.EnableHTTP2 = true
svr.StartTLS()
defer svr.Close()
if err := factory.InitConfigFactory("../factory/config.example.yaml"); err != nil {
t.Fatalf("Could not read example configuration file")
}
self := context.UDR_Self()
self.NrfUri = svr.URL
self.RegisterIPv4 = "127.0.0.2"
var udr *UDR
go udr.registerNF()
factory.ConfigPodTrigger <- true

time.Sleep(1 * time.Second)
if self.NrfUri != svr.URL {
t.Errorf("Expected NRF URL to stay %v, but was %v", svr.URL, self.NrfUri)
}
}

0 comments on commit 653cefd

Please sign in to comment.