blob: 8b2110d9ee3aee30ad80d409796f1707a08b7e12 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
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
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;
slowr13fa5b02017-08-08 16:32:31 -070024import org.onosproject.xran.codecs.api.MMEUES1APID;
slowrd337c932017-08-18 13:54:02 -070025import org.onosproject.xran.entities.RnibCell;
slowr13fa5b02017-08-08 16:32:31 -070026import org.onosproject.xran.entities.RnibUe;
slowrc86750e2017-08-22 17:26:47 -070027import org.onosproject.xran.identifiers.EcgiCrntiPair;
slowr13fa5b02017-08-08 16:32:31 -070028
29public class UeMap {
slowrc86750e2017-08-22 17:26:47 -070030 private BiMap<EcgiCrntiPair, Long> crntUe = HashBiMap.create();
slowr13fa5b02017-08-08 16:32:31 -070031
32 private XranStore xranStore;
33
34 public UeMap(XranStore xranStore) {
35 this.xranStore = xranStore;
36 }
37
slowrc86750e2017-08-22 17:26:47 -070038 public BiMap<EcgiCrntiPair, Long> getCrntUe() {
slowrd337c932017-08-18 13:54:02 -070039 return crntUe;
40 }
41
42 public void putCrnti(RnibCell cell, RnibUe ue) {
slowrc86750e2017-08-22 17:26:47 -070043 CRNTI ranId = ue.getCrnti();
slowrd337c932017-08-18 13:54:02 -070044 ECGI ecgi = cell.getEcgi();
45 if (ranId != null && ecgi != null) {
slowrc86750e2017-08-22 17:26:47 -070046 EcgiCrntiPair oldPair = crntUe.inverse().get(ue.getId()),
47 newPair = EcgiCrntiPair.valueOf(cell.getEcgi(), ue.getCrnti());
48 if (oldPair == null) {
49 crntUe.put(newPair, ue.getId());
50 } else {
51 crntUe.inverse().remove(ue.getId());
52 crntUe.put(newPair, ue.getId());
53 }
slowrd337c932017-08-18 13:54:02 -070054 }
55 }
56
57 public void put(RnibCell cell, RnibUe ue) {
slowrc86750e2017-08-22 17:26:47 -070058 xranStore.storeUe(ue);
59 putCrnti(cell, ue);
slowr13fa5b02017-08-08 16:32:31 -070060 }
61
slowrd337c932017-08-18 13:54:02 -070062 public RnibUe get(ECGI ecgi, CRNTI crnti) {
slowrc86750e2017-08-22 17:26:47 -070063 Long aLong = crntUe.get(EcgiCrntiPair.valueOf(ecgi, crnti));
64 if (aLong != null) {
65 return xranStore.getUe(aLong);
slowr13fa5b02017-08-08 16:32:31 -070066 }
67 return null;
68 }
69
slowrc86750e2017-08-22 17:26:47 -070070 public RnibUe get(Long ueId) {
71 return xranStore.getUe(ueId);
slowr13fa5b02017-08-08 16:32:31 -070072 }
73
slowrc86750e2017-08-22 17:26:47 -070074 public boolean remove(Long ueId) {
75 crntUe.inverse().remove(ueId);
76 return xranStore.removeUe(ueId);
slowrd337c932017-08-18 13:54:02 -070077 }
slowr13fa5b02017-08-08 16:32:31 -070078}