Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Modify code for indirect communication in free5gc v3.4.4 #51

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@
}
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"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the CHF be supported?
If yes, please add the TODO comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my understanding, SCP can support the selected NF pairs according to demand, without a strict definition of which NFs must be supported, and can provide additional functions as needed. The most basic function is to forward messages.
We chose to implement these NFs because our detection system will use the SBI messages of these NFs to determine if there are any anomalies.

}
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the SCP is enabled before finding whether the NF pair is supported or not.

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)
andy89923 marked this conversation as resolved.
Show resolved Hide resolved
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"`
andy89923 marked this conversation as resolved.
Show resolved Hide resolved
}

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,7 +30,14 @@
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
Loading