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