slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.xran.wrapper; |
| 18 | |
| 19 | import org.onosproject.xran.XranStore; |
| 20 | import org.onosproject.xran.codecs.api.CRNTI; |
| 21 | import org.onosproject.xran.codecs.api.ECGI; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 22 | import org.onosproject.xran.entities.RnibCell; |
| 23 | import org.onosproject.xran.entities.RnibLink; |
| 24 | import org.onosproject.xran.entities.RnibUe; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 25 | import org.slf4j.Logger; |
| 26 | |
| 27 | import java.util.List; |
| 28 | import java.util.Optional; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 29 | |
| 30 | import static org.slf4j.LoggerFactory.getLogger; |
| 31 | |
| 32 | public class LinkMap { |
| 33 | private static final Logger log = getLogger(LinkMap.class); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 34 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 35 | private final XranStore xranStore; |
| 36 | |
| 37 | private UeMap ueMap; |
| 38 | |
| 39 | public LinkMap(XranStore xranStore, UeMap ueMap) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 40 | this.xranStore = xranStore; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 41 | this.ueMap = ueMap; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | public void putPrimaryLink(RnibCell cell, RnibUe ue) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 45 | RnibLink link = new RnibLink(cell, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 46 | link.setType(RnibLink.Type.SERVING_PRIMARY); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 47 | xranStore.storeLink(link); |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 48 | |
| 49 | ueMap.putCrnti(cell, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | public RnibLink putNonServingLink(RnibCell cell, CRNTI crnti) { |
| 53 | RnibLink link = null; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 54 | RnibUe ue = ueMap.get(cell.getEcgi(), crnti); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 55 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 56 | if (ue != null) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 57 | link = new RnibLink(cell, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 58 | 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 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 65 | 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) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 79 | 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) { |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 86 | RnibUe ue = ueMap.get(src, dst); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 87 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 88 | if (ue != null) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 89 | return xranStore.getLink(src, ue.getId()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 90 | } |
| 91 | return null; |
| 92 | } |
| 93 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 94 | public CRNTI getCrnti(Long ueId) { |
| 95 | return ueMap.getCrntUe().inverse().get(ueId).getValue(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 96 | } |
| 97 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 98 | public RnibCell getPrimaryCell(RnibUe ue) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame^] | 99 | List<RnibLink> linksByUeId = xranStore.getLinksByUeId(ue.getId()); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 100 | Optional<RnibLink> primary = linksByUeId.stream() |
| 101 | .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY)) |
| 102 | .findFirst(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 103 | |
| 104 | if (primary.isPresent()) { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 105 | return primary.get().getLinkId().getCell(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 106 | } |
| 107 | return null; |
| 108 | } |
| 109 | } |