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.controller; |
| 18 | |
| 19 | import com.google.common.collect.Sets; |
| 20 | import io.netty.channel.ChannelHandlerContext; |
| 21 | import io.netty.channel.sctp.SctpMessage; |
| 22 | import org.apache.commons.lang.exception.ExceptionUtils; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 23 | import org.apache.felix.scr.annotations.Activate; |
| 24 | import org.apache.felix.scr.annotations.Component; |
| 25 | import org.apache.felix.scr.annotations.Deactivate; |
| 26 | import org.apache.felix.scr.annotations.Reference; |
| 27 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 28 | import org.apache.felix.scr.annotations.Service; |
| 29 | import org.onlab.packet.IpAddress; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.CoreService; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 32 | import org.onosproject.net.config.Config; |
| 33 | import org.onosproject.net.config.ConfigFactory; |
| 34 | import org.onosproject.net.config.NetworkConfigEvent; |
| 35 | import org.onosproject.net.config.NetworkConfigListener; |
| 36 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 37 | import org.onosproject.net.config.NetworkConfigService; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 38 | import org.onosproject.net.config.basics.SubjectFactories; |
| 39 | import org.onosproject.net.device.DeviceEvent; |
| 40 | import org.onosproject.net.device.DeviceListener; |
| 41 | import org.onosproject.net.device.DeviceService; |
| 42 | import org.onosproject.net.host.HostEvent; |
| 43 | import org.onosproject.net.host.HostListener; |
| 44 | import org.onosproject.net.host.HostService; |
| 45 | import org.onosproject.xran.XranStore; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 46 | import org.onosproject.xran.codecs.api.CRNTI; |
| 47 | import org.onosproject.xran.codecs.api.ECGI; |
| 48 | import org.onosproject.xran.codecs.api.ERABID; |
| 49 | import org.onosproject.xran.codecs.api.ERABParams; |
| 50 | import org.onosproject.xran.codecs.api.ERABParamsItem; |
| 51 | import org.onosproject.xran.codecs.api.PCIARFCN; |
| 52 | import org.onosproject.xran.codecs.api.PropScell; |
| 53 | import org.onosproject.xran.codecs.api.RSRPRange; |
| 54 | import org.onosproject.xran.codecs.api.RSRQRange; |
| 55 | import org.onosproject.xran.codecs.api.RXSigReport; |
| 56 | import org.onosproject.xran.codecs.api.RadioRepPerServCell; |
| 57 | import org.onosproject.xran.codecs.api.SchedMeasRepPerServCell; |
| 58 | import org.onosproject.xran.codecs.api.TrafficSplitPercentage; |
slowr | c153ad9 | 2017-08-16 19:47:52 -0700 | [diff] [blame] | 59 | import org.onosproject.xran.codecs.ber.types.BerInteger; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 60 | import org.onosproject.xran.codecs.pdu.BearerAdmissionRequest; |
| 61 | import org.onosproject.xran.codecs.pdu.BearerAdmissionResponse; |
| 62 | import org.onosproject.xran.codecs.pdu.BearerAdmissionStatus; |
| 63 | import org.onosproject.xran.codecs.pdu.BearerReleaseInd; |
| 64 | import org.onosproject.xran.codecs.pdu.CellConfigReport; |
| 65 | import org.onosproject.xran.codecs.pdu.CellConfigRequest; |
| 66 | import org.onosproject.xran.codecs.pdu.HOComplete; |
| 67 | import org.onosproject.xran.codecs.pdu.HOFailure; |
| 68 | import org.onosproject.xran.codecs.pdu.HORequest; |
| 69 | import org.onosproject.xran.codecs.pdu.L2MeasConfig; |
| 70 | import org.onosproject.xran.codecs.pdu.PDCPMeasReportPerUe; |
| 71 | import org.onosproject.xran.codecs.pdu.RRMConfig; |
| 72 | import org.onosproject.xran.codecs.pdu.RRMConfigStatus; |
| 73 | import org.onosproject.xran.codecs.pdu.RXSigMeasConfig; |
| 74 | import org.onosproject.xran.codecs.pdu.RXSigMeasReport; |
| 75 | import org.onosproject.xran.codecs.pdu.RadioMeasReportPerCell; |
| 76 | import org.onosproject.xran.codecs.pdu.RadioMeasReportPerUE; |
| 77 | import org.onosproject.xran.codecs.pdu.ScellAdd; |
| 78 | import org.onosproject.xran.codecs.pdu.ScellAddStatus; |
| 79 | import org.onosproject.xran.codecs.pdu.ScellDelete; |
| 80 | import org.onosproject.xran.codecs.pdu.SchedMeasReportPerCell; |
| 81 | import org.onosproject.xran.codecs.pdu.SchedMeasReportPerUE; |
| 82 | import org.onosproject.xran.codecs.pdu.TrafficSplitConfig; |
| 83 | import org.onosproject.xran.codecs.pdu.UEAdmissionRequest; |
| 84 | import org.onosproject.xran.codecs.pdu.UEAdmissionResponse; |
| 85 | import org.onosproject.xran.codecs.pdu.UEAdmissionStatus; |
| 86 | import org.onosproject.xran.codecs.pdu.UECapabilityEnquiry; |
| 87 | import org.onosproject.xran.codecs.pdu.UECapabilityInfo; |
| 88 | import org.onosproject.xran.codecs.pdu.UEContextUpdate; |
| 89 | import org.onosproject.xran.codecs.pdu.UEReconfigInd; |
| 90 | import org.onosproject.xran.codecs.pdu.UEReleaseInd; |
| 91 | import org.onosproject.xran.codecs.pdu.XICICConfig; |
| 92 | import org.onosproject.xran.codecs.pdu.XrancPdu; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 93 | import org.onosproject.xran.entities.RnibCell; |
| 94 | import org.onosproject.xran.entities.RnibLink; |
| 95 | import org.onosproject.xran.entities.RnibUe; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 96 | import org.onosproject.xran.identifiers.ContextUpdateHandler; |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 97 | import org.onosproject.xran.identifiers.EcgiCrntiPair; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 98 | import org.onosproject.xran.identifiers.LinkId; |
| 99 | import org.onosproject.xran.impl.XranConfig; |
| 100 | import org.onosproject.xran.providers.XranDeviceListener; |
| 101 | import org.onosproject.xran.providers.XranHostListener; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 102 | import org.onosproject.xran.wrapper.CellMap; |
| 103 | import org.onosproject.xran.wrapper.LinkMap; |
| 104 | import org.onosproject.xran.wrapper.UeMap; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 105 | import org.slf4j.Logger; |
| 106 | import org.slf4j.LoggerFactory; |
| 107 | |
| 108 | import java.io.IOException; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 109 | import java.util.ArrayList; |
| 110 | import java.util.List; |
| 111 | import java.util.Optional; |
| 112 | import java.util.Set; |
| 113 | import java.util.Timer; |
| 114 | import java.util.TimerTask; |
| 115 | import java.util.concurrent.BlockingQueue; |
| 116 | import java.util.concurrent.ConcurrentHashMap; |
| 117 | import java.util.concurrent.ConcurrentMap; |
| 118 | import java.util.concurrent.CopyOnWriteArraySet; |
| 119 | import java.util.concurrent.LinkedBlockingQueue; |
| 120 | import java.util.concurrent.SynchronousQueue; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 121 | import java.util.stream.Collectors; |
| 122 | |
| 123 | import static org.onosproject.net.DeviceId.deviceId; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 124 | import static org.onosproject.xran.controller.XranChannelHandler.getSctpMessage; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 125 | import static org.onosproject.xran.entities.RnibCell.decodeDeviceId; |
| 126 | import static org.onosproject.xran.entities.RnibCell.uri; |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 127 | import static org.onosproject.xran.entities.RnibUe.hostIdtoUEId; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * Created by dimitris on 7/20/17. |
| 131 | */ |
| 132 | @Component(immediate = true) |
| 133 | @Service |
| 134 | public class XranControllerImpl implements XranController { |
| 135 | private static final String XRAN_APP_ID = "org.onosproject.xran"; |
| 136 | private static final Class<XranConfig> CONFIG_CLASS = XranConfig.class; |
| 137 | |
| 138 | private static final Logger log = |
| 139 | LoggerFactory.getLogger(XranControllerImpl.class); |
| 140 | /* CONFIG */ |
| 141 | private final InternalNetworkConfigListener configListener = |
| 142 | new InternalNetworkConfigListener(); |
| 143 | /* VARIABLES */ |
| 144 | private final Controller controller = new Controller(); |
| 145 | private XranConfig xranConfig; |
| 146 | private ApplicationId appId; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 147 | private int northboundTimeout; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 148 | /* Services */ |
| 149 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 150 | private DeviceService deviceService; |
| 151 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 152 | private HostService hostService; |
| 153 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 154 | private NetworkConfigRegistry registry; |
| 155 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 156 | private NetworkConfigService configService; |
| 157 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 158 | private CoreService coreService; |
| 159 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 160 | private XranStore xranStore; |
| 161 | private ConfigFactory<ApplicationId, XranConfig> xranConfigFactory = |
| 162 | new ConfigFactory<ApplicationId, XranConfig>( |
| 163 | SubjectFactories.APP_SUBJECT_FACTORY, CONFIG_CLASS, "xran") { |
| 164 | @Override |
| 165 | public XranConfig createConfig() { |
| 166 | return new XranConfig(); |
| 167 | } |
| 168 | }; |
| 169 | /* WRAPPERS */ |
| 170 | private CellMap cellMap; |
| 171 | private UeMap ueMap; |
| 172 | private LinkMap linkMap; |
| 173 | /* MAPS */ |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 174 | private ConcurrentMap<IpAddress, ECGI> legitCells = new ConcurrentHashMap<>(); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 175 | private ConcurrentMap<ECGI, SynchronousQueue<String>> hoMap = new ConcurrentHashMap<>(); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 176 | private ConcurrentMap<ECGI, SynchronousQueue<String>> rrmcellMap = new ConcurrentHashMap<>(); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 177 | private ConcurrentMap<CRNTI, SynchronousQueue<String>> scellAddMap = new ConcurrentHashMap<>(); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 178 | private ConcurrentMap<EcgiCrntiPair, ContextUpdateHandler> contextUpdateMap = new ConcurrentHashMap<>(); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 179 | /* QUEUE */ |
| 180 | private BlockingQueue<Long> ueIdQueue = new LinkedBlockingQueue<>(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 181 | /* AGENTS */ |
| 182 | private InternalXranDeviceAgent deviceAgent = new InternalXranDeviceAgent(); |
| 183 | private InternalXranHostAgent hostAgent = new InternalXranHostAgent(); |
| 184 | private InternalXranPacketAgent packetAgent = new InternalXranPacketAgent(); |
| 185 | /* LISTENERS */ |
| 186 | private Set<XranDeviceListener> xranDeviceListeners = new CopyOnWriteArraySet<>(); |
| 187 | private Set<XranHostListener> xranHostListeners = new CopyOnWriteArraySet<>(); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 188 | private InternalDeviceListener deviceListener = new InternalDeviceListener(); |
| 189 | private InternalHostListener hostListener = new InternalHostListener(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 190 | |
| 191 | @Activate |
| 192 | public void activate() { |
| 193 | appId = coreService.registerApplication(XRAN_APP_ID); |
| 194 | |
| 195 | configService.addListener(configListener); |
| 196 | registry.registerConfigFactory(xranConfigFactory); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 197 | deviceService.addListener(deviceListener); |
| 198 | hostService.addListener(hostListener); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 199 | |
| 200 | cellMap = new CellMap(xranStore); |
| 201 | ueMap = new UeMap(xranStore); |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 202 | linkMap = new LinkMap(xranStore, ueMap); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 203 | |
| 204 | xranStore.setController(this); |
| 205 | |
| 206 | log.info("XRAN Controller Started"); |
| 207 | } |
| 208 | |
| 209 | @Deactivate |
| 210 | public void deactivate() { |
| 211 | controller.stop(); |
| 212 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 213 | deviceService.removeListener(deviceListener); |
| 214 | hostService.removeListener(hostListener); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 215 | |
| 216 | legitCells.clear(); |
| 217 | |
| 218 | configService.removeListener(configListener); |
| 219 | registry.unregisterConfigFactory(xranConfigFactory); |
| 220 | |
| 221 | log.info("XRAN Controller Stopped"); |
| 222 | } |
| 223 | |
| 224 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 225 | public SynchronousQueue<String> sendHORequest(RnibLink linkT, RnibLink linkS) throws InterruptedException { |
| 226 | ECGI ecgiT = linkT.getLinkId().getEcgi(), |
| 227 | ecgiS = linkS.getLinkId().getEcgi(); |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 228 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 229 | CRNTI crnti = linkMap.getCrnti(linkT.getLinkId().getUeId()); |
| 230 | ChannelHandlerContext ctxT = cellMap.getCtx(ecgiT), |
| 231 | ctxS = cellMap.getCtx(ecgiS); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 232 | |
| 233 | SynchronousQueue<String> queue = new SynchronousQueue<>(); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 234 | try { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 235 | XrancPdu xrancPdu = HORequest.constructPacket(crnti, ecgiS, ecgiT); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 236 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 237 | // temporary map that has ECGI source of a handoff to a queue waiting for REST response. |
| 238 | hoMap.put(ecgiS, queue); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 239 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 240 | ctxT.writeAndFlush(getSctpMessage(xrancPdu)); |
| 241 | ctxS.writeAndFlush(getSctpMessage(xrancPdu)); |
| 242 | |
| 243 | // FIXME: only works for one HO at a time. |
| 244 | ueIdQueue.put(linkT.getLinkId().getUeId()); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 245 | } catch (IOException e) { |
| 246 | e.printStackTrace(); |
| 247 | } |
| 248 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 249 | return queue; |
| 250 | } |
| 251 | |
| 252 | @Override |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 253 | public void addListener(XranDeviceListener listener) { |
| 254 | xranDeviceListeners.add(listener); |
| 255 | } |
| 256 | |
| 257 | @Override |
| 258 | public void addListener(XranHostListener listener) { |
| 259 | xranHostListeners.add(listener); |
| 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public void removeListener(XranDeviceListener listener) { |
| 264 | xranDeviceListeners.remove(listener); |
| 265 | } |
| 266 | |
| 267 | @Override |
| 268 | public void removeListener(XranHostListener listener) { |
| 269 | xranHostListeners.remove(listener); |
| 270 | } |
| 271 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 272 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 273 | public int getNorthboundTimeout() { |
| 274 | return northboundTimeout; |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 278 | public SynchronousQueue<String> sendmodifiedrrmconf(RRMConfig rrmConfig, boolean xicic) { |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 279 | ECGI ecgi = rrmConfig.getEcgi(); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 280 | ChannelHandlerContext ctx = cellMap.getCtx(ecgi); |
| 281 | try { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 282 | XrancPdu pdu; |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 283 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 284 | if (xicic) { |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 285 | CellConfigReport cellConfigReport = cellMap.get(ecgi).getConf(); |
| 286 | if (cellConfigReport != null) { |
| 287 | pdu = XICICConfig.constructPacket(rrmConfig, cellConfigReport); |
| 288 | ctx.writeAndFlush(getSctpMessage(pdu)); |
| 289 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 290 | } else { |
| 291 | pdu = RRMConfig.constructPacket(rrmConfig); |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 292 | ctx.writeAndFlush(getSctpMessage(pdu)); |
| 293 | SynchronousQueue<String> queue = new SynchronousQueue<>(); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 294 | rrmcellMap.put(ecgi, queue); |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 295 | return queue; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 296 | } |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 297 | } catch (IOException e) { |
| 298 | e.printStackTrace(); |
| 299 | } |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 300 | |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 301 | return null; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 302 | } |
| 303 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 304 | @Override |
| 305 | public SynchronousQueue<String> sendScellAdd(RnibLink link) { |
| 306 | RnibCell secondaryCell = link.getLinkId().getCell(), |
| 307 | primaryCell = linkMap.getPrimaryCell(link.getLinkId().getUe()); |
| 308 | ECGI primaryEcgi = primaryCell.getEcgi(); |
| 309 | ChannelHandlerContext ctx = cellMap.getCtx(primaryEcgi); |
| 310 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 311 | CRNTI crnti = linkMap.getCrnti(link.getLinkId().getUeId()); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 312 | |
| 313 | CellConfigReport cellReport = secondaryCell.getConf(); |
| 314 | |
| 315 | if (cellReport != null) { |
| 316 | PCIARFCN pciarfcn = new PCIARFCN(); |
| 317 | pciarfcn.setPci(cellReport.getPci()); |
| 318 | pciarfcn.setEarfcnDl(cellReport.getEarfcnDl()); |
| 319 | |
| 320 | PropScell propScell = new PropScell(); |
| 321 | propScell.setPciArfcn(pciarfcn); |
| 322 | |
| 323 | XrancPdu pdu = ScellAdd.constructPacket(primaryEcgi, crnti, propScell); |
| 324 | try { |
| 325 | ctx.writeAndFlush(getSctpMessage(pdu)); |
| 326 | SynchronousQueue<String> queue = new SynchronousQueue<>(); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 327 | scellAddMap.put(crnti, queue); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 328 | |
| 329 | return queue; |
| 330 | } catch (IOException e) { |
| 331 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 332 | e.printStackTrace(); |
| 333 | } |
| 334 | } |
| 335 | return null; |
| 336 | } |
| 337 | |
| 338 | @Override |
| 339 | public boolean sendScellDelete(RnibLink link) { |
| 340 | RnibCell secondaryCell = link.getLinkId().getCell(), |
| 341 | primaryCell = linkMap.getPrimaryCell(link.getLinkId().getUe()); |
| 342 | ECGI primaryEcgi = primaryCell.getEcgi(); |
| 343 | ChannelHandlerContext ctx = cellMap.getCtx(primaryEcgi); |
| 344 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 345 | CRNTI crnti = linkMap.getCrnti(link.getLinkId().getUeId()); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 346 | |
| 347 | CellConfigReport cellReport = secondaryCell.getConf(); |
| 348 | |
| 349 | if (cellReport != null) { |
| 350 | PCIARFCN pciarfcn = new PCIARFCN(); |
| 351 | pciarfcn.setPci(cellReport.getPci()); |
| 352 | pciarfcn.setEarfcnDl(cellReport.getEarfcnDl()); |
| 353 | |
| 354 | XrancPdu pdu = ScellDelete.constructPacket(primaryEcgi, crnti, pciarfcn); |
| 355 | |
| 356 | try { |
| 357 | ctx.writeAndFlush(getSctpMessage(pdu)); |
| 358 | link.setType(RnibLink.Type.NON_SERVING); |
| 359 | return true; |
| 360 | } catch (IOException e) { |
| 361 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 362 | e.printStackTrace(); |
| 363 | } |
| 364 | } |
| 365 | return false; |
| 366 | } |
| 367 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 368 | /** |
| 369 | * Timer to delete UE after being IDLE. |
| 370 | * |
| 371 | * @param ue UE entity |
| 372 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 373 | private void restartTimer(RnibUe ue) { |
| 374 | Timer timer = new Timer(); |
| 375 | ue.setTimer(timer); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 376 | timer.schedule(new TimerTask() { |
| 377 | @Override |
| 378 | public void run() { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 379 | if (ue.getState() == RnibUe.State.IDLE) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 380 | hostAgent.removeConnectedHost(ue); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 381 | log.info("UE is removed after {} ms of IDLE", xranConfig.getIdleUeRemoval()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 382 | } else { |
| 383 | log.info("UE not removed cause its ACTIVE"); |
| 384 | } |
| 385 | } |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 386 | }, xranConfig.getIdleUeRemoval()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 387 | } |
| 388 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 389 | /** |
| 390 | * Timer to delete LINK after not receiving measurements. |
| 391 | * |
| 392 | * @param link LINK entity |
| 393 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 394 | private void restartTimer(RnibLink link) { |
| 395 | Timer timer = new Timer(); |
| 396 | link.setTimer(timer); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 397 | timer.schedule(new TimerTask() { |
| 398 | @Override |
| 399 | public void run() { |
| 400 | LinkId linkId = link.getLinkId(); |
| 401 | xranStore.removeLink(linkId); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 402 | log.info("Link is removed after not receiving Meas Reports for {} ms", |
| 403 | xranConfig.getNoMeasLinkRemoval()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 404 | } |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 405 | }, xranConfig.getNoMeasLinkRemoval()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 406 | |
| 407 | } |
| 408 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 409 | /** |
| 410 | * Request measurement configuration field of specified UE. |
| 411 | * |
| 412 | * @param primary primary CELL |
| 413 | * @param ue UE entity |
| 414 | */ |
| 415 | private void populateMeasConfig(RnibCell primary, RnibUe ue) { |
| 416 | try { |
| 417 | ChannelHandlerContext ctx = cellMap.getCtx(primary.getEcgi()); |
| 418 | RXSigMeasConfig.MeasCells measCells = new RXSigMeasConfig.MeasCells(); |
| 419 | xranStore.getcellnodes().forEach(cell -> { |
| 420 | CellConfigReport cellReport = ((RnibCell) cell).getConf(); |
| 421 | if (cellReport != null) { |
| 422 | PCIARFCN pciarfcn = new PCIARFCN(); |
| 423 | pciarfcn.setPci(cellReport.getPci()); |
| 424 | pciarfcn.setEarfcnDl(cellReport.getEarfcnDl()); |
| 425 | measCells.setPCIARFCN(pciarfcn); |
| 426 | } |
| 427 | }); |
| 428 | XrancPdu xrancPdu = RXSigMeasConfig.constructPacket( |
| 429 | primary.getEcgi(), |
| 430 | ue.getCrnti(), |
| 431 | measCells, |
| 432 | xranConfig.getRxSignalInterval() |
| 433 | ); |
| 434 | ue.setMeasConfig(xrancPdu.getBody().getRXSigMeasConfig()); |
| 435 | ctx.writeAndFlush(getSctpMessage(xrancPdu)); |
| 436 | } catch (IOException e) { |
| 437 | log.warn(ExceptionUtils.getFullStackTrace(e)); |
| 438 | e.printStackTrace(); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * Internal device listener. |
| 444 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 445 | class InternalDeviceListener implements DeviceListener { |
| 446 | |
| 447 | @Override |
| 448 | public void event(DeviceEvent event) { |
| 449 | log.info("Device Event {}", event); |
| 450 | switch (event.type()) { |
| 451 | case DEVICE_ADDED: { |
| 452 | try { |
| 453 | ECGI ecgi = decodeDeviceId(event.subject().id()); |
| 454 | RnibCell cell = cellMap.get(ecgi); |
| 455 | if (cell != null) { |
| 456 | Timer timer = new Timer(); |
| 457 | timer.scheduleAtFixedRate( |
| 458 | new TimerTask() { |
| 459 | @Override |
| 460 | public void run() { |
| 461 | CellConfigReport conf = cell.getConf(); |
| 462 | if (conf == null) { |
| 463 | try { |
| 464 | ChannelHandlerContext ctx = cellMap.getCtx(ecgi); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 465 | XrancPdu xrancPdu = CellConfigRequest.constructPacket(ecgi); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 466 | ctx.writeAndFlush(getSctpMessage(xrancPdu)); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 467 | } catch (IOException e) { |
| 468 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 469 | e.printStackTrace(); |
| 470 | } |
| 471 | } else { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 472 | List<Object> ueNodes = xranStore.getuenodes(); |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 473 | ueNodes.forEach(object -> { |
| 474 | RnibUe ue = (RnibUe) object; |
| 475 | try { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 476 | ECGI primaryEcgi = linkMap.getPrimaryCell(ue).getEcgi(); |
| 477 | ChannelHandlerContext ctx = cellMap.getCtx(primaryEcgi); |
| 478 | RXSigMeasConfig.MeasCells measCells = |
| 479 | new RXSigMeasConfig.MeasCells(); |
| 480 | xranStore.getcellnodes().forEach(cell -> { |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 481 | CellConfigReport cellReport = ((RnibCell) cell).getConf(); |
| 482 | if (cellReport != null) { |
| 483 | PCIARFCN pciarfcn = new PCIARFCN(); |
| 484 | pciarfcn.setPci(cellReport.getPci()); |
| 485 | pciarfcn.setEarfcnDl(cellReport.getEarfcnDl()); |
| 486 | measCells.setPCIARFCN(pciarfcn); |
| 487 | } |
| 488 | }); |
| 489 | XrancPdu xrancPdu = RXSigMeasConfig.constructPacket( |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 490 | primaryEcgi, |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 491 | ue.getCrnti(), |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 492 | measCells, |
| 493 | xranConfig.getRxSignalInterval() |
| 494 | ); |
| 495 | ue.setMeasConfig(xrancPdu.getBody().getRXSigMeasConfig()); |
| 496 | ctx.writeAndFlush(getSctpMessage(xrancPdu)); |
| 497 | } catch (IOException e) { |
| 498 | log.warn(ExceptionUtils.getFullStackTrace(e)); |
| 499 | e.printStackTrace(); |
| 500 | } |
| 501 | }); |
| 502 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 503 | try { |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 504 | ChannelHandlerContext ctx = cellMap.getCtx(ecgi); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 505 | XrancPdu xrancPdu = L2MeasConfig |
| 506 | .constructPacket(ecgi, xranConfig.getL2MeasInterval()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 507 | cell.setMeasConfig(xrancPdu.getBody().getL2MeasConfig()); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 508 | SctpMessage sctpMessage = getSctpMessage(xrancPdu); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 509 | ctx.writeAndFlush(sctpMessage); |
| 510 | } catch (IOException e) { |
| 511 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 512 | e.printStackTrace(); |
| 513 | } |
| 514 | timer.cancel(); |
| 515 | timer.purge(); |
| 516 | } |
| 517 | } |
| 518 | }, |
| 519 | 0, |
| 520 | xranConfig.getConfigRequestInterval() * 1000 |
| 521 | ); |
| 522 | } |
| 523 | } catch (IOException e) { |
| 524 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 525 | e.printStackTrace(); |
| 526 | } |
| 527 | break; |
| 528 | } |
| 529 | default: { |
| 530 | break; |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 536 | /** |
| 537 | * Internal host listener. |
| 538 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 539 | class InternalHostListener implements HostListener { |
| 540 | |
| 541 | @Override |
| 542 | public void event(HostEvent event) { |
| 543 | log.info("Host Event {}", event); |
| 544 | switch (event.type()) { |
| 545 | case HOST_ADDED: |
| 546 | case HOST_MOVED: { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 547 | RnibUe ue = ueMap.get(hostIdtoUEId(event.subject().id())); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 548 | if (ue != null) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 549 | ECGI ecgiPrimary = linkMap.getPrimaryCell(ue).getEcgi(); |
| 550 | RnibCell primary = cellMap.get(ecgiPrimary); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 551 | ue.setMeasConfig(null); |
| 552 | if (primary != null) { |
| 553 | Timer timer = new Timer(); |
| 554 | timer.scheduleAtFixedRate( |
| 555 | new TimerTask() { |
| 556 | @Override |
| 557 | public void run() { |
slowr | ed74ec7 | 2017-08-17 11:25:01 -0700 | [diff] [blame] | 558 | if (ue.getCapability() == null && primary.getVersion() >= 3) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 559 | try { |
| 560 | ChannelHandlerContext ctx = cellMap.getCtx(primary.getEcgi()); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 561 | XrancPdu xrancPdu = UECapabilityEnquiry.constructPacket( |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 562 | primary.getEcgi(), |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 563 | ue.getCrnti()); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 564 | ctx.writeAndFlush(getSctpMessage(xrancPdu)); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 565 | } catch (IOException e) { |
| 566 | log.warn(ExceptionUtils.getFullStackTrace(e)); |
| 567 | e.printStackTrace(); |
| 568 | } |
| 569 | } else { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 570 | timer.cancel(); |
| 571 | timer.purge(); |
| 572 | } |
| 573 | } |
| 574 | }, |
| 575 | 0, |
| 576 | xranConfig.getConfigRequestInterval() * 1000 |
| 577 | ); |
slowr | ed74ec7 | 2017-08-17 11:25:01 -0700 | [diff] [blame] | 578 | if (ue.getMeasConfig() == null) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 579 | populateMeasConfig(primary, ue); |
slowr | ed74ec7 | 2017-08-17 11:25:01 -0700 | [diff] [blame] | 580 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | break; |
| 584 | } |
| 585 | default: { |
| 586 | break; |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 592 | /** |
| 593 | * Internal xran device agent. |
| 594 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 595 | public class InternalXranDeviceAgent implements XranDeviceAgent { |
| 596 | |
| 597 | private final Logger log = LoggerFactory.getLogger(InternalXranDeviceAgent.class); |
| 598 | |
| 599 | @Override |
| 600 | public boolean addConnectedCell(String host, ChannelHandlerContext ctx) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 601 | ECGI ecgi = legitCells.get(IpAddress.valueOf(host)); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 602 | |
| 603 | if (ecgi == null) { |
| 604 | log.error("Device is not a legit source; ignoring..."); |
| 605 | } else { |
| 606 | log.info("Device exists in configuration; registering..."); |
| 607 | RnibCell storeCell = cellMap.get(ecgi); |
| 608 | if (storeCell == null) { |
| 609 | storeCell = new RnibCell(); |
| 610 | storeCell.setEcgi(ecgi); |
| 611 | cellMap.put(storeCell, ctx); |
| 612 | |
| 613 | for (XranDeviceListener l : xranDeviceListeners) { |
| 614 | l.deviceAdded(storeCell); |
| 615 | } |
| 616 | return true; |
| 617 | } else { |
| 618 | log.error("Device already registered; ignoring..."); |
| 619 | } |
| 620 | } |
| 621 | ctx.close(); |
| 622 | return false; |
| 623 | } |
| 624 | |
| 625 | @Override |
| 626 | public boolean removeConnectedCell(String host) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 627 | ECGI ecgi = legitCells.get(IpAddress.valueOf(host)); |
| 628 | List<RnibLink> linksbyecgi = xranStore.getlinksbyecgi(ecgi); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 629 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 630 | linksbyecgi.forEach(rnibLink -> xranStore.removeLink(rnibLink.getLinkId())); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 631 | |
| 632 | if (cellMap.remove(ecgi)) { |
| 633 | for (XranDeviceListener l : xranDeviceListeners) { |
| 634 | l.deviceRemoved(deviceId(uri(ecgi))); |
| 635 | } |
| 636 | return true; |
| 637 | } |
| 638 | return false; |
| 639 | } |
| 640 | } |
| 641 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 642 | /** |
| 643 | * Internal xran host agent. |
| 644 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 645 | public class InternalXranHostAgent implements XranHostAgent { |
| 646 | |
| 647 | @Override |
| 648 | public boolean addConnectedHost(RnibUe ue, RnibCell cell, ChannelHandlerContext ctx) { |
| 649 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 650 | if (ue.getId() != null && ueMap.get(ue.getId()) != null) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 651 | linkMap.putPrimaryLink(cell, ue); |
| 652 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 653 | Set<ECGI> ecgiSet = Sets.newConcurrentHashSet(); |
| 654 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 655 | xranStore.getlinksbyueid(ue.getId()) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 656 | .stream() |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 657 | .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY)) |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 658 | .findFirst() |
| 659 | .ifPresent(l -> ecgiSet.add(l.getLinkId().getEcgi())); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 660 | |
| 661 | for (XranHostListener l : xranHostListeners) { |
| 662 | l.hostAdded(ue, ecgiSet); |
| 663 | } |
| 664 | return true; |
| 665 | } else { |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 666 | ueMap.put(cell, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 667 | linkMap.putPrimaryLink(cell, ue); |
| 668 | |
| 669 | Set<ECGI> ecgiSet = Sets.newConcurrentHashSet(); |
| 670 | ecgiSet.add(cell.getEcgi()); |
| 671 | for (XranHostListener l : xranHostListeners) { |
| 672 | l.hostAdded(ue, ecgiSet); |
| 673 | } |
| 674 | return true; |
| 675 | } |
| 676 | |
| 677 | } |
| 678 | |
| 679 | @Override |
| 680 | public boolean removeConnectedHost(RnibUe ue) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 681 | List<RnibLink> links = xranStore.getlinksbyueid(ue.getId()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 682 | links.forEach(rnibLink -> xranStore.removeLink(rnibLink.getLinkId())); |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 683 | if (ueMap.remove(ue.getId())) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 684 | for (XranHostListener l : xranHostListeners) { |
| 685 | l.hostRemoved(ue.getHostId()); |
| 686 | } |
| 687 | return true; |
| 688 | } |
| 689 | return false; |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | public class InternalXranPacketAgent implements XranPacketProcessor { |
| 694 | @Override |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 695 | public void handlePacket(XrancPdu recvPdu, ChannelHandlerContext ctx) |
| 696 | throws IOException, InterruptedException { |
| 697 | XrancPdu sendPdu; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 698 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 699 | int apiID = recvPdu.getHdr().getApiId().intValue(); |
| 700 | log.debug("Received message: {}", recvPdu); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 701 | switch (apiID) { |
| 702 | case 1: { |
| 703 | // Decode Cell config report. |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 704 | CellConfigReport report = recvPdu.getBody().getCellConfigReport(); |
| 705 | handleCellconfigreport(report, recvPdu.getHdr().getVer().toString()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 706 | break; |
| 707 | } |
| 708 | case 2: { |
| 709 | // Decode UE Admission Request. |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 710 | UEAdmissionRequest ueAdmissionRequest = recvPdu.getBody().getUEAdmissionRequest(); |
| 711 | handleUeadmissionrequest(ueAdmissionRequest, ctx); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 712 | break; |
| 713 | } |
| 714 | case 4: { |
| 715 | // Decode UE Admission Status. |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 716 | UEAdmissionStatus ueAdmissionStatus = recvPdu.getBody().getUEAdmissionStatus(); |
| 717 | handleAdmissionstatus(ueAdmissionStatus, ctx); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 718 | break; |
| 719 | } |
| 720 | case 5: { |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 721 | // Decode UE Context Update. |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 722 | UEContextUpdate ueContextUpdate = recvPdu.getBody().getUEContextUpdate(); |
| 723 | handleUecontextupdate(ueContextUpdate, ctx); |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 724 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 725 | break; |
| 726 | } |
| 727 | case 6: { |
| 728 | // Decode UE Reconfig_Ind. |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 729 | UEReconfigInd ueReconfigInd = recvPdu.getBody().getUEReconfigInd(); |
| 730 | handleUereconfigind(ueReconfigInd); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 731 | break; |
| 732 | } |
| 733 | case 7: { |
| 734 | // If xRANc wants to deactivate UE, we pass UEReleaseInd from xRANc to eNB. |
| 735 | // Decode UE Release_Ind. |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 736 | UEReleaseInd ueReleaseInd = recvPdu.getBody().getUEReleaseInd(); |
| 737 | handleUereleaseind(ueReleaseInd); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 738 | break; |
| 739 | } |
| 740 | case 8: { |
| 741 | // Decode Bearer Adm Request |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 742 | BearerAdmissionRequest bearerAdmissionRequest = recvPdu.getBody().getBearerAdmissionRequest(); |
| 743 | handleBeareradmissionrequest(bearerAdmissionRequest, ctx); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 744 | break; |
| 745 | } |
| 746 | case 10: { |
| 747 | //Decode Bearer Admission Status |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 748 | BearerAdmissionStatus bearerAdmissionStatus = recvPdu.getBody().getBearerAdmissionStatus(); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 749 | break; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 750 | } |
| 751 | case 11: { |
| 752 | //Decode Bearer Release Ind |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 753 | BearerReleaseInd bearerReleaseInd = recvPdu.getBody().getBearerReleaseInd(); |
| 754 | handleBearerreleaseind(bearerReleaseInd); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 755 | break; |
| 756 | } |
| 757 | case 13: { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 758 | HOFailure hoFailure = recvPdu.getBody().getHOFailure(); |
| 759 | handleHofailure(hoFailure); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 760 | break; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 761 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 762 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 763 | case 14: { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 764 | HOComplete hoComplete = recvPdu.getBody().getHOComplete(); |
| 765 | handleHocomplete(hoComplete, ctx); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 766 | break; |
| 767 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 768 | |
| 769 | case 16: { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 770 | // Decode Rx Sig Meas Report. |
| 771 | RXSigMeasReport rxSigMeasReport = recvPdu.getBody().getRXSigMeasReport(); |
| 772 | handleRxsigmeasreport(rxSigMeasReport); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 773 | break; |
| 774 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 775 | case 18: { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 776 | RadioMeasReportPerUE radioMeasReportPerUE = recvPdu.getBody().getRadioMeasReportPerUE(); |
| 777 | handleRadionmeasreportperue(radioMeasReportPerUE); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 778 | break; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 779 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 780 | case 19: { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 781 | RadioMeasReportPerCell radioMeasReportPerCell = recvPdu.getBody().getRadioMeasReportPerCell(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 782 | break; |
| 783 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 784 | case 20: { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 785 | SchedMeasReportPerUE schedMeasReportPerUE = recvPdu.getBody().getSchedMeasReportPerUE(); |
| 786 | handleSchedmeasreportperue(schedMeasReportPerUE); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 787 | break; |
| 788 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 789 | case 21: { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 790 | SchedMeasReportPerCell schedMeasReportPerCell = recvPdu.getBody().getSchedMeasReportPerCell(); |
| 791 | handleSchedmeasreportpercell(schedMeasReportPerCell); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 792 | break; |
| 793 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 794 | case 22: { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 795 | PDCPMeasReportPerUe pdcpMeasReportPerUe = recvPdu.getBody().getPDCPMeasReportPerUe(); |
| 796 | handlePdcpmeasreportperue(pdcpMeasReportPerUe); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 797 | break; |
| 798 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 799 | case 24: { |
| 800 | // Decode UE Capability Info |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 801 | UECapabilityInfo capabilityInfo = recvPdu.getBody().getUECapabilityInfo(); |
| 802 | handleCapabilityinfo(capabilityInfo); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 803 | break; |
| 804 | } |
| 805 | case 25: { |
| 806 | // Don't know what will invoke sending UE CAPABILITY ENQUIRY |
| 807 | // Encode and send UE CAPABILITY ENQUIRY |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 808 | UECapabilityEnquiry ueCapabilityEnquiry = recvPdu.getBody().getUECapabilityEnquiry(); |
| 809 | handleUecapabilityenquiry(ueCapabilityEnquiry, ctx); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 810 | break; |
| 811 | } |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 812 | case 27: { |
| 813 | //Decode ScellAddStatus |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 814 | ScellAddStatus scellAddStatus = recvPdu.getBody().getScellAddStatus(); |
| 815 | handleScelladdstatus(scellAddStatus); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 816 | break; |
| 817 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 818 | case 30: { |
| 819 | // Decode RRMConfig Status |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 820 | RRMConfigStatus rrmConfigStatus = recvPdu.getBody().getRRMConfigStatus(); |
| 821 | handleRrmconfigstatus(rrmConfigStatus); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 822 | break; |
| 823 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 824 | //TODO Case 31: SeNBAdd 32: SeNBAddStatus 33: SeNBDelete |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 825 | case 34: { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 826 | TrafficSplitConfig trafficSplitConfig = recvPdu.getBody().getTrafficSplitConfig(); |
| 827 | handleTrafficSplitConfig(trafficSplitConfig); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 828 | break; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 829 | } |
| 830 | default: { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 831 | log.warn("Wrong API ID: {}", recvPdu); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 832 | break; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | |
| 836 | } |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 837 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 838 | /** |
| 839 | * Handle Cellconfigreport. |
| 840 | * @param report CellConfigReport |
| 841 | * @param version String version ID |
| 842 | */ |
| 843 | private void handleCellconfigreport(CellConfigReport report, String version) { |
| 844 | ECGI ecgi = report.getEcgi(); |
| 845 | |
| 846 | RnibCell cell = xranStore.getCell(ecgi); |
| 847 | cell.setVersion(version); |
| 848 | cell.setConf(report); |
| 849 | cellMap.putPciArfcn(cell); |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * Handle Ueadmissionrequest. |
| 854 | * @param ueAdmissionRequest UEAdmissionRequest |
| 855 | * @param ctx ChannelHandlerContext |
| 856 | * @throws IOException IO Exception |
| 857 | */ |
| 858 | private void handleUeadmissionrequest(UEAdmissionRequest ueAdmissionRequest, ChannelHandlerContext ctx) |
| 859 | throws IOException { |
| 860 | ECGI ecgi = ueAdmissionRequest.getEcgi(); |
| 861 | if (xranStore.getCell(ecgi) != null) { |
| 862 | CRNTI crnti = ueAdmissionRequest.getCrnti(); |
| 863 | XrancPdu sendPdu = UEAdmissionResponse.constructPacket(ecgi, crnti, xranConfig.admissionFlag()); |
| 864 | ctx.writeAndFlush(getSctpMessage(sendPdu)); |
| 865 | } else { |
| 866 | log.warn("Could not find ECGI in registered cells: {}", ecgi); |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | /** |
| 871 | * Handle UEAdmissionStatus. |
| 872 | * @param ueAdmissionStatus UEAdmissionStatus |
| 873 | * @param ctx ChannelHandlerContext |
| 874 | */ |
| 875 | private void handleAdmissionstatus(UEAdmissionStatus ueAdmissionStatus, ChannelHandlerContext ctx) { |
| 876 | RnibUe ue = ueMap.get(ueAdmissionStatus.getEcgi(), ueAdmissionStatus.getCrnti()); |
| 877 | if (ue != null) { |
| 878 | if (ueAdmissionStatus.getAdmEstStatus().value.intValue() == 0) { |
| 879 | ue.setState(RnibUe.State.ACTIVE); |
| 880 | } else { |
| 881 | ue.setState(RnibUe.State.IDLE); |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | if (ueAdmissionStatus.getAdmEstStatus().value.intValue() == 0) { |
| 886 | EcgiCrntiPair ecgiCrntiPair = EcgiCrntiPair |
| 887 | .valueOf(ueAdmissionStatus.getEcgi(), ueAdmissionStatus.getCrnti()); |
| 888 | contextUpdateMap.compute(ecgiCrntiPair, (k, v) -> { |
| 889 | if (v == null) { |
| 890 | v = new ContextUpdateHandler(); |
| 891 | } |
| 892 | if (v.setAdmissionStatus(ueAdmissionStatus)) { |
| 893 | handleContextUpdate(v.getContextUpdate(), ctx, false); |
| 894 | } |
| 895 | return v; |
| 896 | }); |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | /** |
| 901 | * Handle UEContextUpdate. |
| 902 | * @param ueContextUpdate UEContextUpdate |
| 903 | * @param ctx ChannelHandlerContext |
| 904 | */ |
| 905 | private void handleUecontextupdate(UEContextUpdate ueContextUpdate, ChannelHandlerContext ctx) { |
| 906 | EcgiCrntiPair ecgiCrntiPair = EcgiCrntiPair |
| 907 | .valueOf(ueContextUpdate.getEcgi(), ueContextUpdate.getCrnti()); |
| 908 | |
| 909 | contextUpdateMap.compute(ecgiCrntiPair, (k, v) -> { |
| 910 | if (v == null) { |
| 911 | v = new ContextUpdateHandler(); |
| 912 | } |
| 913 | if (v.setContextUpdate(ueContextUpdate)) { |
| 914 | HOComplete hoComplete = v.getHoComplete(); |
| 915 | handleContextUpdate(ueContextUpdate, ctx, hoComplete != null); |
| 916 | if (hoComplete != null) { |
| 917 | try { |
| 918 | hoMap.get(hoComplete.getEcgiS()).put("Hand Over Completed"); |
| 919 | } catch (InterruptedException e) { |
| 920 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 921 | e.printStackTrace(); |
| 922 | } finally { |
| 923 | hoMap.remove(hoComplete.getEcgiS()); |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | return v; |
| 928 | }); |
| 929 | } |
| 930 | |
| 931 | /** |
| 932 | * Handle UEReconfigInd. |
| 933 | * @param ueReconfigInd UEReconfigInd |
| 934 | */ |
| 935 | private void handleUereconfigind(UEReconfigInd ueReconfigInd) { |
| 936 | RnibUe ue = ueMap.get(ueReconfigInd.getEcgi(), ueReconfigInd.getCrntiOld()); |
| 937 | RnibCell cell = cellMap.get(ueReconfigInd.getEcgi()); |
| 938 | |
| 939 | if (ue != null && cell != null) { |
| 940 | ue.setCrnti(ueReconfigInd.getCrntiNew()); |
| 941 | ueMap.putCrnti(cell, ue); |
| 942 | } else { |
| 943 | log.warn("Could not find UE with this CRNTI: {}", ueReconfigInd.getCrntiOld()); |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | /** |
| 948 | * Handle UEReleaseInd. |
| 949 | * @param ueReleaseInd UEReleaseInd |
| 950 | */ |
| 951 | private void handleUereleaseind(UEReleaseInd ueReleaseInd) { |
| 952 | ECGI ecgi = ueReleaseInd.getEcgi(); |
| 953 | CRNTI crnti = ueReleaseInd.getCrnti(); |
| 954 | RnibUe ue = ueMap.get(ecgi, crnti); |
| 955 | |
| 956 | // Check if there is an ongoing handoff and only remove if ue is not part of the handoff. |
| 957 | Long peek = ueIdQueue.peek(); |
| 958 | if (peek != null) { |
| 959 | EcgiCrntiPair ecgiCrntiPair = ueMap.getCrntUe().inverse().get(peek); |
| 960 | if (ecgiCrntiPair != null && ecgiCrntiPair.equals(EcgiCrntiPair.valueOf(ecgi, crnti))) { |
| 961 | return; |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | if (ue != null) { |
| 966 | ue.setState(RnibUe.State.IDLE); |
| 967 | restartTimer(ue); |
| 968 | } else { |
| 969 | log.warn("Cannot release UE from non primary link."); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | /** |
| 974 | * Handle BearerAdmissionRequest. |
| 975 | * @param bearerAdmissionRequest BearerAdmissionRequest |
| 976 | * @param ctx ChannelHandlerContext |
| 977 | * @throws IOException IO Exception |
| 978 | */ |
| 979 | private void handleBeareradmissionrequest(BearerAdmissionRequest bearerAdmissionRequest, |
| 980 | ChannelHandlerContext ctx) throws IOException { |
| 981 | ECGI ecgi = bearerAdmissionRequest.getEcgi(); |
| 982 | CRNTI crnti = bearerAdmissionRequest.getCrnti(); |
| 983 | ERABParams erabParams = bearerAdmissionRequest.getErabParams(); |
| 984 | RnibLink link = linkMap.get(ecgi, crnti); |
| 985 | if (link != null) { |
| 986 | link.setBearerParameters(erabParams); |
| 987 | } else { |
| 988 | log.warn("Could not find link between {}-{}", ecgi, crnti); |
| 989 | } |
| 990 | |
| 991 | BerInteger numErabs = bearerAdmissionRequest.getNumErabs(); |
| 992 | // Encode and send Bearer Admission Response |
| 993 | XrancPdu sendPdu = BearerAdmissionResponse |
| 994 | .constructPacket(ecgi, crnti, erabParams, numErabs, xranConfig.bearerFlag()); |
| 995 | ctx.writeAndFlush(getSctpMessage(sendPdu)); |
| 996 | } |
| 997 | |
| 998 | /** |
| 999 | * Handle BearerReleaseInd. |
| 1000 | * @param bearerReleaseInd |
| 1001 | */ |
| 1002 | private void handleBearerreleaseind(BearerReleaseInd bearerReleaseInd) { |
| 1003 | ECGI ecgi = bearerReleaseInd.getEcgi(); |
| 1004 | CRNTI crnti = bearerReleaseInd.getCrnti(); |
| 1005 | RnibLink link = linkMap.get(ecgi, crnti); |
| 1006 | |
| 1007 | List<ERABID> erabidsRelease = bearerReleaseInd.getErabIds().getERABID(); |
| 1008 | List<ERABParamsItem> erabParamsItem = link.getBearerParameters().getERABParamsItem(); |
| 1009 | |
| 1010 | List<ERABParamsItem> unreleased = erabParamsItem |
| 1011 | .stream() |
| 1012 | .filter(item -> { |
| 1013 | Optional<ERABID> any = erabidsRelease.stream() |
| 1014 | .filter(id -> id.equals(item.getId())).findAny(); |
| 1015 | return !any.isPresent(); |
| 1016 | }).collect(Collectors.toList()); |
| 1017 | |
| 1018 | link.getBearerParameters().setERABParamsItem(new ArrayList<>(unreleased)); |
| 1019 | } |
| 1020 | |
| 1021 | /** |
| 1022 | * Handle HOFailure. |
| 1023 | * @param hoFailure HOFailure |
| 1024 | * @throws InterruptedException ueIdQueue interruption |
| 1025 | */ |
| 1026 | private void handleHofailure(HOFailure hoFailure) throws InterruptedException { |
| 1027 | try { |
| 1028 | hoMap.get(hoFailure.getEcgi()) |
| 1029 | .put("Hand Over Failed with cause: " + hoFailure.getCause()); |
| 1030 | } catch (InterruptedException e) { |
| 1031 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 1032 | e.printStackTrace(); |
| 1033 | } finally { |
| 1034 | hoMap.remove(hoFailure.getEcgi()); |
| 1035 | ueIdQueue.take(); |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | /** |
| 1040 | * Handle HOComplete. |
| 1041 | * @param hoComplete HOComplete |
| 1042 | * @param ctx ChannelHandlerContext |
| 1043 | */ |
| 1044 | private void handleHocomplete(HOComplete hoComplete, ChannelHandlerContext ctx) { |
| 1045 | EcgiCrntiPair ecgiCrntiPair = EcgiCrntiPair.valueOf(hoComplete.getEcgiT(), |
| 1046 | hoComplete.getCrntiNew()); |
| 1047 | contextUpdateMap.compute(ecgiCrntiPair, (k, v) -> { |
| 1048 | if (v == null) { |
| 1049 | v = new ContextUpdateHandler(); |
| 1050 | } |
| 1051 | if (v.setHoComplete(hoComplete)) { |
| 1052 | handleContextUpdate(v.getContextUpdate(), ctx, true); |
| 1053 | |
| 1054 | try { |
| 1055 | hoMap.get(hoComplete.getEcgiS()).put("Hand Over Completed"); |
| 1056 | } catch (InterruptedException e) { |
| 1057 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 1058 | e.printStackTrace(); |
| 1059 | } finally { |
| 1060 | hoMap.remove(hoComplete.getEcgiS()); |
| 1061 | } |
| 1062 | } |
| 1063 | return v; |
| 1064 | }); |
| 1065 | } |
| 1066 | |
| 1067 | /** |
| 1068 | * Handle RXSigMeasReport. |
| 1069 | * @param rxSigMeasReport RXSigMeasReport |
| 1070 | */ |
| 1071 | private void handleRxsigmeasreport(RXSigMeasReport rxSigMeasReport) { |
| 1072 | List<RXSigReport> rxSigReportList = rxSigMeasReport.getCellMeasReports().getRXSigReport(); |
| 1073 | |
| 1074 | RnibUe ue = ueMap.get(rxSigMeasReport.getEcgi(), rxSigMeasReport.getCrnti()); |
| 1075 | if (ue != null) { |
| 1076 | Long ueId = ue.getId(); |
| 1077 | |
| 1078 | if (!rxSigReportList.isEmpty()) { |
| 1079 | rxSigReportList.forEach(rxSigReport -> { |
| 1080 | RnibCell cell = cellMap.get(rxSigReport.getPciArfcn()); |
| 1081 | if (cell != null) { |
| 1082 | ECGI ecgi = cell.getEcgi(); |
| 1083 | |
| 1084 | RnibLink link = linkMap.get(ecgi, ueId); |
| 1085 | if (link == null) { |
| 1086 | log.warn("Could not find link between: {}-{} | Creating non-serving link..", |
| 1087 | ecgi, ueId); |
| 1088 | link = linkMap.putNonServingLink(cell, ueId); |
| 1089 | } |
| 1090 | |
| 1091 | if (link != null) { |
| 1092 | if (link.getType().equals(RnibLink.Type.NON_SERVING)) { |
| 1093 | restartTimer(link); |
| 1094 | } |
| 1095 | |
| 1096 | RSRQRange rsrq = rxSigReport.getRsrq(); |
| 1097 | RSRPRange rsrp = rxSigReport.getRsrp(); |
| 1098 | |
| 1099 | RnibLink.LinkQuality quality = link.getQuality(); |
| 1100 | quality.setRx(new RnibLink.LinkQuality.Rx( |
| 1101 | rsrp.value.intValue() - 140, |
| 1102 | (rsrq.value.intValue() * 0.5) - 19.5 |
| 1103 | )); |
| 1104 | } |
| 1105 | } else { |
| 1106 | log.warn("case 16: Could not find cell with PCI-ARFCN: {}", |
| 1107 | rxSigReport.getPciArfcn()); |
| 1108 | } |
| 1109 | }); |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | /** |
| 1115 | * Handle RadioMeasReportPerUE. |
| 1116 | * @param radioMeasReportPerUE RadioMeasReportPerUE |
| 1117 | */ |
| 1118 | private void handleRadionmeasreportperue(RadioMeasReportPerUE radioMeasReportPerUE) { |
| 1119 | RnibUe ue = ueMap.get(radioMeasReportPerUE.getEcgi(), radioMeasReportPerUE.getCrnti()); |
| 1120 | if (ue != null) { |
| 1121 | Long ueId = ue.getId(); |
| 1122 | List<RadioRepPerServCell> servCells = radioMeasReportPerUE.getRadioReportServCells() |
| 1123 | .getRadioRepPerServCell(); |
| 1124 | |
| 1125 | servCells.forEach(servCell -> { |
| 1126 | RnibCell cell = cellMap.get(servCell.getPciArfcn()); |
| 1127 | if (cell != null) { |
| 1128 | RnibLink link = linkMap.get(cell.getEcgi(), ueId); |
| 1129 | if (link != null) { |
| 1130 | RadioRepPerServCell.CqiHist cqiHist = servCell.getCqiHist(); |
| 1131 | RnibLink.LinkQuality quality = link.getQuality(); |
| 1132 | |
| 1133 | final double[] values = {0, 0, 0}; |
| 1134 | final int[] i = {1}; |
| 1135 | cqiHist.getBerInteger().forEach(value -> { |
| 1136 | values[0] = Math.max(values[0], value.intValue()); |
| 1137 | values[1] += i[0] * value.intValue(); |
| 1138 | values[2] += value.intValue(); |
| 1139 | i[0]++; |
| 1140 | }); |
| 1141 | |
| 1142 | quality.setCqi(new RnibLink.LinkQuality.Cqi( |
| 1143 | cqiHist, |
| 1144 | values[0], |
| 1145 | values[1] / values[0] |
| 1146 | )); |
| 1147 | |
| 1148 | } else { |
| 1149 | log.warn("Could not find link between: {}-{}", cell.getEcgi(), ueId); |
| 1150 | } |
| 1151 | } else { |
| 1152 | log.warn("case 18: Could not find cell with PCI-ARFCN: {}", servCell.getPciArfcn()); |
| 1153 | } |
| 1154 | }); |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | /** |
| 1159 | * Handle SchedMeasReportPerUE. |
| 1160 | * @param schedMeasReportPerUE SchedMeasReportPerUE |
| 1161 | */ |
| 1162 | private void handleSchedmeasreportperue(SchedMeasReportPerUE schedMeasReportPerUE) { |
| 1163 | RnibUe ue = ueMap.get(schedMeasReportPerUE.getEcgi(), schedMeasReportPerUE.getCrnti()); |
| 1164 | if (ue != null) { |
| 1165 | Long ueId = ue.getId(); |
| 1166 | |
| 1167 | List<SchedMeasRepPerServCell> servCells = schedMeasReportPerUE.getSchedReportServCells() |
| 1168 | .getSchedMeasRepPerServCell(); |
| 1169 | |
| 1170 | servCells.forEach(servCell -> { |
| 1171 | RnibCell cell = cellMap.get(servCell.getPciArfcn()); |
| 1172 | if (cell != null) { |
| 1173 | RnibLink link = linkMap.get(cell.getEcgi(), ueId); |
| 1174 | if (link != null) { |
| 1175 | link.getQuality().setMcs(new RnibLink.LinkQuality.Mcs( |
| 1176 | servCell.getMcsDl(), |
| 1177 | servCell.getMcsUl() |
| 1178 | )); |
| 1179 | |
| 1180 | link.setResourceUsage(new RnibLink.ResourceUsage( |
| 1181 | servCell.getPrbUsage().getPrbUsageDl(), |
| 1182 | servCell.getPrbUsage().getPrbUsageUl() |
| 1183 | )); |
| 1184 | } else { |
| 1185 | log.warn("Could not find link between: {}-{}", cell.getEcgi(), ueId); |
| 1186 | } |
| 1187 | } else { |
| 1188 | log.warn("case 20: Could not find cell with PCI-ARFCN: {}", servCell.getPciArfcn()); |
| 1189 | } |
| 1190 | }); |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | /** |
| 1195 | * Handle SchedMeasReportPerCell. |
| 1196 | * @param schedMeasReportPerCell SchedMeasReportPerCell |
| 1197 | */ |
| 1198 | private void handleSchedmeasreportpercell(SchedMeasReportPerCell schedMeasReportPerCell) { |
| 1199 | RnibCell cell = cellMap.get(schedMeasReportPerCell.getEcgi()); |
| 1200 | if (cell != null) { |
| 1201 | cell.setPrbUsage(new RnibCell.PrbUsageContainer( |
| 1202 | schedMeasReportPerCell.getPrbUsagePcell(), |
| 1203 | schedMeasReportPerCell.getPrbUsageScell() |
| 1204 | )); |
| 1205 | |
| 1206 | cell.setQci(schedMeasReportPerCell.getQciVals()); |
| 1207 | } else { |
| 1208 | log.warn("Could not find cell with ECGI: {}", schedMeasReportPerCell.getEcgi()); |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | /** |
| 1213 | * Handle PDCPMeasReportPerUe. |
| 1214 | * @param pdcpMeasReportPerUe PDCPMeasReportPerUe |
| 1215 | */ |
| 1216 | private void handlePdcpmeasreportperue(PDCPMeasReportPerUe pdcpMeasReportPerUe) { |
| 1217 | RnibUe ue = ueMap.get(pdcpMeasReportPerUe.getEcgi(), pdcpMeasReportPerUe.getCrnti()); |
| 1218 | if (ue != null) { |
| 1219 | Long ueId = ue.getId(); |
| 1220 | RnibLink link = linkMap.get(pdcpMeasReportPerUe.getEcgi(), ueId); |
| 1221 | if (link != null) { |
| 1222 | link.setPdcpThroughput(new RnibLink.PdcpThroughput( |
| 1223 | pdcpMeasReportPerUe.getThroughputDl(), |
| 1224 | pdcpMeasReportPerUe.getThroughputUl() |
| 1225 | )); |
| 1226 | |
| 1227 | link.setPdcpPackDelay(new RnibLink.PdcpPacketdelay( |
| 1228 | pdcpMeasReportPerUe.getPktDelayDl(), |
| 1229 | pdcpMeasReportPerUe.getPktDelayUl() |
| 1230 | )); |
| 1231 | } else { |
| 1232 | log.warn("Could not find link between: {}-{}", pdcpMeasReportPerUe.getEcgi(), ueId); |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | /** |
| 1238 | * Handle UECapabilityInfo. |
| 1239 | * @param capabilityInfo UECapabilityInfo |
| 1240 | */ |
| 1241 | private void handleCapabilityinfo(UECapabilityInfo capabilityInfo) { |
| 1242 | RnibUe ue = ueMap.get(capabilityInfo.getEcgi(), capabilityInfo.getCrnti()); |
| 1243 | if (ue != null) { |
| 1244 | ue.setCapability(capabilityInfo); |
| 1245 | } else { |
| 1246 | log.warn("Could not find UE with this CRNTI: {}", capabilityInfo.getCrnti()); |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | /** |
| 1251 | * Handle UECapabilityEnquiry. |
| 1252 | * @param ueCapabilityEnquiry UECapabilityEnquiry |
| 1253 | * @param ctx ChannelHandlerContext |
| 1254 | * @throws IOException IO Exception |
| 1255 | */ |
| 1256 | private void handleUecapabilityenquiry(UECapabilityEnquiry ueCapabilityEnquiry, ChannelHandlerContext ctx) |
| 1257 | throws IOException { |
| 1258 | XrancPdu xrancPdu = UECapabilityEnquiry.constructPacket(ueCapabilityEnquiry.getEcgi(), |
| 1259 | ueCapabilityEnquiry.getCrnti()); |
| 1260 | ctx.writeAndFlush(getSctpMessage(xrancPdu)); |
| 1261 | } |
| 1262 | |
| 1263 | /** |
| 1264 | * Handle ScellAddStatus. |
| 1265 | * @param scellAddStatus ScellAddStatus |
| 1266 | */ |
| 1267 | private void handleScelladdstatus(ScellAddStatus scellAddStatus) { |
| 1268 | RnibUe ue = ueMap.get(scellAddStatus.getEcgi(), scellAddStatus.getCrnti()); |
| 1269 | if (ue != null) { |
| 1270 | Long ueId = ue.getId(); |
| 1271 | try { |
| 1272 | scellAddMap.get(scellAddStatus.getCrnti()).put("Scell's status: " + |
| 1273 | scellAddStatus.getStatus()); |
| 1274 | final int[] i = {0}; |
| 1275 | scellAddStatus.getScellsInd().getPCIARFCN().forEach( |
| 1276 | pciarfcn -> { |
| 1277 | if (scellAddStatus.getStatus().getBerEnum().get(i[0]).value.intValue() == 0) { |
| 1278 | RnibCell cell = cellMap.get(pciarfcn); |
| 1279 | RnibLink link = linkMap.get(cell.getEcgi(), ueId); |
| 1280 | link.setType(RnibLink.Type.SERVING_SECONDARY_CA); |
| 1281 | } |
| 1282 | i[0]++; |
| 1283 | } |
| 1284 | ); |
| 1285 | |
| 1286 | } catch (InterruptedException e) { |
| 1287 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 1288 | e.printStackTrace(); |
| 1289 | } finally { |
| 1290 | scellAddMap.remove(scellAddStatus.getCrnti()); |
| 1291 | } |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | /** |
| 1296 | * Handle RRMConfigStatus. |
| 1297 | * @param rrmConfigStatus RRMConfigStatus |
| 1298 | */ |
| 1299 | private void handleRrmconfigstatus(RRMConfigStatus rrmConfigStatus) { |
| 1300 | try { |
| 1301 | rrmcellMap.get(rrmConfigStatus.getEcgi()) |
| 1302 | .put("RRM Config's status: " + rrmConfigStatus.getStatus()); |
| 1303 | } catch (InterruptedException e) { |
| 1304 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 1305 | e.printStackTrace(); |
| 1306 | } finally { |
| 1307 | rrmcellMap.remove(rrmConfigStatus.getEcgi()); |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | /** |
| 1312 | * Handle TrafficSplitConfig. |
| 1313 | * @param trafficSplitConfig TrafficSplitConfig |
| 1314 | */ |
| 1315 | private void handleTrafficSplitConfig(TrafficSplitConfig trafficSplitConfig) { |
| 1316 | RnibUe ue = ueMap.get(trafficSplitConfig.getEcgi(), trafficSplitConfig.getCrnti()); |
| 1317 | if (ue != null) { |
| 1318 | Long ueId = ue.getId(); |
| 1319 | List<TrafficSplitPercentage> splitPercentages = trafficSplitConfig |
| 1320 | .getTrafficSplitPercent().getTrafficSplitPercentage(); |
| 1321 | |
| 1322 | splitPercentages.forEach(trafficSplitPercentage -> { |
| 1323 | RnibCell cell = cellMap.get(trafficSplitPercentage.getEcgi()); |
| 1324 | if (cell != null) { |
| 1325 | RnibLink link = linkMap.get(cell.getEcgi(), ueId); |
| 1326 | if (link != null) { |
| 1327 | link.setTrafficPercent(trafficSplitPercentage); |
| 1328 | } else { |
| 1329 | log.warn("Could not find link between: {}-{}", cell.getEcgi(), ueId); |
| 1330 | } |
| 1331 | } else { |
| 1332 | log.warn("Could not find cell with ECGI: {}", trafficSplitConfig.getEcgi()); |
| 1333 | } |
| 1334 | }); |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | /** |
| 1339 | * Handle context update depending if its handoff or not. |
| 1340 | * |
| 1341 | * @param contextUpdate context update packet |
| 1342 | * @param ctx channel context for the CELL |
| 1343 | * @param handoff true if we handle a Hand Off |
| 1344 | */ |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 1345 | private void handleContextUpdate(UEContextUpdate contextUpdate, ChannelHandlerContext ctx, boolean handoff) { |
| 1346 | RnibUe ue; |
| 1347 | RnibCell cell = xranStore.getCell(contextUpdate.getEcgi()); |
| 1348 | |
| 1349 | if (handoff) { |
| 1350 | try { |
| 1351 | ue = ueMap.get(ueIdQueue.take()); |
| 1352 | } catch (InterruptedException e) { |
| 1353 | e.printStackTrace(); |
| 1354 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 1355 | ue = new RnibUe(); |
| 1356 | } |
| 1357 | } else { |
| 1358 | ue = new RnibUe(); |
| 1359 | } |
| 1360 | |
| 1361 | ue.setMmeS1apId(contextUpdate.getMMEUES1APID()); |
| 1362 | ue.setEnbS1apId(contextUpdate.getENBUES1APID()); |
| 1363 | ue.setCrnti(contextUpdate.getCrnti()); |
| 1364 | |
| 1365 | hostAgent.addConnectedHost(ue, cell, ctx); |
| 1366 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 1369 | /** |
| 1370 | * Internal class for NetworkConfigListener. |
| 1371 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1372 | class InternalNetworkConfigListener implements NetworkConfigListener { |
| 1373 | |
| 1374 | @Override |
| 1375 | public void event(NetworkConfigEvent event) { |
| 1376 | switch (event.type()) { |
| 1377 | case CONFIG_REGISTERED: |
| 1378 | break; |
| 1379 | case CONFIG_UNREGISTERED: |
| 1380 | break; |
| 1381 | case CONFIG_ADDED: |
| 1382 | case CONFIG_UPDATED: |
| 1383 | if (event.configClass() == CONFIG_CLASS) { |
| 1384 | handleConfigEvent(event.config()); |
| 1385 | } |
| 1386 | break; |
| 1387 | case CONFIG_REMOVED: |
| 1388 | break; |
| 1389 | default: |
| 1390 | break; |
| 1391 | } |
| 1392 | } |
| 1393 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 1394 | /** |
| 1395 | * Handle config event. |
| 1396 | * |
| 1397 | * @param config |
| 1398 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1399 | private void handleConfigEvent(Optional<Config> config) { |
| 1400 | if (!config.isPresent()) { |
| 1401 | return; |
| 1402 | } |
| 1403 | |
| 1404 | xranConfig = (XranConfig) config.get(); |
| 1405 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 1406 | northboundTimeout = xranConfig.getNorthBoundTimeout(); |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 1407 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1408 | legitCells.putAll(xranConfig.activeCellSet()); |
| 1409 | |
| 1410 | controller.start(deviceAgent, hostAgent, packetAgent, xranConfig.getXrancPort()); |
| 1411 | } |
| 1412 | } |
| 1413 | } |