blob: f3a9fac7d5891a3c71564bbb44df7041f4687ab6 [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()
slowr67d05e42017-08-11 20:37:22 -070089 .filter(k -> k.getSourceId().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()
slowr67d05e42017-08-11 20:37:22 -0700104 .filter(k -> k.getSourceId().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()
slowr67d05e42017-08-11 20:37:22 -0700119 .filter(k -> k.getDestinationId().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()
slowr67d05e42017-08-11 20:37:22 -0700133 .filter(linkId -> linkId.getSourceId().getEUTRANcellIdentifier().equals(eci))
134 .filter(linkId -> linkId.getDestinationId().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
slowr67d05e42017-08-11 20:37:22 -0700148 try {
149 link.setType(RnibLink.Type.valueOf(type));
150 } catch (Exception e) {
151 log.error(ExceptionUtils.getFullStackTrace(e));
152 }
slowr13fa5b02017-08-08 16:32:31 -0700153 linkMap.put(link.getLinkId(), link);
154 return true;
155 }
156
157 return false;
158 }
159
160 @Override
161 public void storeLink(RnibLink link) {
162 if (link.getLinkId() != null) {
163 linkMap.put(link.getLinkId(), link);
164 }
165 }
166
167 @Override
168 public boolean removeLink(LinkId link) {
169 return linkMap.remove(link) != null;
170 }
171
172 @Override
173 public RnibLink getLink(ECGI ecgi, MMEUES1APID mme) {
slowr67d05e42017-08-11 20:37:22 -0700174
175 LinkId linkId = LinkId.valueOf(ecgi, mme);
slowr13fa5b02017-08-08 16:32:31 -0700176 return linkMap.get(linkId);
177 }
178
179 @Override
180 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
188 public List<RnibCell> getCellNodes() {
189 List<RnibCell> list = Lists.newArrayList();
190 list.addAll(cellMap.values());
191 return list;
192 }
193
194 @Override
195 public List<RnibUe> getUeNodes() {
196 List<RnibUe> list = Lists.newArrayList();
197 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
slowr67d05e42017-08-11 20:37:22 -0700236 public boolean modifyCellRrmConf(RnibCell cell, JsonNode rrmConf) {
237
238 List<RnibLink> linkList = getLinksByECGI(cell.getEcgi());
239 List<RnibUe> ueList = linkList.stream().map(link -> link.getLinkId().getUe()).collect(Collectors.toList());
240
241 cell.modifyRrmConfig(rrmConf, ueList);
slowr13fa5b02017-08-08 16:32:31 -0700242 return false;
243 }
244
245 @Override
246 public RnibSlice getSlice(long sliceId) {
247 if (sliceMap.containsKey(sliceId)) {
248 return sliceMap.get(sliceId);
249 }
250 return null;
251 }
252
253 @Override
254 public boolean createSlice(ObjectNode attributes) {
255 return false;
256 }
257
258 @Override
259 public boolean removeCell(long sliceId) {
260 return sliceMap.remove(sliceId) != null;
261 }
262
263 @Override
264 public XranController getController() {
265 return controller;
266 }
267
268 @Override
269 public void setController(XranController controller) {
270 this.controller = controller;
271 }
272
273 @Override
274 public void storeUe(RnibUe ue) {
275 if (ue.getMmeS1apId() != null) {
276 ueMap.putIfAbsent(ue.getMmeS1apId(), ue);
277 }
278 }
279
280 @Override
281 public boolean removeUe(MMEUES1APID mme) {
282 return ueMap.remove(mme) != null;
283 }
284
285 @Override
286 public RnibUe getUe(long euId) {
287 MMEUES1APID mme = new MMEUES1APID(euId);
288 return ueMap.get(mme);
289 }
290
291 @Override
292 public RnibUe getUe(MMEUES1APID mme) {
293 return ueMap.get(mme);
294 }
295
296 private EUTRANCellIdentifier hexToECI(String eciHex) {
297 byte[] hexBinary = DatatypeConverter.parseHexBinary(eciHex);
298 return new EUTRANCellIdentifier(hexBinary, 28);
299 }
300}