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