blob: 2d6b605f43c84ab870b8e107190f47bca856a611 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
slowr577f3222017-08-28 10:49:08 -07002 * Copyright 2015-present Open Networking Foundation
slowr13fa5b02017-08-08 16:32:31 -07003 *
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
17package org.onosproject.xran.entities;
18
slowr60d4d102017-08-16 18:33:58 -070019import com.fasterxml.jackson.annotation.JsonIgnore;
20import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
21import com.fasterxml.jackson.annotation.JsonProperty;
22import com.fasterxml.jackson.annotation.JsonPropertyOrder;
slowr13fa5b02017-08-08 16:32:31 -070023import org.onlab.packet.MacAddress;
24import org.onosproject.net.HostId;
25import org.onosproject.xran.codecs.api.CRNTI;
26import org.onosproject.xran.codecs.api.ENBUES1APID;
27import org.onosproject.xran.codecs.api.MMEUES1APID;
28import org.onosproject.xran.codecs.pdu.RXSigMeasConfig;
29import org.onosproject.xran.codecs.pdu.UECapabilityInfo;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
slowrc86750e2017-08-22 17:26:47 -070033import java.util.Objects;
slowr13fa5b02017-08-08 16:32:31 -070034import java.util.Timer;
35import java.util.stream.Collectors;
36import java.util.stream.Stream;
37
38import static org.onosproject.net.HostId.hostId;
39
40/**
slowr577f3222017-08-28 10:49:08 -070041 * R-NIB UE and its properties.
slowr13fa5b02017-08-08 16:32:31 -070042 */
slowr60d4d102017-08-16 18:33:58 -070043@JsonPropertyOrder({
slowrc86750e2017-08-22 17:26:47 -070044 "ID",
slowr60d4d102017-08-16 18:33:58 -070045 "IMSI",
46 "ENBUES1APID",
47 "MMEUES1APID",
48 "CRNTI",
49 "State",
50 "Capability",
51 "MeasurementConfiguration"
52})
53@JsonIgnoreProperties(ignoreUnknown = true)
slowr13fa5b02017-08-08 16:32:31 -070054public class RnibUe {
slowr60d4d102017-08-16 18:33:58 -070055 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -070056 private static final String SCHEME = "xran";
slowr60d4d102017-08-16 18:33:58 -070057 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -070058 private static final Logger log =
59 LoggerFactory.getLogger(RnibUe.class);
60
slowrc86750e2017-08-22 17:26:47 -070061 @JsonProperty("ID")
62 private Long id;
slowr60d4d102017-08-16 18:33:58 -070063 @JsonProperty("IMSI")
slowr13fa5b02017-08-08 16:32:31 -070064 private String imsi;
slowr60d4d102017-08-16 18:33:58 -070065 @JsonProperty("ENBUES1APID")
slowr13fa5b02017-08-08 16:32:31 -070066 private ENBUES1APID enbS1apId;
slowr60d4d102017-08-16 18:33:58 -070067 @JsonProperty("MMEUES1APID")
slowr13fa5b02017-08-08 16:32:31 -070068 private MMEUES1APID mmeS1apId;
slowr60d4d102017-08-16 18:33:58 -070069 @JsonProperty("CRNTI")
slowrc86750e2017-08-22 17:26:47 -070070 private CRNTI crnti;
slowr60d4d102017-08-16 18:33:58 -070071 @JsonProperty("State")
slowr67d05e42017-08-11 20:37:22 -070072 private State state;
slowr60d4d102017-08-16 18:33:58 -070073 @JsonProperty("Capability")
slowr13fa5b02017-08-08 16:32:31 -070074 private UECapabilityInfo capability;
slowr60d4d102017-08-16 18:33:58 -070075 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -070076 private RXSigMeasConfig measConfig;
slowr60d4d102017-08-16 18:33:58 -070077 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -070078 private Timer timer;
79
80 public RnibUe() {
slowr67d05e42017-08-11 20:37:22 -070081 state = State.ACTIVE;
slowr13fa5b02017-08-08 16:32:31 -070082 timer = new Timer();
83 }
84
slowr577f3222017-08-28 10:49:08 -070085 /**
86 * Convert Host ID to UE ID.
87 * @param hostId hostID
88 * @return Long UE ID
89 */
slowrc86750e2017-08-22 17:26:47 -070090 public static Long hostIdtoUEId(HostId hostId) {
slowr13fa5b02017-08-08 16:32:31 -070091 String mac = hostId.mac().toString();
92 mac = mac.replace(":", "");
93 long l = Long.parseLong(mac, 16);
slowrc86750e2017-08-22 17:26:47 -070094 return l;
slowr13fa5b02017-08-08 16:32:31 -070095 }
96
slowr577f3222017-08-28 10:49:08 -070097 /**
98 * Get timer.
99 * @return Timer
100 */
slowr60d4d102017-08-16 18:33:58 -0700101 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -0700102 public Timer getTimer() {
103 return timer;
104 }
105
slowr577f3222017-08-28 10:49:08 -0700106 /**
107 * Set timer.
108 * @param timer Timer
109 */
slowr60d4d102017-08-16 18:33:58 -0700110 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -0700111 public void setTimer(Timer timer) {
112 this.timer.cancel();
113 this.timer.purge();
114 this.timer = timer;
115 }
116
slowr577f3222017-08-28 10:49:08 -0700117 /**
118 * Get MMEUES1APID.
119 * @return MMEUES1APID
120 */
slowr60d4d102017-08-16 18:33:58 -0700121 @JsonProperty("MMEUES1APID")
slowr13fa5b02017-08-08 16:32:31 -0700122 public MMEUES1APID getMmeS1apId() {
123 return mmeS1apId;
124 }
125
slowr577f3222017-08-28 10:49:08 -0700126 /**
127 * Set MMEUES1APID.
128 * @param mmeS1apId MMEUES1APID
129 */
slowr60d4d102017-08-16 18:33:58 -0700130 @JsonProperty("MMEUES1APID")
slowr13fa5b02017-08-08 16:32:31 -0700131 public void setMmeS1apId(MMEUES1APID mmeS1apId) {
132 this.mmeS1apId = mmeS1apId;
133 }
134
slowr577f3222017-08-28 10:49:08 -0700135 /**
136 * Get ENBUES1APID.
137 * @return ENBUES1APID
138 */
slowr60d4d102017-08-16 18:33:58 -0700139 @JsonProperty("ENBUES1APID")
slowr13fa5b02017-08-08 16:32:31 -0700140 public ENBUES1APID getEnbS1apId() {
141 return enbS1apId;
142 }
143
slowr577f3222017-08-28 10:49:08 -0700144 /**
145 * Set ENBUES1APID.
146 * @param enbS1apId ENBUES1APID
147 */
slowr60d4d102017-08-16 18:33:58 -0700148 @JsonProperty("ENBUES1APID")
slowr13fa5b02017-08-08 16:32:31 -0700149 public void setEnbS1apId(ENBUES1APID enbS1apId) {
150 this.enbS1apId = enbS1apId;
151 }
152
slowr577f3222017-08-28 10:49:08 -0700153 /**
154 * Get CRNTI.
155 * @return CRNTI
156 */
slowr60d4d102017-08-16 18:33:58 -0700157 @JsonProperty("CRNTI")
slowrc86750e2017-08-22 17:26:47 -0700158 public CRNTI getCrnti() {
159 return crnti;
slowr13fa5b02017-08-08 16:32:31 -0700160 }
161
slowr577f3222017-08-28 10:49:08 -0700162 /**
163 * Set CRNTI.
164 * @param crnti CRNTI
165 */
slowr60d4d102017-08-16 18:33:58 -0700166 @JsonProperty("CRNTI")
slowrc86750e2017-08-22 17:26:47 -0700167 public void setCrnti(CRNTI crnti) {
168 this.crnti = crnti;
slowr13fa5b02017-08-08 16:32:31 -0700169 }
170
slowr577f3222017-08-28 10:49:08 -0700171 /**
172 * Get IMSI.
173 * @return IMSI
174 */
slowr60d4d102017-08-16 18:33:58 -0700175 @JsonProperty("IMSI")
slowr13fa5b02017-08-08 16:32:31 -0700176 public String getImsi() {
177 return imsi;
178 }
179
slowr577f3222017-08-28 10:49:08 -0700180 /**
181 * Set IMSI.
182 * @param imsi IMSI
183 */
slowr60d4d102017-08-16 18:33:58 -0700184 @JsonProperty("IMSI")
slowr13fa5b02017-08-08 16:32:31 -0700185 public void setImsi(String imsi) {
186 this.imsi = imsi;
187 }
188
slowr577f3222017-08-28 10:49:08 -0700189 /**
190 * Get Host ID.
191 * @return HostId
192 */
slowr60d4d102017-08-16 18:33:58 -0700193 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -0700194 public HostId getHostId() {
195 try {
slowrc86750e2017-08-22 17:26:47 -0700196 String text = Long.toHexString(this.id),
slowr13fa5b02017-08-08 16:32:31 -0700197 res = "";
198 int charsLeft = 12 - text.length();
199 if (charsLeft > 0) {
200 res += Stream.generate(() -> "0").limit(charsLeft).collect(Collectors.joining(""));
201 } else if (charsLeft < 0) {
202 return null;
203 }
204 res += text;
205
206 String insert = ":";
207 int period = 2;
208
209 StringBuilder builder = new StringBuilder(
210 res.length() + insert.length() * (res.length() / period) + 1);
211
212 int index = 0;
213 String prefix = "";
214 while (index < res.length()) {
215 // Don't putPrimaryLink the insert in the very first iteration.
216 // This is easier than appending it *after* each substring
217 builder.append(prefix);
218 prefix = insert;
219 builder.append(res.substring(index,
220 Math.min(index + period, res.length())));
221 index += period;
222 }
223
224 return hostId(MacAddress.valueOf(builder.toString()));
225 } catch (Exception e) {
226 log.warn(e.getMessage());
227 e.printStackTrace();
228 }
229 return null;
230 }
231
slowr577f3222017-08-28 10:49:08 -0700232 /**
233 * Get RXMeasConfig Report.
234 * @return RXSigMeasConfig
235 */
slowr60d4d102017-08-16 18:33:58 -0700236 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -0700237 public RXSigMeasConfig getMeasConfig() {
238 return measConfig;
239 }
240
slowr577f3222017-08-28 10:49:08 -0700241 /**
242 * Set RXMeasConfig Report.
243 * @param measConfig RXSigMeasConfig
244 */
slowr60d4d102017-08-16 18:33:58 -0700245 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -0700246 public void setMeasConfig(RXSigMeasConfig measConfig) {
247 this.measConfig = measConfig;
248 }
249
slowr577f3222017-08-28 10:49:08 -0700250 /**
251 * Get UE Capability Info.
252 * @return UECapabilityInfo
253 */
slowr60d4d102017-08-16 18:33:58 -0700254 @JsonProperty("Capability")
slowr13fa5b02017-08-08 16:32:31 -0700255 public UECapabilityInfo getCapability() {
256 return capability;
257 }
258
slowr577f3222017-08-28 10:49:08 -0700259 /**
260 * Set UE Capability Info.
261 * @param capability UECapabilityInfo
262 */
slowr60d4d102017-08-16 18:33:58 -0700263 @JsonProperty("Capability")
slowr13fa5b02017-08-08 16:32:31 -0700264 public void setCapability(UECapabilityInfo capability) {
265 this.capability = capability;
266 }
267
slowr577f3222017-08-28 10:49:08 -0700268 /**
269 * Get State.
270 * @return State
271 */
slowr60d4d102017-08-16 18:33:58 -0700272 @JsonProperty("State")
slowr67d05e42017-08-11 20:37:22 -0700273 public State getState() {
274 return state;
slowr13fa5b02017-08-08 16:32:31 -0700275 }
276
slowr577f3222017-08-28 10:49:08 -0700277 /**
278 * Set State.
279 * @param state State
280 */
slowr60d4d102017-08-16 18:33:58 -0700281 @JsonProperty("State")
slowr67d05e42017-08-11 20:37:22 -0700282 public void setState(State state) {
283 this.state = state;
slowr13fa5b02017-08-08 16:32:31 -0700284 }
285
slowr577f3222017-08-28 10:49:08 -0700286 /**
287 * Get UE ID.
288 * @return Long UE ID
289 */
slowrc86750e2017-08-22 17:26:47 -0700290 public Long getId() {
291 return id;
292 }
293
slowr577f3222017-08-28 10:49:08 -0700294 /**
295 * Set UE ID.
296 * @param id Long UE ID
297 */
slowrc86750e2017-08-22 17:26:47 -0700298 public void setId(Long id) {
299 this.id = id;
300 }
301
slowr13fa5b02017-08-08 16:32:31 -0700302 @Override
303 public String toString() {
slowr60d4d102017-08-16 18:33:58 -0700304 return "RnibUe{" +
slowrc86750e2017-08-22 17:26:47 -0700305 "id=" + id +
306 ", imsi='" + imsi + '\'' +
slowr60d4d102017-08-16 18:33:58 -0700307 ", enbS1apId=" + enbS1apId +
308 ", mmeS1apId=" + mmeS1apId +
slowrc86750e2017-08-22 17:26:47 -0700309 ", crnti=" + crnti +
slowr60d4d102017-08-16 18:33:58 -0700310 ", state=" + state +
311 ", capability=" + capability +
312 ", measConfig=" + measConfig +
slowr60d4d102017-08-16 18:33:58 -0700313 '}';
slowr13fa5b02017-08-08 16:32:31 -0700314 }
315
slowr577f3222017-08-28 10:49:08 -0700316 /*
317 * (non-Javadoc)
318 *
319 * @see java.lang.Object#equals()
320 */
slowr13fa5b02017-08-08 16:32:31 -0700321 @Override
322 public boolean equals(Object o) {
slowr577f3222017-08-28 10:49:08 -0700323 if (this == o) {
324 return true;
325 }
326 if (o == null || getClass() != o.getClass()) {
327 return false;
328 }
slowr13fa5b02017-08-08 16:32:31 -0700329 RnibUe rnibUe = (RnibUe) o;
slowrc86750e2017-08-22 17:26:47 -0700330 return Objects.equals(id, rnibUe.id);
slowr13fa5b02017-08-08 16:32:31 -0700331 }
332
slowr577f3222017-08-28 10:49:08 -0700333 /*
334 * (non-Javadoc)
335 *
336 * @see java.lang.Object#hashCode()
337 */
slowr13fa5b02017-08-08 16:32:31 -0700338 @Override
339 public int hashCode() {
slowrc86750e2017-08-22 17:26:47 -0700340 return Objects.hash(id);
slowr13fa5b02017-08-08 16:32:31 -0700341 }
342
slowr577f3222017-08-28 10:49:08 -0700343
344 /**
345 * Enum of State of UE.
346 */
slowr67d05e42017-08-11 20:37:22 -0700347 public enum State {
slowr13fa5b02017-08-08 16:32:31 -0700348 ACTIVE {
349 @Override
350 public String toString() {
slowr577f3222017-08-28 10:49:08 -0700351 return "ACTIVE";
slowr13fa5b02017-08-08 16:32:31 -0700352 }
353 },
354 IDLE {
355 @Override
356 public String toString() {
slowr577f3222017-08-28 10:49:08 -0700357 return "IDLE";
slowr13fa5b02017-08-08 16:32:31 -0700358 }
359 }
360 }
361}