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.entities; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.xran.codecs.api.ECGI; |
| 22 | import org.onosproject.xran.codecs.api.MMEUES1APID; |
| 23 | import org.onosproject.xran.codecs.api.PRBUsage; |
| 24 | import org.onosproject.xran.codecs.pdu.CellConfigReport; |
| 25 | import org.onosproject.xran.codecs.pdu.L2MeasConfig; |
| 26 | import org.onosproject.xran.codecs.pdu.RRMConfig; |
| 27 | import org.onosproject.xran.codecs.pdu.SchedMeasReportPerCell; |
| 28 | import org.openmuc.jasn1.ber.BerByteArrayOutputStream; |
| 29 | |
| 30 | import javax.xml.bind.DatatypeConverter; |
| 31 | import java.io.ByteArrayInputStream; |
| 32 | import java.io.IOException; |
| 33 | import java.io.InputStream; |
| 34 | import java.net.URI; |
| 35 | import java.net.URISyntaxException; |
| 36 | |
| 37 | /** |
| 38 | * Created by dimitris on 7/22/17. |
| 39 | */ |
| 40 | public class RnibCell { |
| 41 | private static final String SCHEME = "xran"; |
| 42 | |
| 43 | private ECGI ecgi; |
| 44 | private CellConfigReport conf; |
| 45 | private PrbUsageContainer prbUsage; |
| 46 | private SchedMeasReportPerCell.QciVals qci; |
| 47 | private RRMConfig rrmConfig; |
| 48 | private L2MeasConfig measConfig; |
| 49 | |
| 50 | public RnibCell() { |
| 51 | prbUsage = new PrbUsageContainer(); |
| 52 | } |
| 53 | |
| 54 | public static URI uri(ECGI ecgi) { |
| 55 | if (ecgi != null) { |
| 56 | try { |
| 57 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(4096); |
| 58 | ecgi.encode(os); |
| 59 | String message = DatatypeConverter.printHexBinary(os.getArray()); |
| 60 | return new URI(SCHEME, message, null); |
| 61 | } catch (URISyntaxException | IOException e) { |
| 62 | return null; |
| 63 | } |
| 64 | } |
| 65 | return null; |
| 66 | } |
| 67 | |
| 68 | public static ECGI decodeDeviceId(DeviceId deviceId) throws IOException { |
| 69 | String uri = deviceId.toString(); |
| 70 | String hexEcgi = uri.substring(uri.lastIndexOf("xran:") + 5); |
| 71 | |
| 72 | ECGI ecgi = new ECGI(); |
| 73 | byte[] bytearray = DatatypeConverter.parseHexBinary(hexEcgi); |
| 74 | InputStream inputStream = new ByteArrayInputStream(bytearray); |
| 75 | |
| 76 | ecgi.decode(inputStream); |
| 77 | return ecgi; |
| 78 | } |
| 79 | |
| 80 | public ECGI getEcgi() { |
| 81 | return ecgi; |
| 82 | } |
| 83 | |
| 84 | public void setEcgi(ECGI ecgi) { |
| 85 | this.ecgi = ecgi; |
| 86 | } |
| 87 | |
| 88 | public CellConfigReport getConf() { |
| 89 | return conf; |
| 90 | } |
| 91 | |
| 92 | public void setConf(CellConfigReport conf) { |
| 93 | this.conf = conf; |
| 94 | } |
| 95 | |
| 96 | public RRMConfig getRrmConfig() { |
| 97 | return rrmConfig; |
| 98 | } |
| 99 | |
| 100 | public void modifyRrmConfig(JsonNode rrmConfig) { |
| 101 | // TODO |
| 102 | } |
| 103 | |
| 104 | public SchedMeasReportPerCell.QciVals getQci() { |
| 105 | return qci; |
| 106 | } |
| 107 | |
| 108 | public void setQci(SchedMeasReportPerCell.QciVals qci) { |
| 109 | this.qci = qci; |
| 110 | } |
| 111 | |
| 112 | public void setPrimaryPrbUsage(PRBUsage primary) { |
| 113 | this.prbUsage.primary = primary; |
| 114 | } |
| 115 | |
| 116 | public void setSecondaryPrbUsage(PRBUsage secondary) { |
| 117 | this.prbUsage.secondary = secondary; |
| 118 | } |
| 119 | |
| 120 | public L2MeasConfig getMeasConfig() { |
| 121 | return measConfig; |
| 122 | } |
| 123 | |
| 124 | public void setMeasConfig(L2MeasConfig measConfig) { |
| 125 | this.measConfig = measConfig; |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public String toString() { |
| 130 | StringBuilder sb = new StringBuilder(); |
| 131 | sb.append("{\n") |
| 132 | .append(ecgi != null ? "\"ecgi\":" + ecgi : "") |
| 133 | .append(conf != null ? ",\n\"config-report\":" + conf : "") |
| 134 | .append(prbUsage != null ? ",\n\"prb-usage\":" + prbUsage : "") |
| 135 | .append(qci != null ? ",\n\"qci-vals\":" + qci : "") |
| 136 | .append(rrmConfig != null ? ",\n\"rrm-config\":" + rrmConfig : "") |
| 137 | .append(measConfig != null ? ",\n\"l2-meas-config\":" + measConfig : "") |
| 138 | .append("\n}\n"); |
| 139 | return sb.toString(); |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public boolean equals(Object o) { |
| 144 | if (this == o) return true; |
| 145 | if (o == null || getClass() != o.getClass()) return false; |
| 146 | |
| 147 | RnibCell rnibCell = (RnibCell) o; |
| 148 | |
| 149 | return ecgi.equals(rnibCell.ecgi); |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public int hashCode() { |
| 154 | return ecgi.hashCode(); |
| 155 | } |
| 156 | |
| 157 | class PrbUsageContainer { |
| 158 | PRBUsage primary; |
| 159 | PRBUsage secondary; |
| 160 | |
| 161 | @Override |
| 162 | public String toString() { |
| 163 | StringBuilder sb = new StringBuilder(); |
| 164 | sb.append("{\n") |
| 165 | .append(primary != null ? "\"primary\":" + primary : "") |
| 166 | .append(secondary != null ? ",\n\"secondary\":" + secondary : "") |
| 167 | .append("\n}\n"); |
| 168 | return sb.toString(); |
| 169 | } |
| 170 | } |
| 171 | } |