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