blob: e3348929a6c0845b419bb8d4d7687f9e8b2a2787 [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
50 private static final String XRANC_PORT = "xranc_port";
51
52 private static final String XRANC_CELLCONFIG_INTERVAL = "xranc_cellconfigrequest_interval_seconds";
53
slowrd337c932017-08-18 13:54:02 -070054 private static final String RX_SIGNAL_MEAS_REPORT_INTERVAL = "rx_signal_meas_report_interval_ms";
slowr13fa5b02017-08-08 16:32:31 -070055
56 private static final String L2_MEAS_REPORT_INTERVAL = "l2_meas_report_interval_ms";
57
slowr8ddc2b12017-08-14 14:13:38 -070058 private static final String ADMISSION_SUCCESS = "admission_success";
59
60 private static final String BEARER_SUCCESS = "bearer_success";
61
slowrd337c932017-08-18 13:54:02 -070062 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
slowr13fa5b02017-08-08 16:32:31 -070068 private final Logger log = LoggerFactory.getLogger(getClass());
69
slowr577f3222017-08-28 10:49:08 -070070 /**
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<>();
slowr13fa5b02017-08-08 16:32:31 -070077
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 -> {
slowr577f3222017-08-28 10:49:08 -070085 String plmnId = cellNode.get(PLMN_ID).asText();
slowr13fa5b02017-08-08 16:32:31 -070086 String eci = cellNode.get(ECI_ID).asText();
87
88 String ipAddress = cellNode.get(IP_ADDR).asText();
89
slowr577f3222017-08-28 10:49:08 -070090 ECGI ecgi = hexToEcgi(plmnId, eci);
91 cells.put(IpAddress.valueOf(ipAddress), ecgi);
slowr13fa5b02017-08-08 16:32:31 -070092 });
93
94 return cells;
95 }
96
slowr577f3222017-08-28 10:49:08 -070097 /**
98 * Get flag for ADMISSION_SUCCESS field in configuration.
99 *
100 * @return boolean value in configuration
101 */
slowr8ddc2b12017-08-14 14:13:38 -0700102 public boolean admissionFlag() {
103 JsonNode flag = object.get(ADMISSION_SUCCESS);
104 return flag != null && flag.asBoolean();
105 }
106
slowr577f3222017-08-28 10:49:08 -0700107 /**
108 * Get flag for BEARER_SUCCESS field in configuration.
109 *
110 * @return boolean value in configuration
111 */
slowr8ddc2b12017-08-14 14:13:38 -0700112 public boolean bearerFlag() {
113 JsonNode flag = object.get(BEARER_SUCCESS);
114 return flag != null && flag.asBoolean();
115 }
116
slowr577f3222017-08-28 10:49:08 -0700117 /**
118 * Get port for xRAN controller server to bind to from configuration.
119 *
120 * @return port number
121 */
slowr13fa5b02017-08-08 16:32:31 -0700122 public int getXrancPort() {
123 return object.get(XRANC_PORT).asInt();
124 }
125
slowr577f3222017-08-28 10:49:08 -0700126 /**
127 * Get config request interval from configuration.
128 *
129 * @return interval in seconds
130 */
slowr13fa5b02017-08-08 16:32:31 -0700131 public int getConfigRequestInterval() {
132 return object.get(XRANC_CELLCONFIG_INTERVAL).asInt();
133 }
134
slowr577f3222017-08-28 10:49:08 -0700135 /**
136 * Get rx signal interval from configuration.
137 *
138 * @return interval in milliseconds
139 */
slowr13fa5b02017-08-08 16:32:31 -0700140 public int getRxSignalInterval() {
141 return object.get(RX_SIGNAL_MEAS_REPORT_INTERVAL).asInt();
142 }
143
slowr577f3222017-08-28 10:49:08 -0700144 /**
145 * Get l2 measurement interval from configuration.
146 *
147 * @return interval in milliseconds
148 */
slowr13fa5b02017-08-08 16:32:31 -0700149 public int getL2MeasInterval() {
150 return object.get(L2_MEAS_REPORT_INTERVAL).asInt();
151 }
152
slowr577f3222017-08-28 10:49:08 -0700153 /**
154 * Get removal time of link after not getting measurement from configuration.
155 *
156 * @return interval in milliseconds
157 */
slowrd337c932017-08-18 13:54:02 -0700158 public int getNoMeasLinkRemoval() {
159 return object.get(NO_MEAS_LINK_REMOVAL).asInt();
160 }
161
slowr577f3222017-08-28 10:49:08 -0700162 /**
163 * Get removal time of UE after being IDLE from configuration.
164 *
165 * @return interval in milliseconds
166 */
slowrd337c932017-08-18 13:54:02 -0700167 public int getIdleUeRemoval() {
168 return object.get(IDLE_UE_REMOVAL).asInt();
169 }
170
slowr577f3222017-08-28 10:49:08 -0700171 /**
172 * Get northbound timeout when waiting for responses from configuration.
173 *
174 * @return interval in milliseconds
175 */
slowrd337c932017-08-18 13:54:02 -0700176 public int getNorthBoundTimeout() {
177 return object.get(NORTHBOUND_TIMEOUT).asInt();
178 }
slowr13fa5b02017-08-08 16:32:31 -0700179
slowr577f3222017-08-28 10:49:08 -0700180 /**
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);
slowr13fa5b02017-08-08 16:32:31 -0700189 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}