blob: 317935745c53050a0d155f0ef59778fd7742e8ab [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;
slowr73b4eae2017-08-17 16:09:09 -070021import com.google.common.collect.Lists;
slowr13fa5b02017-08-08 16:32:31 -070022import org.onosproject.net.DeviceId;
slowrc153ad92017-08-16 19:47:52 -070023import org.onosproject.store.Timestamp;
24import org.onosproject.store.service.WallClockTimestamp;
slowr13fa5b02017-08-08 16:32:31 -070025import org.onosproject.xran.codecs.api.ECGI;
slowr13fa5b02017-08-08 16:32:31 -070026import org.onosproject.xran.codecs.api.PRBUsage;
slowr73b4eae2017-08-17 16:09:09 -070027import org.onosproject.xran.codecs.api.XICICPA;
slowrc153ad92017-08-16 19:47:52 -070028import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream;
slowr73b4eae2017-08-17 16:09:09 -070029import org.onosproject.xran.codecs.ber.types.BerBitString;
slowrc153ad92017-08-16 19:47:52 -070030import org.onosproject.xran.codecs.ber.types.BerInteger;
slowr13fa5b02017-08-08 16:32:31 -070031import org.onosproject.xran.codecs.pdu.CellConfigReport;
32import org.onosproject.xran.codecs.pdu.L2MeasConfig;
33import org.onosproject.xran.codecs.pdu.RRMConfig;
34import org.onosproject.xran.codecs.pdu.SchedMeasReportPerCell;
slowr13fa5b02017-08-08 16:32:31 -070035
36import javax.xml.bind.DatatypeConverter;
37import java.io.ByteArrayInputStream;
38import java.io.IOException;
39import java.io.InputStream;
40import java.net.URI;
41import java.net.URISyntaxException;
slowr67d05e42017-08-11 20:37:22 -070042import java.util.List;
slowr8ddc2b12017-08-14 14:13:38 -070043import java.util.stream.Collectors;
44import java.util.stream.Stream;
slowr13fa5b02017-08-08 16:32:31 -070045
46/**
47 * Created by dimitris on 7/22/17.
48 */
slowr60d4d102017-08-16 18:33:58 -070049
50@JsonPropertyOrder({
51 "ECGI",
52 "Configuration",
53 "PRB-Usage",
54 "QCI",
55 "RRMConfiguration",
56 "MeasurementConfiguration"
57})
58@JsonIgnoreProperties(ignoreUnknown = true)
slowr13fa5b02017-08-08 16:32:31 -070059public class RnibCell {
slowr60d4d102017-08-16 18:33:58 -070060 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -070061 private static final String SCHEME = "xran";
62
slowr60d4d102017-08-16 18:33:58 -070063 @JsonProperty("ECGI")
slowr13fa5b02017-08-08 16:32:31 -070064 private ECGI ecgi;
slowr60d4d102017-08-16 18:33:58 -070065 @JsonProperty("Configuration")
slowr13fa5b02017-08-08 16:32:31 -070066 private CellConfigReport conf;
slowr60d4d102017-08-16 18:33:58 -070067 @JsonProperty("PRB-Usage")
slowr13fa5b02017-08-08 16:32:31 -070068 private PrbUsageContainer prbUsage;
slowr60d4d102017-08-16 18:33:58 -070069 @JsonProperty("QCI")
slowr13fa5b02017-08-08 16:32:31 -070070 private SchedMeasReportPerCell.QciVals qci;
slowr60d4d102017-08-16 18:33:58 -070071 @JsonProperty("RRMConfiguration")
slowr13fa5b02017-08-08 16:32:31 -070072 private RRMConfig rrmConfig;
slowr60d4d102017-08-16 18:33:58 -070073 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -070074 private L2MeasConfig measConfig;
75
slowr60d4d102017-08-16 18:33:58 -070076 @JsonIgnore
slowr8ddc2b12017-08-14 14:13:38 -070077 private String version;
78
slowr13fa5b02017-08-08 16:32:31 -070079 public RnibCell() {
slowr8ddc2b12017-08-14 14:13:38 -070080 version = "3";
slowr89c2ac12017-08-15 16:20:06 -070081
82 rrmConfig = new RRMConfig();
83 rrmConfig.setEcgi(ecgi);
slowr13fa5b02017-08-08 16:32:31 -070084 }
85
86 public static URI uri(ECGI ecgi) {
87 if (ecgi != null) {
88 try {
89 BerByteArrayOutputStream os = new BerByteArrayOutputStream(4096);
90 ecgi.encode(os);
91 String message = DatatypeConverter.printHexBinary(os.getArray());
92 return new URI(SCHEME, message, null);
93 } catch (URISyntaxException | IOException e) {
94 return null;
95 }
96 }
97 return null;
98 }
99
100 public static ECGI decodeDeviceId(DeviceId deviceId) throws IOException {
101 String uri = deviceId.toString();
102 String hexEcgi = uri.substring(uri.lastIndexOf("xran:") + 5);
103
104 ECGI ecgi = new ECGI();
105 byte[] bytearray = DatatypeConverter.parseHexBinary(hexEcgi);
106 InputStream inputStream = new ByteArrayInputStream(bytearray);
107
108 ecgi.decode(inputStream);
109 return ecgi;
110 }
111
slowred74ec72017-08-17 11:25:01 -0700112 public int getVersion() {
113 return Integer.parseInt(version);
slowr8ddc2b12017-08-14 14:13:38 -0700114 }
115
116 public void setVersion(String version) {
117 this.version = version;
118 }
119
slowr60d4d102017-08-16 18:33:58 -0700120 @JsonProperty("RRMConfiguration")
slowr67d05e42017-08-11 20:37:22 -0700121 public RRMConfig getRrmConfig() {
122 return rrmConfig;
123 }
124
slowr60d4d102017-08-16 18:33:58 -0700125 @JsonProperty("RRMConfiguration")
slowr67d05e42017-08-11 20:37:22 -0700126 public void setRrmConfig(RRMConfig rrmConfig) {
127 this.rrmConfig = rrmConfig;
128 }
129
slowr60d4d102017-08-16 18:33:58 -0700130 @JsonProperty("PRB-Usage")
slowr67d05e42017-08-11 20:37:22 -0700131 public PrbUsageContainer getPrbUsage() {
132 return prbUsage;
133 }
134
slowr60d4d102017-08-16 18:33:58 -0700135 @JsonProperty("PRB-Usage")
slowr67d05e42017-08-11 20:37:22 -0700136 public void setPrbUsage(PrbUsageContainer prbUsage) {
137 this.prbUsage = prbUsage;
138 }
139
slowr60d4d102017-08-16 18:33:58 -0700140 @JsonProperty("ECGI")
slowr13fa5b02017-08-08 16:32:31 -0700141 public ECGI getEcgi() {
142 return ecgi;
143 }
144
slowr60d4d102017-08-16 18:33:58 -0700145 @JsonProperty("ECGI")
slowr13fa5b02017-08-08 16:32:31 -0700146 public void setEcgi(ECGI ecgi) {
147 this.ecgi = ecgi;
148 }
149
slowr60d4d102017-08-16 18:33:58 -0700150 @JsonProperty("Configuration")
slowr13fa5b02017-08-08 16:32:31 -0700151 public CellConfigReport getConf() {
152 return conf;
153 }
154
slowr60d4d102017-08-16 18:33:58 -0700155 @JsonProperty("Configuration")
slowr13fa5b02017-08-08 16:32:31 -0700156 public void setConf(CellConfigReport conf) {
157 this.conf = conf;
158 }
159
slowr73b4eae2017-08-17 16:09:09 -0700160 public void modifyRrmConfig(JsonNode rrmConfigNode, List<RnibUe> ueList) throws Exception {
slowr67d05e42017-08-11 20:37:22 -0700161 RRMConfig.Crnti crnti = new RRMConfig.Crnti();
162 ueList.forEach(ue -> crnti.addCRNTI(ue.getRanId()));
slowr13fa5b02017-08-08 16:32:31 -0700163
slowr8ddc2b12017-08-14 14:13:38 -0700164 {
slowr73b4eae2017-08-17 16:09:09 -0700165 JsonNode p_a = rrmConfigNode.path("p_a");
166 if (!p_a.isMissingNode()) {
167 RRMConfig.Pa pa = new RRMConfig.Pa();
168 if (p_a.isArray()) {
169 if (ueList.size() == p_a.size()) {
170 List<XICICPA> collect = Stream.of(p_a)
171 .map(val -> new XICICPA(val.asInt()))
172 .collect(Collectors.toList());
173 pa.setXICICPA(collect);
174 } else {
175 throw new Exception("p_a size is not the same as UE size");
176 }
177 }
178 rrmConfig.setPa(pa);
179 }
180 }
181
182 {
slowr60d4d102017-08-16 18:33:58 -0700183 JsonNode start_prb_dl = rrmConfigNode.path("start_prb_dl");
184 if (!start_prb_dl.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700185 RRMConfig.StartPrbDl startPrbDl = new RRMConfig.StartPrbDl();
186 if (start_prb_dl.isArray()) {
slowr89c2ac12017-08-15 16:20:06 -0700187 if (ueList.size() == start_prb_dl.size()) {
slowr8ddc2b12017-08-14 14:13:38 -0700188 List<BerInteger> collect = Stream.of(start_prb_dl)
189 .map(val -> new BerInteger(val.asInt()))
190 .collect(Collectors.toList());
191 startPrbDl.setSeqOf(collect);
slowr73b4eae2017-08-17 16:09:09 -0700192 } else {
193 throw new Exception("start_prb_dl size is not the same as UE size");
slowr8ddc2b12017-08-14 14:13:38 -0700194 }
195 }
196 rrmConfig.setStartPrbDl(startPrbDl);
slowr67d05e42017-08-11 20:37:22 -0700197 }
198 }
slowr67d05e42017-08-11 20:37:22 -0700199
slowr8ddc2b12017-08-14 14:13:38 -0700200 {
slowr60d4d102017-08-16 18:33:58 -0700201 JsonNode end_prb_dl = rrmConfigNode.path("end_prb_dl");
202 if (!end_prb_dl.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700203 RRMConfig.EndPrbDl endPrbDl = new RRMConfig.EndPrbDl();
204 if (end_prb_dl.isArray()) {
slowr89c2ac12017-08-15 16:20:06 -0700205 if (ueList.size() == end_prb_dl.size()) {
slowr8ddc2b12017-08-14 14:13:38 -0700206 List<BerInteger> collect = Stream.of(end_prb_dl)
207 .map(val -> new BerInteger(val.asInt()))
208 .collect(Collectors.toList());
209 endPrbDl.setSeqOf(collect);
slowr73b4eae2017-08-17 16:09:09 -0700210 } else {
211 throw new Exception("end_prb_dl size is not the same as UE size");
slowr8ddc2b12017-08-14 14:13:38 -0700212 }
213 }
214 rrmConfig.setEndPrbDl(endPrbDl);
215 }
216 }
217
218 {
slowr73b4eae2017-08-17 16:09:09 -0700219 JsonNode sub_frame_bitmask_dl = rrmConfigNode.path("sub_frame_bitmask_dl");
220 if (!sub_frame_bitmask_dl.isMissingNode()) {
221 RRMConfig.SubframeBitmaskDl subframeBitmaskDl = new RRMConfig.SubframeBitmaskDl();
222 if (sub_frame_bitmask_dl.isArray()) {
223 List<BerBitString> collect = Stream.of(sub_frame_bitmask_dl)
224 .map(val -> new BerBitString(DatatypeConverter.parseHexBinary(val.asText()), 10))
225 .collect(Collectors.toList());
226
227 subframeBitmaskDl.setSeqOf(collect);
228 } else {
229 throw new Exception("sub_frame_bitmask_dl size is not the same as UE size");
230 }
231 rrmConfig.setSubframeBitmaskDl(subframeBitmaskDl);
232 }
233 }
234
235 {
slowr60d4d102017-08-16 18:33:58 -0700236 JsonNode start_prb_ul = rrmConfigNode.path("start_prb_ul");
237 if (!start_prb_ul.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700238 RRMConfig.StartPrbUl startPrbUl = new RRMConfig.StartPrbUl();
239 if (start_prb_ul.isArray()) {
slowr89c2ac12017-08-15 16:20:06 -0700240 if (ueList.size() == start_prb_ul.size()) {
slowr8ddc2b12017-08-14 14:13:38 -0700241 List<BerInteger> collect = Stream.of(start_prb_ul)
242 .map(val -> new BerInteger(val.asInt()))
243 .collect(Collectors.toList());
244 startPrbUl.setSeqOf(collect);
slowr73b4eae2017-08-17 16:09:09 -0700245 } else {
246 throw new Exception("start_prb_ul size is not the same as UE size");
slowr8ddc2b12017-08-14 14:13:38 -0700247 }
248 }
249 rrmConfig.setStartPrbUl(startPrbUl);
250 }
251 }
252
253 {
slowr60d4d102017-08-16 18:33:58 -0700254 JsonNode end_prb_ul = rrmConfigNode.path("end_prb_ul");
255 if (!end_prb_ul.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700256 RRMConfig.EndPrbUl endPrbUl = new RRMConfig.EndPrbUl();
257 if (end_prb_ul.isArray()) {
slowr89c2ac12017-08-15 16:20:06 -0700258 if (ueList.size() == end_prb_ul.size()) {
slowr8ddc2b12017-08-14 14:13:38 -0700259 List<BerInteger> collect = Stream.of(end_prb_ul)
260 .map(val -> new BerInteger(val.asInt()))
261 .collect(Collectors.toList());
262 endPrbUl.setSeqOf(collect);
slowr73b4eae2017-08-17 16:09:09 -0700263 } else {
264 throw new Exception("end_prb_ul size is not the same as UE size");
slowr8ddc2b12017-08-14 14:13:38 -0700265 }
266 }
267 rrmConfig.setEndPrbUl(endPrbUl);
268 }
269 }
270
slowr73b4eae2017-08-17 16:09:09 -0700271 {
272 JsonNode p0_ue_pusch = rrmConfigNode.path("p0_ue_pusch");
273 if (!p0_ue_pusch.isMissingNode()) {
274 RRMConfig.P0UePusch p0UePusch = new RRMConfig.P0UePusch();
275 if (p0_ue_pusch.isArray()) {
276 if (ueList.size() == p0_ue_pusch.size()) {
277 List<BerInteger> collect = Stream.of(p0_ue_pusch)
278 .map(val -> new BerInteger(val.asInt()))
279 .collect(Collectors.toList());
280 p0UePusch.setSeqOf(collect);
281 } else {
282 throw new Exception("p0_ue_pusch size is not the same as UE size");
283 }
284 }
285 rrmConfig.setP0UePusch(p0UePusch);
286 }
287 }
288
289 {
290 JsonNode sub_frame_bitmask_ul = rrmConfigNode.path("sub_frame_bitmask_ul");
291 if (!sub_frame_bitmask_ul.isMissingNode()) {
292 RRMConfig.SubframeBitmaskUl subframeBitmaskUl = new RRMConfig.SubframeBitmaskUl();
293 if (sub_frame_bitmask_ul.isArray()) {
294 List<BerBitString> collect = Stream.of(sub_frame_bitmask_ul)
295 .map(val -> new BerBitString(DatatypeConverter.parseHexBinary(val.asText()), 10))
296 .collect(Collectors.toList());
297
298 subframeBitmaskUl.setSeqOf(collect);
299 } else {
300 throw new Exception("sub_frame_bitmask_ul size is not the same as UE size");
301 }
302 rrmConfig.setSubframeBitmaskUl(subframeBitmaskUl);
303 }
304 }
305
slowr8ddc2b12017-08-14 14:13:38 -0700306 rrmConfig.setCrnti(crnti);
slowr13fa5b02017-08-08 16:32:31 -0700307 }
308
slowr60d4d102017-08-16 18:33:58 -0700309 @JsonProperty("QCI")
slowr13fa5b02017-08-08 16:32:31 -0700310 public SchedMeasReportPerCell.QciVals getQci() {
311 return qci;
312 }
313
slowr60d4d102017-08-16 18:33:58 -0700314 @JsonProperty("QCI")
slowr13fa5b02017-08-08 16:32:31 -0700315 public void setQci(SchedMeasReportPerCell.QciVals qci) {
316 this.qci = qci;
317 }
318
slowr60d4d102017-08-16 18:33:58 -0700319 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -0700320 public L2MeasConfig getMeasConfig() {
321 return measConfig;
322 }
323
slowr60d4d102017-08-16 18:33:58 -0700324 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -0700325 public void setMeasConfig(L2MeasConfig measConfig) {
326 this.measConfig = measConfig;
327 }
328
329 @Override
330 public String toString() {
slowr60d4d102017-08-16 18:33:58 -0700331 return "RnibCell{" +
332 "ecgi=" + ecgi +
333 ", conf=" + conf +
334 ", prbUsage=" + prbUsage +
335 ", qci=" + qci +
336 ", rrmConfig=" + rrmConfig +
337 ", measConfig=" + measConfig +
338 ", version='" + version + '\'' +
339 '}';
slowr13fa5b02017-08-08 16:32:31 -0700340 }
341
342 @Override
343 public boolean equals(Object o) {
344 if (this == o) return true;
345 if (o == null || getClass() != o.getClass()) return false;
346
347 RnibCell rnibCell = (RnibCell) o;
348
349 return ecgi.equals(rnibCell.ecgi);
350 }
351
352 @Override
353 public int hashCode() {
354 return ecgi.hashCode();
355 }
356
slowr60d4d102017-08-16 18:33:58 -0700357 @JsonPropertyOrder({
358 "primary",
slowrc153ad92017-08-16 19:47:52 -0700359 "secondary",
360 "timesincelastupdate"
slowr60d4d102017-08-16 18:33:58 -0700361 })
362 @JsonIgnoreProperties(ignoreUnknown = true)
slowrc153ad92017-08-16 19:47:52 -0700363 public static class PrbUsageContainer {
slowr13fa5b02017-08-08 16:32:31 -0700364 PRBUsage primary;
365 PRBUsage secondary;
slowrc153ad92017-08-16 19:47:52 -0700366 WallClockTimestamp timesincelastupdate;
367
368 @JsonCreator
369 public PrbUsageContainer(@JsonProperty("primary") PRBUsage primary, @JsonProperty("secondary") PRBUsage secondary) {
370 this.primary = primary;
371 this.secondary = secondary;
372 this.timesincelastupdate = new WallClockTimestamp();
373 }
slowr13fa5b02017-08-08 16:32:31 -0700374
slowr60d4d102017-08-16 18:33:58 -0700375 public PRBUsage getPrimary() {
376 return primary;
377 }
378
379 public void setPrimary(PRBUsage primary) {
380 this.primary = primary;
381 }
382
383 public PRBUsage getSecondary() {
384 return secondary;
385 }
386
387 public void setSecondary(PRBUsage secondary) {
388 this.secondary = secondary;
389 }
390
slowrc153ad92017-08-16 19:47:52 -0700391 public long getTimesincelastupdate() {
slowr7bebd7b2017-08-17 11:46:11 -0700392 return new WallClockTimestamp().unixTimestamp() - timesincelastupdate.unixTimestamp();
slowrc153ad92017-08-16 19:47:52 -0700393 }
slowr7bebd7b2017-08-17 11:46:11 -0700394
slowrc153ad92017-08-16 19:47:52 -0700395 public void setTimesincelastupdate(WallClockTimestamp timesincelastupdate) {
396 this.timesincelastupdate = timesincelastupdate;
397 }
398
slowr13fa5b02017-08-08 16:32:31 -0700399 @Override
400 public String toString() {
slowr60d4d102017-08-16 18:33:58 -0700401 return "PrbUsageContainer{" +
402 "primary=" + primary +
403 ", secondary=" + secondary +
slowr7bebd7b2017-08-17 11:46:11 -0700404 ", timesincelastupdate=" + (new WallClockTimestamp().unixTimestamp() - timesincelastupdate.unixTimestamp()) +
slowr60d4d102017-08-16 18:33:58 -0700405 '}';
slowr13fa5b02017-08-08 16:32:31 -0700406 }
407 }
408}