blob: 66851897ad25006fa07ec1f456a3375c0b7232d4 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
slowr577f3222017-08-28 10:49:08 -07002 * Copyright 2015-present Open Networking Foundation
slowr13fa5b02017-08-08 16:32:31 -07003 *
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
17package org.onosproject.xran.wrapper;
18
19import com.google.common.collect.BiMap;
20import com.google.common.collect.HashBiMap;
21import io.netty.channel.ChannelHandlerContext;
slowr13fa5b02017-08-08 16:32:31 -070022import org.onosproject.xran.XranStore;
23import org.onosproject.xran.codecs.api.ECGI;
24import org.onosproject.xran.codecs.api.PCIARFCN;
25import org.onosproject.xran.entities.RnibCell;
slowr13fa5b02017-08-08 16:32:31 -070026
27import java.util.concurrent.ConcurrentHashMap;
28import java.util.concurrent.ConcurrentMap;
29
slowr577f3222017-08-28 10:49:08 -070030/**
31 * CELL wrapper to help put/get/remove.
32 */
slowr13fa5b02017-08-08 16:32:31 -070033public class CellMap {
slowr577f3222017-08-28 10:49:08 -070034 // map to get the context channel based on ecgi
slowr13fa5b02017-08-08 16:32:31 -070035 private ConcurrentMap<ECGI, ChannelHandlerContext> ecgiCtx = new ConcurrentHashMap<>();
36
slowr577f3222017-08-28 10:49:08 -070037 // pci-arfcn to ecgi bimap
slowr13fa5b02017-08-08 16:32:31 -070038 private BiMap<PCIARFCN, ECGI> pciarfcnMap = HashBiMap.create();
39 private XranStore xranStore;
40
41 public CellMap(XranStore xranStore) {
42 this.xranStore = xranStore;
43 }
44
slowr577f3222017-08-28 10:49:08 -070045 /**
46 * Put the PCI-ARFCN to ECGI map from new cell.
47 *
48 * @param value CELL entity
49 */
slowr13fa5b02017-08-08 16:32:31 -070050 public void putPciArfcn(RnibCell value) {
slowr577f3222017-08-28 10:49:08 -070051 PCIARFCN pciarfcn = PCIARFCN.valueOf(value.getConf().getPci(), value.getConf().getEarfcnDl());
slowr13fa5b02017-08-08 16:32:31 -070052 pciarfcnMap.put(pciarfcn, value.getEcgi());
53 }
54
slowr577f3222017-08-28 10:49:08 -070055 /**
56 * Put inside ECGI to CTX map.
57 *
58 * @param value CELL entity to get ECGI from
59 * @param ctx context channel
60 */
slowr13fa5b02017-08-08 16:32:31 -070061 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
slowr577f3222017-08-28 10:49:08 -070068 /**
69 * Get cell based on PCI-ARFCN.
70 *
71 * @param id PCI-ARFCN
72 * @return CELL entity if found
73 */
slowr13fa5b02017-08-08 16:32:31 -070074 public RnibCell get(PCIARFCN id) {
slowr577f3222017-08-28 10:49:08 -070075 ECGI ecgi;
slowr13fa5b02017-08-08 16:32:31 -070076 ecgi = pciarfcnMap.get(id);
77
78 if (ecgi != null) {
79 return xranStore.getCell(ecgi);
80 }
81 return null;
82 }
83
slowr577f3222017-08-28 10:49:08 -070084 /**
85 * Get cell based on ECGI.
86 *
87 * @param ecgi CELL ECGI
88 * @return CELL entity if found
89 */
slowr13fa5b02017-08-08 16:32:31 -070090 public RnibCell get(ECGI ecgi) {
91 if (ecgi != null) {
92 return xranStore.getCell(ecgi);
93 }
94 return null;
95 }
96
slowr577f3222017-08-28 10:49:08 -070097 /**
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 */
slowr13fa5b02017-08-08 16:32:31 -0700103 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
slowr577f3222017-08-28 10:49:08 -0700119 /**
120 * Get context handler for specified ECGI.
121 *
122 * @param id CELL ECGI
123 * @return context handler if found
124 */
slowr13fa5b02017-08-08 16:32:31 -0700125 public ChannelHandlerContext getCtx(ECGI id) {
126 return ecgiCtx.get(id);
127 }
128
129}