slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | package org.onosproject.xran.samplemessages; |
| 2 | |
| 3 | import org.onosproject.xran.codecs.api.*; |
| 4 | import org.onosproject.xran.codecs.pdu.*; |
| 5 | import org.openmuc.jasn1.ber.types.BerInteger; |
| 6 | import org.openmuc.jasn1.ber.types.string.BerUTF8String; |
| 7 | |
| 8 | import java.io.UnsupportedEncodingException; |
| 9 | |
| 10 | public class BearerEncoderDecoder { |
| 11 | |
| 12 | public static XrancPdu constructPacket(ECGI ecgi, CRNTI crnti, ERABParams erabParams, BerInteger numParams) { |
| 13 | ERABResponse erabResponse = new ERABResponse(); |
| 14 | |
| 15 | for (int i = 0; i < numParams.intValue(); i++) { |
| 16 | ERABParamsItem erabParamsItem = erabParams.getERABParamsItem().get(i); |
| 17 | |
| 18 | ERABResponseItem responseItem = new ERABResponseItem(); |
| 19 | responseItem.setId(erabParamsItem.getId()); |
| 20 | |
| 21 | // FIXME: add logic |
| 22 | responseItem.setDecision(new ERABDecision(0)); |
| 23 | |
| 24 | erabResponse.setERABResponse(responseItem); |
| 25 | } |
| 26 | |
| 27 | |
| 28 | BearerAdmissionResponse bearerAdmissionResponse = new BearerAdmissionResponse(); |
| 29 | bearerAdmissionResponse.setCrnti(crnti); |
| 30 | bearerAdmissionResponse.setEcgi(ecgi); |
| 31 | bearerAdmissionResponse.setErabResponse(erabResponse); |
| 32 | bearerAdmissionResponse.setNumErabList(numParams); |
| 33 | |
| 34 | XrancPduBody body = new XrancPduBody(); |
| 35 | body.setBearerAdmissionResponse(bearerAdmissionResponse); |
| 36 | |
| 37 | BerUTF8String ver = null; |
| 38 | try { |
| 39 | ver = new BerUTF8String("2.0"); |
| 40 | } catch (UnsupportedEncodingException e) { |
| 41 | e.printStackTrace(); |
| 42 | } |
| 43 | XrancApiID apiID = new XrancApiID(9); |
| 44 | XrancPduHdr hdr = new XrancPduHdr(); |
| 45 | hdr.setVer(ver); |
| 46 | hdr.setApiId(apiID); |
| 47 | |
| 48 | XrancPdu pdu = new XrancPdu(); |
| 49 | pdu.setHdr(hdr); |
| 50 | pdu.setBody(body); |
| 51 | |
| 52 | return pdu; |
| 53 | } |
| 54 | |
| 55 | public XrancPdu setPacketProperties(XrancPdu mainDecoder) { |
| 56 | CRNTI crnti = mainDecoder.getBody().getBearerAdmissionRequest().getCrnti(); |
| 57 | ECGI ecgi = mainDecoder.getBody().getBearerAdmissionRequest().getEcgi(); |
| 58 | |
| 59 | //TODO: Verify mainDecoder.getBody().getBearerAdmissionRequest().getNumErabs() or |
| 60 | BerInteger numErabs = new BerInteger(5); |
| 61 | |
| 62 | ERABResponseItem responseItem = new ERABResponseItem(); |
| 63 | responseItem.setId(new ERABID(1)); |
| 64 | responseItem.setDecision(new ERABDecision(0)); |
| 65 | |
| 66 | ERABResponseItem responseItem1 = new ERABResponseItem(); |
| 67 | responseItem1.setId(new ERABID(2)); |
| 68 | responseItem1.setDecision(new ERABDecision(0)); |
| 69 | |
| 70 | ERABResponse erabResponse = new ERABResponse(); |
| 71 | erabResponse.setERABResponse(responseItem); |
| 72 | erabResponse.setERABResponse(responseItem1); |
| 73 | |
| 74 | BearerAdmissionResponse bearerAdmissionResponse = new BearerAdmissionResponse(); |
| 75 | bearerAdmissionResponse.setCrnti(crnti); |
| 76 | bearerAdmissionResponse.setEcgi(ecgi); |
| 77 | bearerAdmissionResponse.setErabResponse(erabResponse); |
| 78 | bearerAdmissionResponse.setNumErabList(numErabs); |
| 79 | |
| 80 | XrancPduBody body = new XrancPduBody(); |
| 81 | body.setBearerAdmissionResponse(bearerAdmissionResponse); |
| 82 | |
| 83 | BerUTF8String ver = null; |
| 84 | try { |
| 85 | ver = new BerUTF8String("2.0"); |
| 86 | } catch (UnsupportedEncodingException e) { |
| 87 | e.printStackTrace(); |
| 88 | } |
| 89 | XrancApiID apiID = new XrancApiID(9); |
| 90 | XrancPduHdr hdr = new XrancPduHdr(); |
| 91 | hdr.setVer(ver); |
| 92 | hdr.setApiId(apiID); |
| 93 | |
| 94 | XrancPdu pdu = new XrancPdu(); |
| 95 | pdu.setHdr(hdr); |
| 96 | pdu.setBody(body); |
| 97 | |
| 98 | return pdu; |
| 99 | } |
| 100 | } |