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).
27 "github.com/spf13/viper"
30 type RnibWriterConfig struct {
31 StateChangeMessageChannel string
32 RanManipulationMessageChannel string
35 type Configuration struct {
46 RoutingManager struct {
50 NotificationResponseBuffer int
51 BigRedButtonTimeoutSec int
52 MaxRnibConnectionAttempts int
53 RnibRetryIntervalMs int
54 KeepAliveResponseTimeoutMs int
56 E2TInstanceDeletionTimeoutMs int
63 RnibWriter RnibWriterConfig
66 func ParseConfiguration() *Configuration {
67 viper.SetConfigType("yaml")
68 viper.SetConfigName("configuration")
69 viper.AddConfigPath("E2Manager/resources/")
70 viper.AddConfigPath("./resources/") //For production
71 viper.AddConfigPath("../resources/") //For test under Docker
72 viper.AddConfigPath("../../resources/") //For test under Docker
73 err := viper.ReadInConfig()
75 panic(fmt.Sprintf("#configuration.ParseConfiguration - failed to read configuration file: %s\n", err))
78 config := Configuration{}
79 config.populateRmrConfig(viper.Sub("rmr"))
80 config.populateHttpConfig(viper.Sub("http"))
81 config.populateLoggingConfig(viper.Sub("logging"))
82 config.populateRoutingManagerConfig(viper.Sub("routingManager"))
83 config.NotificationResponseBuffer = viper.GetInt("notificationResponseBuffer")
84 config.BigRedButtonTimeoutSec = viper.GetInt("bigRedButtonTimeoutSec")
85 config.MaxRnibConnectionAttempts = viper.GetInt("maxRnibConnectionAttempts")
86 config.RnibRetryIntervalMs = viper.GetInt("rnibRetryIntervalMs")
87 config.KeepAliveResponseTimeoutMs = viper.GetInt("keepAliveResponseTimeoutMs")
88 config.KeepAliveDelayMs = viper.GetInt("KeepAliveDelayMs")
89 config.E2TInstanceDeletionTimeoutMs = viper.GetInt("e2tInstanceDeletionTimeoutMs")
90 //E2ResetTimeOutSec : timeout expiry threshold required for handling reset and thus the time for which the nodeb is under reset connection state.
91 config.E2ResetTimeOutSec = viper.GetInt("e2ResetTimeOutSec")
92 config.populateGlobalRicIdConfig(viper.Sub("globalRicId"))
93 config.populateRnibWriterConfig(viper.Sub("rnibWriter"))
97 func (c *Configuration) populateLoggingConfig(logConfig *viper.Viper) {
99 panic(fmt.Sprintf("#configuration.populateLoggingConfig - failed to populate logging configuration: The entry 'logging' not found\n"))
101 c.Logging.LogLevel = logConfig.GetString("logLevel")
104 func (c *Configuration) populateHttpConfig(httpConfig *viper.Viper) {
105 if httpConfig == nil {
106 panic(fmt.Sprintf("#configuration.populateHttpConfig - failed to populate HTTP configuration: The entry 'http' not found\n"))
108 c.Http.Port = httpConfig.GetInt("port")
111 func (c *Configuration) populateRmrConfig(rmrConfig *viper.Viper) {
112 if rmrConfig == nil {
113 panic(fmt.Sprintf("#configuration.populateRmrConfig - failed to populate RMR configuration: The entry 'rmr' not found\n"))
115 c.Rmr.Port = rmrConfig.GetInt("port")
116 c.Rmr.MaxMsgSize = rmrConfig.GetInt("maxMsgSize")
119 func (c *Configuration) populateRoutingManagerConfig(rmConfig *viper.Viper) {
121 panic(fmt.Sprintf("#configuration.populateRoutingManagerConfig - failed to populate Routing Manager configuration: The entry 'routingManager' not found\n"))
123 c.RoutingManager.BaseUrl = rmConfig.GetString("baseUrl")
126 func (c *Configuration) populateRnibWriterConfig(rnibWriterConfig *viper.Viper) {
127 if rnibWriterConfig == nil {
128 panic(fmt.Sprintf("#configuration.populateRnibWriterConfig - failed to populate Rnib Writer configuration: The entry 'rnibWriter' not found\n"))
130 c.RnibWriter.StateChangeMessageChannel = rnibWriterConfig.GetString("stateChangeMessageChannel")
131 c.RnibWriter.RanManipulationMessageChannel = rnibWriterConfig.GetString("ranManipulationMessageChannel")
134 func (c *Configuration) populateGlobalRicIdConfig(globalRicIdConfig *viper.Viper) {
135 err := validateGlobalRicIdConfig(globalRicIdConfig)
139 c.GlobalRicId.RicId = globalRicIdConfig.GetString("ricId")
140 c.GlobalRicId.Mcc = globalRicIdConfig.GetString("mcc")
141 c.GlobalRicId.Mnc = globalRicIdConfig.GetString("mnc")
144 func validateGlobalRicIdConfig(globalRicIdConfig *viper.Viper) error {
145 if globalRicIdConfig == nil {
146 return errors.New("#configuration.validateGlobalRicIdConfig - failed to populate Global RicId configuration: The entry 'globalRicId' not found\n")
149 err := validateRicId(globalRicIdConfig.GetString("ricId"))
155 err = validateMcc(globalRicIdConfig.GetString("mcc"))
161 err = validateMnc(globalRicIdConfig.GetString("mnc"))
170 func validateMcc(mcc string) error {
173 return errors.New("#configuration.validateMcc - mcc is missing or empty\n")
177 return errors.New("#configuration.validateMcc - mcc is not 3 digits\n")
180 mccInt, err := strconv.Atoi(mcc)
183 return errors.New("#configuration.validateMcc - mcc is not a number\n")
187 return errors.New("#configuration.validateMcc - mcc is negative\n")
192 func validateMnc(mnc string) error {
195 return errors.New("#configuration.validateMnc - mnc is missing or empty\n")
198 if len(mnc) < 2 || len(mnc) > 3 {
199 return errors.New("#configuration.validateMnc - mnc is not 2 or 3 digits\n")
202 mncAsInt, err := strconv.Atoi(mnc)
205 return errors.New("#configuration.validateMnc - mnc is not a number\n")
209 return errors.New("#configuration.validateMnc - mnc is negative\n")
215 func validateRicId(ricId string) error {
218 return errors.New("#configuration.validateRicId - ricId is missing or empty\n")
222 return errors.New("#configuration.validateRicId - ricId length should be 5 hex characters\n")
225 _, err := strconv.ParseUint(ricId, 16, 64)
227 return errors.New("#configuration.validateRicId - ricId is not hex number\n")
233 func (c *Configuration) String() string {
234 return fmt.Sprintf("{logging.logLevel: %s, http.port: %d, rmr: { port: %d, maxMsgSize: %d}, routingManager.baseUrl: %s, "+
235 "notificationResponseBuffer: %d, bigRedButtonTimeoutSec: %d, maxRnibConnectionAttempts: %d, "+
236 "rnibRetryIntervalMs: %d, keepAliveResponseTimeoutMs: %d, keepAliveDelayMs: %d, e2tInstanceDeletionTimeoutMs: %d,e2ResetTimeOutSec: %d,"+
237 "globalRicId: { ricId: %s, mcc: %s, mnc: %s}, rnibWriter: { stateChangeMessageChannel: %s, ranManipulationChannel: %s}",
242 c.RoutingManager.BaseUrl,
243 c.NotificationResponseBuffer,
244 c.BigRedButtonTimeoutSec,
245 c.MaxRnibConnectionAttempts,
246 c.RnibRetryIntervalMs,
247 c.KeepAliveResponseTimeoutMs,
249 c.E2TInstanceDeletionTimeoutMs,
254 c.RnibWriter.StateChangeMessageChannel,
255 c.RnibWriter.RanManipulationMessageChannel,