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