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.wrapper; |
| 18 | |
| 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; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 23 | import org.onosproject.xran.codecs.api.ECGI; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 24 | import org.onosproject.xran.entities.RnibCell; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 25 | import org.onosproject.xran.entities.RnibUe; |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 26 | import org.onosproject.xran.identifiers.EcgiCrntiPair; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 27 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 28 | /** |
| 29 | * UE wrapper to help put/get/remove. |
| 30 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 31 | public class UeMap { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 32 | // ECGI, CRNTI pair of primary cell for specified UE. |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 33 | private BiMap<EcgiCrntiPair, Long> crntUe = HashBiMap.create(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 34 | |
| 35 | private XranStore xranStore; |
| 36 | |
| 37 | public UeMap(XranStore xranStore) { |
| 38 | this.xranStore = xranStore; |
| 39 | } |
| 40 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 41 | /** |
| 42 | * Get the ECGI, CRNTI to UE bimap. |
| 43 | * |
| 44 | * @return BiMap of EcgiCrntiPair to Long |
| 45 | */ |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 46 | public BiMap<EcgiCrntiPair, Long> getCrntUe() { |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 47 | return crntUe; |
| 48 | } |
| 49 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 50 | /** |
| 51 | * Put new ECGI, CRNTI pair of primary link to UE and remove old one. |
| 52 | * |
| 53 | * @param cell new primary CELL |
| 54 | * @param ue UE |
| 55 | */ |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 56 | public void putCrnti(RnibCell cell, RnibUe ue) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 57 | CRNTI crnti = ue.getCrnti(); |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 58 | ECGI ecgi = cell.getEcgi(); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 59 | |
| 60 | if (crnti != null && ecgi != null) { |
| 61 | // check if there is an ecgi, crnti pair for this UE id. |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 62 | EcgiCrntiPair oldPair = crntUe.inverse().get(ue.getId()), |
| 63 | newPair = EcgiCrntiPair.valueOf(cell.getEcgi(), ue.getCrnti()); |
| 64 | if (oldPair == null) { |
| 65 | crntUe.put(newPair, ue.getId()); |
| 66 | } else { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 67 | // remove old pair and add the new pair which corresponds to the primary cell. |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 68 | crntUe.inverse().remove(ue.getId()); |
| 69 | crntUe.put(newPair, ue.getId()); |
| 70 | } |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 74 | /** |
| 75 | * Put new UE to the store and update the ECGI, CRNTI pair. |
| 76 | * |
| 77 | * @param cell new primary CELL |
| 78 | * @param ue UE |
| 79 | */ |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 80 | public void put(RnibCell cell, RnibUe ue) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 81 | xranStore.storeUe(ue); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 82 | // after adding new primary cell update the bimap as well. |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 83 | putCrnti(cell, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 84 | } |
| 85 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 86 | /** |
| 87 | * Get UE based on ECGI and CRNTI. |
| 88 | * |
| 89 | * @param ecgi CELL ECGI |
| 90 | * @param crnti CELL unique CRNTI |
| 91 | * @return UE entity if found |
| 92 | */ |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 93 | public RnibUe get(ECGI ecgi, CRNTI crnti) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 94 | Long aLong = crntUe.get(EcgiCrntiPair.valueOf(ecgi, crnti)); |
| 95 | if (aLong != null) { |
| 96 | return xranStore.getUe(aLong); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 97 | } |
| 98 | return null; |
| 99 | } |
| 100 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 101 | /** |
| 102 | * Get UE based on its id. |
| 103 | * |
| 104 | * @param ueId UE id |
| 105 | * @return UE entity if found |
| 106 | */ |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 107 | public RnibUe get(Long ueId) { |
| 108 | return xranStore.getUe(ueId); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 109 | } |
| 110 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 111 | /** |
| 112 | * Remove UE based on its id. |
| 113 | * |
| 114 | * @param ueId UE id |
| 115 | * @return true if remove succeeded |
| 116 | */ |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 117 | public boolean remove(Long ueId) { |
| 118 | crntUe.inverse().remove(ueId); |
| 119 | return xranStore.removeUe(ueId); |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 120 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 121 | } |