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