slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /** |
| 2 | * This class file was automatically generated by jASN1 v1.8.0 (http://www.openmuc.org) |
| 3 | */ |
| 4 | |
| 5 | package org.onosproject.xran.codecs.pdu; |
| 6 | |
| 7 | import org.onosproject.xran.codecs.api.*; |
| 8 | import org.openmuc.jasn1.ber.BerByteArrayOutputStream; |
| 9 | import org.openmuc.jasn1.ber.BerLength; |
| 10 | import org.openmuc.jasn1.ber.BerTag; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 11 | import org.openmuc.jasn1.ber.types.string.BerUTF8String; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 12 | |
| 13 | import java.io.IOException; |
| 14 | import java.io.InputStream; |
| 15 | import java.io.Serializable; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 16 | import java.io.UnsupportedEncodingException; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 17 | import java.util.ArrayList; |
| 18 | import java.util.Iterator; |
| 19 | import java.util.List; |
| 20 | |
| 21 | public class RXSigMeasConfig implements Serializable { |
| 22 | |
| 23 | private static final long serialVersionUID = 1L; |
| 24 | |
| 25 | public static class MeasCells implements Serializable { |
| 26 | |
| 27 | private static final long serialVersionUID = 1L; |
| 28 | |
| 29 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 30 | public byte[] code = null; |
| 31 | private List<PCIARFCN> seqOf = null; |
| 32 | |
| 33 | public MeasCells() { |
| 34 | seqOf = new ArrayList<PCIARFCN>(); |
| 35 | } |
| 36 | |
| 37 | public MeasCells(byte[] code) { |
| 38 | this.code = code; |
| 39 | } |
| 40 | |
| 41 | public List<PCIARFCN> getPCIARFCN() { |
| 42 | if (seqOf == null) { |
| 43 | seqOf = new ArrayList<PCIARFCN>(); |
| 44 | } |
| 45 | return seqOf; |
| 46 | } |
| 47 | |
| 48 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 49 | return encode(os, true); |
| 50 | } |
| 51 | |
| 52 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 53 | |
| 54 | if (code != null) { |
| 55 | for (int i = code.length - 1; i >= 0; i--) { |
| 56 | os.write(code[i]); |
| 57 | } |
| 58 | if (withTag) { |
| 59 | return tag.encode(os) + code.length; |
| 60 | } |
| 61 | return code.length; |
| 62 | } |
| 63 | |
| 64 | int codeLength = 0; |
| 65 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 66 | codeLength += seqOf.get(i).encode(os, true); |
| 67 | } |
| 68 | |
| 69 | codeLength += BerLength.encodeLength(os, codeLength); |
| 70 | |
| 71 | if (withTag) { |
| 72 | codeLength += tag.encode(os); |
| 73 | } |
| 74 | |
| 75 | return codeLength; |
| 76 | } |
| 77 | |
| 78 | public int decode(InputStream is) throws IOException { |
| 79 | return decode(is, true); |
| 80 | } |
| 81 | |
| 82 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 83 | int codeLength = 0; |
| 84 | int subCodeLength = 0; |
| 85 | if (withTag) { |
| 86 | codeLength += tag.decodeAndCheck(is); |
| 87 | } |
| 88 | |
| 89 | BerLength length = new BerLength(); |
| 90 | codeLength += length.decode(is); |
| 91 | int totalLength = length.val; |
| 92 | |
| 93 | while (subCodeLength < totalLength) { |
| 94 | PCIARFCN element = new PCIARFCN(); |
| 95 | subCodeLength += element.decode(is, true); |
| 96 | seqOf.add(element); |
| 97 | } |
| 98 | if (subCodeLength != totalLength) { |
| 99 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
| 100 | |
| 101 | } |
| 102 | codeLength += subCodeLength; |
| 103 | |
| 104 | return codeLength; |
| 105 | } |
| 106 | |
| 107 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 108 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 109 | encode(os, false); |
| 110 | code = os.getArray(); |
| 111 | } |
| 112 | |
| 113 | public String toString() { |
| 114 | StringBuilder sb = new StringBuilder(); |
| 115 | appendAsString(sb, 0); |
| 116 | return sb.toString(); |
| 117 | } |
| 118 | |
| 119 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 120 | |
| 121 | sb.append("[\n"); |
| 122 | for (int i = 0; i < indentLevel + 1; i++) { |
| 123 | sb.append("\t"); |
| 124 | } |
| 125 | if (seqOf == null) { |
| 126 | // sb.append("null"); |
| 127 | } |
| 128 | else { |
| 129 | Iterator<PCIARFCN> it = seqOf.iterator(); |
| 130 | if (it.hasNext()) { |
| 131 | it.next().appendAsString(sb, indentLevel + 1); |
| 132 | while (it.hasNext()) { |
| 133 | sb.append(",\n"); |
| 134 | for (int i = 0; i < indentLevel + 1; i++) { |
| 135 | sb.append("\t"); |
| 136 | } |
| 137 | it.next().appendAsString(sb, indentLevel + 1); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | sb.append("\n"); |
| 143 | for (int i = 0; i < indentLevel; i++) { |
| 144 | sb.append("\t"); |
| 145 | } |
| 146 | sb.append("]"); |
| 147 | } |
| 148 | |
| 149 | public void setPCIARFCN(PCIARFCN pciarfcn) { |
| 150 | seqOf.add(pciarfcn); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 155 | |
| 156 | public byte[] code = null; |
| 157 | private ECGI ecgi = null; |
| 158 | private CRNTI crnti = null; |
| 159 | private RXSigRepQty reportQty = null; |
| 160 | private MeasCells measCells = null; |
| 161 | private RXSigMeasRepInterval reportInterval = null; |
| 162 | |
| 163 | public RXSigMeasConfig() { |
| 164 | } |
| 165 | |
| 166 | public RXSigMeasConfig(byte[] code) { |
| 167 | this.code = code; |
| 168 | } |
| 169 | |
| 170 | public void setEcgi(ECGI ecgi) { |
| 171 | this.ecgi = ecgi; |
| 172 | } |
| 173 | |
| 174 | public ECGI getEcgi() { |
| 175 | return ecgi; |
| 176 | } |
| 177 | |
| 178 | public void setCrnti(CRNTI crnti) { |
| 179 | this.crnti = crnti; |
| 180 | } |
| 181 | |
| 182 | public CRNTI getCrnti() { |
| 183 | return crnti; |
| 184 | } |
| 185 | |
| 186 | public void setReportQty(RXSigRepQty reportQty) { |
| 187 | this.reportQty = reportQty; |
| 188 | } |
| 189 | |
| 190 | public RXSigRepQty getReportQty() { |
| 191 | return reportQty; |
| 192 | } |
| 193 | |
| 194 | public void setMeasCells(MeasCells measCells) { |
| 195 | this.measCells = measCells; |
| 196 | } |
| 197 | |
| 198 | public MeasCells getMeasCells() { |
| 199 | return measCells; |
| 200 | } |
| 201 | |
| 202 | public void setReportInterval(RXSigMeasRepInterval reportInterval) { |
| 203 | this.reportInterval = reportInterval; |
| 204 | } |
| 205 | |
| 206 | public RXSigMeasRepInterval getReportInterval() { |
| 207 | return reportInterval; |
| 208 | } |
| 209 | |
| 210 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 211 | return encode(os, true); |
| 212 | } |
| 213 | |
| 214 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 215 | |
| 216 | if (code != null) { |
| 217 | for (int i = code.length - 1; i >= 0; i--) { |
| 218 | os.write(code[i]); |
| 219 | } |
| 220 | if (withTag) { |
| 221 | return tag.encode(os) + code.length; |
| 222 | } |
| 223 | return code.length; |
| 224 | } |
| 225 | |
| 226 | int codeLength = 0; |
| 227 | codeLength += reportInterval.encode(os, false); |
| 228 | // write tag: CONTEXT_CLASS, PRIMITIVE, 4 |
| 229 | os.write(0x84); |
| 230 | codeLength += 1; |
| 231 | |
| 232 | codeLength += measCells.encode(os, false); |
| 233 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 3 |
| 234 | os.write(0xA3); |
| 235 | codeLength += 1; |
| 236 | |
| 237 | codeLength += reportQty.encode(os, false); |
| 238 | // write tag: CONTEXT_CLASS, PRIMITIVE, 2 |
| 239 | os.write(0x82); |
| 240 | codeLength += 1; |
| 241 | |
| 242 | codeLength += crnti.encode(os, false); |
| 243 | // write tag: CONTEXT_CLASS, PRIMITIVE, 1 |
| 244 | os.write(0x81); |
| 245 | codeLength += 1; |
| 246 | |
| 247 | codeLength += ecgi.encode(os, false); |
| 248 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 0 |
| 249 | os.write(0xA0); |
| 250 | codeLength += 1; |
| 251 | |
| 252 | codeLength += BerLength.encodeLength(os, codeLength); |
| 253 | |
| 254 | if (withTag) { |
| 255 | codeLength += tag.encode(os); |
| 256 | } |
| 257 | |
| 258 | return codeLength; |
| 259 | |
| 260 | } |
| 261 | |
| 262 | public int decode(InputStream is) throws IOException { |
| 263 | return decode(is, true); |
| 264 | } |
| 265 | |
| 266 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 267 | int codeLength = 0; |
| 268 | int subCodeLength = 0; |
| 269 | BerTag berTag = new BerTag(); |
| 270 | |
| 271 | if (withTag) { |
| 272 | codeLength += tag.decodeAndCheck(is); |
| 273 | } |
| 274 | |
| 275 | BerLength length = new BerLength(); |
| 276 | codeLength += length.decode(is); |
| 277 | |
| 278 | int totalLength = length.val; |
| 279 | codeLength += totalLength; |
| 280 | |
| 281 | subCodeLength += berTag.decode(is); |
| 282 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { |
| 283 | ecgi = new ECGI(); |
| 284 | subCodeLength += ecgi.decode(is, false); |
| 285 | subCodeLength += berTag.decode(is); |
| 286 | } |
| 287 | else { |
| 288 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 289 | } |
| 290 | |
| 291 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { |
| 292 | crnti = new CRNTI(); |
| 293 | subCodeLength += crnti.decode(is, false); |
| 294 | subCodeLength += berTag.decode(is); |
| 295 | } |
| 296 | else { |
| 297 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 298 | } |
| 299 | |
| 300 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { |
| 301 | reportQty = new RXSigRepQty(); |
| 302 | subCodeLength += reportQty.decode(is, false); |
| 303 | subCodeLength += berTag.decode(is); |
| 304 | } |
| 305 | else { |
| 306 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 307 | } |
| 308 | |
| 309 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) { |
| 310 | measCells = new MeasCells(); |
| 311 | subCodeLength += measCells.decode(is, false); |
| 312 | subCodeLength += berTag.decode(is); |
| 313 | } |
| 314 | else { |
| 315 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 316 | } |
| 317 | |
| 318 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) { |
| 319 | reportInterval = new RXSigMeasRepInterval(); |
| 320 | subCodeLength += reportInterval.decode(is, false); |
| 321 | if (subCodeLength == totalLength) { |
| 322 | return codeLength; |
| 323 | } |
| 324 | } |
| 325 | throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); |
| 326 | |
| 327 | |
| 328 | } |
| 329 | |
| 330 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 331 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 332 | encode(os, false); |
| 333 | code = os.getArray(); |
| 334 | } |
| 335 | |
| 336 | public String toString() { |
| 337 | StringBuilder sb = new StringBuilder(); |
| 338 | appendAsString(sb, 0); |
| 339 | return sb.toString(); |
| 340 | } |
| 341 | |
| 342 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 343 | |
| 344 | sb.append("{"); |
| 345 | sb.append("\n"); |
| 346 | for (int i = 0; i < indentLevel + 1; i++) { |
| 347 | sb.append("\t"); |
| 348 | } |
| 349 | if (ecgi != null) { |
| 350 | sb.append("\"ecgi\": "); |
| 351 | ecgi.appendAsString(sb, indentLevel + 1); |
| 352 | } |
| 353 | |
| 354 | sb.append(",\n"); |
| 355 | for (int i = 0; i < indentLevel + 1; i++) { |
| 356 | sb.append("\t"); |
| 357 | } |
| 358 | if (crnti != null) { |
| 359 | sb.append("\"crnti\": ").append(crnti); |
| 360 | } |
| 361 | |
| 362 | sb.append(",\n"); |
| 363 | for (int i = 0; i < indentLevel + 1; i++) { |
| 364 | sb.append("\t"); |
| 365 | } |
| 366 | if (reportQty != null) { |
| 367 | sb.append("\"reportQty\": ").append(reportQty); |
| 368 | } |
| 369 | |
| 370 | sb.append(",\n"); |
| 371 | for (int i = 0; i < indentLevel + 1; i++) { |
| 372 | sb.append("\t"); |
| 373 | } |
| 374 | if (measCells != null) { |
| 375 | sb.append("\"measCells\": "); |
| 376 | measCells.appendAsString(sb, indentLevel + 1); |
| 377 | } |
| 378 | |
| 379 | sb.append(",\n"); |
| 380 | for (int i = 0; i < indentLevel + 1; i++) { |
| 381 | sb.append("\t"); |
| 382 | } |
| 383 | if (reportInterval != null) { |
| 384 | sb.append("\"reportInterval\": ").append(reportInterval); |
| 385 | } |
| 386 | |
| 387 | sb.append("\n"); |
| 388 | for (int i = 0; i < indentLevel; i++) { |
| 389 | sb.append("\t"); |
| 390 | } |
| 391 | sb.append("}"); |
| 392 | } |
| 393 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 394 | public static XrancPdu constructPacket(ECGI ecgi, CRNTI crnti, RXSigMeasConfig.MeasCells measCells, int interval) { |
| 395 | RXSigRepQty rxSigRepQty = new RXSigRepQty(2); |
| 396 | RXSigMeasRepInterval repInterval = new RXSigMeasRepInterval(interval); |
| 397 | |
| 398 | RXSigMeasConfig sigMeasConfig = new RXSigMeasConfig(); |
| 399 | sigMeasConfig.setCrnti(crnti); |
| 400 | sigMeasConfig.setEcgi(ecgi); |
| 401 | sigMeasConfig.setReportQty(rxSigRepQty); |
| 402 | sigMeasConfig.setMeasCells(measCells); |
| 403 | sigMeasConfig.setReportInterval(repInterval); |
| 404 | |
| 405 | XrancPduBody body = new XrancPduBody(); |
| 406 | body.setRXSigMeasConfig(sigMeasConfig); |
| 407 | |
| 408 | BerUTF8String ver = null; |
| 409 | try { |
| 410 | ver = new BerUTF8String("3"); |
| 411 | } catch (UnsupportedEncodingException e) { |
| 412 | e.printStackTrace(); |
| 413 | } |
| 414 | XrancApiID apiID = new XrancApiID(15); |
| 415 | XrancPduHdr hdr = new XrancPduHdr(); |
| 416 | hdr.setVer(ver); |
| 417 | hdr.setApiId(apiID); |
| 418 | |
| 419 | XrancPdu pdu = new XrancPdu(); |
| 420 | pdu.setHdr(hdr); |
| 421 | pdu.setBody(body); |
| 422 | |
| 423 | return pdu; |
| 424 | } |
| 425 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 426 | } |
| 427 | |