blob: 4f5e20bc2c0554af2e4f2458a0405f53ebc9499c [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/**
2 * This class file was automatically generated by jASN1 v1.8.0 (http://www.openmuc.org)
3 */
4
5package org.onosproject.xran.codecs.pdu;
6
slowr60d4d102017-08-16 18:33:58 -07007import com.fasterxml.jackson.annotation.JsonIgnore;
8import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream;
9import org.onosproject.xran.codecs.ber.BerLength;
10import org.onosproject.xran.codecs.ber.BerTag;
slowr13fa5b02017-08-08 16:32:31 -070011import org.onosproject.xran.codecs.api.ECGI;
slowr60d4d102017-08-16 18:33:58 -070012import org.onosproject.xran.codecs.ber.types.string.BerUTF8String;
slowr13fa5b02017-08-08 16:32:31 -070013
14import java.io.IOException;
15import java.io.InputStream;
16import java.io.Serializable;
slowr8ddc2b12017-08-14 14:13:38 -070017import java.io.UnsupportedEncodingException;
slowr13fa5b02017-08-08 16:32:31 -070018
19public class CellConfigRequest implements Serializable {
20
21 private static final long serialVersionUID = 1L;
22
23 public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
24
slowr60d4d102017-08-16 18:33:58 -070025 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -070026 public byte[] code = null;
27 private ECGI ecgi = null;
28
29 public CellConfigRequest() {
30 }
31
32 public CellConfigRequest(byte[] code) {
33 this.code = code;
34 }
35
36 public void setEcgi(ECGI ecgi) {
37 this.ecgi = ecgi;
38 }
39
40 public ECGI getEcgi() {
41 return ecgi;
42 }
43
44 public int encode(BerByteArrayOutputStream os) throws IOException {
45 return encode(os, true);
46 }
47
48 public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
49
50 if (code != null) {
51 for (int i = code.length - 1; i >= 0; i--) {
52 os.write(code[i]);
53 }
54 if (withTag) {
55 return tag.encode(os) + code.length;
56 }
57 return code.length;
58 }
59
60 int codeLength = 0;
61 codeLength += ecgi.encode(os, false);
62 // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
63 os.write(0xA0);
64 codeLength += 1;
65
66 codeLength += BerLength.encodeLength(os, codeLength);
67
68 if (withTag) {
69 codeLength += tag.encode(os);
70 }
71
72 return codeLength;
73
74 }
75
76 public int decode(InputStream is) throws IOException {
77 return decode(is, true);
78 }
79
80 public int decode(InputStream is, boolean withTag) throws IOException {
81 int codeLength = 0;
82 int subCodeLength = 0;
83 BerTag berTag = new BerTag();
84
85 if (withTag) {
86 codeLength += tag.decodeAndCheck(is);
87 }
88
89 BerLength length = new BerLength();
90 codeLength += length.decode(is);
91
92 int totalLength = length.val;
93 codeLength += totalLength;
94
95 subCodeLength += berTag.decode(is);
96 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
97 ecgi = new ECGI();
98 subCodeLength += ecgi.decode(is, false);
99 if (subCodeLength == totalLength) {
100 return codeLength;
101 }
102 }
103 throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
104
105
106 }
107
108 public void encodeAndSave(int encodingSizeGuess) throws IOException {
109 BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
110 encode(os, false);
111 code = os.getArray();
112 }
113
114 public String toString() {
115 StringBuilder sb = new StringBuilder();
116 appendAsString(sb, 0);
117 return sb.toString();
118 }
119
120 public void appendAsString(StringBuilder sb, int indentLevel) {
121
122 sb.append("{");
123 sb.append("\n");
124 for (int i = 0; i < indentLevel + 1; i++) {
125 sb.append("\t");
126 }
127 if (ecgi != null) {
slowr60d4d102017-08-16 18:33:58 -0700128 sb.append("ecgi: ");
slowr13fa5b02017-08-08 16:32:31 -0700129 ecgi.appendAsString(sb, indentLevel + 1);
130 }
131
132 sb.append("\n");
133 for (int i = 0; i < indentLevel; i++) {
134 sb.append("\t");
135 }
136 sb.append("}");
137 }
138
slowr8ddc2b12017-08-14 14:13:38 -0700139 public static XrancPdu constructPacket(ECGI ecgi) throws UnsupportedEncodingException {
140 CellConfigRequest cellConfigRequest = new CellConfigRequest();
141 cellConfigRequest.setEcgi(ecgi);
142
143 BerUTF8String ver = new BerUTF8String("3");
144
145 XrancApiID apiID = new XrancApiID(0);
146 XrancPduBody body = new XrancPduBody();
147 body.setCellConfigRequest(cellConfigRequest);
148
149 XrancPduHdr hdr = new XrancPduHdr();
150 hdr.setVer(ver);
151 hdr.setApiId(apiID);
152
153 XrancPdu pdu = new XrancPdu();
154 pdu.setBody(body);
155 pdu.setHdr(hdr);
156
157 return pdu;
158 }
159
slowr13fa5b02017-08-08 16:32:31 -0700160}
161