blob: ed7b4f1aa7016972e7b51b38718a7bdf68fee3f0 [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 org.onosproject.xran.XranStore;
20import org.onosproject.xran.codecs.api.CRNTI;
21import org.onosproject.xran.codecs.api.ECGI;
slowr13fa5b02017-08-08 16:32:31 -070022import org.onosproject.xran.entities.RnibCell;
23import org.onosproject.xran.entities.RnibLink;
24import org.onosproject.xran.entities.RnibUe;
slowr13fa5b02017-08-08 16:32:31 -070025import org.slf4j.Logger;
26
27import java.util.List;
28import java.util.Optional;
slowr13fa5b02017-08-08 16:32:31 -070029
30import static org.slf4j.LoggerFactory.getLogger;
31
32public class LinkMap {
33 private static final Logger log = getLogger(LinkMap.class);
slowr13fa5b02017-08-08 16:32:31 -070034
slowrd337c932017-08-18 13:54:02 -070035 private final XranStore xranStore;
36
37 private UeMap ueMap;
38
39 public LinkMap(XranStore xranStore, UeMap ueMap) {
slowr13fa5b02017-08-08 16:32:31 -070040 this.xranStore = xranStore;
slowrd337c932017-08-18 13:54:02 -070041 this.ueMap = ueMap;
slowr13fa5b02017-08-08 16:32:31 -070042 }
43
44 public void putPrimaryLink(RnibCell cell, RnibUe ue) {
slowr67d05e42017-08-11 20:37:22 -070045 RnibLink link = new RnibLink(cell, ue);
slowr13fa5b02017-08-08 16:32:31 -070046 link.setType(RnibLink.Type.SERVING_PRIMARY);
slowr89c2ac12017-08-15 16:20:06 -070047 xranStore.storeLink(link);
slowrd337c932017-08-18 13:54:02 -070048
49 ueMap.putCrnti(cell, ue);
slowr13fa5b02017-08-08 16:32:31 -070050 }
51
52 public RnibLink putNonServingLink(RnibCell cell, CRNTI crnti) {
53 RnibLink link = null;
slowrd337c932017-08-18 13:54:02 -070054 RnibUe ue = ueMap.get(cell.getEcgi(), crnti);
slowr13fa5b02017-08-08 16:32:31 -070055
slowrd337c932017-08-18 13:54:02 -070056 if (ue != null) {
slowr67d05e42017-08-11 20:37:22 -070057 link = new RnibLink(cell, ue);
slowr13fa5b02017-08-08 16:32:31 -070058 xranStore.storeLink(link);
59 } else {
60 log.error("Could not find mapping for CRNTI to UE. Aborting creation of non-serving link");
61 }
62 return link;
63 }
64
slowrc86750e2017-08-22 17:26:47 -070065 public RnibLink putNonServingLink(RnibCell cell, Long ueId) {
66 RnibLink link = null;
67 RnibUe ue = ueMap.get(ueId);
68
69 if (ue != null) {
70 link = new RnibLink(cell, ue);
71 xranStore.storeLink(link);
72 } else {
73 log.error("Could not find mapping for CRNTI to UE. Aborting creation of non-serving link");
74 }
75 return link;
76 }
77
78 public RnibLink get(ECGI src, Long dst) {
slowr13fa5b02017-08-08 16:32:31 -070079 if (src != null && dst != null) {
80 return xranStore.getLink(src, dst);
81 }
82 return null;
83 }
84
85 public RnibLink get(ECGI src, CRNTI dst) {
slowrd337c932017-08-18 13:54:02 -070086 RnibUe ue = ueMap.get(src, dst);
slowr13fa5b02017-08-08 16:32:31 -070087
slowrd337c932017-08-18 13:54:02 -070088 if (ue != null) {
slowrc86750e2017-08-22 17:26:47 -070089 return xranStore.getLink(src, ue.getId());
slowr13fa5b02017-08-08 16:32:31 -070090 }
91 return null;
92 }
93
slowrc86750e2017-08-22 17:26:47 -070094 public CRNTI getCrnti(Long ueId) {
95 return ueMap.getCrntUe().inverse().get(ueId).getValue();
slowr13fa5b02017-08-08 16:32:31 -070096 }
97
slowr89c2ac12017-08-15 16:20:06 -070098 public RnibCell getPrimaryCell(RnibUe ue) {
slowrc86750e2017-08-22 17:26:47 -070099 List<RnibLink> linksByUeId = xranStore.getLinksByUeId(ue.getId());
slowr89c2ac12017-08-15 16:20:06 -0700100 Optional<RnibLink> primary = linksByUeId.stream()
101 .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY))
102 .findFirst();
slowr13fa5b02017-08-08 16:32:31 -0700103
104 if (primary.isPresent()) {
slowr89c2ac12017-08-15 16:20:06 -0700105 return primary.get().getLinkId().getCell();
slowr13fa5b02017-08-08 16:32:31 -0700106 }
107 return null;
108 }
109}