blob: ac29eba85781fdaa4b47da13808a3c65dc66fa09 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
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
17package org.onosproject.xran.entities;
18
slowrc153ad92017-08-16 19:47:52 -070019import com.fasterxml.jackson.annotation.*;
slowr13fa5b02017-08-08 16:32:31 -070020import com.fasterxml.jackson.databind.JsonNode;
21import org.onosproject.net.DeviceId;
slowrc153ad92017-08-16 19:47:52 -070022import org.onosproject.store.service.WallClockTimestamp;
slowr13fa5b02017-08-08 16:32:31 -070023import org.onosproject.xran.codecs.api.ECGI;
slowr13fa5b02017-08-08 16:32:31 -070024import org.onosproject.xran.codecs.api.PRBUsage;
slowr73b4eae2017-08-17 16:09:09 -070025import org.onosproject.xran.codecs.api.XICICPA;
slowrc153ad92017-08-16 19:47:52 -070026import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream;
slowr73b4eae2017-08-17 16:09:09 -070027import org.onosproject.xran.codecs.ber.types.BerBitString;
slowrc153ad92017-08-16 19:47:52 -070028import org.onosproject.xran.codecs.ber.types.BerInteger;
slowr13fa5b02017-08-08 16:32:31 -070029import org.onosproject.xran.codecs.pdu.CellConfigReport;
30import org.onosproject.xran.codecs.pdu.L2MeasConfig;
31import org.onosproject.xran.codecs.pdu.RRMConfig;
32import org.onosproject.xran.codecs.pdu.SchedMeasReportPerCell;
slowr13fa5b02017-08-08 16:32:31 -070033
34import javax.xml.bind.DatatypeConverter;
35import java.io.ByteArrayInputStream;
36import java.io.IOException;
37import java.io.InputStream;
38import java.net.URI;
39import java.net.URISyntaxException;
slowr67d05e42017-08-11 20:37:22 -070040import java.util.List;
slowr8ddc2b12017-08-14 14:13:38 -070041import java.util.stream.Collectors;
42import java.util.stream.Stream;
slowr13fa5b02017-08-08 16:32:31 -070043
44/**
45 * Created by dimitris on 7/22/17.
46 */
slowr60d4d102017-08-16 18:33:58 -070047
48@JsonPropertyOrder({
49 "ECGI",
50 "Configuration",
51 "PRB-Usage",
52 "QCI",
53 "RRMConfiguration",
54 "MeasurementConfiguration"
55})
56@JsonIgnoreProperties(ignoreUnknown = true)
slowr13fa5b02017-08-08 16:32:31 -070057public class RnibCell {
slowr60d4d102017-08-16 18:33:58 -070058 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -070059 private static final String SCHEME = "xran";
60
slowr60d4d102017-08-16 18:33:58 -070061 @JsonProperty("ECGI")
slowr13fa5b02017-08-08 16:32:31 -070062 private ECGI ecgi;
slowr60d4d102017-08-16 18:33:58 -070063 @JsonProperty("Configuration")
slowr13fa5b02017-08-08 16:32:31 -070064 private CellConfigReport conf;
slowr60d4d102017-08-16 18:33:58 -070065 @JsonProperty("PRB-Usage")
slowr13fa5b02017-08-08 16:32:31 -070066 private PrbUsageContainer prbUsage;
slowr60d4d102017-08-16 18:33:58 -070067 @JsonProperty("QCI")
slowr13fa5b02017-08-08 16:32:31 -070068 private SchedMeasReportPerCell.QciVals qci;
slowr60d4d102017-08-16 18:33:58 -070069 @JsonProperty("RRMConfiguration")
slowr13fa5b02017-08-08 16:32:31 -070070 private RRMConfig rrmConfig;
slowr60d4d102017-08-16 18:33:58 -070071 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -070072 private L2MeasConfig measConfig;
73
slowr60d4d102017-08-16 18:33:58 -070074 @JsonIgnore
slowr8ddc2b12017-08-14 14:13:38 -070075 private String version;
76
slowr13fa5b02017-08-08 16:32:31 -070077 public RnibCell() {
slowr8ddc2b12017-08-14 14:13:38 -070078 version = "3";
slowr89c2ac12017-08-15 16:20:06 -070079
80 rrmConfig = new RRMConfig();
81 rrmConfig.setEcgi(ecgi);
slowr13fa5b02017-08-08 16:32:31 -070082 }
83
84 public static URI uri(ECGI ecgi) {
85 if (ecgi != null) {
86 try {
87 BerByteArrayOutputStream os = new BerByteArrayOutputStream(4096);
88 ecgi.encode(os);
89 String message = DatatypeConverter.printHexBinary(os.getArray());
90 return new URI(SCHEME, message, null);
91 } catch (URISyntaxException | IOException e) {
92 return null;
93 }
94 }
95 return null;
96 }
97
98 public static ECGI decodeDeviceId(DeviceId deviceId) throws IOException {
99 String uri = deviceId.toString();
100 String hexEcgi = uri.substring(uri.lastIndexOf("xran:") + 5);
101
102 ECGI ecgi = new ECGI();
103 byte[] bytearray = DatatypeConverter.parseHexBinary(hexEcgi);
104 InputStream inputStream = new ByteArrayInputStream(bytearray);
105
106 ecgi.decode(inputStream);
107 return ecgi;
108 }
109
slowred74ec72017-08-17 11:25:01 -0700110 public int getVersion() {
111 return Integer.parseInt(version);
slowr8ddc2b12017-08-14 14:13:38 -0700112 }
113
114 public void setVersion(String version) {
115 this.version = version;
116 }
117
slowr60d4d102017-08-16 18:33:58 -0700118 @JsonProperty("RRMConfiguration")
slowr67d05e42017-08-11 20:37:22 -0700119 public RRMConfig getRrmConfig() {
120 return rrmConfig;
121 }
122
slowr60d4d102017-08-16 18:33:58 -0700123 @JsonProperty("RRMConfiguration")
slowr67d05e42017-08-11 20:37:22 -0700124 public void setRrmConfig(RRMConfig rrmConfig) {
125 this.rrmConfig = rrmConfig;
126 }
127
slowr60d4d102017-08-16 18:33:58 -0700128 @JsonProperty("PRB-Usage")
slowr67d05e42017-08-11 20:37:22 -0700129 public PrbUsageContainer getPrbUsage() {
130 return prbUsage;
131 }
132
slowr60d4d102017-08-16 18:33:58 -0700133 @JsonProperty("PRB-Usage")
slowr67d05e42017-08-11 20:37:22 -0700134 public void setPrbUsage(PrbUsageContainer prbUsage) {
135 this.prbUsage = prbUsage;
136 }
137
slowr60d4d102017-08-16 18:33:58 -0700138 @JsonProperty("ECGI")
slowr13fa5b02017-08-08 16:32:31 -0700139 public ECGI getEcgi() {
140 return ecgi;
141 }
142
slowr60d4d102017-08-16 18:33:58 -0700143 @JsonProperty("ECGI")
slowr13fa5b02017-08-08 16:32:31 -0700144 public void setEcgi(ECGI ecgi) {
145 this.ecgi = ecgi;
146 }
147
slowr60d4d102017-08-16 18:33:58 -0700148 @JsonProperty("Configuration")
slowr13fa5b02017-08-08 16:32:31 -0700149 public CellConfigReport getConf() {
150 return conf;
151 }
152
slowr60d4d102017-08-16 18:33:58 -0700153 @JsonProperty("Configuration")
slowr13fa5b02017-08-08 16:32:31 -0700154 public void setConf(CellConfigReport conf) {
155 this.conf = conf;
156 }
157
slowr73b4eae2017-08-17 16:09:09 -0700158 public void modifyRrmConfig(JsonNode rrmConfigNode, List<RnibUe> ueList) throws Exception {
slowr67d05e42017-08-11 20:37:22 -0700159 RRMConfig.Crnti crnti = new RRMConfig.Crnti();
slowrc86750e2017-08-22 17:26:47 -0700160 ueList.forEach(ue -> crnti.addCRNTI(ue.getCrnti()));
slowr13fa5b02017-08-08 16:32:31 -0700161
slowr8ddc2b12017-08-14 14:13:38 -0700162 {
slowr73b4eae2017-08-17 16:09:09 -0700163 JsonNode p_a = rrmConfigNode.path("p_a");
164 if (!p_a.isMissingNode()) {
165 RRMConfig.Pa pa = new RRMConfig.Pa();
166 if (p_a.isArray()) {
167 if (ueList.size() == p_a.size()) {
168 List<XICICPA> collect = Stream.of(p_a)
169 .map(val -> new XICICPA(val.asInt()))
170 .collect(Collectors.toList());
171 pa.setXICICPA(collect);
172 } else {
173 throw new Exception("p_a size is not the same as UE size");
174 }
175 }
176 rrmConfig.setPa(pa);
177 }
178 }
179
180 {
slowr60d4d102017-08-16 18:33:58 -0700181 JsonNode start_prb_dl = rrmConfigNode.path("start_prb_dl");
182 if (!start_prb_dl.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700183 RRMConfig.StartPrbDl startPrbDl = new RRMConfig.StartPrbDl();
184 if (start_prb_dl.isArray()) {
slowr89c2ac12017-08-15 16:20:06 -0700185 if (ueList.size() == start_prb_dl.size()) {
slowr8ddc2b12017-08-14 14:13:38 -0700186 List<BerInteger> collect = Stream.of(start_prb_dl)
187 .map(val -> new BerInteger(val.asInt()))
188 .collect(Collectors.toList());
189 startPrbDl.setSeqOf(collect);
slowr73b4eae2017-08-17 16:09:09 -0700190 } else {
191 throw new Exception("start_prb_dl size is not the same as UE size");
slowr8ddc2b12017-08-14 14:13:38 -0700192 }
193 }
194 rrmConfig.setStartPrbDl(startPrbDl);
slowr67d05e42017-08-11 20:37:22 -0700195 }
196 }
slowr67d05e42017-08-11 20:37:22 -0700197
slowr8ddc2b12017-08-14 14:13:38 -0700198 {
slowr60d4d102017-08-16 18:33:58 -0700199 JsonNode end_prb_dl = rrmConfigNode.path("end_prb_dl");
200 if (!end_prb_dl.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700201 RRMConfig.EndPrbDl endPrbDl = new RRMConfig.EndPrbDl();
202 if (end_prb_dl.isArray()) {
slowr89c2ac12017-08-15 16:20:06 -0700203 if (ueList.size() == end_prb_dl.size()) {
slowr8ddc2b12017-08-14 14:13:38 -0700204 List<BerInteger> collect = Stream.of(end_prb_dl)
205 .map(val -> new BerInteger(val.asInt()))
206 .collect(Collectors.toList());
207 endPrbDl.setSeqOf(collect);
slowr73b4eae2017-08-17 16:09:09 -0700208 } else {
209 throw new Exception("end_prb_dl size is not the same as UE size");
slowr8ddc2b12017-08-14 14:13:38 -0700210 }
211 }
212 rrmConfig.setEndPrbDl(endPrbDl);
213 }
214 }
215
216 {
slowr73b4eae2017-08-17 16:09:09 -0700217 JsonNode sub_frame_bitmask_dl = rrmConfigNode.path("sub_frame_bitmask_dl");
218 if (!sub_frame_bitmask_dl.isMissingNode()) {
219 RRMConfig.SubframeBitmaskDl subframeBitmaskDl = new RRMConfig.SubframeBitmaskDl();
220 if (sub_frame_bitmask_dl.isArray()) {
221 List<BerBitString> collect = Stream.of(sub_frame_bitmask_dl)
222 .map(val -> new BerBitString(DatatypeConverter.parseHexBinary(val.asText()), 10))
223 .collect(Collectors.toList());
224
225 subframeBitmaskDl.setSeqOf(collect);
226 } else {
227 throw new Exception("sub_frame_bitmask_dl size is not the same as UE size");
228 }
229 rrmConfig.setSubframeBitmaskDl(subframeBitmaskDl);
230 }
231 }
232
233 {
slowr60d4d102017-08-16 18:33:58 -0700234 JsonNode start_prb_ul = rrmConfigNode.path("start_prb_ul");
235 if (!start_prb_ul.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700236 RRMConfig.StartPrbUl startPrbUl = new RRMConfig.StartPrbUl();
237 if (start_prb_ul.isArray()) {
slowr89c2ac12017-08-15 16:20:06 -0700238 if (ueList.size() == start_prb_ul.size()) {
slowr8ddc2b12017-08-14 14:13:38 -0700239 List<BerInteger> collect = Stream.of(start_prb_ul)
240 .map(val -> new BerInteger(val.asInt()))
241 .collect(Collectors.toList());
242 startPrbUl.setSeqOf(collect);
slowr73b4eae2017-08-17 16:09:09 -0700243 } else {
244 throw new Exception("start_prb_ul size is not the same as UE size");
slowr8ddc2b12017-08-14 14:13:38 -0700245 }
246 }
247 rrmConfig.setStartPrbUl(startPrbUl);
248 }
249 }
250
251 {
slowr60d4d102017-08-16 18:33:58 -0700252 JsonNode end_prb_ul = rrmConfigNode.path("end_prb_ul");
253 if (!end_prb_ul.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700254 RRMConfig.EndPrbUl endPrbUl = new RRMConfig.EndPrbUl();
255 if (end_prb_ul.isArray()) {
slowr89c2ac12017-08-15 16:20:06 -0700256 if (ueList.size() == end_prb_ul.size()) {
slowr8ddc2b12017-08-14 14:13:38 -0700257 List<BerInteger> collect = Stream.of(end_prb_ul)
258 .map(val -> new BerInteger(val.asInt()))
259 .collect(Collectors.toList());
260 endPrbUl.setSeqOf(collect);
slowr73b4eae2017-08-17 16:09:09 -0700261 } else {
262 throw new Exception("end_prb_ul size is not the same as UE size");
slowr8ddc2b12017-08-14 14:13:38 -0700263 }
264 }
265 rrmConfig.setEndPrbUl(endPrbUl);
266 }
267 }
268
slowr73b4eae2017-08-17 16:09:09 -0700269 {
270 JsonNode p0_ue_pusch = rrmConfigNode.path("p0_ue_pusch");
271 if (!p0_ue_pusch.isMissingNode()) {
272 RRMConfig.P0UePusch p0UePusch = new RRMConfig.P0UePusch();
273 if (p0_ue_pusch.isArray()) {
274 if (ueList.size() == p0_ue_pusch.size()) {
275 List<BerInteger> collect = Stream.of(p0_ue_pusch)
276 .map(val -> new BerInteger(val.asInt()))
277 .collect(Collectors.toList());
278 p0UePusch.setSeqOf(collect);
279 } else {
280 throw new Exception("p0_ue_pusch size is not the same as UE size");
281 }
282 }
283 rrmConfig.setP0UePusch(p0UePusch);
284 }
285 }
286
287 {
288 JsonNode sub_frame_bitmask_ul = rrmConfigNode.path("sub_frame_bitmask_ul");
289 if (!sub_frame_bitmask_ul.isMissingNode()) {
290 RRMConfig.SubframeBitmaskUl subframeBitmaskUl = new RRMConfig.SubframeBitmaskUl();
291 if (sub_frame_bitmask_ul.isArray()) {
292 List<BerBitString> collect = Stream.of(sub_frame_bitmask_ul)
293 .map(val -> new BerBitString(DatatypeConverter.parseHexBinary(val.asText()), 10))
294 .collect(Collectors.toList());
295
296 subframeBitmaskUl.setSeqOf(collect);
297 } else {
298 throw new Exception("sub_frame_bitmask_ul size is not the same as UE size");
299 }
300 rrmConfig.setSubframeBitmaskUl(subframeBitmaskUl);
301 }
302 }
303
slowr8ddc2b12017-08-14 14:13:38 -0700304 rrmConfig.setCrnti(crnti);
slowr13fa5b02017-08-08 16:32:31 -0700305 }
306
slowr60d4d102017-08-16 18:33:58 -0700307 @JsonProperty("QCI")
slowr13fa5b02017-08-08 16:32:31 -0700308 public SchedMeasReportPerCell.QciVals getQci() {
309 return qci;
310 }
311
slowr60d4d102017-08-16 18:33:58 -0700312 @JsonProperty("QCI")
slowr13fa5b02017-08-08 16:32:31 -0700313 public void setQci(SchedMeasReportPerCell.QciVals qci) {
314 this.qci = qci;
315 }
316
slowr60d4d102017-08-16 18:33:58 -0700317 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -0700318 public L2MeasConfig getMeasConfig() {
319 return measConfig;
320 }
321
slowr60d4d102017-08-16 18:33:58 -0700322 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -0700323 public void setMeasConfig(L2MeasConfig measConfig) {
324 this.measConfig = measConfig;
325 }
326
327 @Override
328 public String toString() {
slowr60d4d102017-08-16 18:33:58 -0700329 return "RnibCell{" +
330 "ecgi=" + ecgi +
331 ", conf=" + conf +
332 ", prbUsage=" + prbUsage +
333 ", qci=" + qci +
334 ", rrmConfig=" + rrmConfig +
335 ", measConfig=" + measConfig +
336 ", version='" + version + '\'' +
337 '}';
slowr13fa5b02017-08-08 16:32:31 -0700338 }
339
340 @Override
341 public boolean equals(Object o) {
342 if (this == o) return true;
343 if (o == null || getClass() != o.getClass()) return false;
344
345 RnibCell rnibCell = (RnibCell) o;
346
347 return ecgi.equals(rnibCell.ecgi);
348 }
349
350 @Override
351 public int hashCode() {
352 return ecgi.hashCode();
353 }
354
slowr60d4d102017-08-16 18:33:58 -0700355 @JsonPropertyOrder({
356 "primary",
slowrc153ad92017-08-16 19:47:52 -0700357 "secondary",
358 "timesincelastupdate"
slowr60d4d102017-08-16 18:33:58 -0700359 })
360 @JsonIgnoreProperties(ignoreUnknown = true)
slowrc153ad92017-08-16 19:47:52 -0700361 public static class PrbUsageContainer {
slowr13fa5b02017-08-08 16:32:31 -0700362 PRBUsage primary;
363 PRBUsage secondary;
slowrc153ad92017-08-16 19:47:52 -0700364 WallClockTimestamp timesincelastupdate;
365
366 @JsonCreator
367 public PrbUsageContainer(@JsonProperty("primary") PRBUsage primary, @JsonProperty("secondary") PRBUsage secondary) {
368 this.primary = primary;
369 this.secondary = secondary;
370 this.timesincelastupdate = new WallClockTimestamp();
371 }
slowr13fa5b02017-08-08 16:32:31 -0700372
slowr60d4d102017-08-16 18:33:58 -0700373 public PRBUsage getPrimary() {
374 return primary;
375 }
376
377 public void setPrimary(PRBUsage primary) {
378 this.primary = primary;
379 }
380
381 public PRBUsage getSecondary() {
382 return secondary;
383 }
384
385 public void setSecondary(PRBUsage secondary) {
386 this.secondary = secondary;
387 }
388
slowrc153ad92017-08-16 19:47:52 -0700389 public long getTimesincelastupdate() {
slowr7bebd7b2017-08-17 11:46:11 -0700390 return new WallClockTimestamp().unixTimestamp() - timesincelastupdate.unixTimestamp();
slowrc153ad92017-08-16 19:47:52 -0700391 }
slowr7bebd7b2017-08-17 11:46:11 -0700392
slowrc153ad92017-08-16 19:47:52 -0700393 public void setTimesincelastupdate(WallClockTimestamp timesincelastupdate) {
394 this.timesincelastupdate = timesincelastupdate;
395 }
396
slowr13fa5b02017-08-08 16:32:31 -0700397 @Override
398 public String toString() {
slowr60d4d102017-08-16 18:33:58 -0700399 return "PrbUsageContainer{" +
400 "primary=" + primary +
401 ", secondary=" + secondary +
slowr7bebd7b2017-08-17 11:46:11 -0700402 ", timesincelastupdate=" + (new WallClockTimestamp().unixTimestamp() - timesincelastupdate.unixTimestamp()) +
slowr60d4d102017-08-16 18:33:58 -0700403 '}';
slowr13fa5b02017-08-08 16:32:31 -0700404 }
405 }
406}