blob: 033f1327a7075500d0781e6d37c8b87f44cf2d5c [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
slowr67d05e42017-08-11 20:37:22 -070019import 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;
23import org.onosproject.xran.codecs.api.ECGI;
24import org.onosproject.xran.codecs.api.MMEUES1APID;
25import org.onosproject.xran.entities.RnibCell;
26import org.onosproject.xran.entities.RnibLink;
27import org.onosproject.xran.entities.RnibUe;
28import org.onosproject.xran.identifiers.LinkId;
29import org.slf4j.Logger;
30
31import java.util.List;
32import java.util.Optional;
slowr13fa5b02017-08-08 16:32:31 -070033
34import static org.slf4j.LoggerFactory.getLogger;
35
36public class LinkMap {
37 private static final Logger log = getLogger(LinkMap.class);
slowr67d05e42017-08-11 20:37:22 -070038 private final XranStore xranStore;
39 private BiMap<CRNTI, MMEUES1APID> crntiMme = HashBiMap.create();
slowr13fa5b02017-08-08 16:32:31 -070040
41 public LinkMap(XranStore xranStore) {
42 this.xranStore = xranStore;
43 }
44
45 public void putPrimaryLink(RnibCell cell, RnibUe ue) {
slowr67d05e42017-08-11 20:37:22 -070046 RnibLink link = new RnibLink(cell, ue);
slowr13fa5b02017-08-08 16:32:31 -070047 link.setType(RnibLink.Type.SERVING_PRIMARY);
slowr89c2ac12017-08-15 16:20:06 -070048 xranStore.storeLink(link);
slowr13fa5b02017-08-08 16:32:31 -070049 crntiMme.put(ue.getRanId(), ue.getMmeS1apId());
50 }
51
52 public RnibLink putNonServingLink(RnibCell cell, CRNTI crnti) {
53 RnibLink link = null;
54 MMEUES1APID mmeues1APID = crntiMme.get(crnti);
55
56 if (mmeues1APID != null) {
slowr13fa5b02017-08-08 16:32:31 -070057 RnibUe ue = xranStore.getUe(mmeues1APID);
slowr67d05e42017-08-11 20:37:22 -070058 link = new RnibLink(cell, ue);
slowr13fa5b02017-08-08 16:32:31 -070059 xranStore.storeLink(link);
60 } else {
61 log.error("Could not find mapping for CRNTI to UE. Aborting creation of non-serving link");
62 }
63 return link;
64 }
65
66 public RnibLink get(ECGI src, MMEUES1APID dst) {
67 if (src != null && dst != null) {
68 return xranStore.getLink(src, dst);
69 }
70 return null;
71 }
72
73 public RnibLink get(ECGI src, CRNTI dst) {
74 MMEUES1APID mmeues1APID = crntiMme.get(dst);
75
76 if (mmeues1APID != null) {
77 return xranStore.getLink(src, mmeues1APID);
78 }
79 return null;
80 }
81
slowr67d05e42017-08-11 20:37:22 -070082 public CRNTI getCrnti(MMEUES1APID mme) {
83 return crntiMme.inverse().get(mme);
84 }
85
slowr13fa5b02017-08-08 16:32:31 -070086 public boolean remove(ECGI src, MMEUES1APID dst) {
87 RnibLink link = xranStore.getLink(src, dst);
88
89 if (link != null) {
90 LinkId linkId = link.getLinkId();
91 if (linkId != null) {
92 return xranStore.removeLink(linkId);
93 }
94 }
95 return false;
96 }
97
98 public boolean remove(ECGI src, CRNTI dst) {
99 MMEUES1APID mmeues1APID = crntiMme.get(dst);
100
101 RnibLink link = xranStore.getLink(src, mmeues1APID);
102 if (link != null) {
103 LinkId linkId = link.getLinkId();
104 if (linkId != null) {
105 return xranStore.removeLink(linkId);
106 }
107 }
108 return false;
109 }
110
slowr89c2ac12017-08-15 16:20:06 -0700111 public RnibCell getPrimaryCell(RnibUe ue) {
slowr13fa5b02017-08-08 16:32:31 -0700112 List<RnibLink> linksByUeId = xranStore.getLinksByUeId(ue.getMmeS1apId().longValue());
slowr89c2ac12017-08-15 16:20:06 -0700113 Optional<RnibLink> primary = linksByUeId.stream()
114 .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY))
115 .findFirst();
slowr13fa5b02017-08-08 16:32:31 -0700116
117 if (primary.isPresent()) {
slowr89c2ac12017-08-15 16:20:06 -0700118 return primary.get().getLinkId().getCell();
slowr13fa5b02017-08-08 16:32:31 -0700119 }
120 return null;
121 }
122}