blob: d2a8b69e393286719548b10e2aa375e4ab7f8207 [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.openmuc.jasn1.ber.BerByteArrayOutputStream;
8import org.openmuc.jasn1.ber.BerLength;
9import org.openmuc.jasn1.ber.BerTag;
10import org.onosproject.xran.codecs.api.ECGI;
slowr8ddc2b12017-08-14 14:13:38 -070011import org.openmuc.jasn1.ber.types.string.BerUTF8String;
slowr13fa5b02017-08-08 16:32:31 -070012
13import java.io.IOException;
14import java.io.InputStream;
15import java.io.Serializable;
slowr8ddc2b12017-08-14 14:13:38 -070016import java.io.UnsupportedEncodingException;
slowr13fa5b02017-08-08 16:32:31 -070017
18public class CellConfigRequest implements Serializable {
19
20 private static final long serialVersionUID = 1L;
21
22 public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
23
24 public byte[] code = null;
25 private ECGI ecgi = null;
26
27 public CellConfigRequest() {
28 }
29
30 public CellConfigRequest(byte[] code) {
31 this.code = code;
32 }
33
34 public void setEcgi(ECGI ecgi) {
35 this.ecgi = ecgi;
36 }
37
38 public ECGI getEcgi() {
39 return ecgi;
40 }
41
42 public int encode(BerByteArrayOutputStream os) throws IOException {
43 return encode(os, true);
44 }
45
46 public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
47
48 if (code != null) {
49 for (int i = code.length - 1; i >= 0; i--) {
50 os.write(code[i]);
51 }
52 if (withTag) {
53 return tag.encode(os) + code.length;
54 }
55 return code.length;
56 }
57
58 int codeLength = 0;
59 codeLength += ecgi.encode(os, false);
60 // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
61 os.write(0xA0);
62 codeLength += 1;
63
64 codeLength += BerLength.encodeLength(os, codeLength);
65
66 if (withTag) {
67 codeLength += tag.encode(os);
68 }
69
70 return codeLength;
71
72 }
73
74 public int decode(InputStream is) throws IOException {
75 return decode(is, true);
76 }
77
78 public int decode(InputStream is, boolean withTag) throws IOException {
79 int codeLength = 0;
80 int subCodeLength = 0;
81 BerTag berTag = new BerTag();
82
83 if (withTag) {
84 codeLength += tag.decodeAndCheck(is);
85 }
86
87 BerLength length = new BerLength();
88 codeLength += length.decode(is);
89
90 int totalLength = length.val;
91 codeLength += totalLength;
92
93 subCodeLength += berTag.decode(is);
94 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
95 ecgi = new ECGI();
96 subCodeLength += ecgi.decode(is, false);
97 if (subCodeLength == totalLength) {
98 return codeLength;
99 }
100 }
101 throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
102
103
104 }
105
106 public void encodeAndSave(int encodingSizeGuess) throws IOException {
107 BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
108 encode(os, false);
109 code = os.getArray();
110 }
111
112 public String toString() {
113 StringBuilder sb = new StringBuilder();
114 appendAsString(sb, 0);
115 return sb.toString();
116 }
117
118 public void appendAsString(StringBuilder sb, int indentLevel) {
119
120 sb.append("{");
121 sb.append("\n");
122 for (int i = 0; i < indentLevel + 1; i++) {
123 sb.append("\t");
124 }
125 if (ecgi != null) {
126 sb.append("\"ecgi\": ");
127 ecgi.appendAsString(sb, indentLevel + 1);
128 }
129
130 sb.append("\n");
131 for (int i = 0; i < indentLevel; i++) {
132 sb.append("\t");
133 }
134 sb.append("}");
135 }
136
slowr8ddc2b12017-08-14 14:13:38 -0700137 public static XrancPdu constructPacket(ECGI ecgi) throws UnsupportedEncodingException {
138 CellConfigRequest cellConfigRequest = new CellConfigRequest();
139 cellConfigRequest.setEcgi(ecgi);
140
141 BerUTF8String ver = new BerUTF8String("3");
142
143 XrancApiID apiID = new XrancApiID(0);
144 XrancPduBody body = new XrancPduBody();
145 body.setCellConfigRequest(cellConfigRequest);
146
147 XrancPduHdr hdr = new XrancPduHdr();
148 hdr.setVer(ver);
149 hdr.setApiId(apiID);
150
151 XrancPdu pdu = new XrancPdu();
152 pdu.setBody(body);
153 pdu.setHdr(hdr);
154
155 return pdu;
156 }
157
slowr13fa5b02017-08-08 16:32:31 -0700158}
159