blob: 279f46d7ff56fd019bfcdf509e94f1383c472f98 [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;
25import org.onosproject.store.AbstractStore;
26import org.onosproject.xran.XranStore;
27import org.onosproject.xran.codecs.api.ECGI;
28import org.onosproject.xran.codecs.api.EUTRANCellIdentifier;
29import org.onosproject.xran.codecs.api.MMEUES1APID;
30import 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<>();
60 private ConcurrentMap<MMEUES1APID, RnibUe> ueMap = new ConcurrentHashMap<>();
61 private ConcurrentMap<Object, RnibSlice> sliceMap = new ConcurrentHashMap<>();
62 private XranController controller;
63
64 @Activate
65 public void activate() {
66 ApplicationId appId = coreService.getAppId(XRAN_APP_ID);
67 log.info("XRAN Default Store Started");
68 }
69
70 @Deactivate
71 public void deactive() {
72 log.info("XRAN Default Store Stopped");
73 }
74
75 @Override
76 public List<RnibLink> getLinks() {
77 List<RnibLink> list = Lists.newArrayList();
78 list.addAll(linkMap.values());
79 return list;
80 }
81
82 @Override
83 public List<RnibLink> getLinksByECGI(ECGI ecgi) {
84 List<RnibLink> list = Lists.newArrayList();
85 list.addAll(
86 linkMap.keySet()
87 .stream()
slowr8ddc2b12017-08-14 14:13:38 -070088 .filter(k -> k.getEcgi().equals(ecgi))
slowr13fa5b02017-08-08 16:32:31 -070089 .map(v -> linkMap.get(v))
90 .collect(Collectors.toList()));
91
92 return list;
93 }
94
95 @Override
96 public List<RnibLink> getLinksByCellId(String eciHex) {
97 List<RnibLink> list = Lists.newArrayList();
98 EUTRANCellIdentifier eci = hexToECI(eciHex);
99
100 list.addAll(
101 linkMap.keySet()
102 .stream()
slowr8ddc2b12017-08-14 14:13:38 -0700103 .filter(k -> k.getEcgi().getEUTRANcellIdentifier().equals(eci))
slowr13fa5b02017-08-08 16:32:31 -0700104 .map(v -> linkMap.get(v))
105 .collect(Collectors.toList()));
106
107 return list;
108 }
109
110 @Override
111 public List<RnibLink> getLinksByUeId(long euId) {
112 List<RnibLink> list = Lists.newArrayList();
113 MMEUES1APID mme = new MMEUES1APID(euId);
114
115 list.addAll(
116 linkMap.keySet()
117 .stream()
slowr8ddc2b12017-08-14 14:13:38 -0700118 .filter(k -> k.getMmeues1apid().equals(mme))
slowr13fa5b02017-08-08 16:32:31 -0700119 .map(v -> linkMap.get(v))
120 .collect(Collectors.toList()));
121
122 return list;
123 }
124
slowr89c2ac12017-08-15 16:20:06 -0700125
slowr13fa5b02017-08-08 16:32:31 -0700126 @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
slowr13fa5b02017-08-08 16:32:31 -0700141 public void storeLink(RnibLink link) {
slowr89c2ac12017-08-15 16:20:06 -0700142 synchronized (this) {
143 if (link.getLinkId() != null) {
144 // if we add a primary link then change the primary to non serving
145 if (link.getType().equals(RnibLink.Type.SERVING_PRIMARY)) {
146 RnibUe ue = link.getLinkId().getUe();
147 getLinksByUeId(ue.getMmeS1apId().longValue())
148 .forEach(l -> {
149 if (l.getType().equals(RnibLink.Type.SERVING_PRIMARY)) {
150 l.setType(RnibLink.Type.NON_SERVING);
151 }
152 });
153 }
154 linkMap.put(link.getLinkId(), link);
155 }
slowr13fa5b02017-08-08 16:32:31 -0700156 }
157 }
158
159 @Override
160 public boolean removeLink(LinkId link) {
161 return linkMap.remove(link) != null;
162 }
163
164 @Override
165 public RnibLink getLink(ECGI ecgi, MMEUES1APID mme) {
slowr67d05e42017-08-11 20:37:22 -0700166
167 LinkId linkId = LinkId.valueOf(ecgi, mme);
slowr13fa5b02017-08-08 16:32:31 -0700168 return linkMap.get(linkId);
169 }
170
171 @Override
slowr8ddc2b12017-08-14 14:13:38 -0700172 public void modifyLinkRrmConf(RnibLink link, JsonNode rrmConf) {
173 link.modifyRrmParameters(rrmConf);
174 }
175
176 @Override
slowr13fa5b02017-08-08 16:32:31 -0700177 public List<Object> getNodes() {
178 List<Object> list = Lists.newArrayList();
179 list.add(cellMap.values());
180 list.add(ueMap.values());
181 return list;
182 }
183
184 @Override
slowr60d4d102017-08-16 18:33:58 -0700185 public List<Object> getCellNodes() {
186 List<Object> list = Lists.newArrayList();
slowr13fa5b02017-08-08 16:32:31 -0700187 list.addAll(cellMap.values());
188 return list;
189 }
190
191 @Override
slowr60d4d102017-08-16 18:33:58 -0700192 public List<Object> getUeNodes() {
193 List<Object> list = Lists.newArrayList();
slowr13fa5b02017-08-08 16:32:31 -0700194 list.addAll(ueMap.values());
195 return list;
196 }
197
198 @Override
199 public Object getByNodeId(String nodeId) {
200 try {
201 return getCell(nodeId);
202 } catch (Exception e) {
203
204 }
205 return getUe(Long.parseLong(nodeId));
206 }
207
208 @Override
209 public void storeCell(RnibCell cell) {
210 if (cell.getEcgi() != null) {
211 cellMap.putIfAbsent(cell.getEcgi(), cell);
212 }
213 }
214
215 @Override
216 public boolean removeCell(ECGI ecgi) {
217 return cellMap.remove(ecgi) != null;
218 }
219
220 @Override
221 public RnibCell getCell(String hexeci) {
222 EUTRANCellIdentifier eci = hexToECI(hexeci);
223 Optional<ECGI> first = cellMap.keySet().stream().filter(ecgi -> ecgi.getEUTRANcellIdentifier().equals(eci)).findFirst();
224 return first.map(ecgi -> cellMap.get(ecgi)).orElse(null);
225 }
226
227 @Override
228 public RnibCell getCell(ECGI ecgi) {
229 return cellMap.get(ecgi);
230 }
231
232 @Override
slowr8ddc2b12017-08-14 14:13:38 -0700233 public void modifyCellRrmConf(RnibCell cell, JsonNode rrmConf) {
slowr67d05e42017-08-11 20:37:22 -0700234 List<RnibLink> linkList = getLinksByECGI(cell.getEcgi());
235 List<RnibUe> ueList = linkList.stream().map(link -> link.getLinkId().getUe()).collect(Collectors.toList());
236
237 cell.modifyRrmConfig(rrmConf, ueList);
slowr13fa5b02017-08-08 16:32:31 -0700238 }
239
240 @Override
241 public RnibSlice getSlice(long sliceId) {
242 if (sliceMap.containsKey(sliceId)) {
243 return sliceMap.get(sliceId);
244 }
245 return null;
246 }
247
248 @Override
249 public boolean createSlice(ObjectNode attributes) {
250 return false;
251 }
252
253 @Override
254 public boolean removeCell(long sliceId) {
255 return sliceMap.remove(sliceId) != null;
256 }
257
258 @Override
259 public XranController getController() {
260 return controller;
261 }
262
263 @Override
264 public void setController(XranController controller) {
265 this.controller = controller;
266 }
267
268 @Override
269 public void storeUe(RnibUe ue) {
270 if (ue.getMmeS1apId() != null) {
271 ueMap.putIfAbsent(ue.getMmeS1apId(), ue);
272 }
273 }
274
275 @Override
276 public boolean removeUe(MMEUES1APID mme) {
277 return ueMap.remove(mme) != null;
278 }
279
280 @Override
281 public RnibUe getUe(long euId) {
282 MMEUES1APID mme = new MMEUES1APID(euId);
283 return ueMap.get(mme);
284 }
285
286 @Override
287 public RnibUe getUe(MMEUES1APID mme) {
288 return ueMap.get(mme);
289 }
290
291 private EUTRANCellIdentifier hexToECI(String eciHex) {
292 byte[] hexBinary = DatatypeConverter.parseHexBinary(eciHex);
293 return new EUTRANCellIdentifier(hexBinary, 28);
294 }
295}