slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /* |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Foundation |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.xran.impl; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 20 | import org.onlab.packet.IpAddress; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 21 | import org.onosproject.core.ApplicationId; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 22 | import org.onosproject.net.config.Config; |
| 23 | import org.onosproject.xran.codecs.api.ECGI; |
| 24 | import org.onosproject.xran.codecs.api.EUTRANCellIdentifier; |
| 25 | import org.onosproject.xran.codecs.api.PLMNIdentity; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 26 | import org.onosproject.xran.codecs.util.HexConverter; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 27 | import org.slf4j.Logger; |
| 28 | import org.slf4j.LoggerFactory; |
| 29 | |
| 30 | import javax.xml.bind.DatatypeConverter; |
| 31 | import java.io.ByteArrayInputStream; |
| 32 | import java.io.IOException; |
| 33 | import java.io.InputStream; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 34 | import java.util.Map; |
| 35 | import java.util.concurrent.ConcurrentHashMap; |
| 36 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 37 | /** |
| 38 | * Xran config. |
| 39 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 40 | public class XranConfig extends Config<ApplicationId> { |
| 41 | |
| 42 | private static final String CELLS = "active_cells"; |
| 43 | |
| 44 | private static final String PLMN_ID = "plmn_id"; |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 45 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 46 | private static final String ECI_ID = "eci"; |
| 47 | |
| 48 | private static final String IP_ADDR = "ip_addr"; |
| 49 | |
| 50 | private static final String XRANC_PORT = "xranc_port"; |
| 51 | |
| 52 | private static final String XRANC_CELLCONFIG_INTERVAL = "xranc_cellconfigrequest_interval_seconds"; |
| 53 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 54 | 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] | 55 | |
| 56 | private static final String L2_MEAS_REPORT_INTERVAL = "l2_meas_report_interval_ms"; |
| 57 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 58 | private static final String ADMISSION_SUCCESS = "admission_success"; |
| 59 | |
| 60 | private static final String BEARER_SUCCESS = "bearer_success"; |
| 61 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 62 | private static final String NO_MEAS_LINK_REMOVAL = "no_meas_link_removal_ms"; |
| 63 | |
| 64 | private static final String IDLE_UE_REMOVAL = "idle_ue_removal_ms"; |
| 65 | |
| 66 | private static final String NORTHBOUND_TIMEOUT = "nb_response_timeout_ms"; |
| 67 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 68 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 69 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 70 | /** |
| 71 | * Get a list of all CELLs inside the configuration file. |
| 72 | * |
| 73 | * @return Map of CELL IP to ECGI |
| 74 | */ |
| 75 | public Map<IpAddress, ECGI> activeCellSet() { |
| 76 | Map<IpAddress, ECGI> cells = new ConcurrentHashMap<>(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 77 | |
| 78 | JsonNode cellsNode = object.get(CELLS); |
| 79 | if (cellsNode == null) { |
| 80 | log.warn("no cells have been provided!"); |
| 81 | return cells; |
| 82 | } |
| 83 | |
| 84 | cellsNode.forEach(cellNode -> { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 85 | String plmnId = cellNode.get(PLMN_ID).asText(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 86 | String eci = cellNode.get(ECI_ID).asText(); |
| 87 | |
| 88 | String ipAddress = cellNode.get(IP_ADDR).asText(); |
| 89 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 90 | ECGI ecgi = hexToEcgi(plmnId, eci); |
| 91 | cells.put(IpAddress.valueOf(ipAddress), ecgi); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 92 | }); |
| 93 | |
| 94 | return cells; |
| 95 | } |
| 96 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 97 | /** |
| 98 | * Get flag for ADMISSION_SUCCESS field in configuration. |
| 99 | * |
| 100 | * @return boolean value in configuration |
| 101 | */ |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 102 | public boolean admissionFlag() { |
| 103 | JsonNode flag = object.get(ADMISSION_SUCCESS); |
| 104 | return flag != null && flag.asBoolean(); |
| 105 | } |
| 106 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 107 | /** |
| 108 | * Get flag for BEARER_SUCCESS field in configuration. |
| 109 | * |
| 110 | * @return boolean value in configuration |
| 111 | */ |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 112 | public boolean bearerFlag() { |
| 113 | JsonNode flag = object.get(BEARER_SUCCESS); |
| 114 | return flag != null && flag.asBoolean(); |
| 115 | } |
| 116 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 117 | /** |
| 118 | * Get port for xRAN controller server to bind to from configuration. |
| 119 | * |
| 120 | * @return port number |
| 121 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 122 | public int getXrancPort() { |
| 123 | return object.get(XRANC_PORT).asInt(); |
| 124 | } |
| 125 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 126 | /** |
| 127 | * Get config request interval from configuration. |
| 128 | * |
| 129 | * @return interval in seconds |
| 130 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 131 | public int getConfigRequestInterval() { |
| 132 | return object.get(XRANC_CELLCONFIG_INTERVAL).asInt(); |
| 133 | } |
| 134 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 135 | /** |
| 136 | * Get rx signal interval from configuration. |
| 137 | * |
| 138 | * @return interval in milliseconds |
| 139 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 140 | public int getRxSignalInterval() { |
| 141 | return object.get(RX_SIGNAL_MEAS_REPORT_INTERVAL).asInt(); |
| 142 | } |
| 143 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 144 | /** |
| 145 | * Get l2 measurement interval from configuration. |
| 146 | * |
| 147 | * @return interval in milliseconds |
| 148 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 149 | public int getL2MeasInterval() { |
| 150 | return object.get(L2_MEAS_REPORT_INTERVAL).asInt(); |
| 151 | } |
| 152 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 153 | /** |
| 154 | * Get removal time of link after not getting measurement from configuration. |
| 155 | * |
| 156 | * @return interval in milliseconds |
| 157 | */ |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 158 | public int getNoMeasLinkRemoval() { |
| 159 | return object.get(NO_MEAS_LINK_REMOVAL).asInt(); |
| 160 | } |
| 161 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 162 | /** |
| 163 | * Get removal time of UE after being IDLE from configuration. |
| 164 | * |
| 165 | * @return interval in milliseconds |
| 166 | */ |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 167 | public int getIdleUeRemoval() { |
| 168 | return object.get(IDLE_UE_REMOVAL).asInt(); |
| 169 | } |
| 170 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 171 | /** |
| 172 | * Get northbound timeout when waiting for responses from configuration. |
| 173 | * |
| 174 | * @return interval in milliseconds |
| 175 | */ |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 176 | public int getNorthBoundTimeout() { |
| 177 | return object.get(NORTHBOUND_TIMEOUT).asInt(); |
| 178 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 179 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 180 | /** |
| 181 | * Get ECGI from HEX representation of PLMN_ID and ECI. |
| 182 | * |
| 183 | * @param plmnId HEX string of PLMN_ID |
| 184 | * @param eci HEX string of ECI |
| 185 | * @return new ECGI object |
| 186 | */ |
| 187 | private ECGI hexToEcgi(String plmnId, String eci) { |
| 188 | byte[] bytes = HexConverter.fromShortHexString(plmnId); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 189 | byte[] bytearray = DatatypeConverter.parseHexBinary(eci); |
| 190 | |
| 191 | InputStream inputStream = new ByteArrayInputStream(bytearray); |
| 192 | |
| 193 | PLMNIdentity plmnIdentity = new PLMNIdentity(bytes); |
| 194 | EUTRANCellIdentifier eutranCellIdentifier = new EUTRANCellIdentifier(bytearray, 28); |
| 195 | |
| 196 | ECGI ecgi = new ECGI(); |
| 197 | ecgi.setEUTRANcellIdentifier(eutranCellIdentifier); |
| 198 | ecgi.setPLMNIdentity(plmnIdentity); |
| 199 | try { |
| 200 | ecgi.decode(inputStream); |
| 201 | } catch (IOException e) { |
| 202 | e.printStackTrace(); |
| 203 | } |
| 204 | |
| 205 | return ecgi; |
| 206 | } |
| 207 | } |