slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /** |
| 2 | * This class file was automatically generated by jASN1 v1.8.0 (http://www.openmuc.org) |
| 3 | */ |
| 4 | |
| 5 | package org.onosproject.xran.codecs.pdu; |
| 6 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 7 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 8 | import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream; |
| 9 | import org.onosproject.xran.codecs.ber.BerLength; |
| 10 | import org.onosproject.xran.codecs.ber.BerTag; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 11 | import org.onosproject.xran.codecs.api.ECGI; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 12 | import org.onosproject.xran.codecs.ber.types.string.BerUTF8String; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 13 | |
| 14 | import java.io.IOException; |
| 15 | import java.io.InputStream; |
| 16 | import java.io.Serializable; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 17 | import java.io.UnsupportedEncodingException; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 18 | |
| 19 | public class CellConfigRequest 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 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 25 | @JsonIgnore |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 26 | public byte[] code = null; |
| 27 | private ECGI ecgi = null; |
| 28 | |
| 29 | public CellConfigRequest() { |
| 30 | } |
| 31 | |
| 32 | public CellConfigRequest(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 int encode(BerByteArrayOutputStream os) throws IOException { |
| 45 | return encode(os, true); |
| 46 | } |
| 47 | |
| 48 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 49 | |
| 50 | if (code != null) { |
| 51 | for (int i = code.length - 1; i >= 0; i--) { |
| 52 | os.write(code[i]); |
| 53 | } |
| 54 | if (withTag) { |
| 55 | return tag.encode(os) + code.length; |
| 56 | } |
| 57 | return code.length; |
| 58 | } |
| 59 | |
| 60 | int codeLength = 0; |
| 61 | codeLength += ecgi.encode(os, false); |
| 62 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 0 |
| 63 | os.write(0xA0); |
| 64 | codeLength += 1; |
| 65 | |
| 66 | codeLength += BerLength.encodeLength(os, codeLength); |
| 67 | |
| 68 | if (withTag) { |
| 69 | codeLength += tag.encode(os); |
| 70 | } |
| 71 | |
| 72 | return codeLength; |
| 73 | |
| 74 | } |
| 75 | |
| 76 | public int decode(InputStream is) throws IOException { |
| 77 | return decode(is, true); |
| 78 | } |
| 79 | |
| 80 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 81 | int codeLength = 0; |
| 82 | int subCodeLength = 0; |
| 83 | BerTag berTag = new BerTag(); |
| 84 | |
| 85 | if (withTag) { |
| 86 | codeLength += tag.decodeAndCheck(is); |
| 87 | } |
| 88 | |
| 89 | BerLength length = new BerLength(); |
| 90 | codeLength += length.decode(is); |
| 91 | |
| 92 | int totalLength = length.val; |
| 93 | codeLength += totalLength; |
| 94 | |
| 95 | subCodeLength += berTag.decode(is); |
| 96 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { |
| 97 | ecgi = new ECGI(); |
| 98 | subCodeLength += ecgi.decode(is, false); |
| 99 | if (subCodeLength == totalLength) { |
| 100 | return codeLength; |
| 101 | } |
| 102 | } |
| 103 | throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); |
| 104 | |
| 105 | |
| 106 | } |
| 107 | |
| 108 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 109 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 110 | encode(os, false); |
| 111 | code = os.getArray(); |
| 112 | } |
| 113 | |
| 114 | public String toString() { |
| 115 | StringBuilder sb = new StringBuilder(); |
| 116 | appendAsString(sb, 0); |
| 117 | return sb.toString(); |
| 118 | } |
| 119 | |
| 120 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 121 | |
| 122 | sb.append("{"); |
| 123 | sb.append("\n"); |
| 124 | for (int i = 0; i < indentLevel + 1; i++) { |
| 125 | sb.append("\t"); |
| 126 | } |
| 127 | if (ecgi != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 128 | sb.append("ecgi: "); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 129 | ecgi.appendAsString(sb, indentLevel + 1); |
| 130 | } |
| 131 | |
| 132 | sb.append("\n"); |
| 133 | for (int i = 0; i < indentLevel; i++) { |
| 134 | sb.append("\t"); |
| 135 | } |
| 136 | sb.append("}"); |
| 137 | } |
| 138 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 139 | public static XrancPdu constructPacket(ECGI ecgi) throws UnsupportedEncodingException { |
| 140 | CellConfigRequest cellConfigRequest = new CellConfigRequest(); |
| 141 | cellConfigRequest.setEcgi(ecgi); |
| 142 | |
| 143 | BerUTF8String ver = new BerUTF8String("3"); |
| 144 | |
| 145 | XrancApiID apiID = new XrancApiID(0); |
| 146 | XrancPduBody body = new XrancPduBody(); |
| 147 | body.setCellConfigRequest(cellConfigRequest); |
| 148 | |
| 149 | XrancPduHdr hdr = new XrancPduHdr(); |
| 150 | hdr.setVer(ver); |
| 151 | hdr.setApiId(apiID); |
| 152 | |
| 153 | XrancPdu pdu = new XrancPdu(); |
| 154 | pdu.setBody(body); |
| 155 | pdu.setHdr(hdr); |
| 156 | |
| 157 | return pdu; |
| 158 | } |
| 159 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 160 | } |
| 161 | |