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