2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
18 This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 platform project (RICP).
21 ==================================================================================
25 Abstract: File SDL implementation. Only for testing purpose.
34 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
37 "routing-manager/pkg/models"
38 "routing-manager/pkg/rtmgr"
43 Reads the content of the rt.json file
44 Parses the JSON content and loads each xApp entry into an xApp object
45 Returns an array os xApp object
52 func NewFile() *File {
57 func (f *File) ReadAll(file string) (*rtmgr.RicComponents, error) {
58 xapp.Logger.Debug("Invoked sdl.ReadAll(" + file + ")")
59 var rcs *rtmgr.RicComponents
60 jsonFile, err := os.Open(file)
62 return nil, errors.New("Cannot open the file due to: " + err.Error())
64 defer jsonFile.Close()
65 byteValue, err := ioutil.ReadAll(jsonFile)
67 return nil, errors.New("cannot read the file due to: " + err.Error())
70 err = json.Unmarshal(byteValue, &rcs)
72 return nil, errors.New("cannot parse data due to: " + err.Error())
74 xapp.Logger.Debug("file.fileReadAll returns: %v", rcs)
78 func (f *File) WriteAll(file string, rcs *rtmgr.RicComponents) error {
79 xapp.Logger.Debug("Invoked sdl.WriteAll:" + file + ", file.fileWriteAll writes data: %v", *rcs )
80 byteValue, err := json.Marshal(rcs)
82 return errors.New("Cannot convert data due to: " + err.Error())
84 err = ioutil.WriteFile(file, byteValue, 0644)
86 return errors.New("cannot write file due to: " + err.Error())
91 func (f *File) WriteXApps(file string, xApps *[]rtmgr.XApp) error {
92 xapp.Logger.Debug("Invoked sdl.WriteXApps: " + file + ", file.fileWriteXApps writes data: %v", *xApps )
94 ricData, err := NewFile().ReadAll(file)
96 xapp.Logger.Error("Cannot get data from sdl interface due to: " + err.Error())
97 return errors.New("Cannot read full ric data to modify xApps data, due to: " + err.Error())
99 ricData.XApps = *xApps
101 byteValue, err := json.Marshal(ricData)
103 return errors.New("cannot convert data due to: " + err.Error())
105 err = ioutil.WriteFile(file, byteValue, 0644)
107 return errors.New("cannot write file due to: " + err.Error())
112 func (f *File) WriteNewE2TInstance(file string, E2TInst *rtmgr.E2TInstance, meiddata string) error {
113 xapp.Logger.Debug("Invoked sdl.WriteNewE2TInstance: " + file + ", file.WriteNewE2TInstance writes data: %v", *E2TInst )
115 ricData, err := NewFile().ReadAll(file)
117 xapp.Logger.Error("Cannot get data from sdl interface due to: " + err.Error())
118 return errors.New("cannot read full ric data to modify xApps data due to: " + err.Error())
120 ricData.E2Ts[E2TInst.Fqdn] = *E2TInst
121 if len(meiddata) > 0 {
122 ricData.MeidMap = append(ricData.MeidMap, meiddata)
125 ricData.MeidMap = []string {meiddata}
128 ricData.MeidMap = []string {}
131 byteValue, err := json.Marshal(ricData)
133 return errors.New("cannot convert data due to: " + err.Error())
135 err = ioutil.WriteFile(file, byteValue, 0644)
137 return errors.New("cannot write file due to: " + err.Error())
142 func (f *File) WriteAssRANToE2TInstance(file string, rane2tmap models.RanE2tMap) error {
143 xapp.Logger.Debug("Invoked sdl.WriteAssRANToE2TInstance: " + file + ", file.WriteAssRANToE2TInstance writes data: %v", rane2tmap)
145 ricData, err := NewFile().ReadAll(file)
147 xapp.Logger.Error("Cannot get data from sdl interface due to: " + err.Error())
148 return errors.New("cannot read full ric data to modify xApps data due to: " + err.Error())
151 //ricData.MeidMap = []string{}
152 for _, element := range rane2tmap {
153 xapp.Logger.Info("Data received")
154 var str, meidar string
155 for _, meid := range element.RanNamelist {
158 str = "mme_ar|" + *element.E2TAddress + "|" + strings.TrimSuffix(meidar, " ")
159 ricData.MeidMap = append(ricData.MeidMap, str)
161 for key, _ := range ricData.E2Ts {
162 if key == *element.E2TAddress {
163 var estObj rtmgr.E2TInstance
164 estObj = ricData.E2Ts[key]
165 estObj.Ranlist = append(ricData.E2Ts[key].Ranlist, element.RanNamelist...)
166 ricData.E2Ts[key] = estObj
171 byteValue, err := json.Marshal(ricData)
173 return errors.New("cannot convert data due to: " + err.Error())
175 err = ioutil.WriteFile(file, byteValue, 0644)
177 return errors.New("cannot write file due to: " + err.Error())
182 func (f *File) WriteDisAssRANFromE2TInstance(file string, disassranmap models.RanE2tMap) error {
183 xapp.Logger.Debug("Invoked sdl.WriteDisAssRANFromE2TInstance: " + file + ",file.WriteDisAssRANFromE2TInstance writes data: %v", disassranmap)
185 ricData, err := NewFile().ReadAll(file)
187 xapp.Logger.Error("Cannot get data from sdl interface due to: " + err.Error())
188 return errors.New("cannot read full ric data to modify xApps data due to: " + err.Error())
191 var str, meiddel, meiddisdel string
192 //ricData.MeidMap = []string{}
193 for _, element := range disassranmap {
194 xapp.Logger.Info("Data received")
195 for _, meid := range element.RanNamelist {
196 meiddisdel += meid + " "
198 if len(element.RanNamelist) > 0 {
199 str = "mme_del|" + strings.TrimSuffix(meiddisdel, " ")
200 ricData.MeidMap = append(ricData.MeidMap, str)
202 e2taddress_key := *element.E2TAddress
203 //Check whether the provided E2T Address is available in SDL as a key.
204 //If exist, proceed further to check RAN list, Otherwise move to next E2T Instance
205 if _, exist := ricData.E2Ts[e2taddress_key]; exist {
206 var estObj rtmgr.E2TInstance
207 estObj = ricData.E2Ts[e2taddress_key]
208 // If RAN list is empty, then routing manager assumes that all RANs attached associated to the particular E2T Instance to be removed.
209 if len(element.RanNamelist) == 0 {
210 xapp.Logger.Debug("RAN List is empty. So disassociating all RANs from the E2T Instance: %v ", *element.E2TAddress)
211 for _, meid := range estObj.Ranlist {
212 meiddel += meid + " "
214 str = "mme_del|" + strings.TrimSuffix(meiddel, " ")
215 ricData.MeidMap = append(ricData.MeidMap, str)
217 estObj.Ranlist = []string{}
219 xapp.Logger.Debug("Remove only selected rans from E2T Instance: %v and %v ", ricData.E2Ts[e2taddress_key].Ranlist, element.RanNamelist)
220 for _, disRanValue := range element.RanNamelist {
221 for ranIndex, ranValue := range ricData.E2Ts[e2taddress_key].Ranlist {
222 if disRanValue == ranValue {
223 estObj.Ranlist[ranIndex] = estObj.Ranlist[len(estObj.Ranlist)-1]
224 estObj.Ranlist[len(estObj.Ranlist)-1] = ""
225 estObj.Ranlist = estObj.Ranlist[:len(estObj.Ranlist)-1]
230 ricData.E2Ts[e2taddress_key] = estObj
234 xapp.Logger.Debug("Final data after disassociate: %v", ricData)
236 byteValue, err := json.Marshal(ricData)
238 return errors.New("cannot convert data due to: " + err.Error())
240 err = ioutil.WriteFile(file, byteValue, 0644)
242 return errors.New("cannot write file due to: " + err.Error())
247 func (f *File) WriteDeleteE2TInstance(file string, E2TInst *models.E2tDeleteData) error {
248 xapp.Logger.Debug("Invoked sdl.WriteDeleteE2TInstance: " + file + ",file.WriteDeleteE2TInstance writes data: %v", *E2TInst)
250 ricData, err := NewFile().ReadAll(file)
252 xapp.Logger.Error("Cannot get data from sdl interface due to: " + err.Error())
253 return errors.New("cannot read full ric data to modify xApps data due to: " + err.Error())
256 //ricData.MeidMap = []string{}
257 var delrow, meiddel string
258 if len(E2TInst.RanNamelistTobeDissociated) > 0 {
259 for _, meid := range E2TInst.RanNamelistTobeDissociated {
260 meiddel += meid + " "
262 delrow = "mme_del|" + strings.TrimSuffix(meiddel, " ")
263 ricData.MeidMap = append(ricData.MeidMap, delrow)
265 if len(ricData.E2Ts[*E2TInst.E2TAddress].Ranlist) > 0 {
266 for _, meid := range ricData.E2Ts[*E2TInst.E2TAddress].Ranlist {
267 meiddel += meid + " "
269 delrow = "mme_del|" + strings.TrimSuffix(meiddel, " ")
270 ricData.MeidMap = append(ricData.MeidMap, delrow)
274 delete(ricData.E2Ts, *E2TInst.E2TAddress)
276 for _, element := range E2TInst.RanAssocList {
277 var str, meidar string
278 xapp.Logger.Info("Data received")
279 for _, meid := range element.RanNamelist {
282 str = "mme_ar|" + *element.E2TAddress + "|" + strings.TrimSuffix(meidar, " ")
283 ricData.MeidMap = append(ricData.MeidMap, str)
284 key := *element.E2TAddress
286 if val, ok := ricData.E2Ts[key]; ok {
287 var estObj rtmgr.E2TInstance
289 estObj.Ranlist = append(ricData.E2Ts[key].Ranlist, element.RanNamelist...)
290 ricData.E2Ts[key] = estObj
292 xapp.Logger.Error("file.WriteDeleteE2TInstance E2T instance is not found for provided E2TAddress : %v", errors.New(key).Error())
297 byteValue, err := json.Marshal(ricData)
299 return errors.New("cannot convert data due to: " + err.Error())
301 err = ioutil.WriteFile(file, byteValue, 0644)
303 return errors.New("cannot write file due to: " + err.Error())