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