2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
25 "github.com/spf13/viper"
29 type Configuration struct {
42 MaxRnibConnectionAttempts int
43 RnibRetryIntervalMs int
45 ResourceStatusParams struct {
46 EnableResourceStatus bool
47 PartialSuccessAllowed bool
49 TnlLoadIndPeriodic bool
50 HwLoadIndPeriodic bool
51 AbsStatusPeriodic bool
52 RsrpMeasurementPeriodic bool
54 PeriodicityMs enums.ReportingPeriodicity
55 PeriodicityRsrpMeasurementMs enums.ReportingPeriodicityRSRPMR
56 PeriodicityCsiMs enums.ReportingPeriodicityCSIR
60 func ParseConfiguration() (*Configuration, error) {
61 viper.SetConfigType("yaml")
62 viper.SetConfigName("configuration")
63 viper.AddConfigPath("RSM/resources/")
64 viper.AddConfigPath("./resources/") //For production
65 viper.AddConfigPath("../resources/") //For test under Docker
66 viper.AddConfigPath("../../resources/") //For test under Docker
67 if err := viper.ReadInConfig(); err != nil {
68 return nil, fmt.Errorf("#configuration.parseConfiguration - failed to read configuration file: %s\n", err)
71 config := Configuration{}
72 if err := config.fillRmrConfig(viper.Sub("rmr")); err != nil {
75 if err := config.fillHttpConfig(viper.Sub("http")); err != nil {
78 if err := config.fillLoggingConfig(viper.Sub("logging")); err != nil {
81 if err := config.fillRnibConfig(viper.Sub("rnib")); err != nil {
84 if err := config.fillResourceStatusParamsConfig(viper.Sub("resourceStatusParams")); err != nil {
91 func (c *Configuration) fillLoggingConfig(logConfig *viper.Viper) error {
93 return fmt.Errorf("#configuration.fillLoggingConfig - failed to fill logging configuration: The entry 'logging' not found\n")
95 c.Logging.LogLevel = logConfig.GetString("logLevel")
99 func (c *Configuration) fillHttpConfig(httpConfig *viper.Viper) error {
100 if httpConfig == nil {
101 return fmt.Errorf("#configuration.fillHttpConfig - failed to fill HTTP configuration: The entry 'http' not found\n")
103 c.Http.Port = httpConfig.GetInt("port")
107 func (c *Configuration) fillRmrConfig(rmrConfig *viper.Viper) error {
108 if rmrConfig == nil {
109 return fmt.Errorf("#configuration.fillRmrConfig - failed to fill RMR configuration: The entry 'rmr' not found\n")
111 c.Rmr.Port = rmrConfig.GetInt("port")
112 c.Rmr.MaxMsgSize = rmrConfig.GetInt("maxMsgSize")
113 c.Rmr.ReadyIntervalSec = rmrConfig.GetInt("readyIntervalSec")
117 func (c *Configuration) fillRnibConfig(rnibConfig *viper.Viper) error {
118 if rnibConfig == nil {
119 return fmt.Errorf("#configuration.fillRnibConfig - failed to fill RNib configuration: The entry 'rnib' not found\n")
121 c.Rnib.MaxRnibConnectionAttempts = rnibConfig.GetInt("maxRnibConnectionAttempts")
122 c.Rnib.RnibRetryIntervalMs = rnibConfig.GetInt("rnibRetryIntervalMs")
126 func (c *Configuration) fillResourceStatusParamsConfig(chConfig *viper.Viper) error {
128 return fmt.Errorf("#configuration.fillResourceStatusParamsConfig - failed to fill resourceStatusParams configuration: The entry 'resourceStatusParams' not found\n")
130 c.ResourceStatusParams.EnableResourceStatus = chConfig.GetBool("enableResourceStatus")
131 c.ResourceStatusParams.PartialSuccessAllowed = chConfig.GetBool("partialSuccessAllowed")
132 c.ResourceStatusParams.PrbPeriodic = chConfig.GetBool("prbPeriodic")
133 c.ResourceStatusParams.TnlLoadIndPeriodic = chConfig.GetBool("tnlLoadIndPeriodic")
134 c.ResourceStatusParams.HwLoadIndPeriodic = chConfig.GetBool("hwLoadIndPeriodic")
135 c.ResourceStatusParams.AbsStatusPeriodic = chConfig.GetBool("absStatusPeriodic")
136 c.ResourceStatusParams.RsrpMeasurementPeriodic = chConfig.GetBool("rsrpMeasurementPeriodic")
137 c.ResourceStatusParams.CsiPeriodic = chConfig.GetBool("csiPeriodic")
138 if err := setPeriodicityMs(c, chConfig.GetInt("periodicityMs")); err != nil {
141 if err := setPeriodicityRsrpMeasurementMs(c, chConfig.GetInt("periodicityRsrpMeasurementMs")); err != nil {
144 if err := setPeriodicityCsiMs(c, chConfig.GetInt("periodicityCsiMs")); err != nil {
150 func setPeriodicityMs(c *Configuration, periodicityMs int) error {
151 v, ok := enums.ReportingPeriodicityValues[periodicityMs]
154 return fmt.Errorf("Invalid configuration value supplied for PeriodicityMs. Received: %d. Should be one of: %v\n", periodicityMs, enums.GetReportingPeriodicityValuesAsKeys())
157 c.ResourceStatusParams.PeriodicityMs = v
161 func setPeriodicityRsrpMeasurementMs(c *Configuration, periodicityRsrpMeasurementMs int) error {
162 v, ok := enums.ReportingPeriodicityRsrPmrValues[periodicityRsrpMeasurementMs]
165 return fmt.Errorf("Invalid configuration value supplied for PeriodicityRsrpMeasurementMs. Received: %d. Should be one of: %v\n", periodicityRsrpMeasurementMs, enums.GetReportingPeriodicityRsrPmrValuesAsKeys())
168 c.ResourceStatusParams.PeriodicityRsrpMeasurementMs = v
172 func setPeriodicityCsiMs(c *Configuration, periodicityCsiMs int) error {
173 v, ok := enums.ReportingPeriodicityCsirValues[periodicityCsiMs]
176 return fmt.Errorf("Invalid configuration value supplied for PeriodicityCsiMs. Received: %d. Should be one of: %v\n", periodicityCsiMs, enums.GetReportingPeriodicityCsirValuesAsKeys())
179 c.ResourceStatusParams.PeriodicityCsiMs = v
183 func (c *Configuration) String() string {
184 return fmt.Sprintf("{logging.logLevel: %s, http.port: %d, rmr.port: %d, rmr.maxMsgSize: %d, rmr.readyIntervalSec: %d, rnib.maxRnibConnectionAttempts: %d, rnib.rnibRetryIntervalMs: %d, "+
185 "resourceStatusParams.enableResourceStatus: %t, resourceStatusParams.partialSuccessAllowed: %t, resourceStatusParams.prbPeriodic: %t, "+
186 "resourceStatusParams.tnlLoadIndPeriodic: %t, resourceStatusParams.hwLoadIndPeriodic: %t, resourceStatusParams.absStatusPeriodic: %t,"+
187 "resourceStatusParams.rsrpMeasurementPeriodic: %t, resourceStatusParams.csiPeriodic: %t, resourceStatusParams.periodicityMs: %s, "+
188 "resourceStatusParams.periodicityRsrpMeasurementMs: %s, resourceStatusParams.periodicityCsiMs: %s}",
193 c.Rmr.ReadyIntervalSec,
194 c.Rnib.MaxRnibConnectionAttempts,
195 c.Rnib.RnibRetryIntervalMs,
196 c.ResourceStatusParams.EnableResourceStatus,
197 c.ResourceStatusParams.PartialSuccessAllowed,
198 c.ResourceStatusParams.PrbPeriodic,
199 c.ResourceStatusParams.TnlLoadIndPeriodic,
200 c.ResourceStatusParams.HwLoadIndPeriodic,
201 c.ResourceStatusParams.AbsStatusPeriodic,
202 c.ResourceStatusParams.RsrpMeasurementPeriodic,
203 c.ResourceStatusParams.CsiPeriodic,
205 c.ResourceStatusParams.PeriodicityMs,
206 c.ResourceStatusParams.PeriodicityRsrpMeasurementMs,
207 c.ResourceStatusParams.PeriodicityCsiMs,