blob: 3afcb0490892ff12948d837796a63ea30c932d59 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
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
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/**
41 * Created by dimitris on 7/22/17.
42 */
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
slowrc86750e2017-08-22 17:26:47 -070085 public static Long hostIdtoUEId(HostId hostId) {
slowr13fa5b02017-08-08 16:32:31 -070086 String mac = hostId.mac().toString();
87 mac = mac.replace(":", "");
88 long l = Long.parseLong(mac, 16);
slowrc86750e2017-08-22 17:26:47 -070089 return l;
slowr13fa5b02017-08-08 16:32:31 -070090 }
91
slowr60d4d102017-08-16 18:33:58 -070092 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -070093 public Timer getTimer() {
94 return timer;
95 }
96
slowr60d4d102017-08-16 18:33:58 -070097 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -070098 public void setTimer(Timer timer) {
99 this.timer.cancel();
100 this.timer.purge();
101 this.timer = timer;
102 }
103
slowr60d4d102017-08-16 18:33:58 -0700104 @JsonProperty("MMEUES1APID")
slowr13fa5b02017-08-08 16:32:31 -0700105 public MMEUES1APID getMmeS1apId() {
106 return mmeS1apId;
107 }
108
slowr60d4d102017-08-16 18:33:58 -0700109 @JsonProperty("MMEUES1APID")
slowr13fa5b02017-08-08 16:32:31 -0700110 public void setMmeS1apId(MMEUES1APID mmeS1apId) {
111 this.mmeS1apId = mmeS1apId;
112 }
113
slowr60d4d102017-08-16 18:33:58 -0700114 @JsonProperty("ENBUES1APID")
slowr13fa5b02017-08-08 16:32:31 -0700115 public ENBUES1APID getEnbS1apId() {
116 return enbS1apId;
117 }
118
slowr60d4d102017-08-16 18:33:58 -0700119 @JsonProperty("ENBUES1APID")
slowr13fa5b02017-08-08 16:32:31 -0700120 public void setEnbS1apId(ENBUES1APID enbS1apId) {
121 this.enbS1apId = enbS1apId;
122 }
123
slowr60d4d102017-08-16 18:33:58 -0700124 @JsonProperty("CRNTI")
slowrc86750e2017-08-22 17:26:47 -0700125 public CRNTI getCrnti() {
126 return crnti;
slowr13fa5b02017-08-08 16:32:31 -0700127 }
128
slowr60d4d102017-08-16 18:33:58 -0700129 @JsonProperty("CRNTI")
slowrc86750e2017-08-22 17:26:47 -0700130 public void setCrnti(CRNTI crnti) {
131 this.crnti = crnti;
slowr13fa5b02017-08-08 16:32:31 -0700132 }
133
slowr60d4d102017-08-16 18:33:58 -0700134 @JsonProperty("IMSI")
slowr13fa5b02017-08-08 16:32:31 -0700135 public String getImsi() {
136 return imsi;
137 }
138
slowr60d4d102017-08-16 18:33:58 -0700139 @JsonProperty("IMSI")
slowr13fa5b02017-08-08 16:32:31 -0700140 public void setImsi(String imsi) {
141 this.imsi = imsi;
142 }
143
slowr60d4d102017-08-16 18:33:58 -0700144 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -0700145 public HostId getHostId() {
146 try {
slowrc86750e2017-08-22 17:26:47 -0700147 String text = Long.toHexString(this.id),
slowr13fa5b02017-08-08 16:32:31 -0700148 res = "";
149 int charsLeft = 12 - text.length();
150 if (charsLeft > 0) {
151 res += Stream.generate(() -> "0").limit(charsLeft).collect(Collectors.joining(""));
152 } else if (charsLeft < 0) {
153 return null;
154 }
155 res += text;
156
157 String insert = ":";
158 int period = 2;
159
160 StringBuilder builder = new StringBuilder(
161 res.length() + insert.length() * (res.length() / period) + 1);
162
163 int index = 0;
164 String prefix = "";
165 while (index < res.length()) {
166 // Don't putPrimaryLink the insert in the very first iteration.
167 // This is easier than appending it *after* each substring
168 builder.append(prefix);
169 prefix = insert;
170 builder.append(res.substring(index,
171 Math.min(index + period, res.length())));
172 index += period;
173 }
174
175 return hostId(MacAddress.valueOf(builder.toString()));
176 } catch (Exception e) {
177 log.warn(e.getMessage());
178 e.printStackTrace();
179 }
180 return null;
181 }
182
slowr60d4d102017-08-16 18:33:58 -0700183 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -0700184 public RXSigMeasConfig getMeasConfig() {
185 return measConfig;
186 }
187
slowr60d4d102017-08-16 18:33:58 -0700188 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -0700189 public void setMeasConfig(RXSigMeasConfig measConfig) {
190 this.measConfig = measConfig;
191 }
192
slowr60d4d102017-08-16 18:33:58 -0700193 @JsonProperty("Capability")
slowr13fa5b02017-08-08 16:32:31 -0700194 public UECapabilityInfo getCapability() {
195 return capability;
196 }
197
slowr60d4d102017-08-16 18:33:58 -0700198 @JsonProperty("Capability")
slowr13fa5b02017-08-08 16:32:31 -0700199 public void setCapability(UECapabilityInfo capability) {
200 this.capability = capability;
201 }
202
slowr60d4d102017-08-16 18:33:58 -0700203 @JsonProperty("State")
slowr67d05e42017-08-11 20:37:22 -0700204 public State getState() {
205 return state;
slowr13fa5b02017-08-08 16:32:31 -0700206 }
207
slowr60d4d102017-08-16 18:33:58 -0700208 @JsonProperty("State")
slowr67d05e42017-08-11 20:37:22 -0700209 public void setState(State state) {
210 this.state = state;
slowr13fa5b02017-08-08 16:32:31 -0700211 }
212
slowrc86750e2017-08-22 17:26:47 -0700213 public Long getId() {
214 return id;
215 }
216
217 public void setId(Long id) {
218 this.id = id;
219 }
220
slowr13fa5b02017-08-08 16:32:31 -0700221 @Override
222 public String toString() {
slowr60d4d102017-08-16 18:33:58 -0700223 return "RnibUe{" +
slowrc86750e2017-08-22 17:26:47 -0700224 "id=" + id +
225 ", imsi='" + imsi + '\'' +
slowr60d4d102017-08-16 18:33:58 -0700226 ", enbS1apId=" + enbS1apId +
227 ", mmeS1apId=" + mmeS1apId +
slowrc86750e2017-08-22 17:26:47 -0700228 ", crnti=" + crnti +
slowr60d4d102017-08-16 18:33:58 -0700229 ", state=" + state +
230 ", capability=" + capability +
231 ", measConfig=" + measConfig +
slowr60d4d102017-08-16 18:33:58 -0700232 '}';
slowr13fa5b02017-08-08 16:32:31 -0700233 }
234
235 @Override
236 public boolean equals(Object o) {
237 if (this == o) return true;
238 if (o == null || getClass() != o.getClass()) return false;
slowr13fa5b02017-08-08 16:32:31 -0700239 RnibUe rnibUe = (RnibUe) o;
slowrc86750e2017-08-22 17:26:47 -0700240 return Objects.equals(id, rnibUe.id);
slowr13fa5b02017-08-08 16:32:31 -0700241 }
242
243 @Override
244 public int hashCode() {
slowrc86750e2017-08-22 17:26:47 -0700245 return Objects.hash(id);
slowr13fa5b02017-08-08 16:32:31 -0700246 }
247
slowr67d05e42017-08-11 20:37:22 -0700248 public enum State {
slowr13fa5b02017-08-08 16:32:31 -0700249 ACTIVE {
250 @Override
251 public String toString() {
252 return "\"ACTIVE\"";
253 }
254 },
255 IDLE {
256 @Override
257 public String toString() {
258 return "\"IDLE\"";
259 }
260 }
261 }
262}