X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fconfiguration%2Fconfiguration.go;h=8beac3ced677c9bbce0bfc964eeec129742837ea;hb=7abc043a40d183f290391f6c99dfc98062f5f237;hp=9ef7c330145a57ce3df7dfe1816baa8a02489447;hpb=dbf8e0032295fac936779b0f117d0600b94c85fc;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/configuration/configuration.go b/E2Manager/configuration/configuration.go index 9ef7c33..8beac3c 100644 --- a/E2Manager/configuration/configuration.go +++ b/E2Manager/configuration/configuration.go @@ -20,8 +20,10 @@ package configuration import ( + "errors" "fmt" "github.com/spf13/viper" + "strconv" ) type Configuration struct { @@ -38,17 +40,18 @@ type Configuration struct { RoutingManager struct { BaseUrl string } + NotificationResponseBuffer int BigRedButtonTimeoutSec int - MaxConnectionAttempts int MaxRnibConnectionAttempts int RnibRetryIntervalMs int KeepAliveResponseTimeoutMs int KeepAliveDelayMs int E2TInstanceDeletionTimeoutMs int GlobalRicId struct { - PlmnId string - RicNearRtId string + RicId string + Mcc int + Mnc int } } @@ -71,7 +74,6 @@ func ParseConfiguration() *Configuration { config.populateRoutingManagerConfig(viper.Sub("routingManager")) config.NotificationResponseBuffer = viper.GetInt("notificationResponseBuffer") config.BigRedButtonTimeoutSec = viper.GetInt("bigRedButtonTimeoutSec") - config.MaxConnectionAttempts = viper.GetInt("maxConnectionAttempts") config.MaxRnibConnectionAttempts = viper.GetInt("maxRnibConnectionAttempts") config.RnibRetryIntervalMs = viper.GetInt("rnibRetryIntervalMs") config.KeepAliveResponseTimeoutMs = viper.GetInt("keepAliveResponseTimeoutMs") @@ -111,18 +113,95 @@ func (c *Configuration) populateRoutingManagerConfig(rmConfig *viper.Viper) { } func (c *Configuration) populateGlobalRicIdConfig(globalRicIdConfig *viper.Viper) { + err := validateGlobalRicIdConfig(globalRicIdConfig) + if err != nil { + panic(err.Error()) + } + c.GlobalRicId.RicId = globalRicIdConfig.GetString("ricId") + c.GlobalRicId.Mcc = globalRicIdConfig.GetInt("mcc") + c.GlobalRicId.Mnc = globalRicIdConfig.GetInt("mnc") +} + +func validateGlobalRicIdConfig(globalRicIdConfig *viper.Viper) error { if globalRicIdConfig == nil { - panic(fmt.Sprintf("#configuration.populateGlobalRicIdConfig - failed to populate Global RicId configuration: The entry 'globalRicId' not found\n")) + return errors.New("#configuration.validateGlobalRicIdConfig - failed to populate Global RicId configuration: The entry 'globalRicId' not found\n") + } + + err := validateRicId(globalRicIdConfig.GetString("ricId")) + + if err != nil { + return err } - c.GlobalRicId.PlmnId = globalRicIdConfig.GetString("plmnId") - c.GlobalRicId.RicNearRtId = globalRicIdConfig.GetString("ricNearRtId") + + err = validateMcc(globalRicIdConfig.GetInt("mcc")) + + if err != nil { + return err + } + + err = validateMnc(globalRicIdConfig.GetInt("mnc")) + + if err != nil { + return err + } + + + return nil } +func validateMcc(mcc int) error { + + mccStr := strconv.Itoa(mcc) + + if len(mccStr) != 3{ + return errors.New("#configuration.validateMcc - mcc is not 3 digits\n") + } + + if mcc < 0 { + return errors.New("#configuration.validateMcc - mcc is negative\n") + } + return nil +} + +func validateMnc(mnc int) error { + + mncStr := strconv.Itoa(mnc) + + if len(mncStr) < 2 || len(mncStr) >3 { + return errors.New("#configuration.validateMnc - mnc is not 2 or 3 digits\n") + } + + if mnc < 0 { + return errors.New("#configuration.validateMnc - mnc is negative\n") + } + + return nil +} + +func validateRicId(ricId string) error{ + + if len(ricId) == 0{ + return errors.New("#configuration.validateRicId - ricId is emtpy\n") + } + + if len(ricId) != 5 { + return errors.New("#configuration.validateRicId - ricId length should be 5 hex characters\n") + } + + _, err := strconv.ParseUint(ricId, 16, 64) + if err != nil { + return errors.New("#configuration.validateRicId - ricId is not hex number\n") + } + + return nil +} + + func (c *Configuration) String() string { return fmt.Sprintf("{logging.logLevel: %s, http.port: %d, rmr: { port: %d, maxMsgSize: %d}, routingManager.baseUrl: %s, "+ - "notificationResponseBuffer: %d, bigRedButtonTimeoutSec: %d, maxConnectionAttempts: %d, maxRnibConnectionAttempts: %d, "+ + "notificationResponseBuffer: %d, bigRedButtonTimeoutSec: %d, maxRnibConnectionAttempts: %d, "+ "rnibRetryIntervalMs: %d, keepAliveResponseTimeoutMs: %d, keepAliveDelayMs: %d, e2tInstanceDeletionTimeoutMs: %d, "+ - "globalRicId: { plmnId: %s, ricNearRtId: %s}}", + "globalRicId: { ricId: %s, mcc: %d, mnc: %d}", c.Logging.LogLevel, c.Http.Port, c.Rmr.Port, @@ -130,13 +209,13 @@ func (c *Configuration) String() string { c.RoutingManager.BaseUrl, c.NotificationResponseBuffer, c.BigRedButtonTimeoutSec, - c.MaxConnectionAttempts, c.MaxRnibConnectionAttempts, c.RnibRetryIntervalMs, c.KeepAliveResponseTimeoutMs, c.KeepAliveDelayMs, c.E2TInstanceDeletionTimeoutMs, - c.GlobalRicId.PlmnId, - c.GlobalRicId.RicNearRtId, + c.GlobalRicId.RicId, + c.GlobalRicId.Mcc, + c.GlobalRicId.Mnc, ) }