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; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 22 | import org.onosproject.xran.codecs.api.PRBUsage; |
| 23 | import org.onosproject.xran.codecs.pdu.CellConfigReport; |
| 24 | import org.onosproject.xran.codecs.pdu.L2MeasConfig; |
| 25 | import org.onosproject.xran.codecs.pdu.RRMConfig; |
| 26 | import org.onosproject.xran.codecs.pdu.SchedMeasReportPerCell; |
| 27 | import org.openmuc.jasn1.ber.BerByteArrayOutputStream; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 28 | import org.openmuc.jasn1.ber.types.BerBitString; |
| 29 | import org.openmuc.jasn1.ber.types.BerInteger; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 30 | |
| 31 | import javax.xml.bind.DatatypeConverter; |
| 32 | import java.io.ByteArrayInputStream; |
| 33 | import java.io.IOException; |
| 34 | import java.io.InputStream; |
| 35 | import java.net.URI; |
| 36 | import java.net.URISyntaxException; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 37 | import java.util.List; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame^] | 38 | import java.util.stream.Collectors; |
| 39 | import java.util.stream.Stream; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Created by dimitris on 7/22/17. |
| 43 | */ |
| 44 | public class RnibCell { |
| 45 | private static final String SCHEME = "xran"; |
| 46 | |
| 47 | private ECGI ecgi; |
| 48 | private CellConfigReport conf; |
| 49 | private PrbUsageContainer prbUsage; |
| 50 | private SchedMeasReportPerCell.QciVals qci; |
| 51 | private RRMConfig rrmConfig; |
| 52 | private L2MeasConfig measConfig; |
| 53 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame^] | 54 | private String version; |
| 55 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 56 | public RnibCell() { |
| 57 | prbUsage = new PrbUsageContainer(); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 58 | setDefaultRRMConf(); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame^] | 59 | version = "3"; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | public static URI uri(ECGI ecgi) { |
| 63 | if (ecgi != null) { |
| 64 | try { |
| 65 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(4096); |
| 66 | ecgi.encode(os); |
| 67 | String message = DatatypeConverter.printHexBinary(os.getArray()); |
| 68 | return new URI(SCHEME, message, null); |
| 69 | } catch (URISyntaxException | IOException e) { |
| 70 | return null; |
| 71 | } |
| 72 | } |
| 73 | return null; |
| 74 | } |
| 75 | |
| 76 | public static ECGI decodeDeviceId(DeviceId deviceId) throws IOException { |
| 77 | String uri = deviceId.toString(); |
| 78 | String hexEcgi = uri.substring(uri.lastIndexOf("xran:") + 5); |
| 79 | |
| 80 | ECGI ecgi = new ECGI(); |
| 81 | byte[] bytearray = DatatypeConverter.parseHexBinary(hexEcgi); |
| 82 | InputStream inputStream = new ByteArrayInputStream(bytearray); |
| 83 | |
| 84 | ecgi.decode(inputStream); |
| 85 | return ecgi; |
| 86 | } |
| 87 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame^] | 88 | public String getVersion() { |
| 89 | return version; |
| 90 | } |
| 91 | |
| 92 | public void setVersion(String version) { |
| 93 | this.version = version; |
| 94 | } |
| 95 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 96 | public RRMConfig getRrmConfig() { |
| 97 | return rrmConfig; |
| 98 | } |
| 99 | |
| 100 | public void setRrmConfig(RRMConfig rrmConfig) { |
| 101 | this.rrmConfig = rrmConfig; |
| 102 | } |
| 103 | |
| 104 | public PrbUsageContainer getPrbUsage() { |
| 105 | return prbUsage; |
| 106 | } |
| 107 | |
| 108 | public void setPrbUsage(PrbUsageContainer prbUsage) { |
| 109 | this.prbUsage = prbUsage; |
| 110 | } |
| 111 | |
| 112 | private void setDefaultRRMConf() { |
| 113 | rrmConfig = new RRMConfig(); |
| 114 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 115 | rrmConfig.setEcgi(ecgi); |
| 116 | |
| 117 | RRMConfig.StartPrbDl startPrbDl = new RRMConfig.StartPrbDl(); |
| 118 | startPrbDl.addBerInteger(new BerInteger(0)); |
| 119 | startPrbDl.addBerInteger(new BerInteger(50)); |
| 120 | |
| 121 | rrmConfig.setStartPrbDl(startPrbDl); |
| 122 | |
| 123 | RRMConfig.StartPrbUl startPrbUl = new RRMConfig.StartPrbUl(); |
| 124 | startPrbUl.addBerInteger(new BerInteger(50)); |
| 125 | startPrbUl.addBerInteger(new BerInteger(100)); |
| 126 | |
| 127 | rrmConfig.setStartPrbUl(startPrbUl); |
| 128 | |
| 129 | RRMConfig.EndPrbDl endPrbDl = new RRMConfig.EndPrbDl(); |
| 130 | endPrbDl.addBerInteger(new BerInteger(50)); |
| 131 | endPrbDl.addBerInteger(new BerInteger(100)); |
| 132 | |
| 133 | rrmConfig.setEndPrbDl(endPrbDl); |
| 134 | |
| 135 | RRMConfig.EndPrbUl endPrbUl = new RRMConfig.EndPrbUl(); |
| 136 | endPrbUl.addBerInteger(new BerInteger(50)); |
| 137 | endPrbUl.addBerInteger(new BerInteger(100)); |
| 138 | |
| 139 | rrmConfig.setEndPrbUl(endPrbUl); |
| 140 | |
| 141 | RRMConfig.SubframeBitmaskDl subframeBitmaskDl = new RRMConfig.SubframeBitmaskDl(); |
| 142 | BerBitString berBitString = new BerBitString(new byte[]{(byte) 0xAA, (byte) 0x80}, 10); |
| 143 | BerBitString berBitString1 = new BerBitString(new byte[]{(byte) 0x55, (byte) 0x40}, 10); |
| 144 | |
| 145 | subframeBitmaskDl.addBerBitString(berBitString); |
| 146 | subframeBitmaskDl.addBerBitString(berBitString1); |
| 147 | |
| 148 | rrmConfig.setSubframeBitmaskDl(subframeBitmaskDl); |
| 149 | } |
| 150 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 151 | public ECGI getEcgi() { |
| 152 | return ecgi; |
| 153 | } |
| 154 | |
| 155 | public void setEcgi(ECGI ecgi) { |
| 156 | this.ecgi = ecgi; |
| 157 | } |
| 158 | |
| 159 | public CellConfigReport getConf() { |
| 160 | return conf; |
| 161 | } |
| 162 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 163 | /*public RRMConfig getRrmConfig() { |
| 164 | return rrmConfig; |
| 165 | }*/ |
| 166 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 167 | public void setConf(CellConfigReport conf) { |
| 168 | this.conf = conf; |
| 169 | } |
| 170 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 171 | public void modifyRrmConfig(JsonNode rrmConfigNode, List<RnibUe> ueList) { |
| 172 | RRMConfig.Crnti crnti = new RRMConfig.Crnti(); |
| 173 | ueList.forEach(ue -> crnti.addCRNTI(ue.getRanId())); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 174 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame^] | 175 | { |
| 176 | JsonNode start_prb_dl = rrmConfigNode.get("start_prb_dl"); |
| 177 | if (start_prb_dl != null) { |
| 178 | RRMConfig.StartPrbDl startPrbDl = new RRMConfig.StartPrbDl(); |
| 179 | if (start_prb_dl.isArray()) { |
| 180 | if (rrmConfig.getStartPrbDl().getSeqOf().size() == start_prb_dl.size()) { |
| 181 | List<BerInteger> collect = Stream.of(start_prb_dl) |
| 182 | .map(val -> new BerInteger(val.asInt())) |
| 183 | .collect(Collectors.toList()); |
| 184 | startPrbDl.setSeqOf(collect); |
| 185 | } |
| 186 | } |
| 187 | rrmConfig.setStartPrbDl(startPrbDl); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 190 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame^] | 191 | { |
| 192 | JsonNode end_prb_dl = rrmConfigNode.get("end_prb_dl"); |
| 193 | if (end_prb_dl != null) { |
| 194 | RRMConfig.EndPrbDl endPrbDl = new RRMConfig.EndPrbDl(); |
| 195 | if (end_prb_dl.isArray()) { |
| 196 | if (rrmConfig.getEndPrbDl().getSeqOf().size() == end_prb_dl.size()) { |
| 197 | List<BerInteger> collect = Stream.of(end_prb_dl) |
| 198 | .map(val -> new BerInteger(val.asInt())) |
| 199 | .collect(Collectors.toList()); |
| 200 | endPrbDl.setSeqOf(collect); |
| 201 | } |
| 202 | } |
| 203 | rrmConfig.setEndPrbDl(endPrbDl); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | { |
| 208 | JsonNode start_prb_ul = rrmConfigNode.get("start_prb_ul"); |
| 209 | if (start_prb_ul != null) { |
| 210 | RRMConfig.StartPrbUl startPrbUl = new RRMConfig.StartPrbUl(); |
| 211 | if (start_prb_ul.isArray()) { |
| 212 | if (rrmConfig.getStartPrbUl().getSeqOf().size() == start_prb_ul.size()) { |
| 213 | List<BerInteger> collect = Stream.of(start_prb_ul) |
| 214 | .map(val -> new BerInteger(val.asInt())) |
| 215 | .collect(Collectors.toList()); |
| 216 | startPrbUl.setSeqOf(collect); |
| 217 | } |
| 218 | } |
| 219 | rrmConfig.setStartPrbUl(startPrbUl); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | { |
| 224 | JsonNode end_prb_ul = rrmConfigNode.get("end_prb_ul"); |
| 225 | if (end_prb_ul != null) { |
| 226 | RRMConfig.EndPrbUl endPrbUl = new RRMConfig.EndPrbUl(); |
| 227 | if (end_prb_ul.isArray()) { |
| 228 | if (rrmConfig.getEndPrbUl().getSeqOf().size() == end_prb_ul.size()) { |
| 229 | List<BerInteger> collect = Stream.of(end_prb_ul) |
| 230 | .map(val -> new BerInteger(val.asInt())) |
| 231 | .collect(Collectors.toList()); |
| 232 | endPrbUl.setSeqOf(collect); |
| 233 | } |
| 234 | } |
| 235 | rrmConfig.setEndPrbUl(endPrbUl); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | rrmConfig.setCrnti(crnti); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 240 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 241 | // TODO |
| 242 | } |
| 243 | |
| 244 | public SchedMeasReportPerCell.QciVals getQci() { |
| 245 | return qci; |
| 246 | } |
| 247 | |
| 248 | public void setQci(SchedMeasReportPerCell.QciVals qci) { |
| 249 | this.qci = qci; |
| 250 | } |
| 251 | |
| 252 | public void setPrimaryPrbUsage(PRBUsage primary) { |
| 253 | this.prbUsage.primary = primary; |
| 254 | } |
| 255 | |
| 256 | public void setSecondaryPrbUsage(PRBUsage secondary) { |
| 257 | this.prbUsage.secondary = secondary; |
| 258 | } |
| 259 | |
| 260 | public L2MeasConfig getMeasConfig() { |
| 261 | return measConfig; |
| 262 | } |
| 263 | |
| 264 | public void setMeasConfig(L2MeasConfig measConfig) { |
| 265 | this.measConfig = measConfig; |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public String toString() { |
| 270 | StringBuilder sb = new StringBuilder(); |
| 271 | sb.append("{\n") |
| 272 | .append(ecgi != null ? "\"ecgi\":" + ecgi : "") |
| 273 | .append(conf != null ? ",\n\"config-report\":" + conf : "") |
| 274 | .append(prbUsage != null ? ",\n\"prb-usage\":" + prbUsage : "") |
| 275 | .append(qci != null ? ",\n\"qci-vals\":" + qci : "") |
| 276 | .append(rrmConfig != null ? ",\n\"rrm-config\":" + rrmConfig : "") |
| 277 | .append(measConfig != null ? ",\n\"l2-meas-config\":" + measConfig : "") |
| 278 | .append("\n}\n"); |
| 279 | return sb.toString(); |
| 280 | } |
| 281 | |
| 282 | @Override |
| 283 | public boolean equals(Object o) { |
| 284 | if (this == o) return true; |
| 285 | if (o == null || getClass() != o.getClass()) return false; |
| 286 | |
| 287 | RnibCell rnibCell = (RnibCell) o; |
| 288 | |
| 289 | return ecgi.equals(rnibCell.ecgi); |
| 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public int hashCode() { |
| 294 | return ecgi.hashCode(); |
| 295 | } |
| 296 | |
| 297 | class PrbUsageContainer { |
| 298 | PRBUsage primary; |
| 299 | PRBUsage secondary; |
| 300 | |
| 301 | @Override |
| 302 | public String toString() { |
| 303 | StringBuilder sb = new StringBuilder(); |
| 304 | sb.append("{\n") |
| 305 | .append(primary != null ? "\"primary\":" + primary : "") |
| 306 | .append(secondary != null ? ",\n\"secondary\":" + secondary : "") |
| 307 | .append("\n}\n"); |
| 308 | return sb.toString(); |
| 309 | } |
| 310 | } |
| 311 | } |