blob: 9a1a2592168ad8cc17425e8d16dc6fabf4a083d4 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
slowr577f3222017-08-28 10:49:08 -07002 * Copyright 2015-present Open Networking Foundation
slowr13fa5b02017-08-08 16:32:31 -07003 *
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;
slowr577f3222017-08-28 10:49:08 -070022import org.apache.felix.scr.annotations.Activate;
23import org.apache.felix.scr.annotations.Component;
24import org.apache.felix.scr.annotations.Deactivate;
25import org.apache.felix.scr.annotations.Reference;
26import org.apache.felix.scr.annotations.ReferenceCardinality;
27import org.apache.felix.scr.annotations.Service;
slowr13fa5b02017-08-08 16:32:31 -070028import org.onosproject.core.ApplicationId;
29import org.onosproject.core.CoreService;
slowrc86750e2017-08-22 17:26:47 -070030import org.onosproject.core.IdGenerator;
slowr13fa5b02017-08-08 16:32:31 -070031import org.onosproject.store.AbstractStore;
32import org.onosproject.xran.XranStore;
33import org.onosproject.xran.codecs.api.ECGI;
34import org.onosproject.xran.codecs.api.EUTRANCellIdentifier;
slowr13fa5b02017-08-08 16:32:31 -070035import org.onosproject.xran.controller.XranController;
36import org.onosproject.xran.entities.RnibCell;
37import org.onosproject.xran.entities.RnibLink;
38import org.onosproject.xran.entities.RnibSlice;
39import org.onosproject.xran.entities.RnibUe;
40import org.onosproject.xran.identifiers.LinkId;
41import org.slf4j.Logger;
42
43import javax.xml.bind.DatatypeConverter;
44import java.util.List;
45import java.util.Optional;
46import java.util.concurrent.ConcurrentHashMap;
47import java.util.concurrent.ConcurrentMap;
48import java.util.stream.Collectors;
49
50import static org.slf4j.LoggerFactory.getLogger;
51
52/**
slowr577f3222017-08-28 10:49:08 -070053 * Default xran store.
slowr13fa5b02017-08-08 16:32:31 -070054 */
55@Component(immediate = true)
56@Service
57public class DefaultXranStore extends AbstractStore implements XranStore {
58 private static final String XRAN_APP_ID = "org.onosproject.xran";
59
60 private final Logger log = getLogger(getClass());
61 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 protected CoreService coreService;
63 private ConcurrentMap<LinkId, RnibLink> linkMap = new ConcurrentHashMap<>();
64 private ConcurrentMap<ECGI, RnibCell> cellMap = new ConcurrentHashMap<>();
slowrc86750e2017-08-22 17:26:47 -070065 private ConcurrentMap<Long, RnibUe> ueMap = new ConcurrentHashMap<>();
slowr13fa5b02017-08-08 16:32:31 -070066 private ConcurrentMap<Object, RnibSlice> sliceMap = new ConcurrentHashMap<>();
67 private XranController controller;
68
slowrc86750e2017-08-22 17:26:47 -070069 private IdGenerator ueIdGenerator;
70
slowr13fa5b02017-08-08 16:32:31 -070071 @Activate
72 public void activate() {
73 ApplicationId appId = coreService.getAppId(XRAN_APP_ID);
slowrc86750e2017-08-22 17:26:47 -070074
slowr577f3222017-08-28 10:49:08 -070075 // create ue id generator
slowrc86750e2017-08-22 17:26:47 -070076 ueIdGenerator = coreService.getIdGenerator("xran-ue-id");
77
slowr13fa5b02017-08-08 16:32:31 -070078 log.info("XRAN Default Store Started");
79 }
80
81 @Deactivate
slowrc86750e2017-08-22 17:26:47 -070082 public void deactivate() {
slowr13fa5b02017-08-08 16:32:31 -070083 log.info("XRAN Default Store Stopped");
84 }
85
86 @Override
87 public List<RnibLink> getLinks() {
88 List<RnibLink> list = Lists.newArrayList();
89 list.addAll(linkMap.values());
90 return list;
91 }
92
93 @Override
slowr577f3222017-08-28 10:49:08 -070094 public List<RnibLink> getlinksbyecgi(ECGI ecgi) {
slowr13fa5b02017-08-08 16:32:31 -070095 List<RnibLink> list = Lists.newArrayList();
96 list.addAll(
97 linkMap.keySet()
98 .stream()
slowr8ddc2b12017-08-14 14:13:38 -070099 .filter(k -> k.getEcgi().equals(ecgi))
slowr13fa5b02017-08-08 16:32:31 -0700100 .map(v -> linkMap.get(v))
101 .collect(Collectors.toList()));
102
103 return list;
104 }
105
106 @Override
slowr577f3222017-08-28 10:49:08 -0700107 public List<RnibLink> getlinksbycellid(String eciHex) {
slowr13fa5b02017-08-08 16:32:31 -0700108 List<RnibLink> list = Lists.newArrayList();
slowr577f3222017-08-28 10:49:08 -0700109 EUTRANCellIdentifier eci = hexToEci(eciHex);
slowr13fa5b02017-08-08 16:32:31 -0700110
111 list.addAll(
112 linkMap.keySet()
113 .stream()
slowr8ddc2b12017-08-14 14:13:38 -0700114 .filter(k -> k.getEcgi().getEUTRANcellIdentifier().equals(eci))
slowr13fa5b02017-08-08 16:32:31 -0700115 .map(v -> linkMap.get(v))
116 .collect(Collectors.toList()));
117
118 return list;
119 }
120
121 @Override
slowr577f3222017-08-28 10:49:08 -0700122 public List<RnibLink> getlinksbyueid(long euId) {
slowr13fa5b02017-08-08 16:32:31 -0700123 List<RnibLink> list = Lists.newArrayList();
slowr13fa5b02017-08-08 16:32:31 -0700124
125 list.addAll(
126 linkMap.keySet()
127 .stream()
slowrc86750e2017-08-22 17:26:47 -0700128 .filter(k -> k.getUeId().equals(euId))
slowr13fa5b02017-08-08 16:32:31 -0700129 .map(v -> linkMap.get(v))
130 .collect(Collectors.toList()));
131
132 return list;
133 }
134
slowr89c2ac12017-08-15 16:20:06 -0700135
slowr13fa5b02017-08-08 16:32:31 -0700136 @Override
slowr577f3222017-08-28 10:49:08 -0700137 public RnibLink getlinkbetweencellidueid(String eciHex, long euId) {
138 EUTRANCellIdentifier eci = hexToEci(eciHex);
slowr13fa5b02017-08-08 16:32:31 -0700139
140 Optional<LinkId> first = linkMap.keySet()
141 .stream()
slowr577f3222017-08-28 10:49:08 -0700142 .filter(linkId -> linkId.getEcgi().getEUTRANcellIdentifier().equals(eci) &&
143 linkId.getUeId().equals(euId))
slowr13fa5b02017-08-08 16:32:31 -0700144 .findFirst();
145
146 return first.map(linkId -> linkMap.get(linkId)).orElse(null);
147 }
148
149 @Override
slowr13fa5b02017-08-08 16:32:31 -0700150 public void storeLink(RnibLink link) {
slowr89c2ac12017-08-15 16:20:06 -0700151 synchronized (this) {
152 if (link.getLinkId() != null) {
153 // if we add a primary link then change the primary to non serving
154 if (link.getType().equals(RnibLink.Type.SERVING_PRIMARY)) {
155 RnibUe ue = link.getLinkId().getUe();
slowr577f3222017-08-28 10:49:08 -0700156 getlinksbyueid(ue.getId())
157 .stream()
158 .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY))
159 .forEach(l -> l.setType(RnibLink.Type.NON_SERVING));
slowr89c2ac12017-08-15 16:20:06 -0700160 }
161 linkMap.put(link.getLinkId(), link);
162 }
slowr13fa5b02017-08-08 16:32:31 -0700163 }
164 }
165
166 @Override
167 public boolean removeLink(LinkId link) {
168 return linkMap.remove(link) != null;
169 }
170
171 @Override
slowrc86750e2017-08-22 17:26:47 -0700172 public RnibLink getLink(ECGI ecgi, Long ueId) {
slowrc86750e2017-08-22 17:26:47 -0700173 LinkId linkId = LinkId.valueOf(ecgi, ueId);
slowr13fa5b02017-08-08 16:32:31 -0700174 return linkMap.get(linkId);
175 }
176
177 @Override
slowr577f3222017-08-28 10:49:08 -0700178 public void modifylinkrrmconf(RnibLink link, JsonNode rrmConf) {
slowr8ddc2b12017-08-14 14:13:38 -0700179 link.modifyRrmParameters(rrmConf);
180 }
181
182 @Override
slowr13fa5b02017-08-08 16:32:31 -0700183 public List<Object> getNodes() {
184 List<Object> list = Lists.newArrayList();
185 list.add(cellMap.values());
186 list.add(ueMap.values());
187 return list;
188 }
189
190 @Override
slowr577f3222017-08-28 10:49:08 -0700191 public List<Object> getcellnodes() {
slowr60d4d102017-08-16 18:33:58 -0700192 List<Object> list = Lists.newArrayList();
slowr13fa5b02017-08-08 16:32:31 -0700193 list.addAll(cellMap.values());
194 return list;
195 }
196
197 @Override
slowr577f3222017-08-28 10:49:08 -0700198 public List<Object> getuenodes() {
slowr60d4d102017-08-16 18:33:58 -0700199 List<Object> list = Lists.newArrayList();
slowr13fa5b02017-08-08 16:32:31 -0700200 list.addAll(ueMap.values());
201 return list;
202 }
203
204 @Override
slowr577f3222017-08-28 10:49:08 -0700205 public Object getbynodeid(String nodeId) {
slowr13fa5b02017-08-08 16:32:31 -0700206 try {
207 return getCell(nodeId);
slowr577f3222017-08-28 10:49:08 -0700208 } catch (Exception ignored) {
slowr13fa5b02017-08-08 16:32:31 -0700209 }
210 return getUe(Long.parseLong(nodeId));
211 }
212
213 @Override
214 public void storeCell(RnibCell cell) {
215 if (cell.getEcgi() != null) {
216 cellMap.putIfAbsent(cell.getEcgi(), cell);
217 }
218 }
219
220 @Override
221 public boolean removeCell(ECGI ecgi) {
222 return cellMap.remove(ecgi) != null;
223 }
224
225 @Override
226 public RnibCell getCell(String hexeci) {
slowr577f3222017-08-28 10:49:08 -0700227 EUTRANCellIdentifier eci = hexToEci(hexeci);
228 Optional<ECGI> first = cellMap.keySet()
229 .stream()
230 .filter(ecgi -> ecgi.getEUTRANcellIdentifier().equals(eci))
231 .findFirst();
232 return first.map(ecgi -> cellMap.get(ecgi))
233 .orElse(null);
slowr13fa5b02017-08-08 16:32:31 -0700234 }
235
236 @Override
237 public RnibCell getCell(ECGI ecgi) {
238 return cellMap.get(ecgi);
239 }
240
241 @Override
slowr577f3222017-08-28 10:49:08 -0700242 public void modifycellrrmconf(RnibCell cell, JsonNode rrmConf) throws Exception {
243 List<RnibLink> linkList = getlinksbyecgi(cell.getEcgi());
244 List<RnibUe> ueList = linkList.stream()
245 .map(link -> link.getLinkId().getUe())
246 .collect(Collectors.toList());
slowr67d05e42017-08-11 20:37:22 -0700247
248 cell.modifyRrmConfig(rrmConf, ueList);
slowr13fa5b02017-08-08 16:32:31 -0700249 }
250
251 @Override
252 public RnibSlice getSlice(long sliceId) {
253 if (sliceMap.containsKey(sliceId)) {
254 return sliceMap.get(sliceId);
255 }
256 return null;
257 }
258
259 @Override
260 public boolean createSlice(ObjectNode attributes) {
261 return false;
262 }
263
264 @Override
265 public boolean removeCell(long sliceId) {
266 return sliceMap.remove(sliceId) != null;
267 }
268
269 @Override
270 public XranController getController() {
271 return controller;
272 }
273
274 @Override
275 public void setController(XranController controller) {
276 this.controller = controller;
277 }
278
279 @Override
280 public void storeUe(RnibUe ue) {
slowrc86750e2017-08-22 17:26:47 -0700281 long newId = ueIdGenerator.getNewId();
282 ue.setId(newId);
283 ueMap.put(newId, ue);
slowr13fa5b02017-08-08 16:32:31 -0700284 }
285
286 @Override
slowrc86750e2017-08-22 17:26:47 -0700287 public boolean removeUe(long ueId) {
288 return ueMap.remove(ueId) != null;
slowr13fa5b02017-08-08 16:32:31 -0700289 }
290
291 @Override
slowrc86750e2017-08-22 17:26:47 -0700292 public RnibUe getUe(long ueId) {
293 return ueMap.get(ueId);
slowr13fa5b02017-08-08 16:32:31 -0700294 }
295
slowr577f3222017-08-28 10:49:08 -0700296 /**
297 * Get from HEX string the according ECI class object.
298 *
299 * @param eciHex HEX string
300 * @return ECI object if created successfully
301 */
302 private EUTRANCellIdentifier hexToEci(String eciHex) {
slowr13fa5b02017-08-08 16:32:31 -0700303 byte[] hexBinary = DatatypeConverter.parseHexBinary(eciHex);
304 return new EUTRANCellIdentifier(hexBinary, 28);
305 }
306}