blob: adde62eaa53508f548bc82ebc8be3185bbc19840 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -08002 * Copyright 2017-present Open Networking Foundation
slowr13fa5b02017-08-08 16:32:31 -07003 *
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
17package org.onosproject.xran.impl;
18
19import com.fasterxml.jackson.databind.JsonNode;
slowr577f3222017-08-28 10:49:08 -070020import org.onlab.packet.IpAddress;
slowr13fa5b02017-08-08 16:32:31 -070021import org.onosproject.core.ApplicationId;
slowr13fa5b02017-08-08 16:32:31 -070022import org.onosproject.net.config.Config;
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -080023import org.onosproject.xran.asn1lib.api.ECGI;
24import org.onosproject.xran.asn1lib.api.EUTRANCellIdentifier;
25import org.onosproject.xran.asn1lib.api.PLMNIdentity;
26import org.onosproject.xran.asn1lib.util.HexConverter;
slowr13fa5b02017-08-08 16:32:31 -070027import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
29
30import javax.xml.bind.DatatypeConverter;
31import java.io.ByteArrayInputStream;
32import java.io.IOException;
33import java.io.InputStream;
slowr13fa5b02017-08-08 16:32:31 -070034import java.util.Map;
35import java.util.concurrent.ConcurrentHashMap;
36
slowr577f3222017-08-28 10:49:08 -070037/**
38 * Xran config.
39 */
slowr13fa5b02017-08-08 16:32:31 -070040public class XranConfig extends Config<ApplicationId> {
41
42 private static final String CELLS = "active_cells";
43
44 private static final String PLMN_ID = "plmn_id";
slowrd337c932017-08-18 13:54:02 -070045
slowr13fa5b02017-08-08 16:32:31 -070046 private static final String ECI_ID = "eci";
47
48 private static final String IP_ADDR = "ip_addr";
49
slowr23a93e12017-09-01 13:26:18 -070050 private static final String XRANC_IP = "xranc_bind_ip";
51
slowr13fa5b02017-08-08 16:32:31 -070052 private static final String XRANC_PORT = "xranc_port";
53
54 private static final String XRANC_CELLCONFIG_INTERVAL = "xranc_cellconfigrequest_interval_seconds";
55
slowrd337c932017-08-18 13:54:02 -070056 private static final String RX_SIGNAL_MEAS_REPORT_INTERVAL = "rx_signal_meas_report_interval_ms";
slowr13fa5b02017-08-08 16:32:31 -070057
58 private static final String L2_MEAS_REPORT_INTERVAL = "l2_meas_report_interval_ms";
59
slowr8ddc2b12017-08-14 14:13:38 -070060 private static final String ADMISSION_SUCCESS = "admission_success";
61
62 private static final String BEARER_SUCCESS = "bearer_success";
63
slowrd337c932017-08-18 13:54:02 -070064 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
slowr13fa5b02017-08-08 16:32:31 -070070 private final Logger log = LoggerFactory.getLogger(getClass());
71
slowr577f3222017-08-28 10:49:08 -070072 /**
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<>();
slowr13fa5b02017-08-08 16:32:31 -070079
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 -> {
slowr577f3222017-08-28 10:49:08 -070087 String plmnId = cellNode.get(PLMN_ID).asText();
slowr13fa5b02017-08-08 16:32:31 -070088 String eci = cellNode.get(ECI_ID).asText();
89
90 String ipAddress = cellNode.get(IP_ADDR).asText();
91
slowr577f3222017-08-28 10:49:08 -070092 ECGI ecgi = hexToEcgi(plmnId, eci);
93 cells.put(IpAddress.valueOf(ipAddress), ecgi);
slowr13fa5b02017-08-08 16:32:31 -070094 });
95
96 return cells;
97 }
98
slowr577f3222017-08-28 10:49:08 -070099 /**
100 * Get flag for ADMISSION_SUCCESS field in configuration.
101 *
102 * @return boolean value in configuration
103 */
slowr8ddc2b12017-08-14 14:13:38 -0700104 public boolean admissionFlag() {
105 JsonNode flag = object.get(ADMISSION_SUCCESS);
106 return flag != null && flag.asBoolean();
107 }
108
slowr577f3222017-08-28 10:49:08 -0700109 /**
110 * Get flag for BEARER_SUCCESS field in configuration.
111 *
112 * @return boolean value in configuration
113 */
slowr8ddc2b12017-08-14 14:13:38 -0700114 public boolean bearerFlag() {
115 JsonNode flag = object.get(BEARER_SUCCESS);
116 return flag != null && flag.asBoolean();
117 }
118
slowr577f3222017-08-28 10:49:08 -0700119 /**
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -0800120 * Get IP where the XranServer binds to.
slowr23a93e12017-09-01 13:26:18 -0700121 *
122 * @return IP address in configuration
123 */
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -0800124 public IpAddress getXrancIp() {
125 return IpAddress.valueOf(object.get(XRANC_IP).asText());
126 }
slowr23a93e12017-09-01 13:26:18 -0700127
128 /**
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -0800129 * Get port for xRAN xranServer server to bind to from configuration.
slowr577f3222017-08-28 10:49:08 -0700130 *
131 * @return port number
132 */
slowr13fa5b02017-08-08 16:32:31 -0700133 public int getXrancPort() {
134 return object.get(XRANC_PORT).asInt();
135 }
136
slowr577f3222017-08-28 10:49:08 -0700137 /**
138 * Get config request interval from configuration.
139 *
140 * @return interval in seconds
141 */
slowr13fa5b02017-08-08 16:32:31 -0700142 public int getConfigRequestInterval() {
143 return object.get(XRANC_CELLCONFIG_INTERVAL).asInt();
144 }
145
slowr577f3222017-08-28 10:49:08 -0700146 /**
147 * Get rx signal interval from configuration.
148 *
149 * @return interval in milliseconds
150 */
slowr13fa5b02017-08-08 16:32:31 -0700151 public int getRxSignalInterval() {
152 return object.get(RX_SIGNAL_MEAS_REPORT_INTERVAL).asInt();
153 }
154
slowr577f3222017-08-28 10:49:08 -0700155 /**
156 * Get l2 measurement interval from configuration.
157 *
158 * @return interval in milliseconds
159 */
slowr13fa5b02017-08-08 16:32:31 -0700160 public int getL2MeasInterval() {
161 return object.get(L2_MEAS_REPORT_INTERVAL).asInt();
162 }
163
slowr577f3222017-08-28 10:49:08 -0700164 /**
165 * Get removal time of link after not getting measurement from configuration.
166 *
167 * @return interval in milliseconds
168 */
slowrd337c932017-08-18 13:54:02 -0700169 public int getNoMeasLinkRemoval() {
170 return object.get(NO_MEAS_LINK_REMOVAL).asInt();
171 }
172
slowr577f3222017-08-28 10:49:08 -0700173 /**
174 * Get removal time of UE after being IDLE from configuration.
175 *
176 * @return interval in milliseconds
177 */
slowrd337c932017-08-18 13:54:02 -0700178 public int getIdleUeRemoval() {
179 return object.get(IDLE_UE_REMOVAL).asInt();
180 }
181
slowr577f3222017-08-28 10:49:08 -0700182 /**
183 * Get northbound timeout when waiting for responses from configuration.
184 *
185 * @return interval in milliseconds
186 */
slowrd337c932017-08-18 13:54:02 -0700187 public int getNorthBoundTimeout() {
188 return object.get(NORTHBOUND_TIMEOUT).asInt();
189 }
slowr13fa5b02017-08-08 16:32:31 -0700190
slowr577f3222017-08-28 10:49:08 -0700191 /**
192 * Get ECGI from HEX representation of PLMN_ID and ECI.
193 *
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -0800194 * @param plmnId HEX string of PLMN_ID
195 * @param eci HEX string of ECI
slowr577f3222017-08-28 10:49:08 -0700196 * @return new ECGI object
197 */
198 private ECGI hexToEcgi(String plmnId, String eci) {
199 byte[] bytes = HexConverter.fromShortHexString(plmnId);
slowr13fa5b02017-08-08 16:32:31 -0700200 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}