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.DeviceId; |
| 23 | import org.onosproject.xran.XranStore; |
| 24 | import org.onosproject.xran.codecs.api.ECGI; |
| 25 | import org.onosproject.xran.codecs.api.PCIARFCN; |
| 26 | import org.onosproject.xran.entities.RnibCell; |
| 27 | import org.slf4j.Logger; |
| 28 | import org.slf4j.LoggerFactory; |
| 29 | |
| 30 | import java.util.concurrent.ConcurrentHashMap; |
| 31 | import java.util.concurrent.ConcurrentMap; |
| 32 | |
| 33 | public class CellMap { |
| 34 | private ConcurrentMap<ECGI, ChannelHandlerContext> ecgiCtx = new ConcurrentHashMap<>(); |
| 35 | |
| 36 | private BiMap<PCIARFCN, ECGI> pciarfcnMap = HashBiMap.create(); |
| 37 | private XranStore xranStore; |
| 38 | |
| 39 | public CellMap(XranStore xranStore) { |
| 40 | this.xranStore = xranStore; |
| 41 | } |
| 42 | |
| 43 | public void putPciArfcn(RnibCell value) { |
| 44 | PCIARFCN pciarfcn = new PCIARFCN(); |
| 45 | pciarfcn.setPci(value.getConf().getPci()); |
| 46 | pciarfcn.setEarfcnDl(value.getConf().getEarfcnDl()); |
| 47 | pciarfcnMap.put(pciarfcn, value.getEcgi()); |
| 48 | } |
| 49 | |
| 50 | public void put(RnibCell value, ChannelHandlerContext ctx) { |
| 51 | if (value.getEcgi() != null) { |
| 52 | ecgiCtx.put(value.getEcgi(), ctx); |
| 53 | xranStore.storeCell(value); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | public RnibCell get(PCIARFCN id) { |
| 58 | ECGI ecgi = null; |
| 59 | ecgi = pciarfcnMap.get(id); |
| 60 | |
| 61 | if (ecgi != null) { |
| 62 | return xranStore.getCell(ecgi); |
| 63 | } |
| 64 | return null; |
| 65 | } |
| 66 | |
| 67 | public RnibCell get(ECGI ecgi) { |
| 68 | if (ecgi != null) { |
| 69 | return xranStore.getCell(ecgi); |
| 70 | } |
| 71 | return null; |
| 72 | } |
| 73 | |
| 74 | public boolean remove(Object key) { |
| 75 | ECGI ecgi = null; |
| 76 | if (key instanceof ECGI) { |
| 77 | ecgi = (ECGI) key; |
| 78 | } else if (key instanceof PCIARFCN) { |
| 79 | ecgi = pciarfcnMap.get(key); |
| 80 | } |
| 81 | |
| 82 | if (ecgi != null) { |
| 83 | pciarfcnMap.inverse().remove(ecgi); |
| 84 | ecgiCtx.remove(ecgi); |
| 85 | } |
| 86 | |
| 87 | return ecgi != null && xranStore.removeCell(ecgi); |
| 88 | } |
| 89 | |
| 90 | public ChannelHandlerContext getCtx(ECGI id) { |
| 91 | return ecgiCtx.get(id); |
| 92 | } |
| 93 | |
| 94 | } |