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; |
| 68 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 69 | private IdGenerator ueIdGenerator; |
| 70 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 71 | @Activate |
| 72 | public void activate() { |
| 73 | ApplicationId appId = coreService.getAppId(XRAN_APP_ID); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 74 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 75 | // create ue id generator |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 76 | ueIdGenerator = coreService.getIdGenerator("xran-ue-id"); |
| 77 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 78 | log.info("XRAN Default Store Started"); |
| 79 | } |
| 80 | |
| 81 | @Deactivate |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 82 | public void deactivate() { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 83 | log.info("XRAN Default Store Stopped"); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public List<RnibLink> getLinks() { |
| 88 | List<RnibLink> list = Lists.newArrayList(); |
| 89 | list.addAll(linkMap.values()); |
| 90 | return list; |
| 91 | } |
| 92 | |
| 93 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 94 | public List<RnibLink> getlinksbyecgi(ECGI ecgi) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 95 | List<RnibLink> list = Lists.newArrayList(); |
| 96 | list.addAll( |
| 97 | linkMap.keySet() |
| 98 | .stream() |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 99 | .filter(k -> k.getEcgi().equals(ecgi)) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 100 | .map(v -> linkMap.get(v)) |
| 101 | .collect(Collectors.toList())); |
| 102 | |
| 103 | return list; |
| 104 | } |
| 105 | |
| 106 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 107 | public List<RnibLink> getlinksbycellid(String eciHex) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 108 | List<RnibLink> list = Lists.newArrayList(); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 109 | EUTRANCellIdentifier eci = hexToEci(eciHex); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 110 | |
| 111 | list.addAll( |
| 112 | linkMap.keySet() |
| 113 | .stream() |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 114 | .filter(k -> k.getEcgi().getEUTRANcellIdentifier().equals(eci)) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 115 | .map(v -> linkMap.get(v)) |
| 116 | .collect(Collectors.toList())); |
| 117 | |
| 118 | return list; |
| 119 | } |
| 120 | |
| 121 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 122 | public List<RnibLink> getlinksbyueid(long euId) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 123 | List<RnibLink> list = Lists.newArrayList(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 124 | |
| 125 | list.addAll( |
| 126 | linkMap.keySet() |
| 127 | .stream() |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 128 | .filter(k -> k.getUeId().equals(euId)) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 129 | .map(v -> linkMap.get(v)) |
| 130 | .collect(Collectors.toList())); |
| 131 | |
| 132 | return list; |
| 133 | } |
| 134 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 135 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 136 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 137 | public RnibLink getlinkbetweencellidueid(String eciHex, long euId) { |
| 138 | EUTRANCellIdentifier eci = hexToEci(eciHex); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 139 | |
| 140 | Optional<LinkId> first = linkMap.keySet() |
| 141 | .stream() |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 142 | .filter(linkId -> linkId.getEcgi().getEUTRANcellIdentifier().equals(eci) && |
| 143 | linkId.getUeId().equals(euId)) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 144 | .findFirst(); |
| 145 | |
| 146 | return first.map(linkId -> linkMap.get(linkId)).orElse(null); |
| 147 | } |
| 148 | |
| 149 | @Override |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 150 | public void storeLink(RnibLink link) { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 151 | synchronized (this) { |
| 152 | if (link.getLinkId() != null) { |
| 153 | // if we add a primary link then change the primary to non serving |
| 154 | if (link.getType().equals(RnibLink.Type.SERVING_PRIMARY)) { |
| 155 | RnibUe ue = link.getLinkId().getUe(); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 156 | getlinksbyueid(ue.getId()) |
| 157 | .stream() |
| 158 | .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY)) |
| 159 | .forEach(l -> l.setType(RnibLink.Type.NON_SERVING)); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 160 | } |
| 161 | linkMap.put(link.getLinkId(), link); |
| 162 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public boolean removeLink(LinkId link) { |
| 168 | return linkMap.remove(link) != null; |
| 169 | } |
| 170 | |
| 171 | @Override |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 172 | public RnibLink getLink(ECGI ecgi, Long ueId) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 173 | LinkId linkId = LinkId.valueOf(ecgi, ueId); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 174 | return linkMap.get(linkId); |
| 175 | } |
| 176 | |
| 177 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 178 | public void modifylinkrrmconf(RnibLink link, JsonNode rrmConf) { |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 179 | link.modifyRrmParameters(rrmConf); |
| 180 | } |
| 181 | |
| 182 | @Override |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 183 | public List<Object> getNodes() { |
| 184 | List<Object> list = Lists.newArrayList(); |
| 185 | list.add(cellMap.values()); |
| 186 | list.add(ueMap.values()); |
| 187 | return list; |
| 188 | } |
| 189 | |
| 190 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 191 | public List<Object> getcellnodes() { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 192 | List<Object> list = Lists.newArrayList(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 193 | list.addAll(cellMap.values()); |
| 194 | return list; |
| 195 | } |
| 196 | |
| 197 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 198 | public List<Object> getuenodes() { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 199 | List<Object> list = Lists.newArrayList(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 200 | list.addAll(ueMap.values()); |
| 201 | return list; |
| 202 | } |
| 203 | |
| 204 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 205 | public Object getbynodeid(String nodeId) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 206 | try { |
| 207 | return getCell(nodeId); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 208 | } catch (Exception ignored) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 209 | } |
| 210 | return getUe(Long.parseLong(nodeId)); |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public void storeCell(RnibCell cell) { |
| 215 | if (cell.getEcgi() != null) { |
| 216 | cellMap.putIfAbsent(cell.getEcgi(), cell); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | @Override |
| 221 | public boolean removeCell(ECGI ecgi) { |
| 222 | return cellMap.remove(ecgi) != null; |
| 223 | } |
| 224 | |
| 225 | @Override |
| 226 | public RnibCell getCell(String hexeci) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 227 | EUTRANCellIdentifier eci = hexToEci(hexeci); |
| 228 | Optional<ECGI> first = cellMap.keySet() |
| 229 | .stream() |
| 230 | .filter(ecgi -> ecgi.getEUTRANcellIdentifier().equals(eci)) |
| 231 | .findFirst(); |
| 232 | return first.map(ecgi -> cellMap.get(ecgi)) |
| 233 | .orElse(null); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | @Override |
| 237 | public RnibCell getCell(ECGI ecgi) { |
| 238 | return cellMap.get(ecgi); |
| 239 | } |
| 240 | |
| 241 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 242 | public void modifycellrrmconf(RnibCell cell, JsonNode rrmConf) throws Exception { |
| 243 | List<RnibLink> linkList = getlinksbyecgi(cell.getEcgi()); |
| 244 | List<RnibUe> ueList = linkList.stream() |
| 245 | .map(link -> link.getLinkId().getUe()) |
| 246 | .collect(Collectors.toList()); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 247 | |
| 248 | cell.modifyRrmConfig(rrmConf, ueList); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public RnibSlice getSlice(long sliceId) { |
| 253 | if (sliceMap.containsKey(sliceId)) { |
| 254 | return sliceMap.get(sliceId); |
| 255 | } |
| 256 | return null; |
| 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public boolean createSlice(ObjectNode attributes) { |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | @Override |
| 265 | public boolean removeCell(long sliceId) { |
| 266 | return sliceMap.remove(sliceId) != null; |
| 267 | } |
| 268 | |
| 269 | @Override |
| 270 | public XranController getController() { |
| 271 | return controller; |
| 272 | } |
| 273 | |
| 274 | @Override |
| 275 | public void setController(XranController controller) { |
| 276 | this.controller = controller; |
| 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public void storeUe(RnibUe ue) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 281 | long newId = ueIdGenerator.getNewId(); |
| 282 | ue.setId(newId); |
| 283 | ueMap.put(newId, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Override |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 287 | public boolean removeUe(long ueId) { |
| 288 | return ueMap.remove(ueId) != null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | @Override |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 292 | public RnibUe getUe(long ueId) { |
| 293 | return ueMap.get(ueId); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 294 | } |
| 295 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 296 | /** |
| 297 | * Get from HEX string the according ECI class object. |
| 298 | * |
| 299 | * @param eciHex HEX string |
| 300 | * @return ECI object if created successfully |
| 301 | */ |
| 302 | private EUTRANCellIdentifier hexToEci(String eciHex) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 303 | byte[] hexBinary = DatatypeConverter.parseHexBinary(eciHex); |
| 304 | return new EUTRANCellIdentifier(hexBinary, 28); |
| 305 | } |
| 306 | } |