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; |
| 22 | import org.onosproject.xran.codecs.api.MMEUES1APID; |
| 23 | import org.onosproject.xran.entities.RnibCell; |
| 24 | import org.onosproject.xran.entities.RnibLink; |
| 25 | import org.onosproject.xran.entities.RnibUe; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 26 | import org.slf4j.Logger; |
| 27 | |
| 28 | import java.util.List; |
| 29 | import java.util.Optional; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 30 | |
| 31 | import static org.slf4j.LoggerFactory.getLogger; |
| 32 | |
| 33 | public class LinkMap { |
| 34 | private static final Logger log = getLogger(LinkMap.class); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 35 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 36 | private final XranStore xranStore; |
| 37 | |
| 38 | private UeMap ueMap; |
| 39 | |
| 40 | public LinkMap(XranStore xranStore, UeMap ueMap) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 41 | this.xranStore = xranStore; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 42 | this.ueMap = ueMap; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | public void putPrimaryLink(RnibCell cell, RnibUe ue) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 46 | RnibLink link = new RnibLink(cell, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 47 | link.setType(RnibLink.Type.SERVING_PRIMARY); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 48 | xranStore.storeLink(link); |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 49 | |
| 50 | ueMap.putCrnti(cell, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | public RnibLink putNonServingLink(RnibCell cell, CRNTI crnti) { |
| 54 | RnibLink link = null; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 55 | RnibUe ue = ueMap.get(cell.getEcgi(), crnti); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 56 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 57 | if (ue != null) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 58 | link = new RnibLink(cell, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 59 | 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) { |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 74 | RnibUe ue = ueMap.get(src, dst); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 75 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 76 | if (ue != null) { |
| 77 | return xranStore.getLink(src, ue.getMmeS1apId()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 78 | } |
| 79 | return null; |
| 80 | } |
| 81 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 82 | public CRNTI getCrnti(MMEUES1APID mme) { |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 83 | return ueMap.getCrntUe().inverse().get(mme).getValue(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 84 | } |
| 85 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 86 | public RnibCell getPrimaryCell(RnibUe ue) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 87 | List<RnibLink> linksByUeId = xranStore.getLinksByUeId(ue.getMmeS1apId().longValue()); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 88 | Optional<RnibLink> primary = linksByUeId.stream() |
| 89 | .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY)) |
| 90 | .findFirst(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 91 | |
| 92 | if (primary.isPresent()) { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 93 | return primary.get().getLinkId().getCell(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 94 | } |
| 95 | return null; |
| 96 | } |
| 97 | } |