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; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 8 | import org.onosproject.xran.codecs.api.*; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 9 | import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream; |
| 10 | import org.onosproject.xran.codecs.ber.BerLength; |
| 11 | import org.onosproject.xran.codecs.ber.BerTag; |
| 12 | import org.onosproject.xran.codecs.ber.types.BerInteger; |
| 13 | import org.onosproject.xran.codecs.ber.types.string.BerUTF8String; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 14 | |
| 15 | import java.io.IOException; |
| 16 | import java.io.InputStream; |
| 17 | import java.io.Serializable; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 18 | import java.io.UnsupportedEncodingException; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 19 | |
| 20 | public class BearerAdmissionResponse 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 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 26 | @JsonIgnore |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 27 | public byte[] code = null; |
| 28 | private CRNTI crnti = null; |
| 29 | private ECGI ecgi = null; |
| 30 | private BerInteger numErabList = null; |
| 31 | private ERABResponse erabResponse = null; |
| 32 | |
| 33 | public BearerAdmissionResponse() { |
| 34 | } |
| 35 | |
| 36 | public BearerAdmissionResponse(byte[] code) { |
| 37 | this.code = code; |
| 38 | } |
| 39 | |
| 40 | public void setCrnti(CRNTI crnti) { |
| 41 | this.crnti = crnti; |
| 42 | } |
| 43 | |
| 44 | public CRNTI getCrnti() { |
| 45 | return crnti; |
| 46 | } |
| 47 | |
| 48 | public void setEcgi(ECGI ecgi) { |
| 49 | this.ecgi = ecgi; |
| 50 | } |
| 51 | |
| 52 | public ECGI getEcgi() { |
| 53 | return ecgi; |
| 54 | } |
| 55 | |
| 56 | public void setNumErabList(BerInteger numErabList) { |
| 57 | this.numErabList = numErabList; |
| 58 | } |
| 59 | |
| 60 | public BerInteger getNumErabList() { |
| 61 | return numErabList; |
| 62 | } |
| 63 | |
| 64 | public void setErabResponse(ERABResponse erabResponse) { |
| 65 | this.erabResponse = erabResponse; |
| 66 | } |
| 67 | |
| 68 | public ERABResponse getErabResponse() { |
| 69 | return erabResponse; |
| 70 | } |
| 71 | |
| 72 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 73 | return encode(os, true); |
| 74 | } |
| 75 | |
| 76 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 77 | |
| 78 | if (code != null) { |
| 79 | for (int i = code.length - 1; i >= 0; i--) { |
| 80 | os.write(code[i]); |
| 81 | } |
| 82 | if (withTag) { |
| 83 | return tag.encode(os) + code.length; |
| 84 | } |
| 85 | return code.length; |
| 86 | } |
| 87 | |
| 88 | int codeLength = 0; |
| 89 | codeLength += erabResponse.encode(os, false); |
| 90 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 3 |
| 91 | os.write(0xA3); |
| 92 | codeLength += 1; |
| 93 | |
| 94 | codeLength += numErabList.encode(os, false); |
| 95 | // write tag: CONTEXT_CLASS, PRIMITIVE, 2 |
| 96 | os.write(0x82); |
| 97 | codeLength += 1; |
| 98 | |
| 99 | codeLength += ecgi.encode(os, false); |
| 100 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 1 |
| 101 | os.write(0xA1); |
| 102 | codeLength += 1; |
| 103 | |
| 104 | codeLength += crnti.encode(os, false); |
| 105 | // write tag: CONTEXT_CLASS, PRIMITIVE, 0 |
| 106 | os.write(0x80); |
| 107 | codeLength += 1; |
| 108 | |
| 109 | codeLength += BerLength.encodeLength(os, codeLength); |
| 110 | |
| 111 | if (withTag) { |
| 112 | codeLength += tag.encode(os); |
| 113 | } |
| 114 | |
| 115 | return codeLength; |
| 116 | |
| 117 | } |
| 118 | |
| 119 | public int decode(InputStream is) throws IOException { |
| 120 | return decode(is, true); |
| 121 | } |
| 122 | |
| 123 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 124 | int codeLength = 0; |
| 125 | int subCodeLength = 0; |
| 126 | BerTag berTag = new BerTag(); |
| 127 | |
| 128 | if (withTag) { |
| 129 | codeLength += tag.decodeAndCheck(is); |
| 130 | } |
| 131 | |
| 132 | BerLength length = new BerLength(); |
| 133 | codeLength += length.decode(is); |
| 134 | |
| 135 | int totalLength = length.val; |
| 136 | codeLength += totalLength; |
| 137 | |
| 138 | subCodeLength += berTag.decode(is); |
| 139 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { |
| 140 | crnti = new CRNTI(); |
| 141 | subCodeLength += crnti.decode(is, false); |
| 142 | subCodeLength += berTag.decode(is); |
| 143 | } |
| 144 | else { |
| 145 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 146 | } |
| 147 | |
| 148 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { |
| 149 | ecgi = new ECGI(); |
| 150 | subCodeLength += ecgi.decode(is, false); |
| 151 | subCodeLength += berTag.decode(is); |
| 152 | } |
| 153 | else { |
| 154 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 155 | } |
| 156 | |
| 157 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { |
| 158 | numErabList = new BerInteger(); |
| 159 | subCodeLength += numErabList.decode(is, false); |
| 160 | subCodeLength += berTag.decode(is); |
| 161 | } |
| 162 | else { |
| 163 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 164 | } |
| 165 | |
| 166 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) { |
| 167 | erabResponse = new ERABResponse(); |
| 168 | subCodeLength += erabResponse.decode(is, false); |
| 169 | if (subCodeLength == totalLength) { |
| 170 | return codeLength; |
| 171 | } |
| 172 | } |
| 173 | throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); |
| 174 | |
| 175 | |
| 176 | } |
| 177 | |
| 178 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 179 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 180 | encode(os, false); |
| 181 | code = os.getArray(); |
| 182 | } |
| 183 | |
| 184 | public String toString() { |
| 185 | StringBuilder sb = new StringBuilder(); |
| 186 | appendAsString(sb, 0); |
| 187 | return sb.toString(); |
| 188 | } |
| 189 | |
| 190 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 191 | |
| 192 | sb.append("{"); |
| 193 | sb.append("\n"); |
| 194 | for (int i = 0; i < indentLevel + 1; i++) { |
| 195 | sb.append("\t"); |
| 196 | } |
| 197 | if (crnti != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 198 | sb.append("crnti: ").append(crnti); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | sb.append(",\n"); |
| 202 | for (int i = 0; i < indentLevel + 1; i++) { |
| 203 | sb.append("\t"); |
| 204 | } |
| 205 | if (ecgi != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 206 | sb.append("ecgi: "); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 207 | ecgi.appendAsString(sb, indentLevel + 1); |
| 208 | } |
| 209 | |
| 210 | sb.append(",\n"); |
| 211 | for (int i = 0; i < indentLevel + 1; i++) { |
| 212 | sb.append("\t"); |
| 213 | } |
| 214 | if (numErabList != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 215 | sb.append("numErabList: ").append(numErabList); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | sb.append(",\n"); |
| 219 | for (int i = 0; i < indentLevel + 1; i++) { |
| 220 | sb.append("\t"); |
| 221 | } |
| 222 | if (erabResponse != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 223 | sb.append("erabResponse: "); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 224 | erabResponse.appendAsString(sb, indentLevel + 1); |
| 225 | } |
| 226 | |
| 227 | sb.append("\n"); |
| 228 | for (int i = 0; i < indentLevel; i++) { |
| 229 | sb.append("\t"); |
| 230 | } |
| 231 | sb.append("}"); |
| 232 | } |
| 233 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 234 | public static XrancPdu constructPacket(ECGI ecgi, CRNTI crnti, ERABParams erabParams, BerInteger numParams, boolean b) { |
| 235 | ERABResponse erabResponse = new ERABResponse(); |
| 236 | |
| 237 | for (int i = 0; i < numParams.intValue(); i++) { |
| 238 | ERABParamsItem erabParamsItem = erabParams.getERABParamsItem().get(i); |
| 239 | |
| 240 | ERABResponseItem responseItem = new ERABResponseItem(); |
| 241 | responseItem.setId(erabParamsItem.getId()); |
| 242 | |
| 243 | // FIXME: add logic |
| 244 | responseItem.setDecision(new ERABDecision(b ? 0 : 1)); |
| 245 | |
| 246 | erabResponse.setERABResponse(responseItem); |
| 247 | } |
| 248 | |
| 249 | |
| 250 | BearerAdmissionResponse bearerAdmissionResponse = new BearerAdmissionResponse(); |
| 251 | bearerAdmissionResponse.setCrnti(crnti); |
| 252 | bearerAdmissionResponse.setEcgi(ecgi); |
| 253 | bearerAdmissionResponse.setErabResponse(erabResponse); |
| 254 | bearerAdmissionResponse.setNumErabList(numParams); |
| 255 | |
| 256 | XrancPduBody body = new XrancPduBody(); |
| 257 | body.setBearerAdmissionResponse(bearerAdmissionResponse); |
| 258 | |
| 259 | BerUTF8String ver = null; |
| 260 | try { |
| 261 | ver = new BerUTF8String("3"); |
| 262 | } catch (UnsupportedEncodingException e) { |
| 263 | e.printStackTrace(); |
| 264 | } |
| 265 | XrancApiID apiID = new XrancApiID(9); |
| 266 | XrancPduHdr hdr = new XrancPduHdr(); |
| 267 | hdr.setVer(ver); |
| 268 | hdr.setApiId(apiID); |
| 269 | |
| 270 | XrancPdu pdu = new XrancPdu(); |
| 271 | pdu.setHdr(hdr); |
| 272 | pdu.setBody(body); |
| 273 | |
| 274 | return pdu; |
| 275 | } |
| 276 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 277 | } |
| 278 | |