blob: f7e2c0700da9799c5cb179c4f2c8087616f9b116 [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;
slowrc86750e2017-08-22 17:26:47 -070068 private IdGenerator ueIdGenerator;
69
slowr13fa5b02017-08-08 16:32:31 -070070 @Activate
71 public void activate() {
72 ApplicationId appId = coreService.getAppId(XRAN_APP_ID);
slowrc86750e2017-08-22 17:26:47 -070073
slowr577f3222017-08-28 10:49:08 -070074 // create ue id generator
slowrc86750e2017-08-22 17:26:47 -070075 ueIdGenerator = coreService.getIdGenerator("xran-ue-id");
76
slowr13fa5b02017-08-08 16:32:31 -070077 log.info("XRAN Default Store Started");
78 }
79
80 @Deactivate
slowrc86750e2017-08-22 17:26:47 -070081 public void deactivate() {
slowr23a93e12017-09-01 13:26:18 -070082 linkMap.clear();
83 cellMap.clear();
84 ueMap.clear();
85 sliceMap.clear();
86 controller = null;
87 ueIdGenerator = null;
slowr13fa5b02017-08-08 16:32:31 -070088 log.info("XRAN Default Store Stopped");
89 }
90
91 @Override
92 public List<RnibLink> getLinks() {
93 List<RnibLink> list = Lists.newArrayList();
94 list.addAll(linkMap.values());
95 return list;
96 }
97
98 @Override
slowr577f3222017-08-28 10:49:08 -070099 public List<RnibLink> getlinksbyecgi(ECGI ecgi) {
slowr13fa5b02017-08-08 16:32:31 -0700100 List<RnibLink> list = Lists.newArrayList();
101 list.addAll(
102 linkMap.keySet()
103 .stream()
slowr8ddc2b12017-08-14 14:13:38 -0700104 .filter(k -> k.getEcgi().equals(ecgi))
slowr13fa5b02017-08-08 16:32:31 -0700105 .map(v -> linkMap.get(v))
106 .collect(Collectors.toList()));
slowr13fa5b02017-08-08 16:32:31 -0700107 return list;
108 }
109
110 @Override
slowr577f3222017-08-28 10:49:08 -0700111 public List<RnibLink> getlinksbycellid(String eciHex) {
slowr13fa5b02017-08-08 16:32:31 -0700112 List<RnibLink> list = Lists.newArrayList();
slowr577f3222017-08-28 10:49:08 -0700113 EUTRANCellIdentifier eci = hexToEci(eciHex);
slowr13fa5b02017-08-08 16:32:31 -0700114
115 list.addAll(
116 linkMap.keySet()
117 .stream()
slowr8ddc2b12017-08-14 14:13:38 -0700118 .filter(k -> k.getEcgi().getEUTRANcellIdentifier().equals(eci))
slowr13fa5b02017-08-08 16:32:31 -0700119 .map(v -> linkMap.get(v))
120 .collect(Collectors.toList()));
121
122 return list;
123 }
124
125 @Override
slowr577f3222017-08-28 10:49:08 -0700126 public List<RnibLink> getlinksbyueid(long euId) {
slowr13fa5b02017-08-08 16:32:31 -0700127 List<RnibLink> list = Lists.newArrayList();
slowr13fa5b02017-08-08 16:32:31 -0700128
129 list.addAll(
130 linkMap.keySet()
131 .stream()
slowrc86750e2017-08-22 17:26:47 -0700132 .filter(k -> k.getUeId().equals(euId))
slowr13fa5b02017-08-08 16:32:31 -0700133 .map(v -> linkMap.get(v))
134 .collect(Collectors.toList()));
135
136 return list;
137 }
138
slowr89c2ac12017-08-15 16:20:06 -0700139
slowr13fa5b02017-08-08 16:32:31 -0700140 @Override
slowr577f3222017-08-28 10:49:08 -0700141 public RnibLink getlinkbetweencellidueid(String eciHex, long euId) {
142 EUTRANCellIdentifier eci = hexToEci(eciHex);
slowr13fa5b02017-08-08 16:32:31 -0700143
144 Optional<LinkId> first = linkMap.keySet()
145 .stream()
slowr577f3222017-08-28 10:49:08 -0700146 .filter(linkId -> linkId.getEcgi().getEUTRANcellIdentifier().equals(eci) &&
147 linkId.getUeId().equals(euId))
slowr13fa5b02017-08-08 16:32:31 -0700148 .findFirst();
149
150 return first.map(linkId -> linkMap.get(linkId)).orElse(null);
151 }
152
153 @Override
slowr13fa5b02017-08-08 16:32:31 -0700154 public void storeLink(RnibLink link) {
slowr89c2ac12017-08-15 16:20:06 -0700155 synchronized (this) {
156 if (link.getLinkId() != null) {
157 // if we add a primary link then change the primary to non serving
158 if (link.getType().equals(RnibLink.Type.SERVING_PRIMARY)) {
159 RnibUe ue = link.getLinkId().getUe();
slowr577f3222017-08-28 10:49:08 -0700160 getlinksbyueid(ue.getId())
161 .stream()
162 .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY))
163 .forEach(l -> l.setType(RnibLink.Type.NON_SERVING));
slowr89c2ac12017-08-15 16:20:06 -0700164 }
165 linkMap.put(link.getLinkId(), link);
166 }
slowr13fa5b02017-08-08 16:32:31 -0700167 }
168 }
169
170 @Override
171 public boolean removeLink(LinkId link) {
172 return linkMap.remove(link) != null;
173 }
174
175 @Override
slowrc86750e2017-08-22 17:26:47 -0700176 public RnibLink getLink(ECGI ecgi, Long ueId) {
slowrc86750e2017-08-22 17:26:47 -0700177 LinkId linkId = LinkId.valueOf(ecgi, ueId);
slowr13fa5b02017-08-08 16:32:31 -0700178 return linkMap.get(linkId);
179 }
180
181 @Override
slowr577f3222017-08-28 10:49:08 -0700182 public void modifylinkrrmconf(RnibLink link, JsonNode rrmConf) {
slowr8ddc2b12017-08-14 14:13:38 -0700183 link.modifyRrmParameters(rrmConf);
184 }
185
186 @Override
slowr13fa5b02017-08-08 16:32:31 -0700187 public List<Object> getNodes() {
188 List<Object> list = Lists.newArrayList();
189 list.add(cellMap.values());
190 list.add(ueMap.values());
191 return list;
192 }
193
194 @Override
slowr577f3222017-08-28 10:49:08 -0700195 public List<Object> getcellnodes() {
slowr60d4d102017-08-16 18:33:58 -0700196 List<Object> list = Lists.newArrayList();
slowr13fa5b02017-08-08 16:32:31 -0700197 list.addAll(cellMap.values());
198 return list;
199 }
200
201 @Override
slowr577f3222017-08-28 10:49:08 -0700202 public List<Object> getuenodes() {
slowr60d4d102017-08-16 18:33:58 -0700203 List<Object> list = Lists.newArrayList();
slowr13fa5b02017-08-08 16:32:31 -0700204 list.addAll(ueMap.values());
205 return list;
206 }
207
208 @Override
slowr577f3222017-08-28 10:49:08 -0700209 public Object getbynodeid(String nodeId) {
slowr13fa5b02017-08-08 16:32:31 -0700210 try {
211 return getCell(nodeId);
slowr577f3222017-08-28 10:49:08 -0700212 } catch (Exception ignored) {
slowr13fa5b02017-08-08 16:32:31 -0700213 }
214 return getUe(Long.parseLong(nodeId));
215 }
216
217 @Override
218 public void storeCell(RnibCell cell) {
219 if (cell.getEcgi() != null) {
220 cellMap.putIfAbsent(cell.getEcgi(), cell);
221 }
222 }
223
224 @Override
225 public boolean removeCell(ECGI ecgi) {
226 return cellMap.remove(ecgi) != null;
227 }
228
229 @Override
230 public RnibCell getCell(String hexeci) {
slowr577f3222017-08-28 10:49:08 -0700231 EUTRANCellIdentifier eci = hexToEci(hexeci);
232 Optional<ECGI> first = cellMap.keySet()
233 .stream()
234 .filter(ecgi -> ecgi.getEUTRANcellIdentifier().equals(eci))
235 .findFirst();
236 return first.map(ecgi -> cellMap.get(ecgi))
237 .orElse(null);
slowr13fa5b02017-08-08 16:32:31 -0700238 }
239
240 @Override
241 public RnibCell getCell(ECGI ecgi) {
242 return cellMap.get(ecgi);
243 }
244
245 @Override
slowr577f3222017-08-28 10:49:08 -0700246 public void modifycellrrmconf(RnibCell cell, JsonNode rrmConf) throws Exception {
247 List<RnibLink> linkList = getlinksbyecgi(cell.getEcgi());
248 List<RnibUe> ueList = linkList.stream()
249 .map(link -> link.getLinkId().getUe())
250 .collect(Collectors.toList());
slowr67d05e42017-08-11 20:37:22 -0700251
252 cell.modifyRrmConfig(rrmConf, ueList);
slowr13fa5b02017-08-08 16:32:31 -0700253 }
254
255 @Override
256 public RnibSlice getSlice(long sliceId) {
257 if (sliceMap.containsKey(sliceId)) {
258 return sliceMap.get(sliceId);
259 }
260 return null;
261 }
262
263 @Override
264 public boolean createSlice(ObjectNode attributes) {
265 return false;
266 }
267
268 @Override
269 public boolean removeCell(long sliceId) {
270 return sliceMap.remove(sliceId) != null;
271 }
272
273 @Override
274 public XranController getController() {
275 return controller;
276 }
277
278 @Override
279 public void setController(XranController controller) {
280 this.controller = controller;
281 }
282
283 @Override
284 public void storeUe(RnibUe ue) {
slowrc86750e2017-08-22 17:26:47 -0700285 long newId = ueIdGenerator.getNewId();
286 ue.setId(newId);
287 ueMap.put(newId, ue);
slowr13fa5b02017-08-08 16:32:31 -0700288 }
289
290 @Override
slowrc86750e2017-08-22 17:26:47 -0700291 public boolean removeUe(long ueId) {
292 return ueMap.remove(ueId) != null;
slowr13fa5b02017-08-08 16:32:31 -0700293 }
294
295 @Override
slowrc86750e2017-08-22 17:26:47 -0700296 public RnibUe getUe(long ueId) {
297 return ueMap.get(ueId);
slowr13fa5b02017-08-08 16:32:31 -0700298 }
299
slowr577f3222017-08-28 10:49:08 -0700300 /**
301 * Get from HEX string the according ECI class object.
302 *
303 * @param eciHex HEX string
304 * @return ECI object if created successfully
305 */
306 private EUTRANCellIdentifier hexToEci(String eciHex) {
slowr13fa5b02017-08-08 16:32:31 -0700307 byte[] hexBinary = DatatypeConverter.parseHexBinary(eciHex);
308 return new EUTRANCellIdentifier(hexBinary, 28);
309 }
310}