slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.xran.samplemessages; |
| 18 | |
| 19 | import org.onosproject.xran.codecs.api.ECGI; |
| 20 | import org.onosproject.xran.codecs.api.EUTRANCellIdentifier; |
| 21 | import org.onosproject.xran.codecs.api.PLMNIdentity; |
| 22 | import org.onosproject.xran.codecs.pdu.*; |
| 23 | import org.openmuc.jasn1.ber.types.string.BerUTF8String; |
| 24 | import org.slf4j.Logger; |
| 25 | import org.slf4j.LoggerFactory; |
| 26 | |
| 27 | import java.io.UnsupportedEncodingException; |
| 28 | |
| 29 | /** |
| 30 | * Created by dimitris on 7/25/17. |
| 31 | */ |
| 32 | public class ConfigEncoderDecoder { |
| 33 | private static final Logger log = |
| 34 | LoggerFactory.getLogger(ConfigEncoderDecoder.class); |
| 35 | |
| 36 | /*public String decode(String s) throws IOException { |
| 37 | byte[] bytearray = DatatypeConverter.parseHexBinary(s); |
| 38 | InputStream inputStream = new ByteArrayInputStream(bytearray); |
| 39 | XrancPdu pdu_decoded = new XrancPdu(); |
| 40 | pdu_decoded.decode(inputStream); |
| 41 | return pdu_decoded.toString(); |
| 42 | }*/ |
| 43 | /* |
| 44 | public String encodeConfigRequest() |
| 45 | throws IOException { |
| 46 | pdu = setPacketProperties(); |
| 47 | pdu.encode(os); |
| 48 | return DatatypeConverter.printHexBinary(os.getArray()); |
| 49 | }*/ |
| 50 | |
| 51 | public static XrancPdu constructPacket(ECGI ecgi) throws UnsupportedEncodingException { |
| 52 | CellConfigRequest cellConfigRequest = new CellConfigRequest(); |
| 53 | cellConfigRequest.setEcgi(ecgi); |
| 54 | |
| 55 | BerUTF8String ver = new BerUTF8String("2a"); |
| 56 | |
| 57 | XrancApiID apiID = new XrancApiID(0); |
| 58 | XrancPduBody body = new XrancPduBody(); |
| 59 | body.setCellConfigRequest(cellConfigRequest); |
| 60 | |
| 61 | XrancPduHdr hdr = new XrancPduHdr(); |
| 62 | hdr.setVer(ver); |
| 63 | hdr.setApiId(apiID); |
| 64 | |
| 65 | XrancPdu pdu = new XrancPdu(); |
| 66 | pdu.setBody(body); |
| 67 | pdu.setHdr(hdr); |
| 68 | |
| 69 | return pdu; |
| 70 | } |
| 71 | |
| 72 | public XrancPdu setPacketProperties() throws UnsupportedEncodingException { |
| 73 | PLMNIdentity plmnIdentity = new PLMNIdentity(new byte[]{(byte) 0x22, (byte) 0x08, (byte) 0x41}); |
| 74 | EUTRANCellIdentifier eutranCellIdentifier = new EUTRANCellIdentifier(new byte[]{ |
| 75 | (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xF0 |
| 76 | }, 28); |
| 77 | |
| 78 | ECGI ecgi = new ECGI(); |
| 79 | |
| 80 | ecgi.setPLMNIdentity(plmnIdentity); |
| 81 | ecgi.setEUTRANcellIdentifier(eutranCellIdentifier); |
| 82 | |
| 83 | CellConfigRequest cellConfigRequest = new CellConfigRequest(); |
| 84 | cellConfigRequest.setEcgi(ecgi); |
| 85 | |
| 86 | BerUTF8String ver = new BerUTF8String("2a"); |
| 87 | |
| 88 | XrancApiID apiID = new XrancApiID(0); |
| 89 | XrancPduBody body = new XrancPduBody(); |
| 90 | body.setCellConfigRequest(cellConfigRequest); |
| 91 | |
| 92 | XrancPduHdr hdr = new XrancPduHdr(); |
| 93 | hdr.setVer(ver); |
| 94 | hdr.setApiId(apiID); |
| 95 | |
| 96 | XrancPdu pdu = new XrancPdu(); |
| 97 | pdu.setBody(body); |
| 98 | pdu.setHdr(hdr); |
| 99 | |
| 100 | return pdu; |
| 101 | } |
| 102 | |
| 103 | } |