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 | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 19 | import com.google.common.base.Objects; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 20 | import com.google.common.collect.BiMap; |
| 21 | import com.google.common.collect.HashBiMap; |
| 22 | import io.netty.channel.ChannelHandlerContext; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 23 | import javafx.util.Pair; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 24 | import org.onosproject.net.HostId; |
| 25 | import org.onosproject.xran.XranStore; |
| 26 | import org.onosproject.xran.codecs.api.CRNTI; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 27 | import org.onosproject.xran.codecs.api.ECGI; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 28 | import org.onosproject.xran.codecs.api.ENBUES1APID; |
| 29 | import org.onosproject.xran.codecs.api.MMEUES1APID; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 30 | import org.onosproject.xran.entities.RnibCell; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 31 | import org.onosproject.xran.entities.RnibUe; |
| 32 | |
| 33 | import java.util.concurrent.ConcurrentHashMap; |
| 34 | import java.util.concurrent.ConcurrentMap; |
| 35 | |
| 36 | public class UeMap { |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 37 | private BiMap<EcgiCrntiPair, MMEUES1APID> crntUe = HashBiMap.create(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 38 | |
| 39 | private XranStore xranStore; |
| 40 | |
| 41 | public UeMap(XranStore xranStore) { |
| 42 | this.xranStore = xranStore; |
| 43 | } |
| 44 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 45 | public BiMap<EcgiCrntiPair, MMEUES1APID> getCrntUe() { |
| 46 | return crntUe; |
| 47 | } |
| 48 | |
| 49 | public void putCrnti(RnibCell cell, RnibUe ue) { |
| 50 | CRNTI ranId = ue.getRanId(); |
| 51 | ECGI ecgi = cell.getEcgi(); |
| 52 | if (ranId != null && ecgi != null) { |
| 53 | crntUe.put(EcgiCrntiPair.valueOf(cell.getEcgi(),ue.getRanId()), ue.getMmeS1apId()); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | public void put(RnibCell cell, RnibUe ue) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 58 | |
| 59 | MMEUES1APID mmeS1apId = ue.getMmeS1apId(); |
| 60 | if (mmeS1apId != null) { |
| 61 | xranStore.storeUe(ue); |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 62 | putCrnti(cell, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 66 | public RnibUe get(ECGI ecgi, CRNTI crnti) { |
| 67 | MMEUES1APID mme = crntUe.get(EcgiCrntiPair.valueOf(ecgi, crnti)); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 68 | if (mme != null) { |
| 69 | return xranStore.getUe(mme); |
| 70 | } |
| 71 | return null; |
| 72 | } |
| 73 | |
| 74 | public RnibUe get(MMEUES1APID mme) { |
| 75 | if (mme != null) { |
| 76 | return xranStore.getUe(mme); |
| 77 | } |
| 78 | return null; |
| 79 | } |
| 80 | |
| 81 | public boolean remove(MMEUES1APID id) { |
| 82 | crntUe.inverse().remove(id); |
| 83 | return xranStore.removeUe(id); |
| 84 | } |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 85 | |
| 86 | public static class EcgiCrntiPair extends Pair<ECGI, CRNTI> { |
| 87 | |
| 88 | /** |
| 89 | * Creates a new pair |
| 90 | * |
| 91 | * @param key The key for this pair |
| 92 | * @param value The value to use for this pair |
| 93 | */ |
| 94 | public EcgiCrntiPair(ECGI key, CRNTI value) { |
| 95 | super(key, value); |
| 96 | } |
| 97 | |
| 98 | public static EcgiCrntiPair valueOf(ECGI key, CRNTI value) { |
| 99 | return new EcgiCrntiPair(key, value); |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public int hashCode() { |
| 104 | return Objects.hashCode(getKey(), getValue()); |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public boolean equals(Object o) { |
| 109 | if (o instanceof EcgiCrntiPair) { |
| 110 | return ((EcgiCrntiPair) o).getKey().equals(getKey()) && |
| 111 | ((EcgiCrntiPair) o).getValue().equals(getValue()); |
| 112 | } |
| 113 | return super.equals(o); |
| 114 | } |
| 115 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 116 | } |