/
init_context.go
executable file
·48 lines (43 loc) · 1.46 KB
/
init_context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package util
import (
"fmt"
"os"
"github.com/google/uuid"
nwdaf_context "github.com/wsilvad/nwdaf/context"
"github.com/wsilvad/nwdaf/factory"
"github.com/wsilvad/nwdaf/logger"
"github.com/free5gc/openapi/models"
)
func InitNwdafContext(context *nwdaf_context.NWDAFContext) {
config := factory.NwdafConfig
logger.UtilLog.Infof("nwdafconfig Info: Version[%s] Description[%s]", config.Info.Version, config.Info.Description)
configuration := config.Configuration
context.NfId = uuid.New().String()
context.RegisterIPv4 = "127.0.0.1" // default localhost
context.SBIPort = 29504 // default port
if sbi := configuration.Sbi; sbi != nil {
context.UriScheme = models.UriScheme(sbi.Scheme)
if sbi.RegisterIPv4 != "" {
context.RegisterIPv4 = sbi.RegisterIPv4
}
if sbi.Port != 0 {
context.SBIPort = sbi.Port
}
context.BindingIPv4 = os.Getenv(sbi.BindingIPv4)
if context.BindingIPv4 != "" {
logger.UtilLog.Info("Parsing ServerIPv4 address from ENV Variable.")
} else {
context.BindingIPv4 = sbi.BindingIPv4
if context.BindingIPv4 == "" {
logger.UtilLog.Warn("Error parsing ServerIPv4 address as string. Using the 0.0.0.0 address as default.")
context.BindingIPv4 = "0.0.0.0"
}
}
}
if configuration.NrfUri != "" {
context.NrfUri = configuration.NrfUri
} else {
logger.UtilLog.Warn("NRF Uri is empty! Using localhost as NRF IPv4 address.")
context.NrfUri = fmt.Sprintf("%s://%s:%d", context.UriScheme, "127.0.0.1", 29510)
}
}