blob: f3f41d94b21fbe25a7bed9b7034417a341a325a4 [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.Timestamp;
23import org.onosproject.store.service.WallClockTimestamp;
slowr13fa5b02017-08-08 16:32:31 -070024import org.onosproject.xran.codecs.api.ECGI;
slowr13fa5b02017-08-08 16:32:31 -070025import org.onosproject.xran.codecs.api.PRBUsage;
slowrc153ad92017-08-16 19:47:52 -070026import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream;
27import org.onosproject.xran.codecs.ber.types.BerInteger;
slowr13fa5b02017-08-08 16:32:31 -070028import org.onosproject.xran.codecs.pdu.CellConfigReport;
29import org.onosproject.xran.codecs.pdu.L2MeasConfig;
30import org.onosproject.xran.codecs.pdu.RRMConfig;
31import org.onosproject.xran.codecs.pdu.SchedMeasReportPerCell;
slowr13fa5b02017-08-08 16:32:31 -070032
33import javax.xml.bind.DatatypeConverter;
34import java.io.ByteArrayInputStream;
35import java.io.IOException;
36import java.io.InputStream;
37import java.net.URI;
38import java.net.URISyntaxException;
slowr67d05e42017-08-11 20:37:22 -070039import java.util.List;
slowr8ddc2b12017-08-14 14:13:38 -070040import java.util.stream.Collectors;
41import java.util.stream.Stream;
slowr13fa5b02017-08-08 16:32:31 -070042
43/**
44 * Created by dimitris on 7/22/17.
45 */
slowr60d4d102017-08-16 18:33:58 -070046
47@JsonPropertyOrder({
48 "ECGI",
49 "Configuration",
50 "PRB-Usage",
51 "QCI",
52 "RRMConfiguration",
53 "MeasurementConfiguration"
54})
55@JsonIgnoreProperties(ignoreUnknown = true)
slowr13fa5b02017-08-08 16:32:31 -070056public class RnibCell {
slowr60d4d102017-08-16 18:33:58 -070057 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -070058 private static final String SCHEME = "xran";
59
slowr60d4d102017-08-16 18:33:58 -070060 @JsonProperty("ECGI")
slowr13fa5b02017-08-08 16:32:31 -070061 private ECGI ecgi;
slowr60d4d102017-08-16 18:33:58 -070062 @JsonProperty("Configuration")
slowr13fa5b02017-08-08 16:32:31 -070063 private CellConfigReport conf;
slowr60d4d102017-08-16 18:33:58 -070064 @JsonProperty("PRB-Usage")
slowr13fa5b02017-08-08 16:32:31 -070065 private PrbUsageContainer prbUsage;
slowr60d4d102017-08-16 18:33:58 -070066 @JsonProperty("QCI")
slowr13fa5b02017-08-08 16:32:31 -070067 private SchedMeasReportPerCell.QciVals qci;
slowr60d4d102017-08-16 18:33:58 -070068 @JsonProperty("RRMConfiguration")
slowr13fa5b02017-08-08 16:32:31 -070069 private RRMConfig rrmConfig;
slowr60d4d102017-08-16 18:33:58 -070070 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -070071 private L2MeasConfig measConfig;
72
slowr60d4d102017-08-16 18:33:58 -070073 @JsonIgnore
slowr8ddc2b12017-08-14 14:13:38 -070074 private String version;
75
slowr13fa5b02017-08-08 16:32:31 -070076 public RnibCell() {
slowr8ddc2b12017-08-14 14:13:38 -070077 version = "3";
slowr89c2ac12017-08-15 16:20:06 -070078
79 rrmConfig = new RRMConfig();
80 rrmConfig.setEcgi(ecgi);
slowr13fa5b02017-08-08 16:32:31 -070081 }
82
83 public static URI uri(ECGI ecgi) {
84 if (ecgi != null) {
85 try {
86 BerByteArrayOutputStream os = new BerByteArrayOutputStream(4096);
87 ecgi.encode(os);
88 String message = DatatypeConverter.printHexBinary(os.getArray());
89 return new URI(SCHEME, message, null);
90 } catch (URISyntaxException | IOException e) {
91 return null;
92 }
93 }
94 return null;
95 }
96
97 public static ECGI decodeDeviceId(DeviceId deviceId) throws IOException {
98 String uri = deviceId.toString();
99 String hexEcgi = uri.substring(uri.lastIndexOf("xran:") + 5);
100
101 ECGI ecgi = new ECGI();
102 byte[] bytearray = DatatypeConverter.parseHexBinary(hexEcgi);
103 InputStream inputStream = new ByteArrayInputStream(bytearray);
104
105 ecgi.decode(inputStream);
106 return ecgi;
107 }
108
slowred74ec72017-08-17 11:25:01 -0700109 public int getVersion() {
110 return Integer.parseInt(version);
slowr8ddc2b12017-08-14 14:13:38 -0700111 }
112
113 public void setVersion(String version) {
114 this.version = version;
115 }
116
slowr60d4d102017-08-16 18:33:58 -0700117 @JsonProperty("RRMConfiguration")
slowr67d05e42017-08-11 20:37:22 -0700118 public RRMConfig getRrmConfig() {
119 return rrmConfig;
120 }
121
slowr60d4d102017-08-16 18:33:58 -0700122 @JsonProperty("RRMConfiguration")
slowr67d05e42017-08-11 20:37:22 -0700123 public void setRrmConfig(RRMConfig rrmConfig) {
124 this.rrmConfig = rrmConfig;
125 }
126
slowr60d4d102017-08-16 18:33:58 -0700127 @JsonProperty("PRB-Usage")
slowr67d05e42017-08-11 20:37:22 -0700128 public PrbUsageContainer getPrbUsage() {
129 return prbUsage;
130 }
131
slowr60d4d102017-08-16 18:33:58 -0700132 @JsonProperty("PRB-Usage")
slowr67d05e42017-08-11 20:37:22 -0700133 public void setPrbUsage(PrbUsageContainer prbUsage) {
134 this.prbUsage = prbUsage;
135 }
136
slowr60d4d102017-08-16 18:33:58 -0700137 @JsonProperty("ECGI")
slowr13fa5b02017-08-08 16:32:31 -0700138 public ECGI getEcgi() {
139 return ecgi;
140 }
141
slowr60d4d102017-08-16 18:33:58 -0700142 @JsonProperty("ECGI")
slowr13fa5b02017-08-08 16:32:31 -0700143 public void setEcgi(ECGI ecgi) {
144 this.ecgi = ecgi;
145 }
146
slowr60d4d102017-08-16 18:33:58 -0700147 @JsonProperty("Configuration")
slowr13fa5b02017-08-08 16:32:31 -0700148 public CellConfigReport getConf() {
149 return conf;
150 }
151
slowr60d4d102017-08-16 18:33:58 -0700152 @JsonProperty("Configuration")
slowr13fa5b02017-08-08 16:32:31 -0700153 public void setConf(CellConfigReport conf) {
154 this.conf = conf;
155 }
156
slowr67d05e42017-08-11 20:37:22 -0700157 public void modifyRrmConfig(JsonNode rrmConfigNode, List<RnibUe> ueList) {
158 RRMConfig.Crnti crnti = new RRMConfig.Crnti();
159 ueList.forEach(ue -> crnti.addCRNTI(ue.getRanId()));
slowr13fa5b02017-08-08 16:32:31 -0700160
slowr8ddc2b12017-08-14 14:13:38 -0700161 {
slowr60d4d102017-08-16 18:33:58 -0700162 JsonNode start_prb_dl = rrmConfigNode.path("start_prb_dl");
163 if (!start_prb_dl.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700164 RRMConfig.StartPrbDl startPrbDl = new RRMConfig.StartPrbDl();
165 if (start_prb_dl.isArray()) {
slowr89c2ac12017-08-15 16:20:06 -0700166 if (ueList.size() == start_prb_dl.size()) {
slowr8ddc2b12017-08-14 14:13:38 -0700167 List<BerInteger> collect = Stream.of(start_prb_dl)
168 .map(val -> new BerInteger(val.asInt()))
169 .collect(Collectors.toList());
170 startPrbDl.setSeqOf(collect);
171 }
172 }
173 rrmConfig.setStartPrbDl(startPrbDl);
slowr67d05e42017-08-11 20:37:22 -0700174 }
175 }
slowr67d05e42017-08-11 20:37:22 -0700176
slowr8ddc2b12017-08-14 14:13:38 -0700177 {
slowr60d4d102017-08-16 18:33:58 -0700178 JsonNode end_prb_dl = rrmConfigNode.path("end_prb_dl");
179 if (!end_prb_dl.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700180 RRMConfig.EndPrbDl endPrbDl = new RRMConfig.EndPrbDl();
181 if (end_prb_dl.isArray()) {
slowr89c2ac12017-08-15 16:20:06 -0700182 if (ueList.size() == end_prb_dl.size()) {
slowr8ddc2b12017-08-14 14:13:38 -0700183 List<BerInteger> collect = Stream.of(end_prb_dl)
184 .map(val -> new BerInteger(val.asInt()))
185 .collect(Collectors.toList());
186 endPrbDl.setSeqOf(collect);
187 }
188 }
189 rrmConfig.setEndPrbDl(endPrbDl);
190 }
191 }
192
193 {
slowr60d4d102017-08-16 18:33:58 -0700194 JsonNode start_prb_ul = rrmConfigNode.path("start_prb_ul");
195 if (!start_prb_ul.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700196 RRMConfig.StartPrbUl startPrbUl = new RRMConfig.StartPrbUl();
197 if (start_prb_ul.isArray()) {
slowr89c2ac12017-08-15 16:20:06 -0700198 if (ueList.size() == start_prb_ul.size()) {
slowr8ddc2b12017-08-14 14:13:38 -0700199 List<BerInteger> collect = Stream.of(start_prb_ul)
200 .map(val -> new BerInteger(val.asInt()))
201 .collect(Collectors.toList());
202 startPrbUl.setSeqOf(collect);
203 }
204 }
205 rrmConfig.setStartPrbUl(startPrbUl);
206 }
207 }
208
209 {
slowr60d4d102017-08-16 18:33:58 -0700210 JsonNode end_prb_ul = rrmConfigNode.path("end_prb_ul");
211 if (!end_prb_ul.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700212 RRMConfig.EndPrbUl endPrbUl = new RRMConfig.EndPrbUl();
213 if (end_prb_ul.isArray()) {
slowr89c2ac12017-08-15 16:20:06 -0700214 if (ueList.size() == end_prb_ul.size()) {
slowr8ddc2b12017-08-14 14:13:38 -0700215 List<BerInteger> collect = Stream.of(end_prb_ul)
216 .map(val -> new BerInteger(val.asInt()))
217 .collect(Collectors.toList());
218 endPrbUl.setSeqOf(collect);
219 }
220 }
221 rrmConfig.setEndPrbUl(endPrbUl);
222 }
223 }
224
225 rrmConfig.setCrnti(crnti);
slowr13fa5b02017-08-08 16:32:31 -0700226 }
227
slowr60d4d102017-08-16 18:33:58 -0700228 @JsonProperty("QCI")
slowr13fa5b02017-08-08 16:32:31 -0700229 public SchedMeasReportPerCell.QciVals getQci() {
230 return qci;
231 }
232
slowr60d4d102017-08-16 18:33:58 -0700233 @JsonProperty("QCI")
slowr13fa5b02017-08-08 16:32:31 -0700234 public void setQci(SchedMeasReportPerCell.QciVals qci) {
235 this.qci = qci;
236 }
237
slowr60d4d102017-08-16 18:33:58 -0700238 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -0700239 public L2MeasConfig getMeasConfig() {
240 return measConfig;
241 }
242
slowr60d4d102017-08-16 18:33:58 -0700243 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -0700244 public void setMeasConfig(L2MeasConfig measConfig) {
245 this.measConfig = measConfig;
246 }
247
248 @Override
249 public String toString() {
slowr60d4d102017-08-16 18:33:58 -0700250 return "RnibCell{" +
251 "ecgi=" + ecgi +
252 ", conf=" + conf +
253 ", prbUsage=" + prbUsage +
254 ", qci=" + qci +
255 ", rrmConfig=" + rrmConfig +
256 ", measConfig=" + measConfig +
257 ", version='" + version + '\'' +
258 '}';
slowr13fa5b02017-08-08 16:32:31 -0700259 }
260
261 @Override
262 public boolean equals(Object o) {
263 if (this == o) return true;
264 if (o == null || getClass() != o.getClass()) return false;
265
266 RnibCell rnibCell = (RnibCell) o;
267
268 return ecgi.equals(rnibCell.ecgi);
269 }
270
271 @Override
272 public int hashCode() {
273 return ecgi.hashCode();
274 }
275
slowr60d4d102017-08-16 18:33:58 -0700276 @JsonPropertyOrder({
277 "primary",
slowrc153ad92017-08-16 19:47:52 -0700278 "secondary",
279 "timesincelastupdate"
slowr60d4d102017-08-16 18:33:58 -0700280 })
281 @JsonIgnoreProperties(ignoreUnknown = true)
slowrc153ad92017-08-16 19:47:52 -0700282 public static class PrbUsageContainer {
slowr13fa5b02017-08-08 16:32:31 -0700283 PRBUsage primary;
284 PRBUsage secondary;
slowrc153ad92017-08-16 19:47:52 -0700285 WallClockTimestamp timesincelastupdate;
286
287 @JsonCreator
288 public PrbUsageContainer(@JsonProperty("primary") PRBUsage primary, @JsonProperty("secondary") PRBUsage secondary) {
289 this.primary = primary;
290 this.secondary = secondary;
291 this.timesincelastupdate = new WallClockTimestamp();
292 }
slowr13fa5b02017-08-08 16:32:31 -0700293
slowr60d4d102017-08-16 18:33:58 -0700294 public PRBUsage getPrimary() {
295 return primary;
296 }
297
298 public void setPrimary(PRBUsage primary) {
299 this.primary = primary;
300 }
301
302 public PRBUsage getSecondary() {
303 return secondary;
304 }
305
306 public void setSecondary(PRBUsage secondary) {
307 this.secondary = secondary;
308 }
309
slowrc153ad92017-08-16 19:47:52 -0700310 public long getTimesincelastupdate() {
slowr7bebd7b2017-08-17 11:46:11 -0700311 return new WallClockTimestamp().unixTimestamp() - timesincelastupdate.unixTimestamp();
slowrc153ad92017-08-16 19:47:52 -0700312 }
slowr7bebd7b2017-08-17 11:46:11 -0700313
slowrc153ad92017-08-16 19:47:52 -0700314 public void setTimesincelastupdate(WallClockTimestamp timesincelastupdate) {
315 this.timesincelastupdate = timesincelastupdate;
316 }
317
slowr13fa5b02017-08-08 16:32:31 -0700318 @Override
319 public String toString() {
slowr60d4d102017-08-16 18:33:58 -0700320 return "PrbUsageContainer{" +
321 "primary=" + primary +
322 ", secondary=" + secondary +
slowr7bebd7b2017-08-17 11:46:11 -0700323 ", timesincelastupdate=" + (new WallClockTimestamp().unixTimestamp() - timesincelastupdate.unixTimestamp()) +
slowr60d4d102017-08-16 18:33:58 -0700324 '}';
slowr13fa5b02017-08-08 16:32:31 -0700325 }
326 }
327}