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.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; |
| 23 | import org.apache.felix.scr.annotations.*; |
| 24 | import org.onosproject.core.ApplicationId; |
| 25 | import org.onosproject.core.CoreService; |
| 26 | import org.onosproject.net.config.*; |
| 27 | import org.onosproject.net.config.basics.SubjectFactories; |
| 28 | import org.onosproject.net.device.DeviceEvent; |
| 29 | import org.onosproject.net.device.DeviceListener; |
| 30 | import org.onosproject.net.device.DeviceService; |
| 31 | import org.onosproject.net.host.HostEvent; |
| 32 | import org.onosproject.net.host.HostListener; |
| 33 | import org.onosproject.net.host.HostService; |
| 34 | import org.onosproject.xran.XranStore; |
| 35 | import org.onosproject.xran.codecs.api.*; |
slowr | c153ad9 | 2017-08-16 19:47:52 -0700 | [diff] [blame] | 36 | import org.onosproject.xran.codecs.ber.types.BerInteger; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 37 | import org.onosproject.xran.codecs.pdu.*; |
| 38 | import org.onosproject.xran.entities.RnibCell; |
| 39 | import org.onosproject.xran.entities.RnibLink; |
| 40 | import org.onosproject.xran.entities.RnibUe; |
| 41 | import org.onosproject.xran.identifiers.LinkId; |
| 42 | import org.onosproject.xran.impl.XranConfig; |
| 43 | import org.onosproject.xran.providers.XranDeviceListener; |
| 44 | import org.onosproject.xran.providers.XranHostListener; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 45 | import org.onosproject.xran.wrapper.CellMap; |
| 46 | import org.onosproject.xran.wrapper.LinkMap; |
| 47 | import org.onosproject.xran.wrapper.UeMap; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 48 | import org.slf4j.Logger; |
| 49 | import org.slf4j.LoggerFactory; |
| 50 | |
| 51 | import java.io.IOException; |
| 52 | import java.util.*; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 53 | import java.util.concurrent.ConcurrentHashMap; |
| 54 | import java.util.concurrent.ConcurrentMap; |
| 55 | import java.util.concurrent.CopyOnWriteArraySet; |
| 56 | import java.util.concurrent.SynchronousQueue; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 57 | import java.util.stream.Collectors; |
| 58 | |
| 59 | import static org.onosproject.net.DeviceId.deviceId; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 60 | import static org.onosproject.xran.controller.XranChannelHandler.getSctpMessage; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 61 | import static org.onosproject.xran.entities.RnibCell.decodeDeviceId; |
| 62 | import static org.onosproject.xran.entities.RnibCell.uri; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 63 | import static org.onosproject.xran.entities.RnibUe.hostIdtoMME; |
| 64 | |
| 65 | /** |
| 66 | * Created by dimitris on 7/20/17. |
| 67 | */ |
| 68 | @Component(immediate = true) |
| 69 | @Service |
| 70 | public class XranControllerImpl implements XranController { |
| 71 | private static final String XRAN_APP_ID = "org.onosproject.xran"; |
| 72 | private static final Class<XranConfig> CONFIG_CLASS = XranConfig.class; |
| 73 | |
| 74 | private static final Logger log = |
| 75 | LoggerFactory.getLogger(XranControllerImpl.class); |
| 76 | /* CONFIG */ |
| 77 | private final InternalNetworkConfigListener configListener = |
| 78 | new InternalNetworkConfigListener(); |
| 79 | /* VARIABLES */ |
| 80 | private final Controller controller = new Controller(); |
| 81 | private XranConfig xranConfig; |
| 82 | private ApplicationId appId; |
| 83 | /* Services */ |
| 84 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 85 | private DeviceService deviceService; |
| 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 87 | private HostService hostService; |
| 88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 89 | private NetworkConfigRegistry registry; |
| 90 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 91 | private NetworkConfigService configService; |
| 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 93 | private CoreService coreService; |
| 94 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 95 | private XranStore xranStore; |
| 96 | private ConfigFactory<ApplicationId, XranConfig> xranConfigFactory = |
| 97 | new ConfigFactory<ApplicationId, XranConfig>( |
| 98 | SubjectFactories.APP_SUBJECT_FACTORY, CONFIG_CLASS, "xran") { |
| 99 | @Override |
| 100 | public XranConfig createConfig() { |
| 101 | return new XranConfig(); |
| 102 | } |
| 103 | }; |
| 104 | /* WRAPPERS */ |
| 105 | private CellMap cellMap; |
| 106 | private UeMap ueMap; |
| 107 | private LinkMap linkMap; |
| 108 | /* MAPS */ |
| 109 | private ConcurrentMap<String, ECGI> legitCells = new ConcurrentHashMap<>(); |
slowr | 7c0e167 | 2017-08-15 17:09:14 -0700 | [diff] [blame] | 110 | private ConcurrentMap<CRNTI, UEContextUpdate> hoContextUpdateMap = new ConcurrentHashMap<>(); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 111 | private ConcurrentMap<CRNTI, SynchronousQueue<String>> hoQueue = new ConcurrentHashMap<>(); |
| 112 | private ConcurrentMap<ECGI, SynchronousQueue<String>> RRMCellQueue = new ConcurrentHashMap<>(); |
| 113 | private ConcurrentMap<CRNTI, SynchronousQueue<String>> scellAddQueue = new ConcurrentHashMap<>(); |
| 114 | private ConcurrentMap<CRNTI, SynchronousQueue<String>> scellDeleteQueue = new ConcurrentHashMap<>(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 115 | /* AGENTS */ |
| 116 | private InternalXranDeviceAgent deviceAgent = new InternalXranDeviceAgent(); |
| 117 | private InternalXranHostAgent hostAgent = new InternalXranHostAgent(); |
| 118 | private InternalXranPacketAgent packetAgent = new InternalXranPacketAgent(); |
| 119 | /* LISTENERS */ |
| 120 | private Set<XranDeviceListener> xranDeviceListeners = new CopyOnWriteArraySet<>(); |
| 121 | private Set<XranHostListener> xranHostListeners = new CopyOnWriteArraySet<>(); |
| 122 | private InternalDeviceListener device_listener = new InternalDeviceListener(); |
| 123 | private InternalHostListener host_listener = new InternalHostListener(); |
| 124 | |
| 125 | @Activate |
| 126 | public void activate() { |
| 127 | appId = coreService.registerApplication(XRAN_APP_ID); |
| 128 | |
| 129 | configService.addListener(configListener); |
| 130 | registry.registerConfigFactory(xranConfigFactory); |
| 131 | deviceService.addListener(device_listener); |
| 132 | hostService.addListener(host_listener); |
| 133 | |
| 134 | cellMap = new CellMap(xranStore); |
| 135 | ueMap = new UeMap(xranStore); |
| 136 | linkMap = new LinkMap(xranStore); |
| 137 | |
| 138 | xranStore.setController(this); |
| 139 | |
| 140 | log.info("XRAN Controller Started"); |
| 141 | } |
| 142 | |
| 143 | @Deactivate |
| 144 | public void deactivate() { |
| 145 | controller.stop(); |
| 146 | |
| 147 | deviceService.removeListener(device_listener); |
| 148 | hostService.removeListener(host_listener); |
| 149 | |
| 150 | legitCells.clear(); |
| 151 | |
| 152 | configService.removeListener(configListener); |
| 153 | registry.unregisterConfigFactory(xranConfigFactory); |
| 154 | |
| 155 | log.info("XRAN Controller Stopped"); |
| 156 | } |
| 157 | |
| 158 | @Override |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 159 | public SynchronousQueue<String> sendHORequest(RnibLink newLink, RnibLink oldLink) { |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 160 | ECGI newEcgi = newLink.getLinkId().getEcgi(), |
| 161 | oldEcgi = oldLink.getLinkId().getEcgi(); |
| 162 | CRNTI crnti = linkMap.getCrnti(newLink.getLinkId().getMmeues1apid()); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 163 | ChannelHandlerContext newCtx = cellMap.getCtx(newEcgi), |
| 164 | oldCtx = cellMap.getCtx(oldEcgi); |
| 165 | |
| 166 | try { |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 167 | XrancPdu xrancPdu = HORequest.constructPacket(crnti, oldEcgi, newEcgi); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 168 | newCtx.writeAndFlush(getSctpMessage(xrancPdu)); |
| 169 | oldCtx.writeAndFlush(getSctpMessage(xrancPdu)); |
| 170 | } catch (IOException e) { |
| 171 | e.printStackTrace(); |
| 172 | } |
| 173 | |
| 174 | SynchronousQueue<String> queue = new SynchronousQueue<>(); |
| 175 | hoQueue.put(crnti, queue); |
| 176 | |
| 177 | return queue; |
| 178 | } |
| 179 | |
| 180 | @Override |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 181 | public void addListener(XranDeviceListener listener) { |
| 182 | xranDeviceListeners.add(listener); |
| 183 | } |
| 184 | |
| 185 | @Override |
| 186 | public void addListener(XranHostListener listener) { |
| 187 | xranHostListeners.add(listener); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public void removeListener(XranDeviceListener listener) { |
| 192 | xranDeviceListeners.remove(listener); |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void removeListener(XranHostListener listener) { |
| 197 | xranHostListeners.remove(listener); |
| 198 | } |
| 199 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 200 | @Override |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 201 | public SynchronousQueue<String> sendModifiedRRMConf(RRMConfig rrmConfig, boolean xICIC) { |
| 202 | ECGI ecgi = rrmConfig.getEcgi(); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 203 | ChannelHandlerContext ctx = cellMap.getCtx(ecgi); |
| 204 | try { |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 205 | XrancPdu pdu; |
| 206 | if (xICIC) { |
| 207 | pdu = XICICConfig.constructPacket(rrmConfig); |
| 208 | } else { |
| 209 | pdu = RRMConfig.constructPacket(rrmConfig); |
| 210 | } |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 211 | ctx.writeAndFlush(getSctpMessage(pdu)); |
| 212 | } catch (IOException e) { |
| 213 | e.printStackTrace(); |
| 214 | } |
| 215 | SynchronousQueue<String> queue = new SynchronousQueue<>(); |
| 216 | RRMCellQueue.put(ecgi, queue); |
| 217 | |
| 218 | return queue; |
| 219 | } |
| 220 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 221 | @Override |
| 222 | public SynchronousQueue<String> sendScellAdd(RnibLink link) { |
| 223 | RnibCell secondaryCell = link.getLinkId().getCell(), |
| 224 | primaryCell = linkMap.getPrimaryCell(link.getLinkId().getUe()); |
| 225 | ECGI primaryEcgi = primaryCell.getEcgi(); |
| 226 | ChannelHandlerContext ctx = cellMap.getCtx(primaryEcgi); |
| 227 | |
| 228 | CRNTI crnti = linkMap.getCrnti(link.getLinkId().getMmeues1apid()); |
| 229 | |
| 230 | CellConfigReport cellReport = secondaryCell.getConf(); |
| 231 | |
| 232 | if (cellReport != null) { |
| 233 | PCIARFCN pciarfcn = new PCIARFCN(); |
| 234 | pciarfcn.setPci(cellReport.getPci()); |
| 235 | pciarfcn.setEarfcnDl(cellReport.getEarfcnDl()); |
| 236 | |
| 237 | PropScell propScell = new PropScell(); |
| 238 | propScell.setPciArfcn(pciarfcn); |
| 239 | |
| 240 | XrancPdu pdu = ScellAdd.constructPacket(primaryEcgi, crnti, propScell); |
| 241 | try { |
| 242 | ctx.writeAndFlush(getSctpMessage(pdu)); |
| 243 | SynchronousQueue<String> queue = new SynchronousQueue<>(); |
| 244 | scellAddQueue.put(crnti, queue); |
| 245 | |
| 246 | return queue; |
| 247 | } catch (IOException e) { |
| 248 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 249 | e.printStackTrace(); |
| 250 | } |
| 251 | } |
| 252 | return null; |
| 253 | } |
| 254 | |
| 255 | @Override |
| 256 | public boolean sendScellDelete(RnibLink link) { |
| 257 | RnibCell secondaryCell = link.getLinkId().getCell(), |
| 258 | primaryCell = linkMap.getPrimaryCell(link.getLinkId().getUe()); |
| 259 | ECGI primaryEcgi = primaryCell.getEcgi(); |
| 260 | ChannelHandlerContext ctx = cellMap.getCtx(primaryEcgi); |
| 261 | |
| 262 | CRNTI crnti = linkMap.getCrnti(link.getLinkId().getMmeues1apid()); |
| 263 | |
| 264 | CellConfigReport cellReport = secondaryCell.getConf(); |
| 265 | |
| 266 | if (cellReport != null) { |
| 267 | PCIARFCN pciarfcn = new PCIARFCN(); |
| 268 | pciarfcn.setPci(cellReport.getPci()); |
| 269 | pciarfcn.setEarfcnDl(cellReport.getEarfcnDl()); |
| 270 | |
| 271 | XrancPdu pdu = ScellDelete.constructPacket(primaryEcgi, crnti, pciarfcn); |
| 272 | |
| 273 | try { |
| 274 | ctx.writeAndFlush(getSctpMessage(pdu)); |
| 275 | link.setType(RnibLink.Type.NON_SERVING); |
| 276 | return true; |
| 277 | } catch (IOException e) { |
| 278 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 279 | e.printStackTrace(); |
| 280 | } |
| 281 | } |
| 282 | return false; |
| 283 | } |
| 284 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 285 | private void restartTimer(RnibUe ue) { |
| 286 | Timer timer = new Timer(); |
| 287 | ue.setTimer(timer); |
| 288 | log.info("Starting UE timer..."); |
| 289 | timer.schedule(new TimerTask() { |
| 290 | @Override |
| 291 | public void run() { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 292 | if (ue.getState() == RnibUe.State.IDLE) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 293 | hostAgent.removeConnectedHost(ue); |
| 294 | log.info("UE is removed after 10 seconds of IDLE"); |
| 295 | } else { |
| 296 | log.info("UE not removed cause its ACTIVE"); |
| 297 | } |
| 298 | } |
| 299 | }, 10000); |
| 300 | } |
| 301 | |
| 302 | private void restartTimer(RnibLink link) { |
| 303 | Timer timer = new Timer(); |
| 304 | link.setTimer(timer); |
| 305 | log.info("Starting Link timer..."); |
| 306 | timer.schedule(new TimerTask() { |
| 307 | @Override |
| 308 | public void run() { |
| 309 | LinkId linkId = link.getLinkId(); |
| 310 | xranStore.removeLink(linkId); |
| 311 | log.info("Link is removed after not receiving Meas Reports for 10 seconds"); |
| 312 | } |
| 313 | }, 10000); |
| 314 | |
| 315 | } |
| 316 | |
| 317 | class InternalDeviceListener implements DeviceListener { |
| 318 | |
| 319 | @Override |
| 320 | public void event(DeviceEvent event) { |
| 321 | log.info("Device Event {}", event); |
| 322 | switch (event.type()) { |
| 323 | case DEVICE_ADDED: { |
| 324 | try { |
| 325 | ECGI ecgi = decodeDeviceId(event.subject().id()); |
| 326 | RnibCell cell = cellMap.get(ecgi); |
| 327 | if (cell != null) { |
| 328 | Timer timer = new Timer(); |
| 329 | timer.scheduleAtFixedRate( |
| 330 | new TimerTask() { |
| 331 | @Override |
| 332 | public void run() { |
| 333 | CellConfigReport conf = cell.getConf(); |
| 334 | if (conf == null) { |
| 335 | try { |
| 336 | ChannelHandlerContext ctx = cellMap.getCtx(ecgi); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 337 | XrancPdu xrancPdu = CellConfigRequest.constructPacket(ecgi); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 338 | ctx.writeAndFlush(getSctpMessage(xrancPdu)); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 339 | } catch (IOException e) { |
| 340 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 341 | e.printStackTrace(); |
| 342 | } |
| 343 | } else { |
| 344 | // FIXME: maybe remove this map. |
| 345 | cellMap.putPciArfcn(cell); |
| 346 | try { |
| 347 | ChannelHandlerContext ctx = cellMap. |
| 348 | getCtx(ecgi); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 349 | XrancPdu xrancPdu = L2MeasConfig.constructPacket(ecgi, xranConfig.getL2MeasInterval()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 350 | cell.setMeasConfig(xrancPdu.getBody().getL2MeasConfig()); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 351 | SctpMessage sctpMessage = getSctpMessage(xrancPdu); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 352 | ctx.writeAndFlush(sctpMessage); |
| 353 | } catch (IOException e) { |
| 354 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 355 | e.printStackTrace(); |
| 356 | } |
| 357 | timer.cancel(); |
| 358 | timer.purge(); |
| 359 | } |
| 360 | } |
| 361 | }, |
| 362 | 0, |
| 363 | xranConfig.getConfigRequestInterval() * 1000 |
| 364 | ); |
| 365 | } |
| 366 | } catch (IOException e) { |
| 367 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 368 | e.printStackTrace(); |
| 369 | } |
| 370 | break; |
| 371 | } |
| 372 | default: { |
| 373 | break; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | class InternalHostListener implements HostListener { |
| 380 | |
| 381 | @Override |
| 382 | public void event(HostEvent event) { |
| 383 | log.info("Host Event {}", event); |
| 384 | switch (event.type()) { |
| 385 | case HOST_ADDED: |
| 386 | case HOST_MOVED: { |
| 387 | RnibUe ue = ueMap.get(hostIdtoMME(event.subject().id())); |
| 388 | if (ue != null) { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 389 | ECGI ecgi_primary = linkMap.getPrimaryCell(ue).getEcgi(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 390 | RnibCell primary = cellMap.get(ecgi_primary); |
| 391 | ue.setMeasConfig(null); |
| 392 | if (primary != null) { |
| 393 | Timer timer = new Timer(); |
| 394 | timer.scheduleAtFixedRate( |
| 395 | new TimerTask() { |
| 396 | @Override |
| 397 | public void run() { |
| 398 | if (ue.getCapability() == null) { |
| 399 | try { |
| 400 | ChannelHandlerContext ctx = cellMap.getCtx(primary.getEcgi()); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 401 | XrancPdu xrancPdu = UECapabilityEnquiry.constructPacket( |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 402 | primary.getEcgi(), |
| 403 | ue.getRanId()); |
| 404 | ctx.writeAndFlush(getSctpMessage(xrancPdu)); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 405 | } catch (IOException e) { |
| 406 | log.warn(ExceptionUtils.getFullStackTrace(e)); |
| 407 | e.printStackTrace(); |
| 408 | } |
| 409 | } else { |
| 410 | if (ue.getMeasConfig() == null) { |
| 411 | try { |
| 412 | ChannelHandlerContext ctx = cellMap.getCtx(primary.getEcgi()); |
| 413 | RXSigMeasConfig.MeasCells measCells = new RXSigMeasConfig.MeasCells(); |
| 414 | xranStore.getCellNodes().forEach(cell -> { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 415 | CellConfigReport cellReport = ((RnibCell) cell).getConf(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 416 | if (cellReport != null) { |
| 417 | PCIARFCN pciarfcn = new PCIARFCN(); |
| 418 | pciarfcn.setPci(cellReport.getPci()); |
| 419 | pciarfcn.setEarfcnDl(cellReport.getEarfcnDl()); |
| 420 | measCells.setPCIARFCN(pciarfcn); |
| 421 | } |
| 422 | }); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 423 | XrancPdu xrancPdu = RXSigMeasConfig.constructPacket( |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 424 | primary.getEcgi(), |
| 425 | ue.getRanId(), |
| 426 | measCells, |
| 427 | xranConfig.getRxSignalInterval() |
| 428 | ); |
| 429 | ue.setMeasConfig(xrancPdu.getBody().getRXSigMeasConfig()); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 430 | ctx.writeAndFlush(getSctpMessage(xrancPdu)); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 431 | } catch (IOException e) { |
| 432 | log.warn(ExceptionUtils.getFullStackTrace(e)); |
| 433 | e.printStackTrace(); |
| 434 | } |
| 435 | } |
| 436 | timer.cancel(); |
| 437 | timer.purge(); |
| 438 | } |
| 439 | } |
| 440 | }, |
| 441 | 0, |
| 442 | xranConfig.getConfigRequestInterval() * 1000 |
| 443 | ); |
| 444 | } |
| 445 | } |
| 446 | break; |
| 447 | } |
| 448 | default: { |
| 449 | break; |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | public class InternalXranDeviceAgent implements XranDeviceAgent { |
| 456 | |
| 457 | private final Logger log = LoggerFactory.getLogger(InternalXranDeviceAgent.class); |
| 458 | |
| 459 | @Override |
| 460 | public boolean addConnectedCell(String host, ChannelHandlerContext ctx) { |
| 461 | ECGI ecgi = legitCells.get(host); |
| 462 | |
| 463 | if (ecgi == null) { |
| 464 | log.error("Device is not a legit source; ignoring..."); |
| 465 | } else { |
| 466 | log.info("Device exists in configuration; registering..."); |
| 467 | RnibCell storeCell = cellMap.get(ecgi); |
| 468 | if (storeCell == null) { |
| 469 | storeCell = new RnibCell(); |
| 470 | storeCell.setEcgi(ecgi); |
| 471 | cellMap.put(storeCell, ctx); |
| 472 | |
| 473 | for (XranDeviceListener l : xranDeviceListeners) { |
| 474 | l.deviceAdded(storeCell); |
| 475 | } |
| 476 | return true; |
| 477 | } else { |
| 478 | log.error("Device already registered; ignoring..."); |
| 479 | } |
| 480 | } |
| 481 | ctx.close(); |
| 482 | return false; |
| 483 | } |
| 484 | |
| 485 | @Override |
| 486 | public boolean removeConnectedCell(String host) { |
| 487 | ECGI ecgi = legitCells.get(host); |
| 488 | List<RnibLink> linksByECGI = xranStore.getLinksByECGI(ecgi); |
| 489 | |
| 490 | linksByECGI.forEach(rnibLink -> xranStore.removeLink(rnibLink.getLinkId())); |
| 491 | |
| 492 | if (cellMap.remove(ecgi)) { |
| 493 | for (XranDeviceListener l : xranDeviceListeners) { |
| 494 | l.deviceRemoved(deviceId(uri(ecgi))); |
| 495 | } |
| 496 | return true; |
| 497 | } |
| 498 | return false; |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | public class InternalXranHostAgent implements XranHostAgent { |
| 503 | |
| 504 | @Override |
| 505 | public boolean addConnectedHost(RnibUe ue, RnibCell cell, ChannelHandlerContext ctx) { |
| 506 | |
| 507 | if (ueMap.get(ue.getMmeS1apId()) != null) { |
| 508 | linkMap.putPrimaryLink(cell, ue); |
| 509 | |
| 510 | Set<ECGI> ecgiSet = xranStore.getLinksByUeId(ue.getMmeS1apId().longValue()) |
| 511 | .stream() |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 512 | .map(l -> l.getLinkId().getEcgi()) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 513 | .collect(Collectors.toSet()); |
| 514 | |
| 515 | for (XranHostListener l : xranHostListeners) { |
| 516 | l.hostAdded(ue, ecgiSet); |
| 517 | } |
| 518 | return true; |
| 519 | } else { |
| 520 | ueMap.put(ue); |
| 521 | linkMap.putPrimaryLink(cell, ue); |
| 522 | |
| 523 | Set<ECGI> ecgiSet = Sets.newConcurrentHashSet(); |
| 524 | ecgiSet.add(cell.getEcgi()); |
| 525 | for (XranHostListener l : xranHostListeners) { |
| 526 | l.hostAdded(ue, ecgiSet); |
| 527 | } |
| 528 | return true; |
| 529 | } |
| 530 | |
| 531 | } |
| 532 | |
| 533 | @Override |
| 534 | public boolean removeConnectedHost(RnibUe ue) { |
| 535 | List<RnibLink> links = xranStore.getLinksByUeId(ue.getMmeS1apId().longValue()); |
| 536 | links.forEach(rnibLink -> xranStore.removeLink(rnibLink.getLinkId())); |
| 537 | if (ueMap.remove(ue.getMmeS1apId())) { |
| 538 | for (XranHostListener l : xranHostListeners) { |
| 539 | l.hostRemoved(ue.getHostId()); |
| 540 | } |
| 541 | return true; |
| 542 | } |
| 543 | return false; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | public class InternalXranPacketAgent implements XranPacketProcessor { |
| 548 | @Override |
| 549 | public void handlePacket(XrancPdu recv_pdu, ChannelHandlerContext ctx) throws IOException { |
| 550 | XrancPdu send_pdu; |
| 551 | |
| 552 | int apiID = recv_pdu.getHdr().getApiId().intValue(); |
| 553 | log.debug("Received message: {}", recv_pdu); |
| 554 | switch (apiID) { |
| 555 | case 1: { |
| 556 | // Decode Cell config report. |
| 557 | CellConfigReport report = recv_pdu.getBody().getCellConfigReport(); |
| 558 | |
| 559 | ECGI ecgi = report.getEcgi(); |
| 560 | |
| 561 | RnibCell cell = xranStore.getCell(ecgi); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 562 | cell.setVersion(recv_pdu.getHdr().getVer().toString()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 563 | cell.setConf(report); |
| 564 | |
| 565 | break; |
| 566 | } |
| 567 | case 2: { |
| 568 | // Decode UE Admission Request. |
| 569 | UEAdmissionRequest ueAdmissionRequest = recv_pdu.getBody().getUEAdmissionRequest(); |
| 570 | |
| 571 | ECGI ecgi = ueAdmissionRequest.getEcgi(); |
| 572 | if (xranStore.getCell(ecgi) != null) { |
| 573 | CRNTI crnti = ueAdmissionRequest.getCrnti(); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 574 | send_pdu = UEAdmissionResponse.constructPacket(ecgi, crnti, xranConfig.admissionFlag()); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 575 | ctx.writeAndFlush(getSctpMessage(send_pdu)); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 576 | } else { |
| 577 | log.warn("Could not find ECGI in registered cells: {}", ecgi); |
| 578 | } |
| 579 | break; |
| 580 | } |
| 581 | case 4: { |
| 582 | // Decode UE Admission Status. |
| 583 | UEAdmissionStatus ueAdmissionStatus = recv_pdu.getBody().getUEAdmissionStatus(); |
| 584 | |
| 585 | RnibUe ue = ueMap.get(ueAdmissionStatus.getCrnti()); |
| 586 | if (ue != null) { |
| 587 | if (ueAdmissionStatus.getAdmEstStatus().value.intValue() == 0) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 588 | ue.setState(RnibUe.State.ACTIVE); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 589 | } else { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 590 | ue.setState(RnibUe.State.IDLE); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | break; |
| 594 | } |
| 595 | case 5: { |
| 596 | // Decode UE Admission Context Update. |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 597 | UEContextUpdate ueContextUpdate = recv_pdu.getBody().getUEContextUpdate(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 598 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 599 | RnibUe ue = ueMap.get(ueContextUpdate.getMMEUES1APID()); |
slowr | d999aec | 2017-08-16 08:46:44 -0700 | [diff] [blame] | 600 | if (ue != null && hoQueue.keySet().contains(ue.getRanId())) { |
slowr | 7c0e167 | 2017-08-15 17:09:14 -0700 | [diff] [blame] | 601 | CRNTI crnti = ueContextUpdate.getCrnti(); |
| 602 | hoContextUpdateMap.put(crnti, ueContextUpdate); |
| 603 | hoQueue.remove(ue.getRanId()); |
| 604 | } else { |
| 605 | RnibCell cell = xranStore.getCell(ueContextUpdate.getEcgi()); |
slowr | d999aec | 2017-08-16 08:46:44 -0700 | [diff] [blame] | 606 | if (ue == null) { |
slowr | 7c0e167 | 2017-08-15 17:09:14 -0700 | [diff] [blame] | 607 | ue = new RnibUe(); |
| 608 | } |
| 609 | |
| 610 | ue.setMmeS1apId(ueContextUpdate.getMMEUES1APID()); |
| 611 | ue.setEnbS1apId(ueContextUpdate.getENBUES1APID()); |
| 612 | ue.setRanId(ueContextUpdate.getCrnti()); |
| 613 | |
| 614 | hostAgent.addConnectedHost(ue, cell, ctx); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 615 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 616 | break; |
| 617 | } |
| 618 | case 6: { |
| 619 | // Decode UE Reconfig_Ind. |
| 620 | UEReconfigInd ueReconfigInd = recv_pdu.getBody().getUEReconfigInd(); |
| 621 | RnibUe ue = ueMap.get(ueReconfigInd.getCrntiOld()); |
| 622 | |
| 623 | if (ue != null) { |
| 624 | ue.setRanId(ueReconfigInd.getCrntiNew()); |
| 625 | } else { |
| 626 | log.warn("Could not find UE with this CRNTI: {}", ueReconfigInd.getCrntiOld()); |
| 627 | } |
| 628 | break; |
| 629 | } |
| 630 | case 7: { |
| 631 | // If xRANc wants to deactivate UE, we pass UEReleaseInd from xRANc to eNB. |
| 632 | // Decode UE Release_Ind. |
| 633 | UEReleaseInd ueReleaseInd = recv_pdu.getBody().getUEReleaseInd(); |
| 634 | RnibUe ue = ueMap.get(ueReleaseInd.getCrnti()); |
| 635 | if (ue != null) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 636 | ue.setState(RnibUe.State.IDLE); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 637 | restartTimer(ue); |
| 638 | } |
| 639 | break; |
| 640 | } |
| 641 | case 8: { |
| 642 | // Decode Bearer Adm Request |
| 643 | BearerAdmissionRequest bearerAdmissionRequest = recv_pdu.getBody().getBearerAdmissionRequest(); |
| 644 | |
| 645 | ECGI ecgi = bearerAdmissionRequest.getEcgi(); |
| 646 | CRNTI crnti = bearerAdmissionRequest.getCrnti(); |
| 647 | ERABParams erabParams = bearerAdmissionRequest.getErabParams(); |
| 648 | RnibLink link = linkMap.get(ecgi, crnti); |
| 649 | if (link != null) { |
| 650 | link.setBearerParameters(erabParams); |
| 651 | } else { |
| 652 | log.warn("Could not find link between {}-{}", ecgi, crnti); |
| 653 | } |
| 654 | |
| 655 | BerInteger numErabs = bearerAdmissionRequest.getNumErabs(); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 656 | // Encode and send Bearer Admission Response |
| 657 | send_pdu = BearerAdmissionResponse.constructPacket(ecgi, crnti, erabParams, numErabs, xranConfig.bearerFlag()); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 658 | ctx.writeAndFlush(getSctpMessage(send_pdu)); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 659 | break; |
| 660 | } |
| 661 | case 10: { |
| 662 | //Decode Bearer Admission Status |
| 663 | BearerAdmissionStatus bearerAdmissionStatus = recv_pdu.getBody().getBearerAdmissionStatus(); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 664 | break; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 665 | // ECGI ecgi = bearerAdmissionStatus.getEcgi(); |
| 666 | // CRNTI crnti = bearerAdmissionStatus.getCrnti(); |
| 667 | // |
| 668 | // RnibLink link = linkMap.get(ecgi, crnti); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 669 | } |
| 670 | case 11: { |
| 671 | //Decode Bearer Release Ind |
| 672 | BearerReleaseInd bearerReleaseInd = recv_pdu.getBody().getBearerReleaseInd(); |
| 673 | |
| 674 | ECGI ecgi = bearerReleaseInd.getEcgi(); |
| 675 | CRNTI crnti = bearerReleaseInd.getCrnti(); |
| 676 | RnibLink link = linkMap.get(ecgi, crnti); |
| 677 | |
| 678 | List<ERABID> erabidsRelease = bearerReleaseInd.getErabIds().getERABID(); |
| 679 | List<ERABParamsItem> erabParamsItem = link.getBearerParameters().getERABParamsItem(); |
| 680 | |
| 681 | List<ERABParamsItem> unreleased = erabParamsItem |
| 682 | .stream() |
| 683 | .filter(item -> { |
| 684 | Optional<ERABID> any = erabidsRelease.stream().filter(id -> id.equals(item.getId())).findAny(); |
| 685 | return !any.isPresent(); |
| 686 | }).collect(Collectors.toList()); |
| 687 | |
| 688 | link.getBearerParameters().setERABParamsItem(new ArrayList<>(unreleased)); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 689 | break; |
| 690 | } |
| 691 | case 13: { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 692 | HOFailure hoFailure = recv_pdu.getBody().getHOFailure(); |
| 693 | |
| 694 | try { |
| 695 | hoQueue.get(hoFailure.getCrnti()) |
| 696 | .put("Hand Over Failed with cause: " + hoFailure.getCause()); |
| 697 | } catch (InterruptedException e) { |
| 698 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 699 | e.printStackTrace(); |
| 700 | } finally { |
| 701 | hoQueue.remove(hoFailure.getCrnti()); |
| 702 | } |
| 703 | break; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 704 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 705 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 706 | case 14: { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 707 | HOComplete hoComplete = recv_pdu.getBody().getHOComplete(); |
| 708 | |
| 709 | RnibLink oldLink = linkMap.get(hoComplete.getEcgiS(), hoComplete.getCrntiNew()), |
| 710 | newLink = linkMap.get(hoComplete.getEcgiT(), hoComplete.getCrntiNew()); |
| 711 | |
| 712 | oldLink.setType(RnibLink.Type.NON_SERVING); |
| 713 | newLink.setType(RnibLink.Type.SERVING_PRIMARY); |
| 714 | |
| 715 | try { |
| 716 | hoQueue.get(hoComplete.getCrntiNew()) |
| 717 | .put("Hand Over Completed"); |
| 718 | } catch (InterruptedException e) { |
| 719 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 720 | e.printStackTrace(); |
| 721 | } finally { |
| 722 | hoQueue.remove(hoComplete.getCrntiNew()); |
slowr | 7c0e167 | 2017-08-15 17:09:14 -0700 | [diff] [blame] | 723 | |
| 724 | UEContextUpdate ueContextUpdate = hoContextUpdateMap.get(hoComplete.getCrntiNew()); |
| 725 | |
| 726 | RnibUe ue = ueMap.get(ueContextUpdate.getMMEUES1APID()); |
| 727 | RnibCell cell = xranStore.getCell(ueContextUpdate.getEcgi()); |
| 728 | if (ueMap.get(ueContextUpdate.getMMEUES1APID()) == null) { |
| 729 | ue = new RnibUe(); |
| 730 | } |
| 731 | |
| 732 | ue.setMmeS1apId(ueContextUpdate.getMMEUES1APID()); |
| 733 | ue.setEnbS1apId(ueContextUpdate.getENBUES1APID()); |
| 734 | ue.setRanId(ueContextUpdate.getCrnti()); |
| 735 | |
| 736 | hostAgent.addConnectedHost(ue, cell, ctx); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 737 | } |
| 738 | break; |
| 739 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 740 | |
| 741 | case 16: { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 742 | // Decode RX Sig Meas Report. |
| 743 | RXSigMeasReport rxSigMeasReport = recv_pdu.getBody().getRXSigMeasReport(); |
| 744 | List<RXSigReport> rxSigReportList = rxSigMeasReport.getCellMeasReports().getRXSigReport(); |
| 745 | |
| 746 | if (!rxSigReportList.isEmpty()) { |
| 747 | rxSigReportList.forEach(rxSigReport -> { |
| 748 | RnibCell cell = cellMap.get(rxSigReport.getPciArfcn()); |
| 749 | if (cell != null) { |
| 750 | ECGI ecgi = cell.getEcgi(); |
| 751 | RnibLink link = linkMap.get(ecgi, rxSigMeasReport.getCrnti()); |
| 752 | if (link == null) { |
| 753 | log.warn("Could not find link between: {}-{} | Creating non-serving link..", ecgi, rxSigMeasReport.getCrnti()); |
| 754 | link = linkMap.putNonServingLink(cell, rxSigMeasReport.getCrnti()); |
| 755 | |
| 756 | if (link != null) { |
| 757 | restartTimer(link); |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | if (link != null) { |
| 762 | RSRQRange rsrq = rxSigReport.getRsrq(); |
| 763 | RSRPRange rsrp = rxSigReport.getRsrp(); |
| 764 | |
| 765 | RnibLink.LinkQuality quality = link.getQuality(); |
slowr | c153ad9 | 2017-08-16 19:47:52 -0700 | [diff] [blame] | 766 | quality.setRX(new RnibLink.LinkQuality.RX( |
| 767 | rsrp.value.intValue() - 140, |
| 768 | (rsrq.value.intValue() * 0.5) - 19.5 |
| 769 | )); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 770 | } |
| 771 | } else { |
| 772 | log.warn("Could not find cell with PCI-ARFCN: {}", rxSigReport.getPciArfcn()); |
| 773 | } |
| 774 | }); |
| 775 | } |
| 776 | break; |
| 777 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 778 | case 18: { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 779 | RadioMeasReportPerUE radioMeasReportPerUE = recv_pdu.getBody().getRadioMeasReportPerUE(); |
| 780 | |
| 781 | List<RadioRepPerServCell> servCells = radioMeasReportPerUE.getRadioReportServCells().getRadioRepPerServCell(); |
| 782 | |
| 783 | servCells.forEach(servCell -> { |
| 784 | RnibCell cell = cellMap.get(servCell.getPciArfcn()); |
| 785 | if (cell != null) { |
| 786 | RnibLink link = linkMap.get(cell.getEcgi(), radioMeasReportPerUE.getCrnti()); |
| 787 | if (link != null) { |
| 788 | RadioRepPerServCell.CqiHist cqiHist = servCell.getCqiHist(); |
| 789 | RnibLink.LinkQuality quality = link.getQuality(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 790 | |
| 791 | final double[] values = {0, 0, 0}; |
| 792 | int i = 1; |
| 793 | cqiHist.getBerInteger().forEach(value -> { |
| 794 | values[0] = Math.max(values[0], value.intValue()); |
| 795 | values[1] += i * value.intValue(); |
| 796 | values[2] += value.intValue(); |
| 797 | }); |
| 798 | |
slowr | c153ad9 | 2017-08-16 19:47:52 -0700 | [diff] [blame] | 799 | quality.setCQI(new RnibLink.LinkQuality.CQI( |
| 800 | cqiHist, |
| 801 | values[0], |
| 802 | values[1] / values[0] |
| 803 | )); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 804 | |
| 805 | } else { |
| 806 | log.warn("Could not find link between: {}-{}", cell.getEcgi(), radioMeasReportPerUE.getCrnti()); |
| 807 | } |
| 808 | } else { |
| 809 | log.warn("Could not find cell with PCI-ARFCN: {}", servCell.getPciArfcn()); |
| 810 | } |
| 811 | }); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 812 | break; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 813 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 814 | case 19: { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 815 | RadioMeasReportPerCell radioMeasReportPerCell = recv_pdu.getBody().getRadioMeasReportPerCell(); |
| 816 | break; |
| 817 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 818 | case 20: { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 819 | SchedMeasReportPerUE schedMeasReportPerUE = recv_pdu.getBody().getSchedMeasReportPerUE(); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 820 | List<SchedMeasRepPerServCell> servCells = schedMeasReportPerUE.getSchedReportServCells() |
| 821 | .getSchedMeasRepPerServCell(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 822 | |
| 823 | servCells.forEach(servCell -> { |
| 824 | RnibCell cell = cellMap.get(servCell.getPciArfcn()); |
| 825 | if (cell != null) { |
| 826 | RnibLink link = linkMap.get(cell.getEcgi(), schedMeasReportPerUE.getCrnti()); |
| 827 | if (link != null) { |
slowr | c153ad9 | 2017-08-16 19:47:52 -0700 | [diff] [blame] | 828 | link.getQuality().setMCS(new RnibLink.LinkQuality.MCS( |
| 829 | servCell.getMcsDl(), |
| 830 | servCell.getMcsUl() |
| 831 | )); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 832 | |
slowr | c153ad9 | 2017-08-16 19:47:52 -0700 | [diff] [blame] | 833 | link.setResourceUsage(new RnibLink.ResourceUsage( |
| 834 | servCell.getPrbUsage().getPrbUsageDl(), |
| 835 | servCell.getPrbUsage().getPrbUsageUl() |
| 836 | )); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 837 | } else { |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 838 | log.warn("Could not find link between: {}-{}", cell.getEcgi(), |
| 839 | schedMeasReportPerUE.getCrnti()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 840 | } |
| 841 | } else { |
| 842 | log.warn("Could not find cell with PCI-ARFCN: {}", servCell.getPciArfcn()); |
| 843 | } |
| 844 | }); |
| 845 | break; |
| 846 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 847 | case 21: { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 848 | SchedMeasReportPerCell schedMeasReportPerCell = recv_pdu.getBody().getSchedMeasReportPerCell(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 849 | RnibCell cell = cellMap.get(schedMeasReportPerCell.getEcgi()); |
| 850 | if (cell != null) { |
slowr | c153ad9 | 2017-08-16 19:47:52 -0700 | [diff] [blame] | 851 | cell.setPrbUsage(new RnibCell.PrbUsageContainer( |
| 852 | schedMeasReportPerCell.getPrbUsagePcell(), |
| 853 | schedMeasReportPerCell.getPrbUsageScell() |
| 854 | )); |
| 855 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 856 | cell.setQci(schedMeasReportPerCell.getQciVals()); |
| 857 | } else { |
| 858 | log.warn("Could not find cell with ECGI: {}", schedMeasReportPerCell.getEcgi()); |
| 859 | } |
| 860 | break; |
| 861 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 862 | case 22: { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 863 | PDCPMeasReportPerUe pdcpMeasReportPerUe = recv_pdu.getBody().getPDCPMeasReportPerUe(); |
| 864 | |
| 865 | RnibLink link = linkMap.get(pdcpMeasReportPerUe.getEcgi(), pdcpMeasReportPerUe.getCrnti()); |
| 866 | if (link != null) { |
slowr | c153ad9 | 2017-08-16 19:47:52 -0700 | [diff] [blame] | 867 | link.setPdcpThroughput(new RnibLink.PDCPThroughput( |
| 868 | pdcpMeasReportPerUe.getThroughputDl(), |
| 869 | pdcpMeasReportPerUe.getThroughputUl() |
| 870 | )); |
| 871 | |
| 872 | link.setPdcpPackDelay(new RnibLink.PDCPPacketDelay( |
| 873 | pdcpMeasReportPerUe.getPktDelayDl(), |
| 874 | pdcpMeasReportPerUe.getPktDelayUl() |
| 875 | )); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 876 | } else { |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 877 | log.warn("Could not find link between: {}-{}", pdcpMeasReportPerUe.getEcgi(), |
| 878 | pdcpMeasReportPerUe.getCrnti()); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 879 | } |
| 880 | break; |
| 881 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 882 | case 24: { |
| 883 | // Decode UE Capability Info |
| 884 | UECapabilityInfo capabilityInfo = recv_pdu.getBody().getUECapabilityInfo(); |
| 885 | |
| 886 | RnibUe ue = ueMap.get(capabilityInfo.getCrnti()); |
| 887 | if (ue != null) { |
| 888 | ue.setCapability(capabilityInfo); |
| 889 | } else { |
| 890 | log.warn("Could not find UE with this CRNTI: {}", capabilityInfo.getCrnti()); |
| 891 | } |
| 892 | break; |
| 893 | } |
| 894 | case 25: { |
| 895 | // Don't know what will invoke sending UE CAPABILITY ENQUIRY |
| 896 | // Encode and send UE CAPABILITY ENQUIRY |
| 897 | UECapabilityEnquiry ueCapabilityEnquiry = recv_pdu.getBody().getUECapabilityEnquiry(); |
| 898 | XrancPdu xrancPdu = UECapabilityEnquiry.constructPacket(ueCapabilityEnquiry.getEcgi(), ueCapabilityEnquiry.getCrnti()); |
| 899 | ctx.writeAndFlush(getSctpMessage(xrancPdu)); |
| 900 | break; |
| 901 | } |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 902 | case 27: { |
| 903 | //Decode ScellAddStatus |
| 904 | ScellAddStatus scellAddStatus = recv_pdu.getBody().getScellAddStatus(); |
| 905 | try { |
| 906 | scellAddQueue.get(scellAddStatus.getCrnti()).put("Scell's status: " + scellAddStatus.getStatus()); |
| 907 | if (scellAddStatus.getStatus().getBerEnum().get(0).value.intValue() == 0) { |
| 908 | |
| 909 | scellAddStatus.getScellsInd().getPCIARFCN().forEach( |
| 910 | pciarfcn -> { |
| 911 | RnibCell cell = cellMap.get(pciarfcn); |
| 912 | RnibLink link = linkMap.get(cell.getEcgi(), scellAddStatus.getCrnti()); |
| 913 | link.setType(RnibLink.Type.SERVING_SECONDARY_CA); |
| 914 | } |
| 915 | ); |
| 916 | } else { |
| 917 | log.error("Scell addition failed."); |
| 918 | } |
| 919 | } catch (InterruptedException e) { |
| 920 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 921 | e.printStackTrace(); |
| 922 | } finally { |
| 923 | scellAddQueue.remove(scellAddStatus.getCrnti()); |
| 924 | } |
| 925 | break; |
| 926 | } |
| 927 | // TODO: 28: ScellDelete |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 928 | |
| 929 | case 30: { |
| 930 | // Decode RRMConfig Status |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 931 | RRMConfigStatus rrmConfigStatus = recv_pdu.getBody().getRRMConfigStatus(); |
| 932 | try { |
| 933 | RRMCellQueue.get(rrmConfigStatus.getEcgi()) |
| 934 | .put("RRM Config's status: " + rrmConfigStatus.getStatus()); |
| 935 | } catch (InterruptedException e) { |
| 936 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 937 | e.printStackTrace(); |
| 938 | } finally { |
| 939 | RRMCellQueue.remove(rrmConfigStatus.getEcgi()); |
| 940 | } |
| 941 | break; |
| 942 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 943 | //TODO Case 31: SeNBAdd 32: SeNBAddStatus 33: SeNBDelete |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 944 | case 34: { |
| 945 | TrafficSplitConfig trafficSplitConfig = recv_pdu.getBody().getTrafficSplitConfig(); |
| 946 | |
| 947 | List<TrafficSplitPercentage> splitPercentages = trafficSplitConfig.getTrafficSplitPercent().getTrafficSplitPercentage(); |
| 948 | |
| 949 | splitPercentages.forEach(trafficSplitPercentage -> { |
| 950 | RnibCell cell = cellMap.get(trafficSplitPercentage.getEcgi()); |
| 951 | if (cell != null) { |
| 952 | RnibLink link = linkMap.get(cell.getEcgi(), trafficSplitConfig.getCrnti()); |
| 953 | if (link != null) { |
| 954 | link.setTrafficPercent(trafficSplitPercentage); |
| 955 | } else { |
| 956 | log.warn("Could not find link between: {}-{}", cell.getEcgi(), trafficSplitConfig.getCrnti()); |
| 957 | } |
| 958 | } else { |
| 959 | log.warn("Could not find cell with ECGI: {}", trafficSplitConfig.getEcgi()); |
| 960 | } |
| 961 | }); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 962 | break; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 963 | } |
| 964 | default: { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 965 | log.warn("Wrong API ID: {}", recv_pdu); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 966 | break; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | class InternalNetworkConfigListener implements NetworkConfigListener { |
| 974 | |
| 975 | @Override |
| 976 | public void event(NetworkConfigEvent event) { |
| 977 | switch (event.type()) { |
| 978 | case CONFIG_REGISTERED: |
| 979 | break; |
| 980 | case CONFIG_UNREGISTERED: |
| 981 | break; |
| 982 | case CONFIG_ADDED: |
| 983 | case CONFIG_UPDATED: |
| 984 | if (event.configClass() == CONFIG_CLASS) { |
| 985 | handleConfigEvent(event.config()); |
| 986 | } |
| 987 | break; |
| 988 | case CONFIG_REMOVED: |
| 989 | break; |
| 990 | default: |
| 991 | break; |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | private void handleConfigEvent(Optional<Config> config) { |
| 996 | if (!config.isPresent()) { |
| 997 | return; |
| 998 | } |
| 999 | |
| 1000 | xranConfig = (XranConfig) config.get(); |
| 1001 | |
| 1002 | legitCells.putAll(xranConfig.activeCellSet()); |
| 1003 | |
| 1004 | controller.start(deviceAgent, hostAgent, packetAgent, xranConfig.getXrancPort()); |
| 1005 | } |
| 1006 | } |
| 1007 | } |