slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.xran.impl; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 21 | import com.google.common.collect.Lists; |
| 22 | import org.apache.felix.scr.annotations.*; |
| 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.core.CoreService; |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 25 | import org.onosproject.core.IdGenerator; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 26 | import org.onosproject.store.AbstractStore; |
| 27 | import org.onosproject.xran.XranStore; |
| 28 | import org.onosproject.xran.codecs.api.ECGI; |
| 29 | import org.onosproject.xran.codecs.api.EUTRANCellIdentifier; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 30 | import org.onosproject.xran.controller.XranController; |
| 31 | import org.onosproject.xran.entities.RnibCell; |
| 32 | import org.onosproject.xran.entities.RnibLink; |
| 33 | import org.onosproject.xran.entities.RnibSlice; |
| 34 | import org.onosproject.xran.entities.RnibUe; |
| 35 | import org.onosproject.xran.identifiers.LinkId; |
| 36 | import org.slf4j.Logger; |
| 37 | |
| 38 | import javax.xml.bind.DatatypeConverter; |
| 39 | import java.util.List; |
| 40 | import java.util.Optional; |
| 41 | import java.util.concurrent.ConcurrentHashMap; |
| 42 | import java.util.concurrent.ConcurrentMap; |
| 43 | import java.util.stream.Collectors; |
| 44 | |
| 45 | import static org.slf4j.LoggerFactory.getLogger; |
| 46 | |
| 47 | /** |
| 48 | * Created by dimitris on 7/22/17. |
| 49 | */ |
| 50 | @Component(immediate = true) |
| 51 | @Service |
| 52 | public 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<>(); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 60 | private ConcurrentMap<Long, RnibUe> ueMap = new ConcurrentHashMap<>(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 61 | private ConcurrentMap<Object, RnibSlice> sliceMap = new ConcurrentHashMap<>(); |
| 62 | private XranController controller; |
| 63 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 64 | private IdGenerator ueIdGenerator; |
| 65 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 66 | @Activate |
| 67 | public void activate() { |
| 68 | ApplicationId appId = coreService.getAppId(XRAN_APP_ID); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 69 | |
| 70 | ueIdGenerator = coreService.getIdGenerator("xran-ue-id"); |
| 71 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 72 | log.info("XRAN Default Store Started"); |
| 73 | } |
| 74 | |
| 75 | @Deactivate |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 76 | public void deactivate() { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 77 | log.info("XRAN Default Store Stopped"); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public List<RnibLink> getLinks() { |
| 82 | List<RnibLink> list = Lists.newArrayList(); |
| 83 | list.addAll(linkMap.values()); |
| 84 | return list; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public List<RnibLink> getLinksByECGI(ECGI ecgi) { |
| 89 | List<RnibLink> list = Lists.newArrayList(); |
| 90 | list.addAll( |
| 91 | linkMap.keySet() |
| 92 | .stream() |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 93 | .filter(k -> k.getEcgi().equals(ecgi)) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 94 | .map(v -> linkMap.get(v)) |
| 95 | .collect(Collectors.toList())); |
| 96 | |
| 97 | return list; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public List<RnibLink> getLinksByCellId(String eciHex) { |
| 102 | List<RnibLink> list = Lists.newArrayList(); |
| 103 | EUTRANCellIdentifier eci = hexToECI(eciHex); |
| 104 | |
| 105 | list.addAll( |
| 106 | linkMap.keySet() |
| 107 | .stream() |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 108 | .filter(k -> k.getEcgi().getEUTRANcellIdentifier().equals(eci)) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 109 | .map(v -> linkMap.get(v)) |
| 110 | .collect(Collectors.toList())); |
| 111 | |
| 112 | return list; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public List<RnibLink> getLinksByUeId(long euId) { |
| 117 | List<RnibLink> list = Lists.newArrayList(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 118 | |
| 119 | list.addAll( |
| 120 | linkMap.keySet() |
| 121 | .stream() |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 122 | .filter(k -> k.getUeId().equals(euId)) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 123 | .map(v -> linkMap.get(v)) |
| 124 | .collect(Collectors.toList())); |
| 125 | |
| 126 | return list; |
| 127 | } |
| 128 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 129 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 130 | @Override |
| 131 | public RnibLink getLinkBetweenCellIdUeId(String eciHex, long euId) { |
| 132 | EUTRANCellIdentifier eci = hexToECI(eciHex); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 133 | |
| 134 | Optional<LinkId> first = linkMap.keySet() |
| 135 | .stream() |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 136 | .filter(linkId -> linkId.getEcgi().getEUTRANcellIdentifier().equals(eci)) |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 137 | .filter(linkId -> linkId.getUeId().equals(euId)) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 138 | .findFirst(); |
| 139 | |
| 140 | return first.map(linkId -> linkMap.get(linkId)).orElse(null); |
| 141 | } |
| 142 | |
| 143 | @Override |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 144 | public void storeLink(RnibLink link) { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 145 | synchronized (this) { |
| 146 | if (link.getLinkId() != null) { |
| 147 | // if we add a primary link then change the primary to non serving |
| 148 | if (link.getType().equals(RnibLink.Type.SERVING_PRIMARY)) { |
| 149 | RnibUe ue = link.getLinkId().getUe(); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 150 | getLinksByUeId(ue.getId()) |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 151 | .forEach(l -> { |
| 152 | if (l.getType().equals(RnibLink.Type.SERVING_PRIMARY)) { |
| 153 | l.setType(RnibLink.Type.NON_SERVING); |
| 154 | } |
| 155 | }); |
| 156 | } |
| 157 | linkMap.put(link.getLinkId(), link); |
| 158 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public boolean removeLink(LinkId link) { |
| 164 | return linkMap.remove(link) != null; |
| 165 | } |
| 166 | |
| 167 | @Override |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 168 | public RnibLink getLink(ECGI ecgi, Long ueId) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 169 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 170 | LinkId linkId = LinkId.valueOf(ecgi, ueId); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 171 | return linkMap.get(linkId); |
| 172 | } |
| 173 | |
| 174 | @Override |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 175 | public void modifyLinkRrmConf(RnibLink link, JsonNode rrmConf) { |
| 176 | link.modifyRrmParameters(rrmConf); |
| 177 | } |
| 178 | |
| 179 | @Override |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 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 |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 188 | public List<Object> getCellNodes() { |
| 189 | List<Object> list = Lists.newArrayList(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 190 | list.addAll(cellMap.values()); |
| 191 | return list; |
| 192 | } |
| 193 | |
| 194 | @Override |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 195 | public List<Object> getUeNodes() { |
| 196 | List<Object> list = Lists.newArrayList(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 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 |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 236 | public void modifyCellRrmConf(RnibCell cell, JsonNode rrmConf) throws Exception { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 237 | List<RnibLink> linkList = getLinksByECGI(cell.getEcgi()); |
| 238 | List<RnibUe> ueList = linkList.stream().map(link -> link.getLinkId().getUe()).collect(Collectors.toList()); |
| 239 | |
| 240 | cell.modifyRrmConfig(rrmConf, ueList); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public RnibSlice getSlice(long sliceId) { |
| 245 | if (sliceMap.containsKey(sliceId)) { |
| 246 | return sliceMap.get(sliceId); |
| 247 | } |
| 248 | return null; |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public boolean createSlice(ObjectNode attributes) { |
| 253 | return false; |
| 254 | } |
| 255 | |
| 256 | @Override |
| 257 | public boolean removeCell(long sliceId) { |
| 258 | return sliceMap.remove(sliceId) != null; |
| 259 | } |
| 260 | |
| 261 | @Override |
| 262 | public XranController getController() { |
| 263 | return controller; |
| 264 | } |
| 265 | |
| 266 | @Override |
| 267 | public void setController(XranController controller) { |
| 268 | this.controller = controller; |
| 269 | } |
| 270 | |
| 271 | @Override |
| 272 | public void storeUe(RnibUe ue) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 273 | long newId = ueIdGenerator.getNewId(); |
| 274 | ue.setId(newId); |
| 275 | ueMap.put(newId, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | @Override |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 279 | public boolean removeUe(long ueId) { |
| 280 | return ueMap.remove(ueId) != null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | @Override |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 284 | public RnibUe getUe(long ueId) { |
| 285 | return ueMap.get(ueId); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | private EUTRANCellIdentifier hexToECI(String eciHex) { |
| 289 | byte[] hexBinary = DatatypeConverter.parseHexBinary(eciHex); |
| 290 | return new EUTRANCellIdentifier(hexBinary, 28); |
| 291 | } |
| 292 | } |