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.impl; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 20 | import org.onosproject.core.ApplicationId; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 21 | import org.onosproject.net.config.Config; |
| 22 | import org.onosproject.xran.codecs.api.ECGI; |
| 23 | import org.onosproject.xran.codecs.api.EUTRANCellIdentifier; |
| 24 | import org.onosproject.xran.codecs.api.PLMNIdentity; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 25 | import org.onosproject.xran.codecs.util.HexConverter; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | |
| 29 | import javax.xml.bind.DatatypeConverter; |
| 30 | import java.io.ByteArrayInputStream; |
| 31 | import java.io.IOException; |
| 32 | import java.io.InputStream; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 33 | import java.util.Map; |
| 34 | import java.util.concurrent.ConcurrentHashMap; |
| 35 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 36 | public class XranConfig extends Config<ApplicationId> { |
| 37 | |
| 38 | private static final String CELLS = "active_cells"; |
| 39 | |
| 40 | private static final String PLMN_ID = "plmn_id"; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 41 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 42 | private static final String ECI_ID = "eci"; |
| 43 | |
| 44 | private static final String IP_ADDR = "ip_addr"; |
| 45 | |
| 46 | private static final String XRANC_PORT = "xranc_port"; |
| 47 | |
| 48 | private static final String XRANC_CELLCONFIG_INTERVAL = "xranc_cellconfigrequest_interval_seconds"; |
| 49 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 50 | private static final String RX_SIGNAL_MEAS_REPORT_INTERVAL = "rx_signal_meas_report_interval_ms"; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 51 | |
| 52 | private static final String L2_MEAS_REPORT_INTERVAL = "l2_meas_report_interval_ms"; |
| 53 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 54 | private static final String ADMISSION_SUCCESS = "admission_success"; |
| 55 | |
| 56 | private static final String BEARER_SUCCESS = "bearer_success"; |
| 57 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 58 | private static final String NO_MEAS_LINK_REMOVAL = "no_meas_link_removal_ms"; |
| 59 | |
| 60 | private static final String IDLE_UE_REMOVAL = "idle_ue_removal_ms"; |
| 61 | |
| 62 | private static final String NORTHBOUND_TIMEOUT = "nb_response_timeout_ms"; |
| 63 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 64 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 65 | |
| 66 | public Map<String, ECGI> activeCellSet() { |
| 67 | Map<String, ECGI> cells = new ConcurrentHashMap<>(); |
| 68 | |
| 69 | JsonNode cellsNode = object.get(CELLS); |
| 70 | if (cellsNode == null) { |
| 71 | log.warn("no cells have been provided!"); |
| 72 | return cells; |
| 73 | } |
| 74 | |
| 75 | cellsNode.forEach(cellNode -> { |
| 76 | String plmn_id = cellNode.get(PLMN_ID).asText(); |
| 77 | String eci = cellNode.get(ECI_ID).asText(); |
| 78 | |
| 79 | String ipAddress = cellNode.get(IP_ADDR).asText(); |
| 80 | |
| 81 | ECGI ecgi = hexToECGI(plmn_id, eci); |
| 82 | cells.put(ipAddress, ecgi); |
| 83 | }); |
| 84 | |
| 85 | return cells; |
| 86 | } |
| 87 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 88 | public boolean admissionFlag() { |
| 89 | JsonNode flag = object.get(ADMISSION_SUCCESS); |
| 90 | return flag != null && flag.asBoolean(); |
| 91 | } |
| 92 | |
| 93 | public boolean bearerFlag() { |
| 94 | JsonNode flag = object.get(BEARER_SUCCESS); |
| 95 | return flag != null && flag.asBoolean(); |
| 96 | } |
| 97 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 98 | public int getXrancPort() { |
| 99 | return object.get(XRANC_PORT).asInt(); |
| 100 | } |
| 101 | |
| 102 | public int getConfigRequestInterval() { |
| 103 | return object.get(XRANC_CELLCONFIG_INTERVAL).asInt(); |
| 104 | } |
| 105 | |
| 106 | public int getRxSignalInterval() { |
| 107 | return object.get(RX_SIGNAL_MEAS_REPORT_INTERVAL).asInt(); |
| 108 | } |
| 109 | |
| 110 | public int getL2MeasInterval() { |
| 111 | return object.get(L2_MEAS_REPORT_INTERVAL).asInt(); |
| 112 | } |
| 113 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame^] | 114 | public int getNoMeasLinkRemoval() { |
| 115 | return object.get(NO_MEAS_LINK_REMOVAL).asInt(); |
| 116 | } |
| 117 | |
| 118 | public int getIdleUeRemoval() { |
| 119 | return object.get(IDLE_UE_REMOVAL).asInt(); |
| 120 | } |
| 121 | |
| 122 | public int getNorthBoundTimeout() { |
| 123 | return object.get(NORTHBOUND_TIMEOUT).asInt(); |
| 124 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 125 | |
| 126 | private ECGI hexToECGI(String plmn_id, String eci) { |
| 127 | byte[] bytes = HexConverter.fromShortHexString(plmn_id); |
| 128 | byte[] bytearray = DatatypeConverter.parseHexBinary(eci); |
| 129 | |
| 130 | InputStream inputStream = new ByteArrayInputStream(bytearray); |
| 131 | |
| 132 | PLMNIdentity plmnIdentity = new PLMNIdentity(bytes); |
| 133 | EUTRANCellIdentifier eutranCellIdentifier = new EUTRANCellIdentifier(bytearray, 28); |
| 134 | |
| 135 | ECGI ecgi = new ECGI(); |
| 136 | ecgi.setEUTRANcellIdentifier(eutranCellIdentifier); |
| 137 | ecgi.setPLMNIdentity(plmnIdentity); |
| 138 | try { |
| 139 | ecgi.decode(inputStream); |
| 140 | } catch (IOException e) { |
| 141 | e.printStackTrace(); |
| 142 | } |
| 143 | |
| 144 | return ecgi; |
| 145 | } |
| 146 | } |