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")
80 xapp.Logger.Debug("file.fileWriteAll writes into file: " + file)
81 xapp.Logger.Debug("file.fileWriteAll writes data: %v", *rcs)
82 byteValue, err := json.Marshal(rcs)
84 return errors.New("cannot convert data due to: " + err.Error())
86 err = ioutil.WriteFile(file, byteValue, 0644)
88 return errors.New("cannot write file due to: " + err.Error())
93 func (f *File) WriteXApps(file string, xApps *[]rtmgr.XApp) error {
94 xapp.Logger.Debug("Invoked sdl.WriteXApps")
95 xapp.Logger.Debug("file.fileWriteXApps writes into file: " + file)
96 xapp.Logger.Debug("file.fileWriteXApps writes data: %v", *xApps)
98 ricData, err := NewFile().ReadAll(file)
100 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
101 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
103 ricData.XApps = *xApps
105 byteValue, err := json.Marshal(ricData)
107 return errors.New("cannot convert data due to: " + err.Error())
109 err = ioutil.WriteFile(file, byteValue, 0644)
111 return errors.New("cannot write file due to: " + err.Error())
116 func (f *File) WriteNewE2TInstance(file string, E2TInst *rtmgr.E2TInstance, meiddata string) error {
117 xapp.Logger.Debug("Invoked sdl.WriteNewE2TInstance")
118 xapp.Logger.Debug("file.WriteNewE2TInstance writes into file: " + file)
119 xapp.Logger.Debug("file.WriteNewE2TInstance writes data: %v", *E2TInst)
121 ricData, err := NewFile().ReadAll(file)
123 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
124 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
126 ricData.E2Ts[E2TInst.Fqdn] = *E2TInst
127 if len(meiddata) > 0 {
128 ricData.MeidMap = append(ricData.MeidMap, meiddata)
131 ricData.MeidMap = []string {meiddata}
134 ricData.MeidMap = []string {}
137 byteValue, err := json.Marshal(ricData)
139 return errors.New("cannot convert data due to: " + err.Error())
141 err = ioutil.WriteFile(file, byteValue, 0644)
143 return errors.New("cannot write file due to: " + err.Error())
148 func (f *File) WriteAssRANToE2TInstance(file string, rane2tmap models.RanE2tMap) error {
149 xapp.Logger.Debug("Invoked sdl.WriteAssRANToE2TInstance")
150 xapp.Logger.Debug("file.WriteAssRANToE2TInstance writes into file: " + file)
151 xapp.Logger.Debug("file.WriteAssRANToE2TInstance writes data: %v", rane2tmap)
153 ricData, err := NewFile().ReadAll(file)
155 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
156 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
159 //ricData.MeidMap = []string{}
160 for _, element := range rane2tmap {
161 xapp.Logger.Info("data received")
162 var str, meidar string
163 for _, meid := range element.RanNamelist {
166 str = "mme_ar|" + *element.E2TAddress + "|" + strings.TrimSuffix(meidar, " ")
167 ricData.MeidMap = append(ricData.MeidMap, str)
169 for key, _ := range ricData.E2Ts {
170 if key == *element.E2TAddress {
171 var estObj rtmgr.E2TInstance
172 estObj = ricData.E2Ts[key]
173 estObj.Ranlist = append(ricData.E2Ts[key].Ranlist, element.RanNamelist...)
174 ricData.E2Ts[key] = estObj
179 byteValue, err := json.Marshal(ricData)
181 return errors.New("cannot convert data due to: " + err.Error())
183 err = ioutil.WriteFile(file, byteValue, 0644)
185 return errors.New("cannot write file due to: " + err.Error())
190 func (f *File) WriteDisAssRANFromE2TInstance(file string, disassranmap models.RanE2tMap) error {
191 xapp.Logger.Debug("Invoked sdl.WriteDisAssRANFromE2TInstance")
192 xapp.Logger.Debug("file.WriteDisAssRANFromE2TInstance writes into file: " + file)
193 xapp.Logger.Debug("file.WriteDisAssRANFromE2TInstance writes data: %v", disassranmap)
195 ricData, err := NewFile().ReadAll(file)
197 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
198 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
201 var str, meiddel, meiddisdel string
202 //ricData.MeidMap = []string{}
203 for _, element := range disassranmap {
204 xapp.Logger.Info("data received")
205 for _, meid := range element.RanNamelist {
206 meiddisdel += meid + " "
208 if len(element.RanNamelist) > 0 {
209 str = "mme_del|" + strings.TrimSuffix(meiddisdel, " ")
210 ricData.MeidMap = append(ricData.MeidMap, str)
212 e2taddress_key := *element.E2TAddress
213 //Check whether the provided E2T Address is available in SDL as a key.
214 //If exist, proceed further to check RAN list, Otherwise move to next E2T Instance
215 if _, exist := ricData.E2Ts[e2taddress_key]; exist {
216 var estObj rtmgr.E2TInstance
217 estObj = ricData.E2Ts[e2taddress_key]
218 // If RAN list is empty, then routing manager assumes that all RANs attached associated to the particular E2T Instance to be removed.
219 if len(element.RanNamelist) == 0 {
220 xapp.Logger.Debug("RAN List is empty. So disassociating all RANs from the E2T Instance: %v ", *element.E2TAddress)
221 for _, meid := range estObj.Ranlist {
222 meiddel += meid + " "
224 str = "mme_del|" + strings.TrimSuffix(meiddel, " ")
225 ricData.MeidMap = append(ricData.MeidMap, str)
227 estObj.Ranlist = []string{}
229 xapp.Logger.Debug("Remove only selected rans from E2T Instance: %v and %v ", ricData.E2Ts[e2taddress_key].Ranlist, element.RanNamelist)
230 for _, disRanValue := range element.RanNamelist {
231 for ranIndex, ranValue := range ricData.E2Ts[e2taddress_key].Ranlist {
232 if disRanValue == ranValue {
233 estObj.Ranlist[ranIndex] = estObj.Ranlist[len(estObj.Ranlist)-1]
234 estObj.Ranlist[len(estObj.Ranlist)-1] = ""
235 estObj.Ranlist = estObj.Ranlist[:len(estObj.Ranlist)-1]
240 ricData.E2Ts[e2taddress_key] = estObj
244 xapp.Logger.Debug("Final data after disassociate: %v", ricData)
246 byteValue, err := json.Marshal(ricData)
248 return errors.New("cannot convert data due to: " + err.Error())
250 err = ioutil.WriteFile(file, byteValue, 0644)
252 return errors.New("cannot write file due to: " + err.Error())
257 func (f *File) WriteDeleteE2TInstance(file string, E2TInst *models.E2tDeleteData) error {
258 xapp.Logger.Debug("Invoked sdl.WriteDeleteE2TInstance")
259 xapp.Logger.Debug("file.WriteDeleteE2TInstance writes into file: " + file)
260 xapp.Logger.Debug("file.WriteDeleteE2TInstance writes data: %v", *E2TInst)
262 ricData, err := NewFile().ReadAll(file)
264 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
265 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
268 //ricData.MeidMap = []string{}
269 var delrow, meiddel string
270 if len(E2TInst.RanNamelistTobeDissociated) > 0 {
271 for _, meid := range E2TInst.RanNamelistTobeDissociated {
272 meiddel += meid + " "
274 delrow = "mme_del|" + strings.TrimSuffix(meiddel, " ")
275 ricData.MeidMap = append(ricData.MeidMap, delrow)
277 if len(ricData.E2Ts[*E2TInst.E2TAddress].Ranlist) > 0 {
278 for _, meid := range ricData.E2Ts[*E2TInst.E2TAddress].Ranlist {
279 meiddel += meid + " "
281 delrow = "mme_del|" + strings.TrimSuffix(meiddel, " ")
282 ricData.MeidMap = append(ricData.MeidMap, delrow)
286 delete(ricData.E2Ts, *E2TInst.E2TAddress)
288 for _, element := range E2TInst.RanAssocList {
289 var str, meidar string
290 xapp.Logger.Info("data received")
291 for _, meid := range element.RanNamelist {
294 str = "mme_ar|" + *element.E2TAddress + "|" + strings.TrimSuffix(meidar, " ")
295 ricData.MeidMap = append(ricData.MeidMap, str)
296 key := *element.E2TAddress
298 if val, ok := ricData.E2Ts[key]; ok {
299 var estObj rtmgr.E2TInstance
301 estObj.Ranlist = append(ricData.E2Ts[key].Ranlist, element.RanNamelist...)
302 ricData.E2Ts[key] = estObj
304 xapp.Logger.Error("file.WriteDeleteE2TInstance E2T instance is not found for provided E2TAddress : %v", errors.New(key).Error())
309 byteValue, err := json.Marshal(ricData)
311 return errors.New("cannot convert data due to: " + err.Error())
313 err = ioutil.WriteFile(file, byteValue, 0644)
315 return errors.New("cannot write file due to: " + err.Error())