slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /* |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame^] | 2 | * Copyright 2017-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; |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame^] | 23 | import org.onosproject.xran.asn1lib.api.ECGI; |
| 24 | import org.onosproject.xran.asn1lib.api.EUTRANCellIdentifier; |
| 25 | import org.onosproject.xran.asn1lib.api.PLMNIdentity; |
| 26 | import org.onosproject.xran.asn1lib.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 | |
slowr | 23a93e1 | 2017-09-01 13:26:18 -0700 | [diff] [blame] | 50 | private static final String XRANC_IP = "xranc_bind_ip"; |
| 51 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 52 | private static final String XRANC_PORT = "xranc_port"; |
| 53 | |
| 54 | private static final String XRANC_CELLCONFIG_INTERVAL = "xranc_cellconfigrequest_interval_seconds"; |
| 55 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 56 | 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] | 57 | |
| 58 | private static final String L2_MEAS_REPORT_INTERVAL = "l2_meas_report_interval_ms"; |
| 59 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 60 | private static final String ADMISSION_SUCCESS = "admission_success"; |
| 61 | |
| 62 | private static final String BEARER_SUCCESS = "bearer_success"; |
| 63 | |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 64 | private static final String NO_MEAS_LINK_REMOVAL = "no_meas_link_removal_ms"; |
| 65 | |
| 66 | private static final String IDLE_UE_REMOVAL = "idle_ue_removal_ms"; |
| 67 | |
| 68 | private static final String NORTHBOUND_TIMEOUT = "nb_response_timeout_ms"; |
| 69 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 70 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 71 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 72 | /** |
| 73 | * Get a list of all CELLs inside the configuration file. |
| 74 | * |
| 75 | * @return Map of CELL IP to ECGI |
| 76 | */ |
| 77 | public Map<IpAddress, ECGI> activeCellSet() { |
| 78 | Map<IpAddress, ECGI> cells = new ConcurrentHashMap<>(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 79 | |
| 80 | JsonNode cellsNode = object.get(CELLS); |
| 81 | if (cellsNode == null) { |
| 82 | log.warn("no cells have been provided!"); |
| 83 | return cells; |
| 84 | } |
| 85 | |
| 86 | cellsNode.forEach(cellNode -> { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 87 | String plmnId = cellNode.get(PLMN_ID).asText(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 88 | String eci = cellNode.get(ECI_ID).asText(); |
| 89 | |
| 90 | String ipAddress = cellNode.get(IP_ADDR).asText(); |
| 91 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 92 | ECGI ecgi = hexToEcgi(plmnId, eci); |
| 93 | cells.put(IpAddress.valueOf(ipAddress), ecgi); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 94 | }); |
| 95 | |
| 96 | return cells; |
| 97 | } |
| 98 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Get flag for ADMISSION_SUCCESS field in configuration. |
| 101 | * |
| 102 | * @return boolean value in configuration |
| 103 | */ |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 104 | public boolean admissionFlag() { |
| 105 | JsonNode flag = object.get(ADMISSION_SUCCESS); |
| 106 | return flag != null && flag.asBoolean(); |
| 107 | } |
| 108 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 109 | /** |
| 110 | * Get flag for BEARER_SUCCESS field in configuration. |
| 111 | * |
| 112 | * @return boolean value in configuration |
| 113 | */ |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 114 | public boolean bearerFlag() { |
| 115 | JsonNode flag = object.get(BEARER_SUCCESS); |
| 116 | return flag != null && flag.asBoolean(); |
| 117 | } |
| 118 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 119 | /** |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame^] | 120 | * Get IP where the XranServer binds to. |
slowr | 23a93e1 | 2017-09-01 13:26:18 -0700 | [diff] [blame] | 121 | * |
| 122 | * @return IP address in configuration |
| 123 | */ |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame^] | 124 | public IpAddress getXrancIp() { |
| 125 | return IpAddress.valueOf(object.get(XRANC_IP).asText()); |
| 126 | } |
slowr | 23a93e1 | 2017-09-01 13:26:18 -0700 | [diff] [blame] | 127 | |
| 128 | /** |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame^] | 129 | * Get port for xRAN xranServer server to bind to from configuration. |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 130 | * |
| 131 | * @return port number |
| 132 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 133 | public int getXrancPort() { |
| 134 | return object.get(XRANC_PORT).asInt(); |
| 135 | } |
| 136 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 137 | /** |
| 138 | * Get config request interval from configuration. |
| 139 | * |
| 140 | * @return interval in seconds |
| 141 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 142 | public int getConfigRequestInterval() { |
| 143 | return object.get(XRANC_CELLCONFIG_INTERVAL).asInt(); |
| 144 | } |
| 145 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 146 | /** |
| 147 | * Get rx signal interval from configuration. |
| 148 | * |
| 149 | * @return interval in milliseconds |
| 150 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 151 | public int getRxSignalInterval() { |
| 152 | return object.get(RX_SIGNAL_MEAS_REPORT_INTERVAL).asInt(); |
| 153 | } |
| 154 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 155 | /** |
| 156 | * Get l2 measurement interval from configuration. |
| 157 | * |
| 158 | * @return interval in milliseconds |
| 159 | */ |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 160 | public int getL2MeasInterval() { |
| 161 | return object.get(L2_MEAS_REPORT_INTERVAL).asInt(); |
| 162 | } |
| 163 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 164 | /** |
| 165 | * Get removal time of link after not getting measurement from configuration. |
| 166 | * |
| 167 | * @return interval in milliseconds |
| 168 | */ |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 169 | public int getNoMeasLinkRemoval() { |
| 170 | return object.get(NO_MEAS_LINK_REMOVAL).asInt(); |
| 171 | } |
| 172 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 173 | /** |
| 174 | * Get removal time of UE after being IDLE from configuration. |
| 175 | * |
| 176 | * @return interval in milliseconds |
| 177 | */ |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 178 | public int getIdleUeRemoval() { |
| 179 | return object.get(IDLE_UE_REMOVAL).asInt(); |
| 180 | } |
| 181 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 182 | /** |
| 183 | * Get northbound timeout when waiting for responses from configuration. |
| 184 | * |
| 185 | * @return interval in milliseconds |
| 186 | */ |
slowr | d337c93 | 2017-08-18 13:54:02 -0700 | [diff] [blame] | 187 | public int getNorthBoundTimeout() { |
| 188 | return object.get(NORTHBOUND_TIMEOUT).asInt(); |
| 189 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 190 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 191 | /** |
| 192 | * Get ECGI from HEX representation of PLMN_ID and ECI. |
| 193 | * |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame^] | 194 | * @param plmnId HEX string of PLMN_ID |
| 195 | * @param eci HEX string of ECI |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 196 | * @return new ECGI object |
| 197 | */ |
| 198 | private ECGI hexToEcgi(String plmnId, String eci) { |
| 199 | byte[] bytes = HexConverter.fromShortHexString(plmnId); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 200 | byte[] bytearray = DatatypeConverter.parseHexBinary(eci); |
| 201 | |
| 202 | InputStream inputStream = new ByteArrayInputStream(bytearray); |
| 203 | |
| 204 | PLMNIdentity plmnIdentity = new PLMNIdentity(bytes); |
| 205 | EUTRANCellIdentifier eutranCellIdentifier = new EUTRANCellIdentifier(bytearray, 28); |
| 206 | |
| 207 | ECGI ecgi = new ECGI(); |
| 208 | ecgi.setEUTRANcellIdentifier(eutranCellIdentifier); |
| 209 | ecgi.setPLMNIdentity(plmnIdentity); |
| 210 | try { |
| 211 | ecgi.decode(inputStream); |
| 212 | } catch (IOException e) { |
| 213 | e.printStackTrace(); |
| 214 | } |
| 215 | |
| 216 | return ecgi; |
| 217 | } |
| 218 | } |