blob: d917f02805328e90a78bb51460e8592e21ec213d [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;
slowr13fa5b02017-08-08 16:32:31 -070038
39/**
40 * Created by dimitris on 7/22/17.
41 */
42public class RnibCell {
43 private static final String SCHEME = "xran";
44
45 private ECGI ecgi;
46 private CellConfigReport conf;
47 private PrbUsageContainer prbUsage;
48 private SchedMeasReportPerCell.QciVals qci;
49 private RRMConfig rrmConfig;
50 private L2MeasConfig measConfig;
51
52 public RnibCell() {
53 prbUsage = new PrbUsageContainer();
slowr67d05e42017-08-11 20:37:22 -070054 setDefaultRRMConf();
55
slowr13fa5b02017-08-08 16:32:31 -070056 }
57
58 public static URI uri(ECGI ecgi) {
59 if (ecgi != null) {
60 try {
61 BerByteArrayOutputStream os = new BerByteArrayOutputStream(4096);
62 ecgi.encode(os);
63 String message = DatatypeConverter.printHexBinary(os.getArray());
64 return new URI(SCHEME, message, null);
65 } catch (URISyntaxException | IOException e) {
66 return null;
67 }
68 }
69 return null;
70 }
71
72 public static ECGI decodeDeviceId(DeviceId deviceId) throws IOException {
73 String uri = deviceId.toString();
74 String hexEcgi = uri.substring(uri.lastIndexOf("xran:") + 5);
75
76 ECGI ecgi = new ECGI();
77 byte[] bytearray = DatatypeConverter.parseHexBinary(hexEcgi);
78 InputStream inputStream = new ByteArrayInputStream(bytearray);
79
80 ecgi.decode(inputStream);
81 return ecgi;
82 }
83
slowr67d05e42017-08-11 20:37:22 -070084 public RRMConfig getRrmConfig() {
85 return rrmConfig;
86 }
87
88 public void setRrmConfig(RRMConfig rrmConfig) {
89 this.rrmConfig = rrmConfig;
90 }
91
92 public PrbUsageContainer getPrbUsage() {
93 return prbUsage;
94 }
95
96 public void setPrbUsage(PrbUsageContainer prbUsage) {
97 this.prbUsage = prbUsage;
98 }
99
100 private void setDefaultRRMConf() {
101 rrmConfig = new RRMConfig();
102
103 RRMConfig.Crnti crnti2 = new RRMConfig.Crnti();
104
105 rrmConfig.setCrnti(crnti2);
106
107 rrmConfig.setEcgi(ecgi);
108
109 RRMConfig.StartPrbDl startPrbDl = new RRMConfig.StartPrbDl();
110 startPrbDl.addBerInteger(new BerInteger(0));
111 startPrbDl.addBerInteger(new BerInteger(50));
112
113 rrmConfig.setStartPrbDl(startPrbDl);
114
115 RRMConfig.StartPrbUl startPrbUl = new RRMConfig.StartPrbUl();
116 startPrbUl.addBerInteger(new BerInteger(50));
117 startPrbUl.addBerInteger(new BerInteger(100));
118
119 rrmConfig.setStartPrbUl(startPrbUl);
120
121 RRMConfig.EndPrbDl endPrbDl = new RRMConfig.EndPrbDl();
122 endPrbDl.addBerInteger(new BerInteger(50));
123 endPrbDl.addBerInteger(new BerInteger(100));
124
125 rrmConfig.setEndPrbDl(endPrbDl);
126
127 RRMConfig.EndPrbUl endPrbUl = new RRMConfig.EndPrbUl();
128 endPrbUl.addBerInteger(new BerInteger(50));
129 endPrbUl.addBerInteger(new BerInteger(100));
130
131 rrmConfig.setEndPrbUl(endPrbUl);
132
133 RRMConfig.SubframeBitmaskDl subframeBitmaskDl = new RRMConfig.SubframeBitmaskDl();
134 BerBitString berBitString = new BerBitString(new byte[]{(byte) 0xAA, (byte) 0x80}, 10);
135 BerBitString berBitString1 = new BerBitString(new byte[]{(byte) 0x55, (byte) 0x40}, 10);
136
137 subframeBitmaskDl.addBerBitString(berBitString);
138 subframeBitmaskDl.addBerBitString(berBitString1);
139
140 rrmConfig.setSubframeBitmaskDl(subframeBitmaskDl);
141 }
142
slowr13fa5b02017-08-08 16:32:31 -0700143 public ECGI getEcgi() {
144 return ecgi;
145 }
146
147 public void setEcgi(ECGI ecgi) {
148 this.ecgi = ecgi;
149 }
150
151 public CellConfigReport getConf() {
152 return conf;
153 }
154
slowr67d05e42017-08-11 20:37:22 -0700155 /*public RRMConfig getRrmConfig() {
156 return rrmConfig;
157 }*/
158
slowr13fa5b02017-08-08 16:32:31 -0700159 public void setConf(CellConfigReport conf) {
160 this.conf = conf;
161 }
162
slowr67d05e42017-08-11 20:37:22 -0700163 public void modifyRrmConfig(JsonNode rrmConfigNode, List<RnibUe> ueList) {
164 RRMConfig.Crnti crnti = new RRMConfig.Crnti();
165 ueList.forEach(ue -> crnti.addCRNTI(ue.getRanId()));
slowr13fa5b02017-08-08 16:32:31 -0700166
slowr67d05e42017-08-11 20:37:22 -0700167 RRMConfig.StartPrbDl startPrbDl = new RRMConfig.StartPrbDl();
168 RRMConfig.EndPrbDl endPrbDl = new RRMConfig.EndPrbDl();
169 int i = 0;
170 if (rrmConfigNode.get("start_prb_dl").isArray()) {
171 for (final JsonNode config : rrmConfigNode) {
172 startPrbDl.getSeqOf().set(i, new BerInteger(config.asInt()));
173 i++;
174 }
175 }
176 i = 0;
177 if (rrmConfigNode.get("end_prb_dl").isArray()) {
178 for (final JsonNode config : rrmConfigNode) {
179 endPrbDl.getSeqOf().set(i, new BerInteger(config.asInt()));
180 i++;
181 }
182 }
183 rrmConfig.setEndPrbDl(endPrbDl);
184 rrmConfig.setStartPrbDl(startPrbDl);
185 rrmConfig.setCrnti(crnti);
186 rrmConfig.setEcgi(ecgi);
187
188
slowr13fa5b02017-08-08 16:32:31 -0700189 // TODO
190 }
191
192 public SchedMeasReportPerCell.QciVals getQci() {
193 return qci;
194 }
195
196 public void setQci(SchedMeasReportPerCell.QciVals qci) {
197 this.qci = qci;
198 }
199
200 public void setPrimaryPrbUsage(PRBUsage primary) {
201 this.prbUsage.primary = primary;
202 }
203
204 public void setSecondaryPrbUsage(PRBUsage secondary) {
205 this.prbUsage.secondary = secondary;
206 }
207
208 public L2MeasConfig getMeasConfig() {
209 return measConfig;
210 }
211
212 public void setMeasConfig(L2MeasConfig measConfig) {
213 this.measConfig = measConfig;
214 }
215
216 @Override
217 public String toString() {
218 StringBuilder sb = new StringBuilder();
219 sb.append("{\n")
220 .append(ecgi != null ? "\"ecgi\":" + ecgi : "")
221 .append(conf != null ? ",\n\"config-report\":" + conf : "")
222 .append(prbUsage != null ? ",\n\"prb-usage\":" + prbUsage : "")
223 .append(qci != null ? ",\n\"qci-vals\":" + qci : "")
224 .append(rrmConfig != null ? ",\n\"rrm-config\":" + rrmConfig : "")
225 .append(measConfig != null ? ",\n\"l2-meas-config\":" + measConfig : "")
226 .append("\n}\n");
227 return sb.toString();
228 }
229
230 @Override
231 public boolean equals(Object o) {
232 if (this == o) return true;
233 if (o == null || getClass() != o.getClass()) return false;
234
235 RnibCell rnibCell = (RnibCell) o;
236
237 return ecgi.equals(rnibCell.ecgi);
238 }
239
240 @Override
241 public int hashCode() {
242 return ecgi.hashCode();
243 }
244
245 class PrbUsageContainer {
246 PRBUsage primary;
247 PRBUsage secondary;
248
249 @Override
250 public String toString() {
251 StringBuilder sb = new StringBuilder();
252 sb.append("{\n")
253 .append(primary != null ? "\"primary\":" + primary : "")
254 .append(secondary != null ? ",\n\"secondary\":" + secondary : "")
255 .append("\n}\n");
256 return sb.toString();
257 }
258 }
259}