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