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 | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 19 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 21 | import com.fasterxml.jackson.annotation.JsonProperty; |
| 22 | import com.fasterxml.jackson.annotation.JsonPropertyOrder; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onosproject.net.HostId; |
| 25 | import org.onosproject.xran.codecs.api.CRNTI; |
| 26 | import org.onosproject.xran.codecs.api.ENBUES1APID; |
| 27 | import org.onosproject.xran.codecs.api.MMEUES1APID; |
| 28 | import org.onosproject.xran.codecs.pdu.RXSigMeasConfig; |
| 29 | import org.onosproject.xran.codecs.pdu.UECapabilityInfo; |
| 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
| 33 | import java.net.URI; |
| 34 | import java.net.URISyntaxException; |
| 35 | import java.util.Timer; |
| 36 | import java.util.stream.Collectors; |
| 37 | import java.util.stream.Stream; |
| 38 | |
| 39 | import static org.onosproject.net.HostId.hostId; |
| 40 | |
| 41 | /** |
| 42 | * Created by dimitris on 7/22/17. |
| 43 | */ |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 44 | @JsonPropertyOrder({ |
| 45 | "IMSI", |
| 46 | "ENBUES1APID", |
| 47 | "MMEUES1APID", |
| 48 | "CRNTI", |
| 49 | "State", |
| 50 | "Capability", |
| 51 | "MeasurementConfiguration" |
| 52 | }) |
| 53 | @JsonIgnoreProperties(ignoreUnknown = true) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 54 | public class RnibUe { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 55 | @JsonIgnore |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 56 | private static final String SCHEME = "xran"; |
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 Logger log = |
| 59 | LoggerFactory.getLogger(RnibUe.class); |
| 60 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 61 | @JsonProperty("IMSI") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 62 | private String imsi; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 63 | @JsonProperty("ENBUES1APID") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 64 | private ENBUES1APID enbS1apId; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 65 | @JsonProperty("MMEUES1APID") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 66 | private MMEUES1APID mmeS1apId; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 67 | @JsonProperty("CRNTI") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 68 | private CRNTI ranId; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 69 | @JsonProperty("State") |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 70 | private State state; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 71 | @JsonProperty("Capability") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 72 | private UECapabilityInfo capability; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 73 | @JsonProperty("MeasurementConfiguration") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 74 | private RXSigMeasConfig measConfig; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 75 | @JsonIgnore |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 76 | private Timer timer; |
| 77 | |
| 78 | public RnibUe() { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 79 | state = State.ACTIVE; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 80 | timer = new Timer(); |
| 81 | } |
| 82 | |
| 83 | public static URI uri(RnibUe ue) { |
| 84 | MMEUES1APID mmeS1apId = ue.getMmeS1apId(); |
| 85 | if (mmeS1apId != null) { |
| 86 | try { |
| 87 | return new URI(SCHEME, mmeS1apId.toString(), null); |
| 88 | } catch (URISyntaxException e) { |
| 89 | return null; |
| 90 | } |
| 91 | } |
| 92 | return null; |
| 93 | } |
| 94 | |
| 95 | public static MMEUES1APID hostIdtoMME(HostId hostId) { |
| 96 | String mac = hostId.mac().toString(); |
| 97 | mac = mac.replace(":", ""); |
| 98 | long l = Long.parseLong(mac, 16); |
| 99 | return new MMEUES1APID(l); |
| 100 | } |
| 101 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 102 | @JsonIgnore |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 103 | public Timer getTimer() { |
| 104 | return timer; |
| 105 | } |
| 106 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 107 | @JsonIgnore |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 108 | public void setTimer(Timer timer) { |
| 109 | this.timer.cancel(); |
| 110 | this.timer.purge(); |
| 111 | this.timer = timer; |
| 112 | } |
| 113 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 114 | @JsonProperty("MMEUES1APID") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 115 | public MMEUES1APID getMmeS1apId() { |
| 116 | return mmeS1apId; |
| 117 | } |
| 118 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 119 | @JsonProperty("MMEUES1APID") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 120 | public void setMmeS1apId(MMEUES1APID mmeS1apId) { |
| 121 | this.mmeS1apId = mmeS1apId; |
| 122 | } |
| 123 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 124 | @JsonProperty("ENBUES1APID") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 125 | public ENBUES1APID getEnbS1apId() { |
| 126 | return enbS1apId; |
| 127 | } |
| 128 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 129 | @JsonProperty("ENBUES1APID") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 130 | public void setEnbS1apId(ENBUES1APID enbS1apId) { |
| 131 | this.enbS1apId = enbS1apId; |
| 132 | } |
| 133 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 134 | @JsonProperty("CRNTI") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 135 | public CRNTI getRanId() { |
| 136 | return ranId; |
| 137 | } |
| 138 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 139 | @JsonProperty("CRNTI") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 140 | public void setRanId(CRNTI ranId) { |
| 141 | this.ranId = ranId; |
| 142 | } |
| 143 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 144 | @JsonProperty("IMSI") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 145 | public String getImsi() { |
| 146 | return imsi; |
| 147 | } |
| 148 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 149 | @JsonProperty("IMSI") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 150 | public void setImsi(String imsi) { |
| 151 | this.imsi = imsi; |
| 152 | } |
| 153 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 154 | @JsonIgnore |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 155 | public HostId getHostId() { |
| 156 | try { |
| 157 | String text = this.mmeS1apId.value.toString(16), |
| 158 | res = ""; |
| 159 | int charsLeft = 12 - text.length(); |
| 160 | if (charsLeft > 0) { |
| 161 | res += Stream.generate(() -> "0").limit(charsLeft).collect(Collectors.joining("")); |
| 162 | } else if (charsLeft < 0) { |
| 163 | return null; |
| 164 | } |
| 165 | res += text; |
| 166 | |
| 167 | String insert = ":"; |
| 168 | int period = 2; |
| 169 | |
| 170 | StringBuilder builder = new StringBuilder( |
| 171 | res.length() + insert.length() * (res.length() / period) + 1); |
| 172 | |
| 173 | int index = 0; |
| 174 | String prefix = ""; |
| 175 | while (index < res.length()) { |
| 176 | // Don't putPrimaryLink the insert in the very first iteration. |
| 177 | // This is easier than appending it *after* each substring |
| 178 | builder.append(prefix); |
| 179 | prefix = insert; |
| 180 | builder.append(res.substring(index, |
| 181 | Math.min(index + period, res.length()))); |
| 182 | index += period; |
| 183 | } |
| 184 | |
| 185 | return hostId(MacAddress.valueOf(builder.toString())); |
| 186 | } catch (Exception e) { |
| 187 | log.warn(e.getMessage()); |
| 188 | e.printStackTrace(); |
| 189 | } |
| 190 | return null; |
| 191 | } |
| 192 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 193 | @JsonProperty("MeasurementConfiguration") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 194 | public RXSigMeasConfig getMeasConfig() { |
| 195 | return measConfig; |
| 196 | } |
| 197 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 198 | @JsonProperty("MeasurementConfiguration") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 199 | public void setMeasConfig(RXSigMeasConfig measConfig) { |
| 200 | this.measConfig = measConfig; |
| 201 | } |
| 202 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 203 | @JsonProperty("Capability") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 204 | public UECapabilityInfo getCapability() { |
| 205 | return capability; |
| 206 | } |
| 207 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 208 | @JsonProperty("Capability") |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 209 | public void setCapability(UECapabilityInfo capability) { |
| 210 | this.capability = capability; |
| 211 | } |
| 212 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 213 | @JsonProperty("State") |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 214 | public State getState() { |
| 215 | return state; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 216 | } |
| 217 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 218 | @JsonProperty("State") |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 219 | public void setState(State state) { |
| 220 | this.state = state; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public String toString() { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 225 | return "RnibUe{" + |
| 226 | "imsi='" + imsi + '\'' + |
| 227 | ", enbS1apId=" + enbS1apId + |
| 228 | ", mmeS1apId=" + mmeS1apId + |
| 229 | ", ranId=" + ranId + |
| 230 | ", state=" + state + |
| 231 | ", capability=" + capability + |
| 232 | ", measConfig=" + measConfig + |
| 233 | ", timer=" + timer + |
| 234 | '}'; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public boolean equals(Object o) { |
| 239 | if (this == o) return true; |
| 240 | if (o == null || getClass() != o.getClass()) return false; |
| 241 | |
| 242 | RnibUe rnibUe = (RnibUe) o; |
| 243 | |
| 244 | return mmeS1apId.equals(rnibUe.mmeS1apId) && ranId.equals(rnibUe.ranId); |
| 245 | } |
| 246 | |
| 247 | @Override |
| 248 | public int hashCode() { |
| 249 | int result = mmeS1apId.hashCode(); |
| 250 | result = 31 * result + ranId.hashCode(); |
| 251 | return result; |
| 252 | } |
| 253 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 254 | public enum State { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 255 | ACTIVE { |
| 256 | @Override |
| 257 | public String toString() { |
| 258 | return "\"ACTIVE\""; |
| 259 | } |
| 260 | }, |
| 261 | IDLE { |
| 262 | @Override |
| 263 | public String toString() { |
| 264 | return "\"IDLE\""; |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | } |