blob: 714182ce0f941e48ff7686a1551d190ff4220772 [file] [log] [blame]
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -08001/*
2 * Copyright 2017-present Open Networking Foundation
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
17package org.onosproject.xran.impl.entities;
18
19import com.fasterxml.jackson.annotation.JsonCreator;
20import com.fasterxml.jackson.annotation.JsonIgnore;
21import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
22import com.fasterxml.jackson.annotation.JsonProperty;
23import com.fasterxml.jackson.annotation.JsonPropertyOrder;
24import org.onlab.packet.MacAddress;
25import org.onosproject.net.HostId;
26import org.onosproject.xran.asn1lib.api.CRNTI;
27import org.onosproject.xran.asn1lib.api.ENBUES1APID;
28import org.onosproject.xran.asn1lib.api.MMEUES1APID;
29import org.onosproject.xran.asn1lib.pdu.RRCMeasConfig;
30import org.onosproject.xran.asn1lib.pdu.UECapabilityInfo;
31import org.slf4j.Logger;
32import org.slf4j.LoggerFactory;
33
34import java.util.Objects;
35import java.util.concurrent.Executors;
36import java.util.concurrent.ScheduledExecutorService;
37import java.util.stream.Collectors;
38import java.util.stream.Stream;
39
40import static org.onosproject.net.HostId.hostId;
41
42/**
43 * R-NIB UE and its properties.
44 */
45@JsonPropertyOrder({
46 "Identifier",
47 "Context-IDs",
48 "RAN-ID",
49 "State",
50 "Capability",
51 "MeasurementConfiguration"
52})
53@JsonIgnoreProperties(ignoreUnknown = true)
54public class RnibUe {
55 @JsonIgnore
56 private static final Logger log =
57 LoggerFactory.getLogger(RnibUe.class);
58
59 @JsonProperty("Identifier")
60 private Long id;
61 @JsonProperty("Context-IDs")
62 private ContextIds contextIds = new ContextIds();
63 @JsonProperty("RAN-ID")
64 private CRNTI crnti;
65 @JsonProperty("State")
66 private State state = State.ACTIVE;
67 @JsonProperty("Capability")
68 private UECapabilityInfo capability;
69 @JsonProperty("MeasurementConfiguration")
70 private RRCMeasConfig measConfig;
71 @JsonIgnore
72 private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
73
74 /**
75 * Convert Host ID to UE ID.
76 *
77 * @param hostId hostID
78 * @return Long UE ID
79 */
80 public static Long hostIdtoUEId(HostId hostId) {
81 String mac = hostId.mac().toString();
82 mac = mac.replace(":", "");
83 return Long.parseLong(mac, 16);
84 }
85
86 /**
87 * Get timer.
88 *
89 * @return Timer
90 */
91 public ScheduledExecutorService getExecutor() {
92 return executor;
93 }
94
95 /**
96 * Set executor.
97 *
98 * @param executor executor
99 */
100 public void setExecutor(ScheduledExecutorService executor) {
101 this.executor.shutdown();
102 this.executor = executor;
103 }
104
105 /**
106 * Get CRNTI.
107 *
108 * @return CRNTI
109 */
110 public CRNTI getCrnti() {
111 return crnti;
112 }
113
114 /**
115 * Set CRNTI.
116 *
117 * @param crnti CRNTI
118 */
119 public void setCrnti(CRNTI crnti) {
120 this.crnti = crnti;
121 }
122
123 /**
124 * Get Host ID.
125 *
126 * @return HostId
127 */
128 @JsonIgnore
129 public HostId getHostId() {
130 try {
131 String text = Long.toHexString(this.id),
132 res = "";
133 int charsLeft = 12 - text.length();
134 if (charsLeft > 0) {
135 res += Stream.generate(() -> "0").limit(charsLeft).collect(Collectors.joining(""));
136 } else if (charsLeft < 0) {
137 return null;
138 }
139 res += text;
140
141 String insert = ":";
142 int period = 2;
143
144 StringBuilder builder = new StringBuilder(
145 res.length() + insert.length() * (res.length() / period) + 1);
146
147 int index = 0;
148 String prefix = "";
149 while (index < res.length()) {
150 // Don't putPrimaryLink the insert in the very first iteration.
151 // This is easier than appending it *after* each substring
152 builder.append(prefix);
153 prefix = insert;
154 builder.append(res.substring(index,
155 Math.min(index + period, res.length())));
156 index += period;
157 }
158
159 return hostId(MacAddress.valueOf(builder.toString()));
160 } catch (Exception e) {
161 log.error(e.getMessage());
162 }
163 return null;
164 }
165
166 /**
167 * Get RXMeasConfig Report.
168 *
169 * @return RXSigMeasConfig
170 */
171 public RRCMeasConfig getMeasConfig() {
172 return measConfig;
173 }
174
175 /**
176 * Set RXMeasConfig Report.
177 *
178 * @param measConfig RXSigMeasConfig
179 */
180 public void setMeasConfig(RRCMeasConfig measConfig) {
181 this.measConfig = measConfig;
182 }
183
184 /**
185 * Get UE Capability Info.
186 *
187 * @return UECapabilityInfo
188 */
189 public UECapabilityInfo getCapability() {
190 return capability;
191 }
192
193 /**
194 * Set UE Capability Info.
195 *
196 * @param capability UECapabilityInfo
197 */
198 public void setCapability(UECapabilityInfo capability) {
199 this.capability = capability;
200 }
201
202 /**
203 * Get State.
204 *
205 * @return State
206 */
207 public State getState() {
208 return state;
209 }
210
211 /**
212 * Set State.
213 *
214 * @param state State
215 */
216 public void setState(State state) {
217 this.state = state;
218 }
219
220 /**
221 * Get UE ID.
222 *
223 * @return Long UE ID
224 */
225 public Long getId() {
226 return id;
227 }
228
229 /**
230 * Set UE ID.
231 *
232 * @param id Long UE ID
233 */
234 public void setId(Long id) {
235 this.id = id;
236 }
237
238 public ContextIds getContextIds() {
239 return contextIds;
240 }
241
242 public void setContextIds(ContextIds contextIds) {
243 this.contextIds = contextIds;
244 }
245
246 @Override
247 public String toString() {
248 return "RnibUe{" +
249 "id=" + id +
250 ", contextIds=" + contextIds +
251 ", crnti=" + crnti +
252 ", state=" + state +
253 ", capability=" + capability +
254 ", measConfig=" + measConfig +
255 '}';
256 }
257
258 @Override
259 public boolean equals(Object o) {
260 if (this == o) {
261 return true;
262 }
263 if (o == null || getClass() != o.getClass()) {
264 return false;
265 }
266 RnibUe rnibUe = (RnibUe) o;
267 return Objects.equals(id, rnibUe.id);
268 }
269
270 @Override
271 public int hashCode() {
272 return Objects.hash(id);
273 }
274
275
276 /**
277 * Enum of State of UE.
278 */
279 public enum State {
280 ACTIVE {
281 @Override
282 public String toString() {
283 return "ACTIVE";
284 }
285 },
286 IDLE {
287 @Override
288 public String toString() {
289 return "IDLE";
290 }
291 }
292 }
293
294 /**
295 * Context IDs.
296 */
297 @JsonPropertyOrder({
298 "IMSI",
299 "ENBUES1APID",
300 "MMEUES1APID",
301 })
302 @JsonIgnoreProperties(ignoreUnknown = true)
303 public static class ContextIds {
304 @JsonProperty("IMSI")
305 private String imsi = "";
306 @JsonProperty("ENBUES1APID")
307 private ENBUES1APID enbS1apId;
308 @JsonProperty("MMEUES1APID")
309 private MMEUES1APID mmeS1apId;
310
311 public ContextIds() {
312 }
313
314 @JsonCreator
315 public ContextIds(
316 @JsonProperty("ENBUES1APID") ENBUES1APID enbS1apId,
317 @JsonProperty("MMEUES1APID") MMEUES1APID mmeS1apId
318 ) {
319 this.enbS1apId = enbS1apId;
320 this.mmeS1apId = mmeS1apId;
321 }
322
323 public ContextIds(String imsi, ENBUES1APID enbS1apId, MMEUES1APID mmeS1apId) {
324 this.imsi = imsi;
325 this.enbS1apId = enbS1apId;
326 this.mmeS1apId = mmeS1apId;
327 }
328
329 /**
330 * Get MMEUES1APID.
331 *
332 * @return MMEUES1APID
333 */
334 public MMEUES1APID getMmeS1apId() {
335 return mmeS1apId;
336 }
337
338 /**
339 * Set MMEUES1APID.
340 *
341 * @param mmeS1apId MMEUES1APID
342 */
343 public void setMmeS1apId(MMEUES1APID mmeS1apId) {
344 this.mmeS1apId = mmeS1apId;
345 }
346
347 /**
348 * Get ENBUES1APID.
349 *
350 * @return ENBUES1APID
351 */
352 public ENBUES1APID getEnbS1apId() {
353 return enbS1apId;
354 }
355
356 /**
357 * Set ENBUES1APID.
358 *
359 * @param enbS1apId ENBUES1APID
360 */
361 public void setEnbS1apId(ENBUES1APID enbS1apId) {
362 this.enbS1apId = enbS1apId;
363 }
364
365 /**
366 * Get IMSI.
367 *
368 * @return IMSI
369 */
370 public String getImsi() {
371 return imsi;
372 }
373
374 /**
375 * Set IMSI.
376 *
377 * @param imsi IMSI
378 */
379 public void setImsi(String imsi) {
380 this.imsi = imsi;
381 }
382
383 @Override
384 public String toString() {
385 return "ContextIds{" +
386 "imsi='" + imsi + '\'' +
387 ", enbS1apId=" + enbS1apId +
388 ", mmeS1apId=" + mmeS1apId +
389 '}';
390 }
391 }
392}