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