Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1556845
enforce accept json header
patriciareinoso Jun 11, 2025
242d812
UTs
patriciareinoso Jun 11, 2025
a9e0744
add log
patriciareinoso Jun 12, 2025
0b50b15
implement plmn and plmn-snssai endpoints
patriciareinoso Jun 12, 2025
d023a07
Merge branch 'main' into plmn-snssai-endpoint
patriciareinoso Jun 12, 2025
4520c28
implement synchronization
patriciareinoso Jun 13, 2025
cebca0c
modify mock in tests
patriciareinoso Jun 13, 2025
b89e880
restore mocked functions in UTs
patriciareinoso Jun 16, 2025
30ce8e3
Merge branch 'main' into plmn-snssai-endpoint
patriciareinoso Jun 20, 2025
c1dd654
use openapi new version
patriciareinoso Jun 20, 2025
1deda17
fix invalid SST test
patriciareinoso Jun 20, 2025
3f8b644
fix format
patriciareinoso Jun 20, 2025
929325c
remove pointer
patriciareinoso Jun 20, 2025
61cafbb
fix UTs
patriciareinoso Jun 20, 2025
5ec8033
order lists to guarantee Idempotence
patriciareinoso Jun 23, 2025
ce16fbe
use getter for ordering function
patriciareinoso Jun 23, 2025
8a404ed
Merge branch 'main' into plmn-snssai-endpoint
patriciareinoso Jun 23, 2025
084a54c
fix lint job
patriciareinoso Jun 23, 2025
7dc5a10
refactor design
patriciareinoso Jun 24, 2025
e44d676
refactor UTs
patriciareinoso Jun 24, 2025
ec63d7c
improve logging
patriciareinoso Jun 24, 2025
6388058
refactor sync approach
patriciareinoso Jun 24, 2025
e6d0670
refactor input parameters in webui methdos
patriciareinoso Jun 24, 2025
b9aa450
fix lint
patriciareinoso Jun 24, 2025
2bb34ce
minor format fixes
patriciareinoso Jun 25, 2025
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
2 changes: 2 additions & 0 deletions backend/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
ConfigLog *zap.SugaredLogger
DbLog *zap.SugaredLogger
AuthLog *zap.SugaredLogger
NfConfigLog *zap.SugaredLogger
atomicLevel zap.AtomicLevel
)

Expand Down Expand Up @@ -61,6 +62,7 @@ func init() {
ConfigLog = log.Sugar().With("component", "WebUI", "category", "CONFIG")
DbLog = log.Sugar().With("component", "WebUI", "category", "DB")
AuthLog = log.Sugar().With("component", "WebUI", "category", "Auth")
NfConfigLog = log.Sugar().With("component", "WebUI", "category", "NFConfig")
}

