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