Skip to content

Commit

Permalink
feat: Modify code for indirect communication in free5gc v3.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mamie1031 committed Jan 10, 2025
1 parent 9341e44 commit 773407e
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type NRFContext struct {
NrfCert *x509.Certificate
NfRegistNum int
nfRegistNumLock sync.RWMutex
ScpUri string
}

const (
Expand All @@ -47,6 +48,9 @@ func InitNrfContext() error {
logger.InitLog.Infof("nrfconfig Info: Version[%s] Description[%s]",
config.Info.Version, config.Info.Description)
configuration := config.Configuration
if configuration.ScpUri != "" {
nrfContext.ScpUri = configuration.ScpUri
}

nrfContext.NrfNfProfile.NfInstanceId = uuid.New().String()
nrfContext.NrfNfProfile.NfType = models.NfType_NRF
Expand Down
75 changes: 75 additions & 0 deletions internal/sbi/processor/nf_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func validateQueryParameters(queryParameters url.Values) bool {
"BSF": true,
"CHF": true,
"NWDAF": true,
"SCP": true,
}
var tgt, req string
if queryParameters["target-nf-type"] != nil {
Expand Down Expand Up @@ -173,6 +174,80 @@ func (p *Processor) NFDiscoveryProcedure(c *gin.Context, queryParameters url.Val
}
validityPeriod := 100

// Indirect Communication
// Only the following NF pairs support indirect communication
supportNFPairForIndirectCommunication := false
npPairs := map[string][]string{
"AMF": {"AUSF", "SMF"},
"AUSF": {"UDM", "AMF"},
"UDM": {"UDR", "AUSF"},
"UDR": {"UDM", "NEF"},
"SMF": {"AMF"},
"NEF": {"UDR"},
}
sourceNF := ""
targetNF := ""
if values, exists := queryParameters["requester-nf-type"]; exists && len(values) > 0 {
sourceNF = values[0]
}
if values, exists := queryParameters["target-nf-type"]; exists && len(values) > 0 {
targetNF = values[0]
}

if validTargets, exists := npPairs[sourceNF]; exists {
for _, validTarget := range validTargets {
if validTarget == targetNF {
supportNFPairForIndirectCommunication = true
}
}

Check failure on line 203 in internal/sbi/processor/nf_discovery.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

File is not `gofumpt`-ed (gofumpt)
}

Check failure on line 204 in internal/sbi/processor/nf_discovery.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

unnecessary trailing newline (whitespace)
ScpUri := nrf_context.GetSelf().ScpUri
if ScpUri != "" && supportNFPairForIndirectCommunication {
// parse uri to host and port
parsedURL, err := url.Parse(ScpUri)

Check failure on line 208 in internal/sbi/processor/nf_discovery.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

shadow: declaration of "err" shadows declaration at line 118 (govet)
if err != nil {
logger.DiscLog.Errorln("Error parsing URL:", err)
return
}
host := parsedURL.Host
hostParts := strings.Split(host, ":")
if len(hostParts) != 2 {
logger.DiscLog.Errorln("Invalid host format, expected IP:PORT")
return
}
ScpIp := hostParts[0]
scpPortInt, err := strconv.Atoi(hostParts[1])
if err != nil {
logger.DiscLog.Errorln("Invalid port value: ", err)
}
logger.DiscLog.Infof("ScpIp: %v, scpPortInt: %v", ScpIp, scpPortInt)
logger.DiscLog.Infof("Discovery with indirect communication, the message will pass to SCP: [%v]", ScpUri)
if len(nfProfilesStruct) > 0 {
for i := range nfProfilesStruct {
nfProfilesStruct[i].Ipv4Addresses[0] = ScpUri

if nfProfilesStruct[i].NfServices != nil {
for j := range *nfProfilesStruct[i].NfServices {
nfService := &(*nfProfilesStruct[i].NfServices)[j]

if nfService.IpEndPoints != nil {
for k := range *nfService.IpEndPoints {
ipEndPoint := &(*nfService.IpEndPoints)[k]
ipEndPoint.Ipv4Address = ScpIp
ipEndPoint.Port = int32(scpPortInt)
}
}
// for UDM search
if nfService.ApiPrefix != "" {
nfService.ApiPrefix = ScpUri
}
}
}
}
}

}

Check failure on line 250 in internal/sbi/processor/nf_discovery.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

unnecessary trailing newline (whitespace)
// Build SearchResult model
searchResult := &models.SearchResult{
ValidityPeriod: int32(validityPeriod),
Expand Down
1 change: 1 addition & 0 deletions pkg/factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Configuration struct {
MongoDBUrl string `yaml:"MongoDBUrl" valid:"required"`
DefaultPlmnId models.PlmnId `yaml:"DefaultPlmnId" valid:"required"`
ServiceNameList []string `yaml:"serviceNameList,omitempty" valid:"required"`
ScpUri string `yaml:"scpUri,omitempty"`
}

type Logger struct {
Expand Down
7 changes: 7 additions & 0 deletions pkg/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func InitConfigFactory(f string, cfg *Config) error {
if yamlErr := yaml.Unmarshal(content, cfg); yamlErr != nil {
return fmt.Errorf("[Factory] %+v", yamlErr)
}
// Check Communication Mode
if cfg.Configuration.ScpUri == "" {
logger.CfgLog.Infoln("Direct Communication Mode")
} else {
logger.CfgLog.Infof("Indirect Communication Mode, the control message will pass to SCP: [%v]", cfg.Configuration.ScpUri)

Check failure on line 37 in pkg/factory/factory.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

line is 123 characters (lll)
}

}

Check failure on line 40 in pkg/factory/factory.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

unnecessary trailing newline (whitespace)

return nil
Expand Down

0 comments on commit 773407e

Please sign in to comment.