blob: ef83194766325f38ebbaa22b74e2328445cd0622 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
slowr577f3222017-08-28 10:49:08 -07002 * Copyright 2015-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;
23import org.onosproject.xran.codecs.api.ECGI;
24import org.onosproject.xran.codecs.api.EUTRANCellIdentifier;
25import org.onosproject.xran.codecs.api.PLMNIdentity;
slowr60d4d102017-08-16 18:33:58 -070026import org.onosproject.xran.codecs.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 /**
slowr23a93e12017-09-01 13:26:18 -0700120 * Get IP where the Controller binds to.
121 *
122 * @return IP address in configuration
123 */
124 public IpAddress getXrancIp() { return IpAddress.valueOf(object.get(XRANC_IP).asText()); }
125
126 /**
slowr577f3222017-08-28 10:49:08 -0700127 * Get port for xRAN controller server to bind to from configuration.
128 *
129 * @return port number
130 */
slowr13fa5b02017-08-08 16:32:31 -0700131 public int getXrancPort() {
132 return object.get(XRANC_PORT).asInt();
133 }
134
slowr577f3222017-08-28 10:49:08 -0700135 /**
136 * Get config request interval from configuration.
137 *
138 * @return interval in seconds
139 */
slowr13fa5b02017-08-08 16:32:31 -0700140 public int getConfigRequestInterval() {
141 return object.get(XRANC_CELLCONFIG_INTERVAL).asInt();
142 }
143
slowr577f3222017-08-28 10:49:08 -0700144 /**
145 * Get rx signal interval from configuration.
146 *
147 * @return interval in milliseconds
148 */
slowr13fa5b02017-08-08 16:32:31 -0700149 public int getRxSignalInterval() {
150 return object.get(RX_SIGNAL_MEAS_REPORT_INTERVAL).asInt();
151 }
152
slowr577f3222017-08-28 10:49:08 -0700153 /**
154 * Get l2 measurement interval from configuration.
155 *
156 * @return interval in milliseconds
157 */
slowr13fa5b02017-08-08 16:32:31 -0700158 public int getL2MeasInterval() {
159 return object.get(L2_MEAS_REPORT_INTERVAL).asInt();
160 }
161
slowr577f3222017-08-28 10:49:08 -0700162 /**
163 * Get removal time of link after not getting measurement from configuration.
164 *
165 * @return interval in milliseconds
166 */
slowrd337c932017-08-18 13:54:02 -0700167 public int getNoMeasLinkRemoval() {
168 return object.get(NO_MEAS_LINK_REMOVAL).asInt();
169 }
170
slowr577f3222017-08-28 10:49:08 -0700171 /**
172 * Get removal time of UE after being IDLE from configuration.
173 *
174 * @return interval in milliseconds
175 */
slowrd337c932017-08-18 13:54:02 -0700176 public int getIdleUeRemoval() {
177 return object.get(IDLE_UE_REMOVAL).asInt();
178 }
179
slowr577f3222017-08-28 10:49:08 -0700180 /**
181 * Get northbound timeout when waiting for responses from configuration.
182 *
183 * @return interval in milliseconds
184 */
slowrd337c932017-08-18 13:54:02 -0700185 public int getNorthBoundTimeout() {
186 return object.get(NORTHBOUND_TIMEOUT).asInt();
187 }
slowr13fa5b02017-08-08 16:32:31 -0700188
slowr577f3222017-08-28 10:49:08 -0700189 /**
190 * Get ECGI from HEX representation of PLMN_ID and ECI.
191 *
192 * @param plmnId HEX string of PLMN_ID
193 * @param eci HEX string of ECI
194 * @return new ECGI object
195 */
196 private ECGI hexToEcgi(String plmnId, String eci) {
197 byte[] bytes = HexConverter.fromShortHexString(plmnId);
slowr13fa5b02017-08-08 16:32:31 -0700198 byte[] bytearray = DatatypeConverter.parseHexBinary(eci);
199
200 InputStream inputStream = new ByteArrayInputStream(bytearray);
201
202 PLMNIdentity plmnIdentity = new PLMNIdentity(bytes);
203 EUTRANCellIdentifier eutranCellIdentifier = new EUTRANCellIdentifier(bytearray, 28);
204
205 ECGI ecgi = new ECGI();
206 ecgi.setEUTRANcellIdentifier(eutranCellIdentifier);
207 ecgi.setPLMNIdentity(plmnIdentity);
208 try {
209 ecgi.decode(inputStream);
210 } catch (IOException e) {
211 e.printStackTrace();
212 }
213
214 return ecgi;
215 }
216}