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; |
| 21 | import io.netty.channel.ChannelHandlerContext; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 22 | import org.onosproject.xran.XranStore; |
| 23 | import org.onosproject.xran.codecs.api.ECGI; |
| 24 | import org.onosproject.xran.codecs.api.PCIARFCN; |
| 25 | import org.onosproject.xran.entities.RnibCell; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 26 | |
| 27 | import java.util.concurrent.ConcurrentHashMap; |
| 28 | import java.util.concurrent.ConcurrentMap; |
| 29 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 30 | /** |
| 31 | * CELL wrapper to help put/get/remove. |
| 32 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 33 | public class CellMap { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 34 | // map to get the context channel based on ecgi |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 35 | private ConcurrentMap<ECGI, ChannelHandlerContext> ecgiCtx = new ConcurrentHashMap<>(); |
| 36 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 37 | // pci-arfcn to ecgi bimap |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 38 | private BiMap<PCIARFCN, ECGI> pciarfcnMap = HashBiMap.create(); |
| 39 | private XranStore xranStore; |
| 40 | |
| 41 | public CellMap(XranStore xranStore) { |
| 42 | this.xranStore = xranStore; |
| 43 | } |
| 44 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 45 | /** |
| 46 | * Put the PCI-ARFCN to ECGI map from new cell. |
| 47 | * |
| 48 | * @param value CELL entity |
| 49 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 50 | public void putPciArfcn(RnibCell value) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 51 | PCIARFCN pciarfcn = PCIARFCN.valueOf(value.getConf().getPci(), value.getConf().getEarfcnDl()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 52 | pciarfcnMap.put(pciarfcn, value.getEcgi()); |
| 53 | } |
| 54 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 55 | /** |
| 56 | * Put inside ECGI to CTX map. |
| 57 | * |
| 58 | * @param value CELL entity to get ECGI from |
| 59 | * @param ctx context channel |
| 60 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 61 | public void put(RnibCell value, ChannelHandlerContext ctx) { |
| 62 | if (value.getEcgi() != null) { |
| 63 | ecgiCtx.put(value.getEcgi(), ctx); |
| 64 | xranStore.storeCell(value); |
| 65 | } |
| 66 | } |
| 67 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Get cell based on PCI-ARFCN. |
| 70 | * |
| 71 | * @param id PCI-ARFCN |
| 72 | * @return CELL entity if found |
| 73 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 74 | public RnibCell get(PCIARFCN id) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 75 | ECGI ecgi; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 76 | ecgi = pciarfcnMap.get(id); |
| 77 | |
| 78 | if (ecgi != null) { |
| 79 | return xranStore.getCell(ecgi); |
| 80 | } |
| 81 | return null; |
| 82 | } |
| 83 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 84 | /** |
| 85 | * Get cell based on ECGI. |
| 86 | * |
| 87 | * @param ecgi CELL ECGI |
| 88 | * @return CELL entity if found |
| 89 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 90 | public RnibCell get(ECGI ecgi) { |
| 91 | if (ecgi != null) { |
| 92 | return xranStore.getCell(ecgi); |
| 93 | } |
| 94 | return null; |
| 95 | } |
| 96 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 97 | /** |
| 98 | * Remove cell from three maps based on ECGI or PCI-ARFCN. |
| 99 | * |
| 100 | * @param key ecgECGIi or pci-arfcn of cell to remove |
| 101 | * @return true if remove succeeded |
| 102 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 103 | public boolean remove(Object key) { |
| 104 | ECGI ecgi = null; |
| 105 | if (key instanceof ECGI) { |
| 106 | ecgi = (ECGI) key; |
| 107 | } else if (key instanceof PCIARFCN) { |
| 108 | ecgi = pciarfcnMap.get(key); |
| 109 | } |
| 110 | |
| 111 | if (ecgi != null) { |
| 112 | pciarfcnMap.inverse().remove(ecgi); |
| 113 | ecgiCtx.remove(ecgi); |
| 114 | } |
| 115 | |
| 116 | return ecgi != null && xranStore.removeCell(ecgi); |
| 117 | } |
| 118 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 119 | /** |
| 120 | * Get context handler for specified ECGI. |
| 121 | * |
| 122 | * @param id CELL ECGI |
| 123 | * @return context handler if found |
| 124 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 125 | public ChannelHandlerContext getCtx(ECGI id) { |
| 126 | return ecgiCtx.get(id); |
| 127 | } |
| 128 | |
| 129 | } |