func GetLogger() *zap.Logger {
Expand Down
134 changes: 129 additions & 5 deletions backend/nfconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,136 @@

package nfconfig

type AccessAndMobilityConfig struct{}
import (
"sort"
"strconv"

type PlmnConfig struct{}
"github.com/omec-project/openapi/nfConfigApi"
"github.com/omec-project/webconsole/backend/logger"
"github.com/omec-project/webconsole/configmodels"
)

type PlmnSnssaiConfig struct{}
type inMemoryConfig struct {
plmn []nfConfigApi.PlmnId
plmnSnssai []nfConfigApi.PlmnSnssai
accessAndMobility []nfConfigApi.AccessAndMobility
sessionManagement []nfConfigApi.SessionManagement
policyControl []nfConfigApi.PolicyControl
}

type SessionManagementConfig struct{}
func (c *inMemoryConfig) syncPlmn(slices []configmodels.Slice) {
plmnSet := make(map[nfConfigApi.PlmnId]bool)
newPlmnConfig := []nfConfigApi.PlmnId{}
for _, s := range slices {
plmn := *nfConfigApi.NewPlmnId(s.SiteInfo.Plmn.Mcc, s.SiteInfo.Plmn.Mnc)
if !plmnSet[plmn] {
plmnSet[plmn] = true
newPlmnConfig = append(newPlmnConfig, plmn)
}
}

type PolicyControlConfig struct{}
sort.Slice(newPlmnConfig, func(i, j int) bool {
if newPlmnConfig[i].GetMcc() != newPlmnConfig[j].GetMcc() {
return newPlmnConfig[i].GetMcc() < newPlmnConfig[j].GetMcc()
}
return newPlmnConfig[i].GetMnc() < newPlmnConfig[j].GetMnc()
})

c.plmn = newPlmnConfig
logger.NfConfigLog.Debugln("Updated PLMN in-memory configuration. New configuration:", c.plmn)
}

func (c *inMemoryConfig) syncPlmnSnssai(slices []configmodels.Slice) {
plmnMap := make(map[configmodels.SliceSiteInfoPlmn]map[configmodels.SliceSliceId]struct{})
for _, s := range slices {
plmn := s.SiteInfo.Plmn
if plmnMap[plmn] == nil {
plmnMap[plmn] = map[configmodels.SliceSliceId]struct{}{}
}
plmnMap[plmn][s.SliceId] = struct{}{}
}

c.plmnSnssai = convertPlmnMapToSortedList(plmnMap)
logger.NfConfigLog.Debugln("Updated PLMN S-NSSAI in-memory configuration. New configuration:", c.plmnSnssai)
}

func parseSnssaiFromSlice(sliceId configmodels.SliceSliceId) (nfConfigApi.Snssai, error) {
logger.NfConfigLog.Debugln("Parsing slice ID:", sliceId)
val, err := strconv.ParseInt(sliceId.Sst, 10, 64)
if err != nil {
return *nfConfigApi.NewSnssaiWithDefaults(), err
}

snssai := nfConfigApi.NewSnssai(int32(val))
if sliceId.Sd != "" {
snssai.SetSd(sliceId.Sd)
}
return *snssai, nil
}

func convertPlmnMapToSortedList(plmnMap map[configmodels.SliceSiteInfoPlmn]map[configmodels.SliceSliceId]struct{}) []nfConfigApi.PlmnSnssai {
newPlmnSnssaiConfig := []nfConfigApi.PlmnSnssai{}
for plmn, snssaiSet := range plmnMap {
snssaiList := make([]nfConfigApi.Snssai, 0, len(snssaiSet))
for snssai := range snssaiSet {
newSnssai, err := parseSnssaiFromSlice(snssai)
if err != nil {
logger.NfConfigLog.Warnf("Error in parsing SST: %v. Network slice `%s` will be ignored", err, snssai)
continue
}
snssaiList = append(snssaiList, newSnssai)
}
if len(snssaiList) == 0 {
continue
}
plmnId := nfConfigApi.NewPlmnId(plmn.Mcc, plmn.Mnc)
plmnSnssai := nfConfigApi.NewPlmnSnssai(*plmnId, snssaiList)
newPlmnSnssaiConfig = append(newPlmnSnssaiConfig, *plmnSnssai)
}
sortPlmnSnssaiConfig(newPlmnSnssaiConfig)
return newPlmnSnssaiConfig
}

func sortPlmnSnssaiConfig(plmnSnssai []nfConfigApi.PlmnSnssai) {
sort.Slice(plmnSnssai, func(i, j int) bool {
if plmnSnssai[i].PlmnId.GetMcc() != plmnSnssai[j].PlmnId.GetMcc() {
return plmnSnssai[i].PlmnId.GetMcc() < plmnSnssai[j].PlmnId.GetMcc()
}
return plmnSnssai[i].PlmnId.GetMnc() < plmnSnssai[j].PlmnId.GetMnc()
})

for i := range plmnSnssai {
sort.Slice(plmnSnssai[i].SNssaiList, func(a, b int) bool {
s1 := plmnSnssai[i].SNssaiList[a]
s2 := plmnSnssai[i].SNssaiList[b]
if s1.GetSst() != s2.GetSst() {
return s1.GetSst() < s2.GetSst()
}
if !s1.HasSd() && s2.HasSd() {
return true
}
if s1.HasSd() && !s2.HasSd() {
return false
}
if s1.HasSd() && s2.HasSd() {
return s1.GetSd() < s2.GetSd()
}
return false
})
}
}

func (c *inMemoryConfig) syncAccessAndMobility() {
c.accessAndMobility = []nfConfigApi.AccessAndMobility{}
logger.NfConfigLog.Debugln("Updated Access and Mobility in-memory configuration. New configuration:", c.accessAndMobility)
}

func (c *inMemoryConfig) syncSessionManagement() {
c.sessionManagement = []nfConfigApi.SessionManagement{}
logger.NfConfigLog.Debugln("Updated Session Management in-memory configuration. New configuration:", c.sessionManagement)
}

func (c *inMemoryConfig) syncPolicyControl() {
c.policyControl = []nfConfigApi.PolicyControl{}
logger.NfConfigLog.Debugln("Updated Policy Control in-memory configuration. New configuration:", c.policyControl)
}
20 changes: 10 additions & 10 deletions backend/nfconfig/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ import (
)

func (n *NFConfigServer) GetAccessMobilityConfig(c *gin.Context) {
logger.ConfigLog.Infoln("Handling GET request for access-mobility config")
c.JSON(http.StatusOK, []AccessAndMobilityConfig{})
logger.NfConfigLog.Infoln("Handling GET request for access-mobility config")
c.JSON(http.StatusOK, n.inMemoryConfig.accessAndMobility)
}

func (n *NFConfigServer) GetPlmnConfig(c *gin.Context) {
logger.ConfigLog.Infoln("Handling GET request for plmn config")
c.JSON(http.StatusOK, []PlmnConfig{})
logger.NfConfigLog.Infoln("Handling GET request for plmn config")
c.JSON(http.StatusOK, n.inMemoryConfig.plmn)
}

func (n *NFConfigServer) GetPlmnSnssaiConfig(c *gin.Context) {
logger.ConfigLog.Infoln("Handling GET request for plmn-snssai config")
c.JSON(http.StatusOK, []PlmnSnssaiConfig{})
logger.NfConfigLog.Infoln("Handling GET request for plmn-snssai config")
c.JSON(http.StatusOK, n.inMemoryConfig.plmnSnssai)
}

func (n *NFConfigServer) GetPolicyControlConfig(c *gin.Context) {
logger.ConfigLog.Infoln("Handling GET request for policy-control config")
c.JSON(http.StatusOK, []PolicyControlConfig{})
logger.NfConfigLog.Infoln("Handling GET request for policy-control config")
c.JSON(http.StatusOK, n.inMemoryConfig.policyControl)
}

func (n *NFConfigServer) GetSessionManagementConfig(c *gin.Context) {
logger.ConfigLog.Infoln("Handling GET request for session-management config")
c.JSON(http.StatusOK, []SessionManagementConfig{})
logger.NfConfigLog.Infoln("Handling GET request for session-management config")
c.JSON(http.StatusOK, n.inMemoryConfig.sessionManagement)
}
Loading