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