blob: 543879dec69f89a06638583864354c0736739fac [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 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
slowr577f3222017-08-28 10:49:08 -070032/**
33 * LINK wrapper to help put/get/remove.
34 */
slowr13fa5b02017-08-08 16:32:31 -070035public class LinkMap {
36 private static final Logger log = getLogger(LinkMap.class);
slowr13fa5b02017-08-08 16:32:31 -070037
slowrd337c932017-08-18 13:54:02 -070038 private final XranStore xranStore;
39
40 private UeMap ueMap;
41
42 public LinkMap(XranStore xranStore, UeMap ueMap) {
slowr13fa5b02017-08-08 16:32:31 -070043 this.xranStore = xranStore;
slowrd337c932017-08-18 13:54:02 -070044 this.ueMap = ueMap;
slowr13fa5b02017-08-08 16:32:31 -070045 }
46
slowr577f3222017-08-28 10:49:08 -070047 /**
48 * Put a new primary link between a CELL and a UE.
49 *
50 * @param cell CELL entity
51 * @param ue UE entity
52 */
slowr13fa5b02017-08-08 16:32:31 -070053 public void putPrimaryLink(RnibCell cell, RnibUe ue) {
slowr67d05e42017-08-11 20:37:22 -070054 RnibLink link = new RnibLink(cell, ue);
slowr577f3222017-08-28 10:49:08 -070055 // set link to primary before storing
slowr13fa5b02017-08-08 16:32:31 -070056 link.setType(RnibLink.Type.SERVING_PRIMARY);
slowr89c2ac12017-08-15 16:20:06 -070057 xranStore.storeLink(link);
slowrd337c932017-08-18 13:54:02 -070058
59 ueMap.putCrnti(cell, ue);
slowr13fa5b02017-08-08 16:32:31 -070060 }
61
slowr577f3222017-08-28 10:49:08 -070062 /**
63 * Put non-serving link based on CELL and CRNTI.
64 *
65 * @param cell CELL entity
66 * @param crnti CRNTI
67 * @return new link after creation
68 */
slowr13fa5b02017-08-08 16:32:31 -070069 public RnibLink putNonServingLink(RnibCell cell, CRNTI crnti) {
70 RnibLink link = null;
slowrd337c932017-08-18 13:54:02 -070071 RnibUe ue = ueMap.get(cell.getEcgi(), crnti);
slowr13fa5b02017-08-08 16:32:31 -070072
slowrd337c932017-08-18 13:54:02 -070073 if (ue != null) {
slowr67d05e42017-08-11 20:37:22 -070074 link = new RnibLink(cell, ue);
slowr13fa5b02017-08-08 16:32:31 -070075 xranStore.storeLink(link);
76 } else {
77 log.error("Could not find mapping for CRNTI to UE. Aborting creation of non-serving link");
78 }
79 return link;
80 }
81
slowr577f3222017-08-28 10:49:08 -070082 /**
83 * Put non-serving link based on CELL and UE id.
84 *
85 * @param cell CELL entity
86 * @param ueId UE id
87 * @return new link after creation
88 */
slowrc86750e2017-08-22 17:26:47 -070089 public RnibLink putNonServingLink(RnibCell cell, Long ueId) {
90 RnibLink link = null;
91 RnibUe ue = ueMap.get(ueId);
92
93 if (ue != null) {
94 link = new RnibLink(cell, ue);
95 xranStore.storeLink(link);
96 } else {
97 log.error("Could not find mapping for CRNTI to UE. Aborting creation of non-serving link");
98 }
99 return link;
100 }
101
slowr577f3222017-08-28 10:49:08 -0700102 /**
103 * Get link based on ECGI and UE id.
104 *
105 * @param src CELL ECGI
106 * @param dst UE ID
107 * @return link if found
108 */
slowrc86750e2017-08-22 17:26:47 -0700109 public RnibLink get(ECGI src, Long dst) {
slowr13fa5b02017-08-08 16:32:31 -0700110 if (src != null && dst != null) {
111 return xranStore.getLink(src, dst);
112 }
113 return null;
114 }
115
slowr577f3222017-08-28 10:49:08 -0700116 /**
117 * Get link based on ECGI and CRNTI.
118 *
119 * @param src CELL ECGI
120 * @param dst CELL unique CRNTI
121 * @return link if found
122 */
slowr13fa5b02017-08-08 16:32:31 -0700123 public RnibLink get(ECGI src, CRNTI dst) {
slowrd337c932017-08-18 13:54:02 -0700124 RnibUe ue = ueMap.get(src, dst);
slowr13fa5b02017-08-08 16:32:31 -0700125
slowrd337c932017-08-18 13:54:02 -0700126 if (ue != null) {
slowrc86750e2017-08-22 17:26:47 -0700127 return xranStore.getLink(src, ue.getId());
slowr13fa5b02017-08-08 16:32:31 -0700128 }
129 return null;
130 }
131
slowr577f3222017-08-28 10:49:08 -0700132 /**
133 * Get CRNTI based on UE id.
134 *
135 * @param ueId UE id
136 * @return UE if found
137 */
slowrc86750e2017-08-22 17:26:47 -0700138 public CRNTI getCrnti(Long ueId) {
139 return ueMap.getCrntUe().inverse().get(ueId).getValue();
slowr13fa5b02017-08-08 16:32:31 -0700140 }
141
slowr577f3222017-08-28 10:49:08 -0700142 /**
143 * Get primary CELL for specified UE.
144 *
145 * @param ue UE entity
146 * @return primary CELL if found
147 */
slowr89c2ac12017-08-15 16:20:06 -0700148 public RnibCell getPrimaryCell(RnibUe ue) {
slowr577f3222017-08-28 10:49:08 -0700149 List<RnibLink> linksByUeId = xranStore.getlinksbyueid(ue.getId());
150
151 // TODO: search for primary link from crntUe in UeMap because it has the primary links only!
152 // search all links for this UE and find PRIMARY.
slowr89c2ac12017-08-15 16:20:06 -0700153 Optional<RnibLink> primary = linksByUeId.stream()
154 .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY))
155 .findFirst();
slowr13fa5b02017-08-08 16:32:31 -0700156
157 if (primary.isPresent()) {
slowr89c2ac12017-08-15 16:20:06 -0700158 return primary.get().getLinkId().getCell();
slowr13fa5b02017-08-08 16:32:31 -0700159 }
160 return null;
161 }
162}