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/rtmgr"
38 "routing-manager/pkg/models"
42 Reads the content of the rt.json file
43 Parses the JSON content and loads each xApp entry into an xApp object
44 Returns an array os xApp object
51 func NewFile() *File {
56 func (f *File) ReadAll(file string) (*rtmgr.RicComponents, error) {
57 xapp.Logger.Debug("Invoked sdl.ReadAll(" + file + ")")
58 var rcs *rtmgr.RicComponents
59 jsonFile, err := os.Open(file)
61 return nil, errors.New("cannot open the file due to: " + err.Error())
63 defer jsonFile.Close()
64 byteValue, err := ioutil.ReadAll(jsonFile)
66 return nil, errors.New("cannot read the file due to: " + err.Error())
69 err = json.Unmarshal(byteValue, &rcs)
71 return nil, errors.New("cannot parse data due to: " + err.Error())
73 xapp.Logger.Debug("file.fileReadAll returns: %v", rcs)
77 func (f *File) WriteAll(file string, rcs *rtmgr.RicComponents) error {
78 xapp.Logger.Debug("Invoked sdl.WriteAll")
79 xapp.Logger.Debug("file.fileWriteAll writes into file: " + file)
80 xapp.Logger.Debug("file.fileWriteAll writes data: %v", *rcs)
81 byteValue, err := json.Marshal(rcs)
83 return errors.New("cannot convert data due to: " + err.Error())
85 err = ioutil.WriteFile(file, byteValue, 0644)
87 return errors.New("cannot write file due to: " + err.Error())
92 func (f *File) WriteXApps(file string, xApps *[]rtmgr.XApp) error {
93 xapp.Logger.Debug("Invoked sdl.WriteXApps")
94 xapp.Logger.Debug("file.fileWriteXApps writes into file: " + file)
95 xapp.Logger.Debug("file.fileWriteXApps writes data: %v", *xApps)
97 ricData, err := NewFile().ReadAll(file)
99 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
100 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
102 ricData.XApps = *xApps
104 byteValue, err := json.Marshal(ricData)
106 return errors.New("cannot convert data due to: " + err.Error())
108 err = ioutil.WriteFile(file, byteValue, 0644)
110 return errors.New("cannot write file due to: " + err.Error())
115 func (f *File) WriteNewE2TInstance(file string, E2TInst *rtmgr.E2TInstance) error {
116 xapp.Logger.Debug("Invoked sdl.WriteNewE2TInstance")
117 xapp.Logger.Debug("file.WriteNewE2TInstance writes into file: " + file)
118 xapp.Logger.Debug("file.WriteNewE2TInstance writes data: %v", *E2TInst)
120 ricData, err := NewFile().ReadAll(file)
122 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
123 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
125 ricData.E2Ts[E2TInst.Fqdn] = *E2TInst
127 byteValue, err := json.Marshal(ricData)
129 return errors.New("cannot convert data due to: " + err.Error())
131 err = ioutil.WriteFile(file, byteValue, 0644)
133 return errors.New("cannot write file due to: " + err.Error())
138 func (f *File) WriteAssRANToE2TInstance(file string, rane2tmap models.RanE2tMap) error {
139 xapp.Logger.Debug("Invoked sdl.WriteAssRANToE2TInstance")
140 xapp.Logger.Debug("file.WriteAssRANToE2TInstance writes into file: " + file)
141 xapp.Logger.Debug("file.WriteAssRANToE2TInstance writes data: %v", rane2tmap)
143 ricData, err := NewFile().ReadAll(file)
145 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
146 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
148 for _, element := range rane2tmap {
149 xapp.Logger.Info("data received")
150 for key, _ := range ricData.E2Ts {
151 if key == *element.E2TAddress {
152 var estObj rtmgr.E2TInstance
153 estObj = ricData.E2Ts[key]
154 estObj.Ranlist = append(ricData.E2Ts[key].Ranlist, element.RanNamelist...)
155 ricData.E2Ts[key]= estObj
160 byteValue, err := json.Marshal(ricData)
162 return errors.New("cannot convert data due to: " + err.Error())
164 err = ioutil.WriteFile(file, byteValue, 0644)
166 return errors.New("cannot write file due to: " + err.Error())
171 func (f *File) WriteDisAssRANFromE2TInstance(file string, disassranmap models.RanE2tMap) error {
172 xapp.Logger.Debug("Invoked sdl.WriteDisAssRANFromE2TInstance")
173 xapp.Logger.Debug("file.WriteDisAssRANFromE2TInstance writes into file: " + file)
174 xapp.Logger.Debug("file.WriteDisAssRANFromE2TInstance writes data: %v", disassranmap)
176 ricData, err := NewFile().ReadAll(file)
178 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
179 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
181 for _, element := range disassranmap {
182 xapp.Logger.Info("data received")
183 e2taddress_key := *element.E2TAddress
184 //Check whether the provided E2T Address is available in SDL as a key.
185 //If exist, proceed further to check RAN list, Otherwise move to next E2T Instance
186 if _, exist := ricData.E2Ts[e2taddress_key]; exist {
187 var estObj rtmgr.E2TInstance
188 estObj = ricData.E2Ts[e2taddress_key]
189 // If RAN list is empty, then routing manager assumes that all RANs attached associated to the particular E2T Instance to be removed.
190 if len(element.RanNamelist) == 0 {
191 xapp.Logger.Debug("RAN List is empty. So disassociating all RANs from the E2T Instance: %v ", *element.E2TAddress)
192 estObj.Ranlist = []string{}
194 xapp.Logger.Debug("Remove only selected rans from E2T Instance: %v and %v ", ricData.E2Ts[e2taddress_key].Ranlist, element.RanNamelist)
195 for _, disRanValue := range element.RanNamelist {
196 for ranIndex, ranValue := range ricData.E2Ts[e2taddress_key].Ranlist {
197 if disRanValue == ranValue {
198 estObj.Ranlist[ranIndex] = estObj.Ranlist[len(estObj.Ranlist)-1]
199 estObj.Ranlist[len(estObj.Ranlist)-1] = ""
200 estObj.Ranlist = estObj.Ranlist[:len(estObj.Ranlist)-1]
205 ricData.E2Ts[e2taddress_key]= estObj
209 xapp.Logger.Debug("Final data after disassociate: %v", ricData)
211 byteValue, err := json.Marshal(ricData)
213 return errors.New("cannot convert data due to: " + err.Error())
215 err = ioutil.WriteFile(file, byteValue, 0644)
217 return errors.New("cannot write file due to: " + err.Error())
222 func (f *File) WriteDeleteE2TInstance(file string, E2TInst *models.E2tDeleteData) error {
223 xapp.Logger.Debug("Invoked sdl.WriteDeleteE2TInstance")
224 xapp.Logger.Debug("file.WriteDeleteE2TInstance writes into file: " + file)
225 xapp.Logger.Debug("file.WriteDeleteE2TInstance writes data: %v", *E2TInst)
227 ricData, err := NewFile().ReadAll(file)
229 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
230 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
233 delete(ricData.E2Ts, *E2TInst.E2TAddress)
236 for _, element := range E2TInst.RanAssocList {
237 xapp.Logger.Info("data received")
238 key := *element.E2TAddress
240 if val, ok := ricData.E2Ts[key]; ok {
241 var estObj rtmgr.E2TInstance
243 estObj.Ranlist = append(ricData.E2Ts[key].Ranlist, element.RanNamelist...)
244 ricData.E2Ts[key]= estObj
246 xapp.Logger.Error("file.WriteDeleteE2TInstance E2T instance is not found for provided E2TAddress : %v", errors.New(key).Error())
251 byteValue, err := json.Marshal(ricData)
253 return errors.New("cannot convert data due to: " + err.Error())
255 err = ioutil.WriteFile(file, byteValue, 0644)
257 return errors.New("cannot write file due to: " + err.Error())