blob: 3cc0e010f8ad3a791bd9affa69f5dcaf12755482 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
2 * Copyright 2015-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.xran.impl;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.node.ObjectNode;
21import com.google.common.collect.Lists;
slowr67d05e42017-08-11 20:37:22 -070022import org.apache.commons.lang.exception.ExceptionUtils;
slowr13fa5b02017-08-08 16:32:31 -070023import org.apache.felix.scr.annotations.*;
24import org.onosproject.core.ApplicationId;
25import org.onosproject.core.CoreService;
26import org.onosproject.store.AbstractStore;
27import org.onosproject.xran.XranStore;
28import org.onosproject.xran.codecs.api.ECGI;
29import org.onosproject.xran.codecs.api.EUTRANCellIdentifier;
30import org.onosproject.xran.codecs.api.MMEUES1APID;
31import org.onosproject.xran.controller.XranController;
32import org.onosproject.xran.entities.RnibCell;
33import org.onosproject.xran.entities.RnibLink;
34import org.onosproject.xran.entities.RnibSlice;
35import org.onosproject.xran.entities.RnibUe;
36import org.onosproject.xran.identifiers.LinkId;
37import org.slf4j.Logger;
38
39import javax.xml.bind.DatatypeConverter;
40import java.util.List;
41import java.util.Optional;
42import java.util.concurrent.ConcurrentHashMap;
43import java.util.concurrent.ConcurrentMap;
44import java.util.stream.Collectors;
45
46import static org.slf4j.LoggerFactory.getLogger;
47
48/**
49 * Created by dimitris on 7/22/17.
50 */
51@Component(immediate = true)
52@Service
53public class DefaultXranStore extends AbstractStore implements XranStore {
54 private static final String XRAN_APP_ID = "org.onosproject.xran";
55
56 private final Logger log = getLogger(getClass());
57 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 protected CoreService coreService;
59 private ConcurrentMap<LinkId, RnibLink> linkMap = new ConcurrentHashMap<>();
60 private ConcurrentMap<ECGI, RnibCell> cellMap = new ConcurrentHashMap<>();
61 private ConcurrentMap<MMEUES1APID, RnibUe> ueMap = new ConcurrentHashMap<>();
62 private ConcurrentMap<Object, RnibSlice> sliceMap = new ConcurrentHashMap<>();
63 private XranController controller;
64
65 @Activate
66 public void activate() {
67 ApplicationId appId = coreService.getAppId(XRAN_APP_ID);
68 log.info("XRAN Default Store Started");
69 }
70
71 @Deactivate
72 public void deactive() {
73 log.info("XRAN Default Store Stopped");
74 }
75
76 @Override
77 public List<RnibLink> getLinks() {
78 List<RnibLink> list = Lists.newArrayList();
79 list.addAll(linkMap.values());
80 return list;
81 }
82
83 @Override
84 public List<RnibLink> getLinksByECGI(ECGI ecgi) {
85 List<RnibLink> list = Lists.newArrayList();
86 list.addAll(
87 linkMap.keySet()
88 .stream()
slowr8ddc2b12017-08-14 14:13:38 -070089 .filter(k -> k.getEcgi().equals(ecgi))
slowr13fa5b02017-08-08 16:32:31 -070090 .map(v -> linkMap.get(v))
91 .collect(Collectors.toList()));
92
93 return list;
94 }
95
96 @Override
97 public List<RnibLink> getLinksByCellId(String eciHex) {
98 List<RnibLink> list = Lists.newArrayList();
99 EUTRANCellIdentifier eci = hexToECI(eciHex);
100
101 list.addAll(
102 linkMap.keySet()
103 .stream()
slowr8ddc2b12017-08-14 14:13:38 -0700104 .filter(k -> k.getEcgi().getEUTRANcellIdentifier().equals(eci))
slowr13fa5b02017-08-08 16:32:31 -0700105 .map(v -> linkMap.get(v))
106 .collect(Collectors.toList()));
107
108 return list;
109 }
110
111 @Override
112 public List<RnibLink> getLinksByUeId(long euId) {
113 List<RnibLink> list = Lists.newArrayList();
114 MMEUES1APID mme = new MMEUES1APID(euId);
115
116 list.addAll(
117 linkMap.keySet()
118 .stream()
slowr8ddc2b12017-08-14 14:13:38 -0700119 .filter(k -> k.getMmeues1apid().equals(mme))
slowr13fa5b02017-08-08 16:32:31 -0700120 .map(v -> linkMap.get(v))
121 .collect(Collectors.toList()));
122
123 return list;
124 }
125
126 @Override
127 public RnibLink getLinkBetweenCellIdUeId(String eciHex, long euId) {
128 EUTRANCellIdentifier eci = hexToECI(eciHex);
129 MMEUES1APID mme = new MMEUES1APID(euId);
130
131 Optional<LinkId> first = linkMap.keySet()
132 .stream()
slowr8ddc2b12017-08-14 14:13:38 -0700133 .filter(linkId -> linkId.getEcgi().getEUTRANcellIdentifier().equals(eci))
134 .filter(linkId -> linkId.getMmeues1apid().equals(mme))
slowr13fa5b02017-08-08 16:32:31 -0700135 .findFirst();
136
137 return first.map(linkId -> linkMap.get(linkId)).orElse(null);
138 }
139
140 @Override
141 public boolean createLinkBetweenCellIdUeId(String eciHex, long euId, String type) {
142 RnibCell cell = getCell(eciHex);
143 RnibUe ue = getUe(euId);
144
145 if (cell != null && ue != null) {
slowr67d05e42017-08-11 20:37:22 -0700146 RnibLink link = new RnibLink(cell, ue);
slowr13fa5b02017-08-08 16:32:31 -0700147
slowr8ddc2b12017-08-14 14:13:38 -0700148 // TODO: check logic for each type
slowr67d05e42017-08-11 20:37:22 -0700149 try {
slowr8ddc2b12017-08-14 14:13:38 -0700150 RnibLink.Type linkType = RnibLink.Type.valueOf(type);
151 switch (linkType) {
152 case NON_SERVING:
153 break;
154 case SERVING_PRIMARY:
155 break;
156 case SERVING_SECONDARY:
157 break;
158 }
slowr67d05e42017-08-11 20:37:22 -0700159 } catch (Exception e) {
160 log.error(ExceptionUtils.getFullStackTrace(e));
161 }
slowr13fa5b02017-08-08 16:32:31 -0700162 linkMap.put(link.getLinkId(), link);
163 return true;
164 }
165
166 return false;
167 }
168
169 @Override
170 public void storeLink(RnibLink link) {
171 if (link.getLinkId() != null) {
172 linkMap.put(link.getLinkId(), link);
173 }
174 }
175
176 @Override
177 public boolean removeLink(LinkId link) {
178 return linkMap.remove(link) != null;
179 }
180
181 @Override
182 public RnibLink getLink(ECGI ecgi, MMEUES1APID mme) {
slowr67d05e42017-08-11 20:37:22 -0700183
184 LinkId linkId = LinkId.valueOf(ecgi, mme);
slowr13fa5b02017-08-08 16:32:31 -0700185 return linkMap.get(linkId);
186 }
187
188 @Override
slowr8ddc2b12017-08-14 14:13:38 -0700189 public void modifyLinkRrmConf(RnibLink link, JsonNode rrmConf) {
190 link.modifyRrmParameters(rrmConf);
191 }
192
193 @Override
slowr13fa5b02017-08-08 16:32:31 -0700194 public List<Object> getNodes() {
195 List<Object> list = Lists.newArrayList();
196 list.add(cellMap.values());
197 list.add(ueMap.values());
198 return list;
199 }
200
201 @Override
202 public List<RnibCell> getCellNodes() {
203 List<RnibCell> list = Lists.newArrayList();
204 list.addAll(cellMap.values());
205 return list;
206 }
207
208 @Override
209 public List<RnibUe> getUeNodes() {
210 List<RnibUe> list = Lists.newArrayList();
211 list.addAll(ueMap.values());
212 return list;
213 }
214
215 @Override
216 public Object getByNodeId(String nodeId) {
217 try {
218 return getCell(nodeId);
219 } catch (Exception e) {
220
221 }
222 return getUe(Long.parseLong(nodeId));
223 }
224
225 @Override
226 public void storeCell(RnibCell cell) {
227 if (cell.getEcgi() != null) {
228 cellMap.putIfAbsent(cell.getEcgi(), cell);
229 }
230 }
231
232 @Override
233 public boolean removeCell(ECGI ecgi) {
234 return cellMap.remove(ecgi) != null;
235 }
236
237 @Override
238 public RnibCell getCell(String hexeci) {
239 EUTRANCellIdentifier eci = hexToECI(hexeci);
240 Optional<ECGI> first = cellMap.keySet().stream().filter(ecgi -> ecgi.getEUTRANcellIdentifier().equals(eci)).findFirst();
241 return first.map(ecgi -> cellMap.get(ecgi)).orElse(null);
242 }
243
244 @Override
245 public RnibCell getCell(ECGI ecgi) {
246 return cellMap.get(ecgi);
247 }
248
249 @Override
slowr8ddc2b12017-08-14 14:13:38 -0700250 public void modifyCellRrmConf(RnibCell cell, JsonNode rrmConf) {
slowr67d05e42017-08-11 20:37:22 -0700251 List<RnibLink> linkList = getLinksByECGI(cell.getEcgi());
252 List<RnibUe> ueList = linkList.stream().map(link -> link.getLinkId().getUe()).collect(Collectors.toList());
253
254 cell.modifyRrmConfig(rrmConf, ueList);
slowr13fa5b02017-08-08 16:32:31 -0700255 }
256
257 @Override
258 public RnibSlice getSlice(long sliceId) {
259 if (sliceMap.containsKey(sliceId)) {
260 return sliceMap.get(sliceId);
261 }
262 return null;
263 }
264
265 @Override
266 public boolean createSlice(ObjectNode attributes) {
267 return false;
268 }
269
270 @Override
271 public boolean removeCell(long sliceId) {
272 return sliceMap.remove(sliceId) != null;
273 }
274
275 @Override
276 public XranController getController() {
277 return controller;
278 }
279
280 @Override
281 public void setController(XranController controller) {
282 this.controller = controller;
283 }
284
285 @Override
286 public void storeUe(RnibUe ue) {
287 if (ue.getMmeS1apId() != null) {
288 ueMap.putIfAbsent(ue.getMmeS1apId(), ue);
289 }
290 }
291
292 @Override
293 public boolean removeUe(MMEUES1APID mme) {
294 return ueMap.remove(mme) != null;
295 }
296
297 @Override
298 public RnibUe getUe(long euId) {
299 MMEUES1APID mme = new MMEUES1APID(euId);
300 return ueMap.get(mme);
301 }
302
303 @Override
304 public RnibUe getUe(MMEUES1APID mme) {
305 return ueMap.get(mme);
306 }
307
308 private EUTRANCellIdentifier hexToECI(String eciHex) {
309 byte[] hexBinary = DatatypeConverter.parseHexBinary(eciHex);
310 return new EUTRANCellIdentifier(hexBinary, 28);
311 }
312}