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; |
| 21 | import io.netty.channel.ChannelHandlerContext; |
| 22 | import org.onosproject.net.HostId; |
| 23 | import org.onosproject.xran.XranStore; |
| 24 | import org.onosproject.xran.codecs.api.CRNTI; |
| 25 | import org.onosproject.xran.codecs.api.ENBUES1APID; |
| 26 | import org.onosproject.xran.codecs.api.MMEUES1APID; |
| 27 | import org.onosproject.xran.entities.RnibUe; |
| 28 | |
| 29 | import java.util.concurrent.ConcurrentHashMap; |
| 30 | import java.util.concurrent.ConcurrentMap; |
| 31 | |
| 32 | public class UeMap { |
| 33 | private BiMap<CRNTI, MMEUES1APID> crntUe = HashBiMap.create(); |
| 34 | |
| 35 | private XranStore xranStore; |
| 36 | |
| 37 | public UeMap(XranStore xranStore) { |
| 38 | this.xranStore = xranStore; |
| 39 | } |
| 40 | |
| 41 | public void put(RnibUe ue) { |
| 42 | |
| 43 | MMEUES1APID mmeS1apId = ue.getMmeS1apId(); |
| 44 | if (mmeS1apId != null) { |
| 45 | xranStore.storeUe(ue); |
| 46 | } |
| 47 | |
| 48 | CRNTI ranId = ue.getRanId(); |
| 49 | if (ranId != null) { |
| 50 | crntUe.put(ranId, ue.getMmeS1apId()); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | public RnibUe get(CRNTI id) { |
| 55 | MMEUES1APID mme = crntUe.get(id); |
| 56 | if (mme != null) { |
| 57 | return xranStore.getUe(mme); |
| 58 | } |
| 59 | return null; |
| 60 | } |
| 61 | |
| 62 | public RnibUe get(MMEUES1APID mme) { |
| 63 | if (mme != null) { |
| 64 | return xranStore.getUe(mme); |
| 65 | } |
| 66 | return null; |
| 67 | } |
| 68 | |
| 69 | public boolean remove(MMEUES1APID id) { |
| 70 | crntUe.inverse().remove(id); |
| 71 | return xranStore.removeUe(id); |
| 72 | } |
| 73 | } |