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

refactor: improve config validation code #129

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/antihax/optional v1.0.0
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
github.com/davecgh/go-spew v1.1.1
github.com/free5gc/aper v1.0.5
github.com/free5gc/nas v1.1.3
Expand Down Expand Up @@ -60,6 +60,8 @@ require (
github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
Expand All @@ -70,4 +72,5 @@ require (
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a // indirect
)
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ github.com/antonfisher/nested-logrus-formatter v1.3.1 h1:NFJIr+pzwv5QLHTPyKz9UME
github.com/antonfisher/nested-logrus-formatter v1.3.1/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA=
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
Expand All @@ -57,6 +59,7 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dvyukov/go-fuzz v0.0.0-20210103155950-6a8e9d1f2415/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down Expand Up @@ -235,13 +238,19 @@ github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 h1:UXLjNohABv4S58tHmeuIZDO6e3mHpW2Dx33gaNt03LE=
go4.org/intern v0.0.0-20211027215823-ae77deb06f29/go.mod h1:cS2ma+47FKrLPdXFpr7CuxiTW3eyJbWew4qx0qtQWDA=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20211027215541-db492cf91b37/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 h1:WJhcL4p+YeDxmZWg141nRm7XC8IDmhz7lk5GpadO1Sg=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
Expand Down Expand Up @@ -308,6 +317,7 @@ golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand All @@ -325,6 +335,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -351,6 +362,8 @@ golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
Expand Down Expand Up @@ -406,6 +419,7 @@ golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down Expand Up @@ -507,6 +521,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a h1:1XCVEdxrvL6c0TGOhecLuB7U9zYNdxZEjvOqJreKZiM=
inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a/go.mod h1:e83i32mAQOW1LAqEIweALsuK2Uw4mhQadA5r7b0Wobo=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
Expand Down
25 changes: 6 additions & 19 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,13 @@ func InitSmfContext(config *factory.Config) {
smfContext.ListenAddr = pfcp.ListenAddr
smfContext.ExternalAddr = pfcp.ExternalAddr

if ip := net.ParseIP(pfcp.NodeID); ip == nil {
smfContext.CPNodeID = pfcpType.NodeID{
NodeIdType: pfcpType.NodeIdTypeFqdn,
FQDN: pfcp.NodeID,
}
} else {
ipv4 := ip.To4()
if ipv4 != nil {
smfContext.CPNodeID = pfcpType.NodeID{
NodeIdType: pfcpType.NodeIdTypeIpv4Address,
IP: ipv4,
}
} else {
smfContext.CPNodeID = pfcpType.NodeID{
NodeIdType: pfcpType.NodeIdTypeIpv6Address,
IP: ip,
}
}
nodeID, err := ConfigToNodeID(pfcp.NodeID)
if err != nil {
logger.InitLog.Fatalf("[InitSmfContext] cannot parse PFCP NodeID from config: %+v", err)
}

smfContext.CPNodeID = nodeID

smfContext.PfcpHeartbeatInterval = pfcp.HeartbeatInterval
var multipleOfInterval time.Duration = 5
if pfcp.AssocFailAlertInterval == 0 {
Expand Down Expand Up @@ -239,7 +226,7 @@ func InitSmfContext(config *factory.Config) {

smfContext.SupportedPDUSessionType = "IPv4"

smfContext.UserPlaneInformation = NewUserPlaneInformation(&configuration.UserPlaneInformation)
smfContext.UserPlaneInformation = NewUserPlaneInformation(configuration.UserPlaneInformation)

smfContext.ChargingIDGenerator = idgenerator.NewGenerator(1, math.MaxUint32)

Expand Down
46 changes: 19 additions & 27 deletions internal/context/datapath.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (node *DataPathNode) ActivateUpLinkTunnel(smContext *SMContext) error {

destUPF := node.UPF
if node.UpLinkTunnel.PDR, err = destUPF.AddPDR(); err != nil {
logger.CtxLog.Errorln("In ActivateUpLinkTunnel UPF IP: ", node.UPF.NodeID.ResolveNodeIdToIp().String())
logger.CtxLog.Errorln("In ActivateUpLinkTunnel UPF IP: ", node.GetNodeIP())
logger.CtxLog.Errorln("Allocate PDR Error: ", err)
return fmt.Errorf("Add PDR failed: %s", err)
}
Expand All @@ -159,7 +159,7 @@ func (node *DataPathNode) ActivateDownLinkTunnel(smContext *SMContext) error {

destUPF := node.UPF
if node.DownLinkTunnel.PDR, err = destUPF.AddPDR(); err != nil {
logger.CtxLog.Errorln("In ActivateDownLinkTunnel UPF IP: ", node.UPF.NodeID.ResolveNodeIdToIp().String())
logger.CtxLog.Errorln("In ActivateDownLinkTunnel UPF IP: ", node.GetNodeIP())
logger.CtxLog.Errorln("Allocate PDR Error: ", err)
return fmt.Errorf("Add PDR failed: %s", err)
}
Expand Down Expand Up @@ -244,20 +244,12 @@ func (node *DataPathNode) DeactivateDownLinkTunnel(smContext *SMContext) {
}
}

func (node *DataPathNode) GetUPFID() (id string, err error) {
node_ip := node.GetNodeIP()
var exist bool

if id, exist = smfContext.UserPlaneInformation.UPFsIPtoID[node_ip]; !exist {
err = fmt.Errorf("UPNode IP %s doesn't exist in smfcfg.yaml", node_ip)
return "", err
}

return id, nil
func (node *DataPathNode) GetUPFID() uuid.UUID {
return node.UPF.GetID()
}

func (node *DataPathNode) GetNodeIP() (ip string) {
ip = node.UPF.NodeID.ResolveNodeIdToIp().String()
ip = node.UPF.GetNodeIDString()
return
}

Expand Down Expand Up @@ -319,17 +311,17 @@ func (dataPath *DataPath) String() string {
for curDPNode := firstDPNode; curDPNode != nil; curDPNode = curDPNode.Next() {
str += strconv.Itoa(index) + "th Node in the Path\n"
str += "Current UPF IP: " + curDPNode.GetNodeIP() + "\n"
str += "Current UPF ID: " + curDPNode.UPF.GetUPFID() + "\n"
str += "Current UPF ID: " + curDPNode.UPF.GetID().String() + "\n"
if curDPNode.Prev() != nil {
str += "Previous UPF IP: " + curDPNode.Prev().GetNodeIP() + "\n"
str += "Previous UPF ID: " + curDPNode.Prev().UPF.GetUPFID() + "\n"
str += "Previous UPF ID: " + curDPNode.Prev().UPF.GetID().String() + "\n"
} else {
str += "Previous UPF IP: None\n"
}

if curDPNode.Next() != nil {
str += "Next UPF IP: " + curDPNode.Next().GetNodeIP() + "\n"
str += "Next UPF ID: " + curDPNode.Next().UPF.GetUPFID() + "\n"
str += "Next UPF ID: " + curDPNode.Next().UPF.GetID().String() + "\n"
} else {
str += "Next UPF IP: None\n"
}
Expand All @@ -340,8 +332,8 @@ func (dataPath *DataPath) String() string {
return str
}

func getUrrIdKey(uuid string, urrId uint32) string {
return uuid + ":" + strconv.Itoa(int(urrId))
func getUrrIdKey(uuid uuid.UUID, urrId uint32) string {
return uuid.String() + ":" + strconv.Itoa(int(urrId))
}

func GetUpfIdFromUrrIdKey(urrIdKey string) string {
Expand All @@ -352,7 +344,7 @@ func (node DataPathNode) addUrrToNode(smContext *SMContext, urrId uint32, isMeas
var urr *URR
var ok bool
var err error
currentUUID := node.UPF.UUID()
currentUUID := node.UPF.GetID()
id := getUrrIdKey(currentUUID, urrId)

if urr, ok = smContext.UrrUpfMap[id]; !ok {
Expand Down Expand Up @@ -412,7 +404,7 @@ func (dataPath *DataPath) ActivateTunnelAndPDR(smContext *SMContext, precedence
logger.PduSessLog.Traceln(dataPath.String())
// Activate Tunnels
for node := firstDPNode; node != nil; node = node.Next() {
logger.PduSessLog.Traceln("Current DP Node IP: ", node.UPF.NodeID.ResolveNodeIdToIp().String())
logger.PduSessLog.Traceln("Current DP Node IP: ", node.GetNodeIP())
if err := node.ActivateUpLinkTunnel(smContext); err != nil {
logger.CtxLog.Warnln(err)
return
Expand All @@ -438,7 +430,7 @@ func (dataPath *DataPath) ActivateTunnelAndPDR(smContext *SMContext, precedence
for curDataPathNode := firstDPNode; curDataPathNode != nil; curDataPathNode = curDataPathNode.Next() {
var defaultQER *QER
var ambrQER *QER
currentUUID := curDataPathNode.UPF.uuid
currentUUID := curDataPathNode.UPF.GetID()
if qerId, okCurrentId := smContext.AMBRQerMap[currentUUID]; !okCurrentId {
if newQER, err := curDataPathNode.UPF.AddQER(); err != nil {
logger.PduSessLog.Errorln("new QER failed")
Expand Down Expand Up @@ -644,7 +636,7 @@ func (dataPath *DataPath) ActivateTunnelAndPDR(smContext *SMContext, precedence

DLFAR := DLPDR.FAR

logger.PduSessLog.Traceln("Current DP Node IP: ", curDataPathNode.UPF.NodeID.ResolveNodeIdToIp().String())
logger.PduSessLog.Traceln("Current DP Node IP: ", curDataPathNode.GetNodeIP())
logger.PduSessLog.Traceln("Before DLPDR OuterHeaderCreation")
if nextDLDest := curDataPathNode.Prev(); nextDLDest != nil {
logger.PduSessLog.Traceln("In DLPDR OuterHeaderCreation")
Expand Down Expand Up @@ -768,7 +760,7 @@ func (p *DataPath) AddChargingRules(smContext *SMContext, chgLevel ChargingLevel
chgInfo := &ChargingInfo{
RatingGroup: chgData.RatingGroup,
ChargingLevel: chgLevel,
UpfId: node.UPF.UUID(),
UpfId: node.UPF.GetID().String(),
}

urrId, err := smContext.UrrIDGenerator.Allocate()
Expand All @@ -777,7 +769,7 @@ func (p *DataPath) AddChargingRules(smContext *SMContext, chgLevel ChargingLevel
return
}

currentUUID := node.UPF.UUID()
currentUUID := node.UPF.GetID()
id := getUrrIdKey(currentUUID, uint32(urrId))

if oldURR, ok := smContext.UrrUpfMap[id]; !ok {
Expand Down Expand Up @@ -820,7 +812,7 @@ func (p *DataPath) AddChargingRules(smContext *SMContext, chgLevel ChargingLevel
if !isUrrExist(node.UpLinkTunnel.PDR.URR, urr) {
node.UpLinkTunnel.PDR.AppendURRs([]*URR{urr})
// nolint
nodeId, _ := node.GetUPFID()
nodeId := node.GetUPFID()
logger.PduSessLog.Tracef("UpLinkTunnel add URR for node %s %+v",
nodeId, node.UpLinkTunnel.PDR)
}
Expand All @@ -829,7 +821,7 @@ func (p *DataPath) AddChargingRules(smContext *SMContext, chgLevel ChargingLevel
if !isUrrExist(node.DownLinkTunnel.PDR.URR, urr) {
node.DownLinkTunnel.PDR.AppendURRs([]*URR{urr})
// nolint
nodeId, _ := node.GetUPFID()
nodeId := node.GetUPFID()
logger.PduSessLog.Tracef("DownLinkTunnel add URR for node %s %+v",
nodeId, node.DownLinkTunnel.PDR)
}
Expand All @@ -847,7 +839,7 @@ func (p *DataPath) AddQoS(smContext *SMContext, qfi uint8, qos *models.QosData)
for node := p.FirstDPNode; node != nil; node = node.Next() {
var qer *QER

currentUUID := node.UPF.GetUUID()
currentUUID := node.UPF.GetID()
id := getQosIdKey(currentUUID, qfi)

if qerId, ok := smContext.QerUpfMap[id]; !ok {
Expand Down
71 changes: 71 additions & 0 deletions internal/context/gnb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package context

import (
"fmt"

"github.com/google/uuid"

"github.com/free5gc/smf/internal/logger"
)

// embeds the UPNode struct ("inheritance")
// implements UPNodeInterface
type GNB struct {
*UPNode
}

func (gNB *GNB) GetName() string {
return gNB.Name
}

func (gNB *GNB) GetID() uuid.UUID {
return gNB.ID
}

func (gNB *GNB) GetType() UPNodeType {
return gNB.Type
}

func (gNB *GNB) String() string {
str := "gNB {\n"
prefix := " "
str += prefix + fmt.Sprintf("Name: %s\n", gNB.Name)
str += prefix + fmt.Sprintf("ID: %s\n", gNB.ID)
str += prefix + fmt.Sprintln("Links:")
for _, link := range gNB.Links {
str += prefix + fmt.Sprintf("-- %s: %s\n", link.GetName(), link.GetName())
}
str += "}"
return str
}

func (gNB *GNB) GetLinks() UPPath {
return gNB.Links
}

func (gNB *GNB) AddLink(link UPNodeInterface) bool {
for _, existingLink := range gNB.Links {
if link.GetName() == existingLink.GetName() {
logger.CfgLog.Warningf("UPLink [%s] <=> [%s] already exists, skip\n", existingLink.GetName(), link.GetName())
return false
}
}
gNB.Links = append(gNB.Links, link)
return true
}

func (gNB *GNB) RemoveLink(link UPNodeInterface) bool {
for i, existingLink := range gNB.Links {
if link.GetName() == existingLink.GetName() && existingLink.GetName() == link.GetName() {
logger.CfgLog.Warningf("Remove UPLink [%s] <=> [%s]\n", existingLink.GetName(), link.GetName())
gNB.Links = append(gNB.Links[:i], gNB.Links[i+1:]...)
return true
}
}
return false
}

func (gNB *GNB) RemoveLinkByIndex(index int) bool {
gNB.Links[index] = gNB.Links[len(gNB.Links)-1]
return true
}
2 changes: 1 addition & 1 deletion internal/context/pfcp_reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (smContext *SMContext) HandleReports(
) {
var usageReport UsageReport
upf := RetrieveUPFNodeByNodeID(nodeId)
upfId := upf.UUID()
upfId := upf.GetID()

for _, report := range usageReportRequest {
usageReport.UrrId = report.URRID.UrrIdValue
Expand Down
Loading
Loading