slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /* |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 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; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 22 | import org.apache.felix.scr.annotations.Activate; |
| 23 | import org.apache.felix.scr.annotations.Component; |
| 24 | import org.apache.felix.scr.annotations.Deactivate; |
| 25 | import org.apache.felix.scr.annotations.Reference; |
| 26 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 27 | import org.apache.felix.scr.annotations.Service; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 28 | import org.onosproject.core.ApplicationId; |
| 29 | import org.onosproject.core.CoreService; |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 30 | import org.onosproject.core.IdGenerator; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 31 | import org.onosproject.store.AbstractStore; |
| 32 | import org.onosproject.xran.XranStore; |
| 33 | import org.onosproject.xran.codecs.api.ECGI; |
| 34 | import org.onosproject.xran.codecs.api.EUTRANCellIdentifier; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 35 | import org.onosproject.xran.controller.XranController; |
| 36 | import org.onosproject.xran.entities.RnibCell; |
| 37 | import org.onosproject.xran.entities.RnibLink; |
| 38 | import org.onosproject.xran.entities.RnibSlice; |
| 39 | import org.onosproject.xran.entities.RnibUe; |
| 40 | import org.onosproject.xran.identifiers.LinkId; |
| 41 | import org.slf4j.Logger; |
| 42 | |
| 43 | import javax.xml.bind.DatatypeConverter; |
| 44 | import java.util.List; |
| 45 | import java.util.Optional; |
| 46 | import java.util.concurrent.ConcurrentHashMap; |
| 47 | import java.util.concurrent.ConcurrentMap; |
| 48 | import java.util.stream.Collectors; |
| 49 | |
| 50 | import static org.slf4j.LoggerFactory.getLogger; |
| 51 | |
| 52 | /** |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 53 | * Default xran store. |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 54 | */ |
| 55 | @Component(immediate = true) |
| 56 | @Service |
| 57 | public 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<>(); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 65 | private ConcurrentMap<Long, RnibUe> ueMap = new ConcurrentHashMap<>(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 66 | private ConcurrentMap<Object, RnibSlice> sliceMap = new ConcurrentHashMap<>(); |
| 67 | private XranController controller; |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 68 | private IdGenerator ueIdGenerator; |
| 69 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 70 | @Activate |
| 71 | public void activate() { |
| 72 | ApplicationId appId = coreService.getAppId(XRAN_APP_ID); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 73 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 74 | // create ue id generator |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 75 | ueIdGenerator = coreService.getIdGenerator("xran-ue-id"); |
| 76 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 77 | log.info("XRAN Default Store Started"); |
| 78 | } |
| 79 | |
| 80 | @Deactivate |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 81 | public void deactivate() { |
slowr | 23a93e1 | 2017-09-01 13:26:18 -0700 | [diff] [blame] | 82 | linkMap.clear(); |
| 83 | cellMap.clear(); |
| 84 | ueMap.clear(); |
| 85 | sliceMap.clear(); |
| 86 | controller = null; |
| 87 | ueIdGenerator = null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 88 | 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 |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 99 | public List<RnibLink> getlinksbyecgi(ECGI ecgi) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 100 | List<RnibLink> list = Lists.newArrayList(); |
| 101 | list.addAll( |
| 102 | linkMap.keySet() |
| 103 | .stream() |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 104 | .filter(k -> k.getEcgi().equals(ecgi)) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 105 | .map(v -> linkMap.get(v)) |
| 106 | .collect(Collectors.toList())); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 107 | return list; |
| 108 | } |
| 109 | |
| 110 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 111 | public List<RnibLink> getlinksbycellid(String eciHex) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 112 | List<RnibLink> list = Lists.newArrayList(); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 113 | EUTRANCellIdentifier eci = hexToEci(eciHex); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 114 | |
| 115 | list.addAll( |
| 116 | linkMap.keySet() |
| 117 | .stream() |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 118 | .filter(k -> k.getEcgi().getEUTRANcellIdentifier().equals(eci)) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 119 | .map(v -> linkMap.get(v)) |
| 120 | .collect(Collectors.toList())); |
| 121 | |
| 122 | return list; |
| 123 | } |
| 124 | |
| 125 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 126 | public List<RnibLink> getlinksbyueid(long euId) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 127 | List<RnibLink> list = Lists.newArrayList(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 128 | |
| 129 | list.addAll( |
| 130 | linkMap.keySet() |
| 131 | .stream() |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 132 | .filter(k -> k.getUeId().equals(euId)) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 133 | .map(v -> linkMap.get(v)) |
| 134 | .collect(Collectors.toList())); |
| 135 | |
| 136 | return list; |
| 137 | } |
| 138 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 139 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 140 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 141 | public RnibLink getlinkbetweencellidueid(String eciHex, long euId) { |
| 142 | EUTRANCellIdentifier eci = hexToEci(eciHex); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 143 | |
| 144 | Optional<LinkId> first = linkMap.keySet() |
| 145 | .stream() |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 146 | .filter(linkId -> linkId.getEcgi().getEUTRANcellIdentifier().equals(eci) && |
| 147 | linkId.getUeId().equals(euId)) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 148 | .findFirst(); |
| 149 | |
| 150 | return first.map(linkId -> linkMap.get(linkId)).orElse(null); |
| 151 | } |
| 152 | |
| 153 | @Override |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 154 | public void storeLink(RnibLink link) { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 155 | 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(); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 160 | getlinksbyueid(ue.getId()) |
| 161 | .stream() |
| 162 | .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY)) |
| 163 | .forEach(l -> l.setType(RnibLink.Type.NON_SERVING)); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 164 | } |
| 165 | linkMap.put(link.getLinkId(), link); |
| 166 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public boolean removeLink(LinkId link) { |
| 172 | return linkMap.remove(link) != null; |
| 173 | } |
| 174 | |
| 175 | @Override |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 176 | public RnibLink getLink(ECGI ecgi, Long ueId) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 177 | LinkId linkId = LinkId.valueOf(ecgi, ueId); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 178 | return linkMap.get(linkId); |
| 179 | } |
| 180 | |
| 181 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 182 | public void modifylinkrrmconf(RnibLink link, JsonNode rrmConf) { |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 183 | link.modifyRrmParameters(rrmConf); |
| 184 | } |
| 185 | |
| 186 | @Override |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 187 | 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 |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 195 | public List<Object> getcellnodes() { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 196 | List<Object> list = Lists.newArrayList(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 197 | list.addAll(cellMap.values()); |
| 198 | return list; |
| 199 | } |
| 200 | |
| 201 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 202 | public List<Object> getuenodes() { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 203 | List<Object> list = Lists.newArrayList(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 204 | list.addAll(ueMap.values()); |
| 205 | return list; |
| 206 | } |
| 207 | |
| 208 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 209 | public Object getbynodeid(String nodeId) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 210 | try { |
| 211 | return getCell(nodeId); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 212 | } catch (Exception ignored) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 213 | } |
| 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) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 231 | 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); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public RnibCell getCell(ECGI ecgi) { |
| 242 | return cellMap.get(ecgi); |
| 243 | } |
| 244 | |
| 245 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 246 | 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()); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 251 | |
| 252 | cell.modifyRrmConfig(rrmConf, ueList); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 253 | } |
| 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) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 285 | long newId = ueIdGenerator.getNewId(); |
| 286 | ue.setId(newId); |
| 287 | ueMap.put(newId, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | @Override |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 291 | public boolean removeUe(long ueId) { |
| 292 | return ueMap.remove(ueId) != null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | @Override |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 296 | public RnibUe getUe(long ueId) { |
| 297 | return ueMap.get(ueId); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 298 | } |
| 299 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 300 | /** |
| 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) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 307 | byte[] hexBinary = DatatypeConverter.parseHexBinary(eciHex); |
| 308 | return new EUTRANCellIdentifier(hexBinary, 28); |
| 309 | } |
| 310 | } |