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"
38 "routing-manager/pkg/rtmgr"
39 "routing-manager/pkg/models"
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 = []string {meiddata}
130 ricData.MeidMap = []string {}
134 byteValue, err := json.Marshal(ricData)
136 return errors.New("cannot convert data due to: " + err.Error())
138 err = ioutil.WriteFile(file, byteValue, 0644)
140 return errors.New("cannot write file due to: " + err.Error())
145 func (f *File) WriteAssRANToE2TInstance(file string, rane2tmap models.RanE2tMap) error {
146 xapp.Logger.Debug("Invoked sdl.WriteAssRANToE2TInstance")
147 xapp.Logger.Debug("file.WriteAssRANToE2TInstance writes into file: " + file)
148 xapp.Logger.Debug("file.WriteAssRANToE2TInstance writes data: %v", rane2tmap)
150 ricData, err := NewFile().ReadAll(file)
152 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
153 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
156 ricData.MeidMap = []string{}
157 for _, element := range rane2tmap {
158 xapp.Logger.Info("data received")
159 var str,meidar string
160 for _, meid := range element.RanNamelist {
163 str = "mme_ar|" + *element.E2TAddress + "|" + strings.TrimSuffix(meidar," ")
164 ricData.MeidMap = append(ricData.MeidMap,str)
166 for key, _ := range ricData.E2Ts {
167 if key == *element.E2TAddress {
168 var estObj rtmgr.E2TInstance
169 estObj = ricData.E2Ts[key]
170 estObj.Ranlist = append(ricData.E2Ts[key].Ranlist, element.RanNamelist...)
171 ricData.E2Ts[key]= estObj
176 byteValue, err := json.Marshal(ricData)
178 return errors.New("cannot convert data due to: " + err.Error())
180 err = ioutil.WriteFile(file, byteValue, 0644)
182 return errors.New("cannot write file due to: " + err.Error())
187 func (f *File) WriteDisAssRANFromE2TInstance(file string, disassranmap models.RanE2tMap) error {
188 xapp.Logger.Debug("Invoked sdl.WriteDisAssRANFromE2TInstance")
189 xapp.Logger.Debug("file.WriteDisAssRANFromE2TInstance writes into file: " + file)
190 xapp.Logger.Debug("file.WriteDisAssRANFromE2TInstance writes data: %v", disassranmap)
192 ricData, err := NewFile().ReadAll(file)
194 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
195 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
198 var str,meiddel,meiddisdel string
199 ricData.MeidMap = []string{}
200 for _, element := range disassranmap {
201 xapp.Logger.Info("data received")
202 for _, meid := range element.RanNamelist {
203 meiddisdel += meid + " "
205 if ( len(element.RanNamelist) > 0 ) {
206 str = "mme_del|" + strings.TrimSuffix(meiddisdel," ")
207 ricData.MeidMap = append(ricData.MeidMap,str)
209 e2taddress_key := *element.E2TAddress
210 //Check whether the provided E2T Address is available in SDL as a key.
211 //If exist, proceed further to check RAN list, Otherwise move to next E2T Instance
212 if _, exist := ricData.E2Ts[e2taddress_key]; exist {
213 var estObj rtmgr.E2TInstance
214 estObj = ricData.E2Ts[e2taddress_key]
215 // If RAN list is empty, then routing manager assumes that all RANs attached associated to the particular E2T Instance to be removed.
216 if len(element.RanNamelist) == 0 {
217 xapp.Logger.Debug("RAN List is empty. So disassociating all RANs from the E2T Instance: %v ", *element.E2TAddress)
218 for _, meid := range estObj.Ranlist {
219 meiddel += meid + " "
221 str = "mme_del|" + strings.TrimSuffix(meiddel," ")
222 ricData.MeidMap = append(ricData.MeidMap,str)
224 estObj.Ranlist = []string{}
226 xapp.Logger.Debug("Remove only selected rans from E2T Instance: %v and %v ", ricData.E2Ts[e2taddress_key].Ranlist, element.RanNamelist)
227 for _, disRanValue := range element.RanNamelist {
228 for ranIndex, ranValue := range ricData.E2Ts[e2taddress_key].Ranlist {
229 if disRanValue == ranValue {
230 estObj.Ranlist[ranIndex] = estObj.Ranlist[len(estObj.Ranlist)-1]
231 estObj.Ranlist[len(estObj.Ranlist)-1] = ""
232 estObj.Ranlist = estObj.Ranlist[:len(estObj.Ranlist)-1]
237 ricData.E2Ts[e2taddress_key]= estObj
241 xapp.Logger.Debug("Final data after disassociate: %v", ricData)
243 byteValue, err := json.Marshal(ricData)
245 return errors.New("cannot convert data due to: " + err.Error())
247 err = ioutil.WriteFile(file, byteValue, 0644)
249 return errors.New("cannot write file due to: " + err.Error())
254 func (f *File) WriteDeleteE2TInstance(file string, E2TInst *models.E2tDeleteData) error {
255 xapp.Logger.Debug("Invoked sdl.WriteDeleteE2TInstance")
256 xapp.Logger.Debug("file.WriteDeleteE2TInstance writes into file: " + file)
257 xapp.Logger.Debug("file.WriteDeleteE2TInstance writes data: %v", *E2TInst)
259 ricData, err := NewFile().ReadAll(file)
261 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
262 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
266 ricData.MeidMap = []string {}
267 var delrow,meiddel string
268 if(len(E2TInst.RanNamelistTobeDissociated)>0) {
269 for _, meid := range E2TInst.RanNamelistTobeDissociated {
270 meiddel += meid + " "
272 delrow = "mme_del|" + strings.TrimSuffix(meiddel," ")
273 ricData.MeidMap = append(ricData.MeidMap,delrow)
275 if(len(ricData.E2Ts[*E2TInst.E2TAddress].Ranlist) > 0) {
276 for _, meid := range ricData.E2Ts[*E2TInst.E2TAddress].Ranlist {
277 meiddel += meid + " "
279 delrow = "mme_del|" + strings.TrimSuffix(meiddel," ")
280 ricData.MeidMap = append(ricData.MeidMap,delrow)
284 delete(ricData.E2Ts, *E2TInst.E2TAddress)
286 for _, element := range E2TInst.RanAssocList {
287 var str,meidar string
288 xapp.Logger.Info("data received")
289 for _, meid := range element.RanNamelist {
292 str = "mme_ar|" + *element.E2TAddress + "|" + strings.TrimSuffix(meidar," ")
293 ricData.MeidMap = append(ricData.MeidMap,str)
294 key := *element.E2TAddress
296 if val, ok := ricData.E2Ts[key]; ok {
297 var estObj rtmgr.E2TInstance
299 estObj.Ranlist = append(ricData.E2Ts[key].Ranlist, element.RanNamelist...)
300 ricData.E2Ts[key]= estObj
302 xapp.Logger.Error("file.WriteDeleteE2TInstance E2T instance is not found for provided E2TAddress : %v", errors.New(key).Error())
307 byteValue, err := json.Marshal(ricData)
309 return errors.New("cannot convert data due to: " + err.Error())
311 err = ioutil.WriteFile(file, byteValue, 0644)
313 return errors.New("cannot write file due to: " + err.Error())