blob: 81aeafd56bc4e88ccefad51598ddd99a77cb877d [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
19import com.fasterxml.jackson.databind.JsonNode;
20import org.onosproject.net.DeviceId;
21import org.onosproject.xran.codecs.api.ECGI;
slowr13fa5b02017-08-08 16:32:31 -070022import org.onosproject.xran.codecs.api.PRBUsage;
23import org.onosproject.xran.codecs.pdu.CellConfigReport;
24import org.onosproject.xran.codecs.pdu.L2MeasConfig;
25import org.onosproject.xran.codecs.pdu.RRMConfig;
26import org.onosproject.xran.codecs.pdu.SchedMeasReportPerCell;
27import org.openmuc.jasn1.ber.BerByteArrayOutputStream;
slowr67d05e42017-08-11 20:37:22 -070028import org.openmuc.jasn1.ber.types.BerBitString;
29import org.openmuc.jasn1.ber.types.BerInteger;
slowr13fa5b02017-08-08 16:32:31 -070030
31import javax.xml.bind.DatatypeConverter;
32import java.io.ByteArrayInputStream;
33import java.io.IOException;
34import java.io.InputStream;
35import java.net.URI;
36import java.net.URISyntaxException;
slowr67d05e42017-08-11 20:37:22 -070037import java.util.List;
slowr8ddc2b12017-08-14 14:13:38 -070038import java.util.stream.Collectors;
39import java.util.stream.Stream;
slowr13fa5b02017-08-08 16:32:31 -070040
41/**
42 * Created by dimitris on 7/22/17.
43 */
44public class RnibCell {
45 private static final String SCHEME = "xran";
46
47 private ECGI ecgi;
48 private CellConfigReport conf;
49 private PrbUsageContainer prbUsage;
50 private SchedMeasReportPerCell.QciVals qci;
51 private RRMConfig rrmConfig;
52 private L2MeasConfig measConfig;
53
slowr8ddc2b12017-08-14 14:13:38 -070054 private String version;
55
slowr13fa5b02017-08-08 16:32:31 -070056 public RnibCell() {
57 prbUsage = new PrbUsageContainer();
slowr67d05e42017-08-11 20:37:22 -070058 setDefaultRRMConf();
slowr8ddc2b12017-08-14 14:13:38 -070059 version = "3";
slowr13fa5b02017-08-08 16:32:31 -070060 }
61
62 public static URI uri(ECGI ecgi) {
63 if (ecgi != null) {
64 try {
65 BerByteArrayOutputStream os = new BerByteArrayOutputStream(4096);
66 ecgi.encode(os);
67 String message = DatatypeConverter.printHexBinary(os.getArray());
68 return new URI(SCHEME, message, null);
69 } catch (URISyntaxException | IOException e) {
70 return null;
71 }
72 }
73 return null;
74 }
75
76 public static ECGI decodeDeviceId(DeviceId deviceId) throws IOException {
77 String uri = deviceId.toString();
78 String hexEcgi = uri.substring(uri.lastIndexOf("xran:") + 5);
79
80 ECGI ecgi = new ECGI();
81 byte[] bytearray = DatatypeConverter.parseHexBinary(hexEcgi);
82 InputStream inputStream = new ByteArrayInputStream(bytearray);
83
84 ecgi.decode(inputStream);
85 return ecgi;
86 }
87
slowr8ddc2b12017-08-14 14:13:38 -070088 public String getVersion() {
89 return version;
90 }
91
92 public void setVersion(String version) {
93 this.version = version;
94 }
95
slowr67d05e42017-08-11 20:37:22 -070096 public RRMConfig getRrmConfig() {
97 return rrmConfig;
98 }
99
100 public void setRrmConfig(RRMConfig rrmConfig) {
101 this.rrmConfig = rrmConfig;
102 }
103
104 public PrbUsageContainer getPrbUsage() {
105 return prbUsage;
106 }
107
108 public void setPrbUsage(PrbUsageContainer prbUsage) {
109 this.prbUsage = prbUsage;
110 }
111
112 private void setDefaultRRMConf() {
113 rrmConfig = new RRMConfig();
114
slowr67d05e42017-08-11 20:37:22 -0700115 rrmConfig.setEcgi(ecgi);
116
117 RRMConfig.StartPrbDl startPrbDl = new RRMConfig.StartPrbDl();
118 startPrbDl.addBerInteger(new BerInteger(0));
119 startPrbDl.addBerInteger(new BerInteger(50));
120
121 rrmConfig.setStartPrbDl(startPrbDl);
122
123 RRMConfig.StartPrbUl startPrbUl = new RRMConfig.StartPrbUl();
124 startPrbUl.addBerInteger(new BerInteger(50));
125 startPrbUl.addBerInteger(new BerInteger(100));
126
127 rrmConfig.setStartPrbUl(startPrbUl);
128
129 RRMConfig.EndPrbDl endPrbDl = new RRMConfig.EndPrbDl();
130 endPrbDl.addBerInteger(new BerInteger(50));
131 endPrbDl.addBerInteger(new BerInteger(100));
132
133 rrmConfig.setEndPrbDl(endPrbDl);
134
135 RRMConfig.EndPrbUl endPrbUl = new RRMConfig.EndPrbUl();
136 endPrbUl.addBerInteger(new BerInteger(50));
137 endPrbUl.addBerInteger(new BerInteger(100));
138
139 rrmConfig.setEndPrbUl(endPrbUl);
140
141 RRMConfig.SubframeBitmaskDl subframeBitmaskDl = new RRMConfig.SubframeBitmaskDl();
142 BerBitString berBitString = new BerBitString(new byte[]{(byte) 0xAA, (byte) 0x80}, 10);
143 BerBitString berBitString1 = new BerBitString(new byte[]{(byte) 0x55, (byte) 0x40}, 10);
144
145 subframeBitmaskDl.addBerBitString(berBitString);
146 subframeBitmaskDl.addBerBitString(berBitString1);
147
148 rrmConfig.setSubframeBitmaskDl(subframeBitmaskDl);
149 }
150
slowr13fa5b02017-08-08 16:32:31 -0700151 public ECGI getEcgi() {
152 return ecgi;
153 }
154
155 public void setEcgi(ECGI ecgi) {
156 this.ecgi = ecgi;
157 }
158
159 public CellConfigReport getConf() {
160 return conf;
161 }
162
slowr67d05e42017-08-11 20:37:22 -0700163 /*public RRMConfig getRrmConfig() {
164 return rrmConfig;
165 }*/
166
slowr13fa5b02017-08-08 16:32:31 -0700167 public void setConf(CellConfigReport conf) {
168 this.conf = conf;
169 }
170
slowr67d05e42017-08-11 20:37:22 -0700171 public void modifyRrmConfig(JsonNode rrmConfigNode, List<RnibUe> ueList) {
172 RRMConfig.Crnti crnti = new RRMConfig.Crnti();
173 ueList.forEach(ue -> crnti.addCRNTI(ue.getRanId()));
slowr13fa5b02017-08-08 16:32:31 -0700174
slowr8ddc2b12017-08-14 14:13:38 -0700175 {
176 JsonNode start_prb_dl = rrmConfigNode.get("start_prb_dl");
177 if (start_prb_dl != null) {
178 RRMConfig.StartPrbDl startPrbDl = new RRMConfig.StartPrbDl();
179 if (start_prb_dl.isArray()) {
180 if (rrmConfig.getStartPrbDl().getSeqOf().size() == start_prb_dl.size()) {
181 List<BerInteger> collect = Stream.of(start_prb_dl)
182 .map(val -> new BerInteger(val.asInt()))
183 .collect(Collectors.toList());
184 startPrbDl.setSeqOf(collect);
185 }
186 }
187 rrmConfig.setStartPrbDl(startPrbDl);
slowr67d05e42017-08-11 20:37:22 -0700188 }
189 }
slowr67d05e42017-08-11 20:37:22 -0700190
slowr8ddc2b12017-08-14 14:13:38 -0700191 {
192 JsonNode end_prb_dl = rrmConfigNode.get("end_prb_dl");
193 if (end_prb_dl != null) {
194 RRMConfig.EndPrbDl endPrbDl = new RRMConfig.EndPrbDl();
195 if (end_prb_dl.isArray()) {
196 if (rrmConfig.getEndPrbDl().getSeqOf().size() == end_prb_dl.size()) {
197 List<BerInteger> collect = Stream.of(end_prb_dl)
198 .map(val -> new BerInteger(val.asInt()))
199 .collect(Collectors.toList());
200 endPrbDl.setSeqOf(collect);
201 }
202 }
203 rrmConfig.setEndPrbDl(endPrbDl);
204 }
205 }
206
207 {
208 JsonNode start_prb_ul = rrmConfigNode.get("start_prb_ul");
209 if (start_prb_ul != null) {
210 RRMConfig.StartPrbUl startPrbUl = new RRMConfig.StartPrbUl();
211 if (start_prb_ul.isArray()) {
212 if (rrmConfig.getStartPrbUl().getSeqOf().size() == start_prb_ul.size()) {
213 List<BerInteger> collect = Stream.of(start_prb_ul)
214 .map(val -> new BerInteger(val.asInt()))
215 .collect(Collectors.toList());
216 startPrbUl.setSeqOf(collect);
217 }
218 }
219 rrmConfig.setStartPrbUl(startPrbUl);
220 }
221 }
222
223 {
224 JsonNode end_prb_ul = rrmConfigNode.get("end_prb_ul");
225 if (end_prb_ul != null) {
226 RRMConfig.EndPrbUl endPrbUl = new RRMConfig.EndPrbUl();
227 if (end_prb_ul.isArray()) {
228 if (rrmConfig.getEndPrbUl().getSeqOf().size() == end_prb_ul.size()) {
229 List<BerInteger> collect = Stream.of(end_prb_ul)
230 .map(val -> new BerInteger(val.asInt()))
231 .collect(Collectors.toList());
232 endPrbUl.setSeqOf(collect);
233 }
234 }
235 rrmConfig.setEndPrbUl(endPrbUl);
236 }
237 }
238
239 rrmConfig.setCrnti(crnti);
slowr67d05e42017-08-11 20:37:22 -0700240
slowr13fa5b02017-08-08 16:32:31 -0700241 // TODO
242 }
243
244 public SchedMeasReportPerCell.QciVals getQci() {
245 return qci;
246 }
247
248 public void setQci(SchedMeasReportPerCell.QciVals qci) {
249 this.qci = qci;
250 }
251
252 public void setPrimaryPrbUsage(PRBUsage primary) {
253 this.prbUsage.primary = primary;
254 }
255
256 public void setSecondaryPrbUsage(PRBUsage secondary) {
257 this.prbUsage.secondary = secondary;
258 }
259
260 public L2MeasConfig getMeasConfig() {
261 return measConfig;
262 }
263
264 public void setMeasConfig(L2MeasConfig measConfig) {
265 this.measConfig = measConfig;
266 }
267
268 @Override
269 public String toString() {
270 StringBuilder sb = new StringBuilder();
271 sb.append("{\n")
272 .append(ecgi != null ? "\"ecgi\":" + ecgi : "")
273 .append(conf != null ? ",\n\"config-report\":" + conf : "")
274 .append(prbUsage != null ? ",\n\"prb-usage\":" + prbUsage : "")
275 .append(qci != null ? ",\n\"qci-vals\":" + qci : "")
276 .append(rrmConfig != null ? ",\n\"rrm-config\":" + rrmConfig : "")
277 .append(measConfig != null ? ",\n\"l2-meas-config\":" + measConfig : "")
278 .append("\n}\n");
279 return sb.toString();
280 }
281
282 @Override
283 public boolean equals(Object o) {
284 if (this == o) return true;
285 if (o == null || getClass() != o.getClass()) return false;
286
287 RnibCell rnibCell = (RnibCell) o;
288
289 return ecgi.equals(rnibCell.ecgi);
290 }
291
292 @Override
293 public int hashCode() {
294 return ecgi.hashCode();
295 }
296
297 class PrbUsageContainer {
298 PRBUsage primary;
299 PRBUsage secondary;
300
301 @Override
302 public String toString() {
303 StringBuilder sb = new StringBuilder();
304 sb.append("{\n")
305 .append(primary != null ? "\"primary\":" + primary : "")
306 .append(secondary != null ? ",\n\"secondary\":" + secondary : "")
307 .append("\n}\n");
308 return sb.toString();
309 }
310 }
311}