blob: 1938a7957d8b96777f8b15c9c1346fefaedf99ca [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
slowrd337c932017-08-18 13:54:02 -070019import com.google.common.base.Objects;
slowr13fa5b02017-08-08 16:32:31 -070020import com.google.common.collect.BiMap;
21import com.google.common.collect.HashBiMap;
22import io.netty.channel.ChannelHandlerContext;
slowrd337c932017-08-18 13:54:02 -070023import javafx.util.Pair;
slowr13fa5b02017-08-08 16:32:31 -070024import org.onosproject.net.HostId;
25import org.onosproject.xran.XranStore;
26import org.onosproject.xran.codecs.api.CRNTI;
slowrd337c932017-08-18 13:54:02 -070027import org.onosproject.xran.codecs.api.ECGI;
slowr13fa5b02017-08-08 16:32:31 -070028import org.onosproject.xran.codecs.api.ENBUES1APID;
29import org.onosproject.xran.codecs.api.MMEUES1APID;
slowrd337c932017-08-18 13:54:02 -070030import org.onosproject.xran.entities.RnibCell;
slowr13fa5b02017-08-08 16:32:31 -070031import org.onosproject.xran.entities.RnibUe;
32
33import java.util.concurrent.ConcurrentHashMap;
34import java.util.concurrent.ConcurrentMap;
35
36public class UeMap {
slowrd337c932017-08-18 13:54:02 -070037 private BiMap<EcgiCrntiPair, MMEUES1APID> crntUe = HashBiMap.create();
slowr13fa5b02017-08-08 16:32:31 -070038
39 private XranStore xranStore;
40
41 public UeMap(XranStore xranStore) {
42 this.xranStore = xranStore;
43 }
44
slowrd337c932017-08-18 13:54:02 -070045 public BiMap<EcgiCrntiPair, MMEUES1APID> getCrntUe() {
46 return crntUe;
47 }
48
49 public void putCrnti(RnibCell cell, RnibUe ue) {
50 CRNTI ranId = ue.getRanId();
51 ECGI ecgi = cell.getEcgi();
52 if (ranId != null && ecgi != null) {
53 crntUe.put(EcgiCrntiPair.valueOf(cell.getEcgi(),ue.getRanId()), ue.getMmeS1apId());
54 }
55 }
56
57 public void put(RnibCell cell, RnibUe ue) {
slowr13fa5b02017-08-08 16:32:31 -070058
59 MMEUES1APID mmeS1apId = ue.getMmeS1apId();
60 if (mmeS1apId != null) {
61 xranStore.storeUe(ue);
slowrd337c932017-08-18 13:54:02 -070062 putCrnti(cell, ue);
slowr13fa5b02017-08-08 16:32:31 -070063 }
64 }
65
slowrd337c932017-08-18 13:54:02 -070066 public RnibUe get(ECGI ecgi, CRNTI crnti) {
67 MMEUES1APID mme = crntUe.get(EcgiCrntiPair.valueOf(ecgi, crnti));
slowr13fa5b02017-08-08 16:32:31 -070068 if (mme != null) {
69 return xranStore.getUe(mme);
70 }
71 return null;
72 }
73
74 public RnibUe get(MMEUES1APID mme) {
75 if (mme != null) {
76 return xranStore.getUe(mme);
77 }
78 return null;
79 }
80
81 public boolean remove(MMEUES1APID id) {
82 crntUe.inverse().remove(id);
83 return xranStore.removeUe(id);
84 }
slowrd337c932017-08-18 13:54:02 -070085
86 public static class EcgiCrntiPair extends Pair<ECGI, CRNTI> {
87
88 /**
89 * Creates a new pair
90 *
91 * @param key The key for this pair
92 * @param value The value to use for this pair
93 */
94 public EcgiCrntiPair(ECGI key, CRNTI value) {
95 super(key, value);
96 }
97
98 public static EcgiCrntiPair valueOf(ECGI key, CRNTI value) {
99 return new EcgiCrntiPair(key, value);
100 }
101
102 @Override
103 public int hashCode() {
104 return Objects.hashCode(getKey(), getValue());
105 }
106
107 @Override
108 public boolean equals(Object o) {
109 if (o instanceof EcgiCrntiPair) {
110 return ((EcgiCrntiPair) o).getKey().equals(getKey()) &&
111 ((EcgiCrntiPair) o).getValue().equals(getValue());
112 }
113 return super.equals(o);
114 }
115 }
slowr13fa5b02017-08-08 16:32:31 -0700116}