blob: 5e6227158e4f7b3844adeb9d48c9a044128c9bad [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;
22import org.onosproject.xran.codecs.api.MMEUES1APID;
23import org.onosproject.xran.entities.RnibCell;
24import org.onosproject.xran.entities.RnibLink;
25import org.onosproject.xran.entities.RnibUe;
slowr13fa5b02017-08-08 16:32:31 -070026import org.slf4j.Logger;
27
28import java.util.List;
29import java.util.Optional;
slowr13fa5b02017-08-08 16:32:31 -070030
31import static org.slf4j.LoggerFactory.getLogger;
32
33public class LinkMap {
34 private static final Logger log = getLogger(LinkMap.class);
slowr13fa5b02017-08-08 16:32:31 -070035
slowrd337c932017-08-18 13:54:02 -070036 private final XranStore xranStore;
37
38 private UeMap ueMap;
39
40 public LinkMap(XranStore xranStore, UeMap ueMap) {
slowr13fa5b02017-08-08 16:32:31 -070041 this.xranStore = xranStore;
slowrd337c932017-08-18 13:54:02 -070042 this.ueMap = ueMap;
slowr13fa5b02017-08-08 16:32:31 -070043 }
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);
slowrd337c932017-08-18 13:54:02 -070049
50 ueMap.putCrnti(cell, ue);
slowr13fa5b02017-08-08 16:32:31 -070051 }
52
53 public RnibLink putNonServingLink(RnibCell cell, CRNTI crnti) {
54 RnibLink link = null;
slowrd337c932017-08-18 13:54:02 -070055 RnibUe ue = ueMap.get(cell.getEcgi(), crnti);
slowr13fa5b02017-08-08 16:32:31 -070056
slowrd337c932017-08-18 13:54:02 -070057 if (ue != null) {
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) {
slowrd337c932017-08-18 13:54:02 -070074 RnibUe ue = ueMap.get(src, dst);
slowr13fa5b02017-08-08 16:32:31 -070075
slowrd337c932017-08-18 13:54:02 -070076 if (ue != null) {
77 return xranStore.getLink(src, ue.getMmeS1apId());
slowr13fa5b02017-08-08 16:32:31 -070078 }
79 return null;
80 }
81
slowr67d05e42017-08-11 20:37:22 -070082 public CRNTI getCrnti(MMEUES1APID mme) {
slowrd337c932017-08-18 13:54:02 -070083 return ueMap.getCrntUe().inverse().get(mme).getValue();
slowr13fa5b02017-08-08 16:32:31 -070084 }
85
slowr89c2ac12017-08-15 16:20:06 -070086 public RnibCell getPrimaryCell(RnibUe ue) {
slowr13fa5b02017-08-08 16:32:31 -070087 List<RnibLink> linksByUeId = xranStore.getLinksByUeId(ue.getMmeS1apId().longValue());
slowr89c2ac12017-08-15 16:20:06 -070088 Optional<RnibLink> primary = linksByUeId.stream()
89 .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY))
90 .findFirst();
slowr13fa5b02017-08-08 16:32:31 -070091
92 if (primary.isPresent()) {
slowr89c2ac12017-08-15 16:20:06 -070093 return primary.get().getLinkId().getCell();
slowr13fa5b02017-08-08 16:32:31 -070094 }
95 return null;
96 }
97}