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 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 | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 24 | import org.onosproject.xran.codecs.api.MMEUES1APID; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 25 | import org.onosproject.xran.entities.RnibCell; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 26 | import org.onosproject.xran.entities.RnibUe; |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 27 | import org.onosproject.xran.identifiers.EcgiCrntiPair; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 28 | |
| 29 | public class UeMap { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 30 | private BiMap<EcgiCrntiPair, Long> crntUe = HashBiMap.create(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 31 | |
| 32 | private XranStore xranStore; |
| 33 | |
| 34 | public UeMap(XranStore xranStore) { |
| 35 | this.xranStore = xranStore; |
| 36 | } |
| 37 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 38 | public BiMap<EcgiCrntiPair, Long> getCrntUe() { |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 39 | return crntUe; |
| 40 | } |
| 41 | |
| 42 | public void putCrnti(RnibCell cell, RnibUe ue) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 43 | CRNTI ranId = ue.getCrnti(); |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 44 | ECGI ecgi = cell.getEcgi(); |
| 45 | if (ranId != null && ecgi != null) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 46 | EcgiCrntiPair oldPair = crntUe.inverse().get(ue.getId()), |
| 47 | newPair = EcgiCrntiPair.valueOf(cell.getEcgi(), ue.getCrnti()); |
| 48 | if (oldPair == null) { |
| 49 | crntUe.put(newPair, ue.getId()); |
| 50 | } else { |
| 51 | crntUe.inverse().remove(ue.getId()); |
| 52 | crntUe.put(newPair, ue.getId()); |
| 53 | } |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | public void put(RnibCell cell, RnibUe ue) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 58 | xranStore.storeUe(ue); |
| 59 | putCrnti(cell, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 60 | } |
| 61 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 62 | public RnibUe get(ECGI ecgi, CRNTI crnti) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 63 | Long aLong = crntUe.get(EcgiCrntiPair.valueOf(ecgi, crnti)); |
| 64 | if (aLong != null) { |
| 65 | return xranStore.getUe(aLong); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 66 | } |
| 67 | return null; |
| 68 | } |
| 69 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 70 | public RnibUe get(Long ueId) { |
| 71 | return xranStore.getUe(ueId); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 72 | } |
| 73 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 74 | public boolean remove(Long ueId) { |
| 75 | crntUe.inverse().remove(ueId); |
| 76 | return xranStore.removeUe(ueId); |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 77 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 78 | } |