blob: 19e50abb91a6c6ff9937909ec82cd53f8182555a [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;
22import org.apache.felix.scr.annotations.*;
23import org.onosproject.core.ApplicationId;
24import org.onosproject.core.CoreService;
slowrc86750e2017-08-22 17:26:47 -070025import org.onosproject.core.IdGenerator;
slowr13fa5b02017-08-08 16:32:31 -070026import org.onosproject.store.AbstractStore;
27import org.onosproject.xran.XranStore;
28import org.onosproject.xran.codecs.api.ECGI;
29import org.onosproject.xran.codecs.api.EUTRANCellIdentifier;
slowr13fa5b02017-08-08 16:32:31 -070030import org.onosproject.xran.controller.XranController;
31import org.onosproject.xran.entities.RnibCell;
32import org.onosproject.xran.entities.RnibLink;
33import org.onosproject.xran.entities.RnibSlice;
34import org.onosproject.xran.entities.RnibUe;
35import org.onosproject.xran.identifiers.LinkId;
36import org.slf4j.Logger;
37
38import javax.xml.bind.DatatypeConverter;
39import java.util.List;
40import java.util.Optional;
41import java.util.concurrent.ConcurrentHashMap;
42import java.util.concurrent.ConcurrentMap;
43import java.util.stream.Collectors;
44
45import static org.slf4j.LoggerFactory.getLogger;
46
47/**
48 * Created by dimitris on 7/22/17.
49 */
50@Component(immediate = true)
51@Service
52public class DefaultXranStore extends AbstractStore implements XranStore {
53 private static final String XRAN_APP_ID = "org.onosproject.xran";
54
55 private final Logger log = getLogger(getClass());
56 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
57 protected CoreService coreService;
58 private ConcurrentMap<LinkId, RnibLink> linkMap = new ConcurrentHashMap<>();
59 private ConcurrentMap<ECGI, RnibCell> cellMap = new ConcurrentHashMap<>();
slowrc86750e2017-08-22 17:26:47 -070060 private ConcurrentMap<Long, RnibUe> ueMap = new ConcurrentHashMap<>();
slowr13fa5b02017-08-08 16:32:31 -070061 private ConcurrentMap<Object, RnibSlice> sliceMap = new ConcurrentHashMap<>();
62 private XranController controller;
63
slowrc86750e2017-08-22 17:26:47 -070064 private IdGenerator ueIdGenerator;
65
slowr13fa5b02017-08-08 16:32:31 -070066 @Activate
67 public void activate() {
68 ApplicationId appId = coreService.getAppId(XRAN_APP_ID);
slowrc86750e2017-08-22 17:26:47 -070069
70 ueIdGenerator = coreService.getIdGenerator("xran-ue-id");
71
slowr13fa5b02017-08-08 16:32:31 -070072 log.info("XRAN Default Store Started");
73 }
74
75 @Deactivate
slowrc86750e2017-08-22 17:26:47 -070076 public void deactivate() {
slowr13fa5b02017-08-08 16:32:31 -070077 log.info("XRAN Default Store Stopped");
78 }
79
80 @Override
81 public List<RnibLink> getLinks() {
82 List<RnibLink> list = Lists.newArrayList();
83 list.addAll(linkMap.values());
84 return list;
85 }
86
87 @Override
88 public List<RnibLink> getLinksByECGI(ECGI ecgi) {
89 List<RnibLink> list = Lists.newArrayList();
90 list.addAll(
91 linkMap.keySet()
92 .stream()
slowr8ddc2b12017-08-14 14:13:38 -070093 .filter(k -> k.getEcgi().equals(ecgi))
slowr13fa5b02017-08-08 16:32:31 -070094 .map(v -> linkMap.get(v))
95 .collect(Collectors.toList()));
96
97 return list;
98 }
99
100 @Override
101 public List<RnibLink> getLinksByCellId(String eciHex) {
102 List<RnibLink> list = Lists.newArrayList();
103 EUTRANCellIdentifier eci = hexToECI(eciHex);
104
105 list.addAll(
106 linkMap.keySet()
107 .stream()
slowr8ddc2b12017-08-14 14:13:38 -0700108 .filter(k -> k.getEcgi().getEUTRANcellIdentifier().equals(eci))
slowr13fa5b02017-08-08 16:32:31 -0700109 .map(v -> linkMap.get(v))
110 .collect(Collectors.toList()));
111
112 return list;
113 }
114
115 @Override
116 public List<RnibLink> getLinksByUeId(long euId) {
117 List<RnibLink> list = Lists.newArrayList();
slowr13fa5b02017-08-08 16:32:31 -0700118
119 list.addAll(
120 linkMap.keySet()
121 .stream()
slowrc86750e2017-08-22 17:26:47 -0700122 .filter(k -> k.getUeId().equals(euId))
slowr13fa5b02017-08-08 16:32:31 -0700123 .map(v -> linkMap.get(v))
124 .collect(Collectors.toList()));
125
126 return list;
127 }
128
slowr89c2ac12017-08-15 16:20:06 -0700129
slowr13fa5b02017-08-08 16:32:31 -0700130 @Override
131 public RnibLink getLinkBetweenCellIdUeId(String eciHex, long euId) {
132 EUTRANCellIdentifier eci = hexToECI(eciHex);
slowr13fa5b02017-08-08 16:32:31 -0700133
134 Optional<LinkId> first = linkMap.keySet()
135 .stream()
slowr8ddc2b12017-08-14 14:13:38 -0700136 .filter(linkId -> linkId.getEcgi().getEUTRANcellIdentifier().equals(eci))
slowrc86750e2017-08-22 17:26:47 -0700137 .filter(linkId -> linkId.getUeId().equals(euId))
slowr13fa5b02017-08-08 16:32:31 -0700138 .findFirst();
139
140 return first.map(linkId -> linkMap.get(linkId)).orElse(null);
141 }
142
143 @Override
slowr13fa5b02017-08-08 16:32:31 -0700144 public void storeLink(RnibLink link) {
slowr89c2ac12017-08-15 16:20:06 -0700145 synchronized (this) {
146 if (link.getLinkId() != null) {
147 // if we add a primary link then change the primary to non serving
148 if (link.getType().equals(RnibLink.Type.SERVING_PRIMARY)) {
149 RnibUe ue = link.getLinkId().getUe();
slowrc86750e2017-08-22 17:26:47 -0700150 getLinksByUeId(ue.getId())
slowr89c2ac12017-08-15 16:20:06 -0700151 .forEach(l -> {
152 if (l.getType().equals(RnibLink.Type.SERVING_PRIMARY)) {
153 l.setType(RnibLink.Type.NON_SERVING);
154 }
155 });
156 }
157 linkMap.put(link.getLinkId(), link);
158 }
slowr13fa5b02017-08-08 16:32:31 -0700159 }
160 }
161
162 @Override
163 public boolean removeLink(LinkId link) {
164 return linkMap.remove(link) != null;
165 }
166
167 @Override
slowrc86750e2017-08-22 17:26:47 -0700168 public RnibLink getLink(ECGI ecgi, Long ueId) {
slowr67d05e42017-08-11 20:37:22 -0700169
slowrc86750e2017-08-22 17:26:47 -0700170 LinkId linkId = LinkId.valueOf(ecgi, ueId);
slowr13fa5b02017-08-08 16:32:31 -0700171 return linkMap.get(linkId);
172 }
173
174 @Override
slowr8ddc2b12017-08-14 14:13:38 -0700175 public void modifyLinkRrmConf(RnibLink link, JsonNode rrmConf) {
176 link.modifyRrmParameters(rrmConf);
177 }
178
179 @Override
slowr13fa5b02017-08-08 16:32:31 -0700180 public List<Object> getNodes() {
181 List<Object> list = Lists.newArrayList();
182 list.add(cellMap.values());
183 list.add(ueMap.values());
184 return list;
185 }
186
187 @Override
slowr60d4d102017-08-16 18:33:58 -0700188 public List<Object> getCellNodes() {
189 List<Object> list = Lists.newArrayList();
slowr13fa5b02017-08-08 16:32:31 -0700190 list.addAll(cellMap.values());
191 return list;
192 }
193
194 @Override
slowr60d4d102017-08-16 18:33:58 -0700195 public List<Object> getUeNodes() {
196 List<Object> list = Lists.newArrayList();
slowr13fa5b02017-08-08 16:32:31 -0700197 list.addAll(ueMap.values());
198 return list;
199 }
200
201 @Override
202 public Object getByNodeId(String nodeId) {
203 try {
204 return getCell(nodeId);
205 } catch (Exception e) {
206
207 }
208 return getUe(Long.parseLong(nodeId));
209 }
210
211 @Override
212 public void storeCell(RnibCell cell) {
213 if (cell.getEcgi() != null) {
214 cellMap.putIfAbsent(cell.getEcgi(), cell);
215 }
216 }
217
218 @Override
219 public boolean removeCell(ECGI ecgi) {
220 return cellMap.remove(ecgi) != null;
221 }
222
223 @Override
224 public RnibCell getCell(String hexeci) {
225 EUTRANCellIdentifier eci = hexToECI(hexeci);
226 Optional<ECGI> first = cellMap.keySet().stream().filter(ecgi -> ecgi.getEUTRANcellIdentifier().equals(eci)).findFirst();
227 return first.map(ecgi -> cellMap.get(ecgi)).orElse(null);
228 }
229
230 @Override
231 public RnibCell getCell(ECGI ecgi) {
232 return cellMap.get(ecgi);
233 }
234
235 @Override
slowr73b4eae2017-08-17 16:09:09 -0700236 public void modifyCellRrmConf(RnibCell cell, JsonNode rrmConf) throws Exception {
slowr67d05e42017-08-11 20:37:22 -0700237 List<RnibLink> linkList = getLinksByECGI(cell.getEcgi());
238 List<RnibUe> ueList = linkList.stream().map(link -> link.getLinkId().getUe()).collect(Collectors.toList());
239
240 cell.modifyRrmConfig(rrmConf, ueList);
slowr13fa5b02017-08-08 16:32:31 -0700241 }
242
243 @Override
244 public RnibSlice getSlice(long sliceId) {
245 if (sliceMap.containsKey(sliceId)) {
246 return sliceMap.get(sliceId);
247 }
248 return null;
249 }
250
251 @Override
252 public boolean createSlice(ObjectNode attributes) {
253 return false;
254 }
255
256 @Override
257 public boolean removeCell(long sliceId) {
258 return sliceMap.remove(sliceId) != null;
259 }
260
261 @Override
262 public XranController getController() {
263 return controller;
264 }
265
266 @Override
267 public void setController(XranController controller) {
268 this.controller = controller;
269 }
270
271 @Override
272 public void storeUe(RnibUe ue) {
slowrc86750e2017-08-22 17:26:47 -0700273 long newId = ueIdGenerator.getNewId();
274 ue.setId(newId);
275 ueMap.put(newId, ue);
slowr13fa5b02017-08-08 16:32:31 -0700276 }
277
278 @Override
slowrc86750e2017-08-22 17:26:47 -0700279 public boolean removeUe(long ueId) {
280 return ueMap.remove(ueId) != null;
slowr13fa5b02017-08-08 16:32:31 -0700281 }
282
283 @Override
slowrc86750e2017-08-22 17:26:47 -0700284 public RnibUe getUe(long ueId) {
285 return ueMap.get(ueId);
slowr13fa5b02017-08-08 16:32:31 -0700286 }
287
288 private EUTRANCellIdentifier hexToECI(String eciHex) {
289 byte[] hexBinary = DatatypeConverter.parseHexBinary(eciHex);
290 return new EUTRANCellIdentifier(hexBinary, 28);
291 }
292}