blob: 7894b74e4c495be9e7cbf866ade30c5d9e94a344 [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()
88 .filter(k -> k.getSource().equals(ecgi))
89 .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()
103 .filter(k -> k.getSource().getEUTRANcellIdentifier().equals(eci))
104 .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()
118 .filter(k -> k.getDestination().equals(mme))
119 .map(v -> linkMap.get(v))
120 .collect(Collectors.toList()));
121
122 return list;
123 }
124
125 @Override
126 public RnibLink getLinkBetweenCellIdUeId(String eciHex, long euId) {
127 EUTRANCellIdentifier eci = hexToECI(eciHex);
128 MMEUES1APID mme = new MMEUES1APID(euId);
129
130 Optional<LinkId> first = linkMap.keySet()
131 .stream()
132 .filter(linkId -> linkId.getSource().getEUTRANcellIdentifier().equals(eci))
133 .filter(linkId -> linkId.getDestination().equals(mme))
134 .findFirst();
135
136 return first.map(linkId -> linkMap.get(linkId)).orElse(null);
137 }
138
139 @Override
140 public boolean createLinkBetweenCellIdUeId(String eciHex, long euId, String type) {
141 RnibCell cell = getCell(eciHex);
142 RnibUe ue = getUe(euId);
143
144 if (cell != null && ue != null) {
145 RnibLink link = new RnibLink();
146 link.setLinkId(cell, ue);
147
148 // TODO: string to enum mapping
149// link.setType(type);
150
151 linkMap.put(link.getLinkId(), link);
152 return true;
153 }
154
155 return false;
156 }
157
158 @Override
159 public void storeLink(RnibLink link) {
160 if (link.getLinkId() != null) {
161 linkMap.put(link.getLinkId(), link);
162 }
163 }
164
165 @Override
166 public boolean removeLink(LinkId link) {
167 return linkMap.remove(link) != null;
168 }
169
170 @Override
171 public RnibLink getLink(ECGI ecgi, MMEUES1APID mme) {
172 LinkId linkId = new LinkId(ecgi, mme);
173 return linkMap.get(linkId);
174 }
175
176 @Override
177 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
185 public List<RnibCell> getCellNodes() {
186 List<RnibCell> list = Lists.newArrayList();
187 list.addAll(cellMap.values());
188 return list;
189 }
190
191 @Override
192 public List<RnibUe> getUeNodes() {
193 List<RnibUe> list = Lists.newArrayList();
194 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
233 public boolean modifyCellRrmConf(String hexeci, JsonNode rrmConf) {
234 EUTRANCellIdentifier eci = hexToECI(hexeci);
235 Optional<ECGI> first = cellMap.keySet().stream().filter(ecgi -> ecgi.getEUTRANcellIdentifier().equals(eci)).findFirst();
236 first.ifPresent(ecgi -> cellMap.get(ecgi).modifyRrmConfig(rrmConf));
237 return false;
238 }
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}