slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /* |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 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 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 32 | /** |
| 33 | * LINK wrapper to help put/get/remove. |
| 34 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 35 | public class LinkMap { |
| 36 | private static final Logger log = getLogger(LinkMap.class); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 37 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 38 | private final XranStore xranStore; |
| 39 | |
| 40 | private UeMap ueMap; |
| 41 | |
| 42 | public LinkMap(XranStore xranStore, UeMap ueMap) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 43 | this.xranStore = xranStore; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 44 | this.ueMap = ueMap; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 45 | } |
| 46 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 47 | /** |
| 48 | * Put a new primary link between a CELL and a UE. |
| 49 | * |
| 50 | * @param cell CELL entity |
| 51 | * @param ue UE entity |
| 52 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 53 | public void putPrimaryLink(RnibCell cell, RnibUe ue) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 54 | RnibLink link = new RnibLink(cell, ue); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 55 | // set link to primary before storing |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 56 | link.setType(RnibLink.Type.SERVING_PRIMARY); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 57 | xranStore.storeLink(link); |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 58 | |
| 59 | ueMap.putCrnti(cell, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 60 | } |
| 61 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 62 | /** |
| 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 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 69 | public RnibLink putNonServingLink(RnibCell cell, CRNTI crnti) { |
| 70 | RnibLink link = null; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 71 | RnibUe ue = ueMap.get(cell.getEcgi(), crnti); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 72 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 73 | if (ue != null) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 74 | link = new RnibLink(cell, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 75 | 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 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 82 | /** |
| 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 | */ |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 89 | 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 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 102 | /** |
| 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 | */ |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 109 | public RnibLink get(ECGI src, Long dst) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 110 | if (src != null && dst != null) { |
| 111 | return xranStore.getLink(src, dst); |
| 112 | } |
| 113 | return null; |
| 114 | } |
| 115 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 116 | /** |
| 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 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 123 | public RnibLink get(ECGI src, CRNTI dst) { |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 124 | RnibUe ue = ueMap.get(src, dst); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 125 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 126 | if (ue != null) { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 127 | return xranStore.getLink(src, ue.getId()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 128 | } |
| 129 | return null; |
| 130 | } |
| 131 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 132 | /** |
| 133 | * Get CRNTI based on UE id. |
| 134 | * |
| 135 | * @param ueId UE id |
| 136 | * @return UE if found |
| 137 | */ |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 138 | public CRNTI getCrnti(Long ueId) { |
| 139 | return ueMap.getCrntUe().inverse().get(ueId).getValue(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 140 | } |
| 141 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 142 | /** |
| 143 | * Get primary CELL for specified UE. |
| 144 | * |
| 145 | * @param ue UE entity |
| 146 | * @return primary CELL if found |
| 147 | */ |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 148 | public RnibCell getPrimaryCell(RnibUe ue) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 149 | 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. |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 153 | Optional<RnibLink> primary = linksByUeId.stream() |
| 154 | .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY)) |
| 155 | .findFirst(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 156 | |
| 157 | if (primary.isPresent()) { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 158 | return primary.get().getLinkId().getCell(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 159 | } |
| 160 | return null; |
| 161 | } |
| 162 | } |