blob: f6a30768c3c9b76a737ed63212b332ecb4e1ebb7 [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
7import org.onosproject.xran.codecs.api.CRNTI;
8import org.onosproject.xran.codecs.api.ECGI;
9import org.openmuc.jasn1.ber.BerByteArrayOutputStream;
10import org.openmuc.jasn1.ber.BerLength;
11import org.openmuc.jasn1.ber.BerTag;
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 HORequest 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 ecgiS = null;
28 private ECGI ecgiT = null;
29
30 public HORequest() {
31 }
32
33 public HORequest(byte[] code) {
34 this.code = code;
35 }
36
37 public void setCrnti(CRNTI crnti) {
38 this.crnti = crnti;
39 }
40
41 public CRNTI getCrnti() {
42 return crnti;
43 }
44
45 public void setEcgiS(ECGI ecgiS) {
46 this.ecgiS = ecgiS;
47 }
48
49 public ECGI getEcgiS() {
50 return ecgiS;
51 }
52
53 public void setEcgiT(ECGI ecgiT) {
54 this.ecgiT = ecgiT;
55 }
56
57 public ECGI getEcgiT() {
58 return ecgiT;
59 }
60
61 public int encode(BerByteArrayOutputStream os) throws IOException {
62 return encode(os, true);
63 }
64
65 public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
66
67 if (code != null) {
68 for (int i = code.length - 1; i >= 0; i--) {
69 os.write(code[i]);
70 }
71 if (withTag) {
72 return tag.encode(os) + code.length;
73 }
74 return code.length;
75 }
76
77 int codeLength = 0;
78 codeLength += ecgiT.encode(os, false);
79 // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
80 os.write(0xA2);
81 codeLength += 1;
82
83 codeLength += ecgiS.encode(os, false);
84 // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
85 os.write(0xA1);
86 codeLength += 1;
87
88 codeLength += crnti.encode(os, false);
89 // write tag: CONTEXT_CLASS, PRIMITIVE, 0
90 os.write(0x80);
91 codeLength += 1;
92
93 codeLength += BerLength.encodeLength(os, codeLength);
94
95 if (withTag) {
96 codeLength += tag.encode(os);
97 }
98
99 return codeLength;
100
101 }
102
103 public int decode(InputStream is) throws IOException {
104 return decode(is, true);
105 }
106
107 public int decode(InputStream is, boolean withTag) throws IOException {
108 int codeLength = 0;
109 int subCodeLength = 0;
110 BerTag berTag = new BerTag();
111
112 if (withTag) {
113 codeLength += tag.decodeAndCheck(is);
114 }
115
116 BerLength length = new BerLength();
117 codeLength += length.decode(is);
118
119 int totalLength = length.val;
120 codeLength += totalLength;
121
122 subCodeLength += berTag.decode(is);
123 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
124 crnti = new CRNTI();
125 subCodeLength += crnti.decode(is, false);
126 subCodeLength += berTag.decode(is);
127 }
128 else {
129 throw new IOException("Tag does not match the mandatory sequence element tag.");
130 }
131
132 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
133 ecgiS = new ECGI();
134 subCodeLength += ecgiS.decode(is, false);
135 subCodeLength += berTag.decode(is);
136 }
137 else {
138 throw new IOException("Tag does not match the mandatory sequence element tag.");
139 }
140
141 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
142 ecgiT = new ECGI();
143 subCodeLength += ecgiT.decode(is, false);
144 if (subCodeLength == totalLength) {
145 return codeLength;
146 }
147 }
148 throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
149
150
151 }
152
153 public void encodeAndSave(int encodingSizeGuess) throws IOException {
154 BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
155 encode(os, false);
156 code = os.getArray();
157 }
158
159 public String toString() {
160 StringBuilder sb = new StringBuilder();
161 appendAsString(sb, 0);
162 return sb.toString();
163 }
164
165 public void appendAsString(StringBuilder sb, int indentLevel) {
166
167 sb.append("{");
168 sb.append("\n");
169 for (int i = 0; i < indentLevel + 1; i++) {
170 sb.append("\t");
171 }
172 if (crnti != null) {
173 sb.append("\"crnti\": ").append(crnti);
174 }
175
176 sb.append(",\n");
177 for (int i = 0; i < indentLevel + 1; i++) {
178 sb.append("\t");
179 }
180 if (ecgiS != null) {
181 sb.append("\"ecgiS\": ");
182 ecgiS.appendAsString(sb, indentLevel + 1);
183 }
184
185 sb.append(",\n");
186 for (int i = 0; i < indentLevel + 1; i++) {
187 sb.append("\t");
188 }
189 if (ecgiT != null) {
190 sb.append("\"ecgiT\": ");
191 ecgiT.appendAsString(sb, indentLevel + 1);
192 }
193
194 sb.append("\n");
195 for (int i = 0; i < indentLevel; i++) {
196 sb.append("\t");
197 }
198 sb.append("}");
199 }
200
slowr8ddc2b12017-08-14 14:13:38 -0700201 public static XrancPdu constructPacket(CRNTI crnti, ECGI ecgis, ECGI ecgit) throws UnsupportedEncodingException {
202 HORequest hoRequest = new HORequest();
203
204 hoRequest.setCrnti(crnti);
205 hoRequest.setEcgiS(ecgis);
206 hoRequest.setEcgiT(ecgit);
207
208 BerUTF8String ver = new BerUTF8String("3");
209
210 XrancApiID apiID = new XrancApiID(12);
211 XrancPduBody body = new XrancPduBody();
212 body.setHORequest(hoRequest);
213
214 XrancPduHdr hdr = new XrancPduHdr();
215 hdr.setVer(ver);
216 hdr.setApiId(apiID);
217
218 XrancPdu pdu = new XrancPdu();
219 pdu.setBody(body);
220 pdu.setHdr(hdr);
221
222 return pdu;
223 }
224
slowr13fa5b02017-08-08 16:32:31 -0700225}
226