blob: 333aca137f30c622f5470c9b6ca0809102e5f1d0 [file] [log] [blame]
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -08001/**
2 * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
3 */
4
5package org.onosproject.xran.asn1lib.pdu;
6
7
8import com.fasterxml.jackson.annotation.JsonIgnore;
9import org.onosproject.xran.asn1lib.api.*;
10import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
11import org.onosproject.xran.asn1lib.ber.BerLength;
12import org.onosproject.xran.asn1lib.ber.BerTag;
13import org.onosproject.xran.asn1lib.ber.types.BerInteger;
14import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
15
16import java.io.IOException;
17import java.io.InputStream;
18import java.io.Serializable;
19import java.io.UnsupportedEncodingException;
20
21public class BearerAdmissionResponse implements Serializable {
22
23 public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
24 private static final long serialVersionUID = 1L;
25 @JsonIgnore
26 public byte[] code = null;
27 private CRNTI crnti = null;
28 private ECGI ecgi = null;
29 private BerInteger numErabList = null;
30 private ERABResponse erabResponse = null;
31
32 public BearerAdmissionResponse() {
33 }
34
35 public BearerAdmissionResponse(byte[] code) {
36 this.code = code;
37 }
38
39 public static XrancPdu constructPacket(ECGI ecgi, CRNTI crnti, ERABParams erabParams, BerInteger numParams, boolean b) {
40 ERABResponse erabResponse = new ERABResponse();
41
42 for (int i = 0; i < numParams.intValue(); i++) {
43 ERABParamsItem erabParamsItem = erabParams.getERABParamsItem().get(i);
44
45 ERABResponseItem responseItem = new ERABResponseItem();
46 responseItem.setId(erabParamsItem.getId());
47
48 // FIXME: add logic
49 responseItem.setDecision(new ERABDecision(b ? 0 : 1));
50
51 erabResponse.getERABResponseItem().add(responseItem);
52 }
53
54
55 BearerAdmissionResponse bearerAdmissionResponse = new BearerAdmissionResponse();
56 bearerAdmissionResponse.setCrnti(crnti);
57 bearerAdmissionResponse.setEcgi(ecgi);
58 bearerAdmissionResponse.setErabResponse(erabResponse);
59 bearerAdmissionResponse.setNumErabList(numParams);
60
61 XrancPduBody body = new XrancPduBody();
62 body.setBearerAdmissionResponse(bearerAdmissionResponse);
63
64 BerUTF8String ver = null;
65 try {
66 ver = new BerUTF8String("5");
67 } catch (UnsupportedEncodingException e) {
68 e.printStackTrace();
69 }
70 XrancApiID apiID = new XrancApiID(9);
71 XrancPduHdr hdr = new XrancPduHdr();
72 hdr.setVer(ver);
73 hdr.setApiId(apiID);
74
75 XrancPdu pdu = new XrancPdu();
76 pdu.setHdr(hdr);
77 pdu.setBody(body);
78
79 return pdu;
80 }
81
82 public CRNTI getCrnti() {
83 return crnti;
84 }
85
86 public void setCrnti(CRNTI crnti) {
87 this.crnti = crnti;
88 }
89
90 public ECGI getEcgi() {
91 return ecgi;
92 }
93
94 public void setEcgi(ECGI ecgi) {
95 this.ecgi = ecgi;
96 }
97
98 public BerInteger getNumErabList() {
99 return numErabList;
100 }
101
102 public void setNumErabList(BerInteger numErabList) {
103 this.numErabList = numErabList;
104 }
105
106 public ERABResponse getErabResponse() {
107 return erabResponse;
108 }
109
110 public void setErabResponse(ERABResponse erabResponse) {
111 this.erabResponse = erabResponse;
112 }
113
114 public int encode(BerByteArrayOutputStream os) throws IOException {
115 return encode(os, true);
116 }
117
118 public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
119
120 if (code != null) {
121 for (int i = code.length - 1; i >= 0; i--) {
122 os.write(code[i]);
123 }
124 if (withTag) {
125 return tag.encode(os) + code.length;
126 }
127 return code.length;
128 }
129
130 int codeLength = 0;
131 codeLength += erabResponse.encode(os, false);
132 // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
133 os.write(0xA3);
134 codeLength += 1;
135
136 codeLength += numErabList.encode(os, false);
137 // write tag: CONTEXT_CLASS, PRIMITIVE, 2
138 os.write(0x82);
139 codeLength += 1;
140
141 codeLength += ecgi.encode(os, false);
142 // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
143 os.write(0xA1);
144 codeLength += 1;
145
146 codeLength += crnti.encode(os, false);
147 // write tag: CONTEXT_CLASS, PRIMITIVE, 0
148 os.write(0x80);
149 codeLength += 1;
150
151 codeLength += BerLength.encodeLength(os, codeLength);
152
153 if (withTag) {
154 codeLength += tag.encode(os);
155 }
156
157 return codeLength;
158
159 }
160
161 public int decode(InputStream is) throws IOException {
162 return decode(is, true);
163 }
164
165 public int decode(InputStream is, boolean withTag) throws IOException {
166 int codeLength = 0;
167 int subCodeLength = 0;
168 BerTag berTag = new BerTag();
169
170 if (withTag) {
171 codeLength += tag.decodeAndCheck(is);
172 }
173
174 BerLength length = new BerLength();
175 codeLength += length.decode(is);
176
177 int totalLength = length.val;
178 codeLength += totalLength;
179
180 subCodeLength += berTag.decode(is);
181 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
182 crnti = new CRNTI();
183 subCodeLength += crnti.decode(is, false);
184 subCodeLength += berTag.decode(is);
185 } else {
186 throw new IOException("Tag does not match the mandatory sequence element tag.");
187 }
188
189 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
190 ecgi = new ECGI();
191 subCodeLength += ecgi.decode(is, false);
192 subCodeLength += berTag.decode(is);
193 } else {
194 throw new IOException("Tag does not match the mandatory sequence element tag.");
195 }
196
197 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
198 numErabList = new BerInteger();
199 subCodeLength += numErabList.decode(is, false);
200 subCodeLength += berTag.decode(is);
201 } else {
202 throw new IOException("Tag does not match the mandatory sequence element tag.");
203 }
204
205 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
206 erabResponse = new ERABResponse();
207 subCodeLength += erabResponse.decode(is, false);
208 if (subCodeLength == totalLength) {
209 return codeLength;
210 }
211 }
212 throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
213
214
215 }
216
217 public void encodeAndSave(int encodingSizeGuess) throws IOException {
218 BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
219 encode(os, false);
220 code = os.getArray();
221 }
222
223 public String toString() {
224 StringBuilder sb = new StringBuilder();
225 appendAsString(sb, 0);
226 return sb.toString();
227 }
228
229 public void appendAsString(StringBuilder sb, int indentLevel) {
230
231 sb.append("{");
232 sb.append("\n");
233 for (int i = 0; i < indentLevel + 1; i++) {
234 sb.append("\t");
235 }
236 if (crnti != null) {
237 sb.append("crnti: ").append(crnti);
238 } else {
239 sb.append("crnti: <empty-required-field>");
240 }
241
242 sb.append(",\n");
243 for (int i = 0; i < indentLevel + 1; i++) {
244 sb.append("\t");
245 }
246 if (ecgi != null) {
247 sb.append("ecgi: ");
248 ecgi.appendAsString(sb, indentLevel + 1);
249 } else {
250 sb.append("ecgi: <empty-required-field>");
251 }
252
253 sb.append(",\n");
254 for (int i = 0; i < indentLevel + 1; i++) {
255 sb.append("\t");
256 }
257 if (numErabList != null) {
258 sb.append("numErabList: ").append(numErabList);
259 } else {
260 sb.append("numErabList: <empty-required-field>");
261 }
262
263 sb.append(",\n");
264 for (int i = 0; i < indentLevel + 1; i++) {
265 sb.append("\t");
266 }
267 if (erabResponse != null) {
268 sb.append("erabResponse: ");
269 erabResponse.appendAsString(sb, indentLevel + 1);
270 } else {
271 sb.append("erabResponse: <empty-required-field>");
272 }
273
274 sb.append("\n");
275 for (int i = 0; i < indentLevel; i++) {
276 sb.append("\t");
277 }
278 sb.append("}");
279 }
280}
281