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.wrapper; |
| 18 | |
| 19 | import org.onosproject.xran.XranStore; |
| 20 | import org.onosproject.xran.codecs.api.CRNTI; |
| 21 | import org.onosproject.xran.codecs.api.ECGI; |
| 22 | import org.onosproject.xran.codecs.api.MMEUES1APID; |
| 23 | import org.onosproject.xran.entities.RnibCell; |
| 24 | import org.onosproject.xran.entities.RnibLink; |
| 25 | import org.onosproject.xran.entities.RnibUe; |
| 26 | import org.onosproject.xran.identifiers.LinkId; |
| 27 | import org.slf4j.Logger; |
| 28 | |
| 29 | import java.util.List; |
| 30 | import java.util.Optional; |
| 31 | import java.util.concurrent.ConcurrentHashMap; |
| 32 | import java.util.concurrent.ConcurrentMap; |
| 33 | |
| 34 | import static org.slf4j.LoggerFactory.getLogger; |
| 35 | |
| 36 | public class LinkMap { |
| 37 | private static final Logger log = getLogger(LinkMap.class); |
| 38 | |
| 39 | private ConcurrentMap<CRNTI, MMEUES1APID> crntiMme = new ConcurrentHashMap<>(); |
| 40 | |
| 41 | private XranStore xranStore; |
| 42 | |
| 43 | public LinkMap(XranStore xranStore) { |
| 44 | this.xranStore = xranStore; |
| 45 | } |
| 46 | |
| 47 | public void putPrimaryLink(RnibCell cell, RnibUe ue) { |
| 48 | RnibLink link = new RnibLink(); |
| 49 | link.setLinkId(cell, ue); |
| 50 | link.setType(RnibLink.Type.SERVING_PRIMARY); |
| 51 | xranStore.getLinksByUeId(ue.getMmeS1apId().longValue()) |
| 52 | .forEach(l -> l.setType(RnibLink.Type.SERVING_SECONDARY)); |
| 53 | xranStore.storeLink(link); |
| 54 | crntiMme.put(ue.getRanId(), ue.getMmeS1apId()); |
| 55 | } |
| 56 | |
| 57 | public RnibLink putNonServingLink(RnibCell cell, CRNTI crnti) { |
| 58 | RnibLink link = null; |
| 59 | MMEUES1APID mmeues1APID = crntiMme.get(crnti); |
| 60 | |
| 61 | if (mmeues1APID != null) { |
| 62 | link = new RnibLink(); |
| 63 | RnibUe ue = xranStore.getUe(mmeues1APID); |
| 64 | link.setLinkId(cell, ue); |
| 65 | link.setType(RnibLink.Type.NON_SERVING); |
| 66 | xranStore.storeLink(link); |
| 67 | } else { |
| 68 | log.error("Could not find mapping for CRNTI to UE. Aborting creation of non-serving link"); |
| 69 | } |
| 70 | return link; |
| 71 | } |
| 72 | |
| 73 | public RnibLink get(ECGI src, MMEUES1APID dst) { |
| 74 | if (src != null && dst != null) { |
| 75 | return xranStore.getLink(src, dst); |
| 76 | } |
| 77 | return null; |
| 78 | } |
| 79 | |
| 80 | public RnibLink get(ECGI src, CRNTI dst) { |
| 81 | MMEUES1APID mmeues1APID = crntiMme.get(dst); |
| 82 | |
| 83 | if (mmeues1APID != null) { |
| 84 | return xranStore.getLink(src, mmeues1APID); |
| 85 | } |
| 86 | return null; |
| 87 | } |
| 88 | |
| 89 | public boolean remove(ECGI src, MMEUES1APID dst) { |
| 90 | RnibLink link = xranStore.getLink(src, dst); |
| 91 | |
| 92 | if (link != null) { |
| 93 | LinkId linkId = link.getLinkId(); |
| 94 | if (linkId != null) { |
| 95 | return xranStore.removeLink(linkId); |
| 96 | } |
| 97 | } |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | public boolean remove(ECGI src, CRNTI dst) { |
| 102 | MMEUES1APID mmeues1APID = crntiMme.get(dst); |
| 103 | |
| 104 | RnibLink link = xranStore.getLink(src, mmeues1APID); |
| 105 | if (link != null) { |
| 106 | LinkId linkId = link.getLinkId(); |
| 107 | if (linkId != null) { |
| 108 | return xranStore.removeLink(linkId); |
| 109 | } |
| 110 | } |
| 111 | return false; |
| 112 | } |
| 113 | |
| 114 | public ECGI getPrimaryCell(RnibUe ue) { |
| 115 | List<RnibLink> linksByUeId = xranStore.getLinksByUeId(ue.getMmeS1apId().longValue()); |
| 116 | Optional<RnibLink> primary = linksByUeId.stream().filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY)).findFirst(); |
| 117 | |
| 118 | if (primary.isPresent()) { |
| 119 | return primary.get().getLinkId().getSource(); |
| 120 | } |
| 121 | return null; |
| 122 | } |
| 123 | } |