blob: 4e1f958da826873814f98a7c1d28bccc9dd7ae62 [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.ECGI;
slowr60d4d102017-08-16 18:33:58 -07009import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream;
10import org.onosproject.xran.codecs.ber.BerLength;
11import org.onosproject.xran.codecs.ber.BerTag;
12import org.onosproject.xran.codecs.ber.types.BerInteger;
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 L2MeasConfig 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 ECGI ecgi = null;
29 private BerInteger reportIntervalMs = null;
30
31 public L2MeasConfig() {
32 }
33
34 public L2MeasConfig(byte[] code) {
35 this.code = code;
36 }
37
38 public void setEcgi(ECGI ecgi) {
39 this.ecgi = ecgi;
40 }
41
42 public ECGI getEcgi() {
43 return ecgi;
44 }
45
46 public void setReportIntervalMs(BerInteger reportIntervalMs) {
47 this.reportIntervalMs = reportIntervalMs;
48 }
49
50 public BerInteger getReportIntervalMs() {
51 return reportIntervalMs;
52 }
53
54 public int encode(BerByteArrayOutputStream os) throws IOException {
55 return encode(os, true);
56 }
57
58 public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
59
60 if (code != null) {
61 for (int i = code.length - 1; i >= 0; i--) {
62 os.write(code[i]);
63 }
64 if (withTag) {
65 return tag.encode(os) + code.length;
66 }
67 return code.length;
68 }
69
70 int codeLength = 0;
71 codeLength += reportIntervalMs.encode(os, false);
72 // write tag: CONTEXT_CLASS, PRIMITIVE, 1
73 os.write(0x81);
74 codeLength += 1;
75
76 codeLength += ecgi.encode(os, false);
77 // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
78 os.write(0xA0);
79 codeLength += 1;
80
81 codeLength += BerLength.encodeLength(os, codeLength);
82
83 if (withTag) {
84 codeLength += tag.encode(os);
85 }
86
87 return codeLength;
88
89 }
90
91 public int decode(InputStream is) throws IOException {
92 return decode(is, true);
93 }
94
95 public int decode(InputStream is, boolean withTag) throws IOException {
96 int codeLength = 0;
97 int subCodeLength = 0;
98 BerTag berTag = new BerTag();
99
100 if (withTag) {
101 codeLength += tag.decodeAndCheck(is);
102 }
103
104 BerLength length = new BerLength();
105 codeLength += length.decode(is);
106
107 int totalLength = length.val;
108 codeLength += totalLength;
109
110 subCodeLength += berTag.decode(is);
111 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
112 ecgi = new ECGI();
113 subCodeLength += ecgi.decode(is, false);
114 subCodeLength += berTag.decode(is);
115 }
116 else {
117 throw new IOException("Tag does not match the mandatory sequence element tag.");
118 }
119
120 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
121 reportIntervalMs = new BerInteger();
122 subCodeLength += reportIntervalMs.decode(is, false);
123 if (subCodeLength == totalLength) {
124 return codeLength;
125 }
126 }
127 throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
128
129
130 }
131
132 public void encodeAndSave(int encodingSizeGuess) throws IOException {
133 BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
134 encode(os, false);
135 code = os.getArray();
136 }
137
138 public String toString() {
139 StringBuilder sb = new StringBuilder();
140 appendAsString(sb, 0);
141 return sb.toString();
142 }
143
144 public void appendAsString(StringBuilder sb, int indentLevel) {
145
146 sb.append("{");
147 sb.append("\n");
148 for (int i = 0; i < indentLevel + 1; i++) {
149 sb.append("\t");
150 }
151 if (ecgi != null) {
slowr60d4d102017-08-16 18:33:58 -0700152 sb.append("ecgi: ");
slowr13fa5b02017-08-08 16:32:31 -0700153 ecgi.appendAsString(sb, indentLevel + 1);
154 }
155
156 sb.append(",\n");
157 for (int i = 0; i < indentLevel + 1; i++) {
158 sb.append("\t");
159 }
160 if (reportIntervalMs != null) {
slowr60d4d102017-08-16 18:33:58 -0700161 sb.append("reportIntervalMs: ").append(reportIntervalMs);
slowr13fa5b02017-08-08 16:32:31 -0700162 }
163
164 sb.append("\n");
165 for (int i = 0; i < indentLevel; i++) {
166 sb.append("\t");
167 }
168 sb.append("}");
169 }
170
slowr8ddc2b12017-08-14 14:13:38 -0700171 public static XrancPdu constructPacket(ECGI ecgi, int l2MeasInterval) {
172
173 BerInteger reportIntervalMS = new BerInteger(l2MeasInterval);
174 L2MeasConfig measConfig = new L2MeasConfig();
175 measConfig.setEcgi(ecgi);
176 measConfig.setReportIntervalMs(reportIntervalMS);
177
178 BerUTF8String ver = null;
179 try {
180 ver = new BerUTF8String("3");
181 } catch (UnsupportedEncodingException e) {
182 e.printStackTrace();
183 }
184
185 XrancApiID apiID = new XrancApiID(17);
186 XrancPduBody body = new XrancPduBody();
187 body.setL2MeasConfig(measConfig);
188
189 XrancPduHdr hdr = new XrancPduHdr();
190 hdr.setVer(ver);
191 hdr.setApiId(apiID);
192
193 XrancPdu pdu = new XrancPdu();
194 pdu.setBody(body);
195 pdu.setHdr(hdr);
196
197 return pdu;
198
199 }
200
slowr13fa5b02017-08-08 16:32:31 -0700201}
202