blob: 6ebab7040d56831164564f64eaec56bdf8fcd9da [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;
slowr13fa5b02017-08-08 16:32:31 -070021import org.onosproject.xran.XranStore;
22import org.onosproject.xran.codecs.api.CRNTI;
slowrd337c932017-08-18 13:54:02 -070023import org.onosproject.xran.codecs.api.ECGI;
slowrd337c932017-08-18 13:54:02 -070024import org.onosproject.xran.entities.RnibCell;
slowr13fa5b02017-08-08 16:32:31 -070025import org.onosproject.xran.entities.RnibUe;
slowrc86750e2017-08-22 17:26:47 -070026import org.onosproject.xran.identifiers.EcgiCrntiPair;
slowr13fa5b02017-08-08 16:32:31 -070027
slowr577f3222017-08-28 10:49:08 -070028/**
29 * UE wrapper to help put/get/remove.
30 */
slowr13fa5b02017-08-08 16:32:31 -070031public class UeMap {
slowr577f3222017-08-28 10:49:08 -070032 // ECGI, CRNTI pair of primary cell for specified UE.
slowrc86750e2017-08-22 17:26:47 -070033 private BiMap<EcgiCrntiPair, Long> crntUe = HashBiMap.create();
slowr13fa5b02017-08-08 16:32:31 -070034
35 private XranStore xranStore;
36
37 public UeMap(XranStore xranStore) {
38 this.xranStore = xranStore;
39 }
40
slowr577f3222017-08-28 10:49:08 -070041 /**
42 * Get the ECGI, CRNTI to UE bimap.
43 *
44 * @return BiMap of EcgiCrntiPair to Long
45 */
slowrc86750e2017-08-22 17:26:47 -070046 public BiMap<EcgiCrntiPair, Long> getCrntUe() {
slowrd337c932017-08-18 13:54:02 -070047 return crntUe;
48 }
49
slowr577f3222017-08-28 10:49:08 -070050 /**
51 * Put new ECGI, CRNTI pair of primary link to UE and remove old one.
52 *
53 * @param cell new primary CELL
54 * @param ue UE
55 */
slowrd337c932017-08-18 13:54:02 -070056 public void putCrnti(RnibCell cell, RnibUe ue) {
slowr577f3222017-08-28 10:49:08 -070057 CRNTI crnti = ue.getCrnti();
slowrd337c932017-08-18 13:54:02 -070058 ECGI ecgi = cell.getEcgi();
slowr577f3222017-08-28 10:49:08 -070059
60 if (crnti != null && ecgi != null) {
61 // check if there is an ecgi, crnti pair for this UE id.
slowrc86750e2017-08-22 17:26:47 -070062 EcgiCrntiPair oldPair = crntUe.inverse().get(ue.getId()),
63 newPair = EcgiCrntiPair.valueOf(cell.getEcgi(), ue.getCrnti());
64 if (oldPair == null) {
65 crntUe.put(newPair, ue.getId());
66 } else {
slowr577f3222017-08-28 10:49:08 -070067 // remove old pair and add the new pair which corresponds to the primary cell.
slowrc86750e2017-08-22 17:26:47 -070068 crntUe.inverse().remove(ue.getId());
69 crntUe.put(newPair, ue.getId());
70 }
slowrd337c932017-08-18 13:54:02 -070071 }
72 }
73
slowr577f3222017-08-28 10:49:08 -070074 /**
75 * Put new UE to the store and update the ECGI, CRNTI pair.
76 *
77 * @param cell new primary CELL
78 * @param ue UE
79 */
slowrd337c932017-08-18 13:54:02 -070080 public void put(RnibCell cell, RnibUe ue) {
slowrc86750e2017-08-22 17:26:47 -070081 xranStore.storeUe(ue);
slowr577f3222017-08-28 10:49:08 -070082 // after adding new primary cell update the bimap as well.
slowrc86750e2017-08-22 17:26:47 -070083 putCrnti(cell, ue);
slowr13fa5b02017-08-08 16:32:31 -070084 }
85
slowr577f3222017-08-28 10:49:08 -070086 /**
87 * Get UE based on ECGI and CRNTI.
88 *
89 * @param ecgi CELL ECGI
90 * @param crnti CELL unique CRNTI
91 * @return UE entity if found
92 */
slowrd337c932017-08-18 13:54:02 -070093 public RnibUe get(ECGI ecgi, CRNTI crnti) {
slowrc86750e2017-08-22 17:26:47 -070094 Long aLong = crntUe.get(EcgiCrntiPair.valueOf(ecgi, crnti));
95 if (aLong != null) {
96 return xranStore.getUe(aLong);
slowr13fa5b02017-08-08 16:32:31 -070097 }
98 return null;
99 }
100
slowr577f3222017-08-28 10:49:08 -0700101 /**
102 * Get UE based on its id.
103 *
104 * @param ueId UE id
105 * @return UE entity if found
106 */
slowrc86750e2017-08-22 17:26:47 -0700107 public RnibUe get(Long ueId) {
108 return xranStore.getUe(ueId);
slowr13fa5b02017-08-08 16:32:31 -0700109 }
110
slowr577f3222017-08-28 10:49:08 -0700111 /**
112 * Remove UE based on its id.
113 *
114 * @param ueId UE id
115 * @return true if remove succeeded
116 */
slowrc86750e2017-08-22 17:26:47 -0700117 public boolean remove(Long ueId) {
118 crntUe.inverse().remove(ueId);
119 return xranStore.removeUe(ueId);
slowrd337c932017-08-18 13:54:02 -0700120 }
slowr13fa5b02017-08-08 16:32:31 -0700121}