blob: fb5bb71247115412965934316463c42ad7291776 [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
33import java.net.URI;
34import java.net.URISyntaxException;
35import java.util.Timer;
36import java.util.stream.Collectors;
37import java.util.stream.Stream;
38
39import static org.onosproject.net.HostId.hostId;
40
41/**
42 * Created by dimitris on 7/22/17.
43 */
slowr60d4d102017-08-16 18:33:58 -070044@JsonPropertyOrder({
45 "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
slowr60d4d102017-08-16 18:33:58 -070061 @JsonProperty("IMSI")
slowr13fa5b02017-08-08 16:32:31 -070062 private String imsi;
slowr60d4d102017-08-16 18:33:58 -070063 @JsonProperty("ENBUES1APID")
slowr13fa5b02017-08-08 16:32:31 -070064 private ENBUES1APID enbS1apId;
slowr60d4d102017-08-16 18:33:58 -070065 @JsonProperty("MMEUES1APID")
slowr13fa5b02017-08-08 16:32:31 -070066 private MMEUES1APID mmeS1apId;
slowr60d4d102017-08-16 18:33:58 -070067 @JsonProperty("CRNTI")
slowr13fa5b02017-08-08 16:32:31 -070068 private CRNTI ranId;
slowr60d4d102017-08-16 18:33:58 -070069 @JsonProperty("State")
slowr67d05e42017-08-11 20:37:22 -070070 private State state;
slowr60d4d102017-08-16 18:33:58 -070071 @JsonProperty("Capability")
slowr13fa5b02017-08-08 16:32:31 -070072 private UECapabilityInfo capability;
slowr60d4d102017-08-16 18:33:58 -070073 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -070074 private RXSigMeasConfig measConfig;
slowr60d4d102017-08-16 18:33:58 -070075 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -070076 private Timer timer;
77
78 public RnibUe() {
slowr67d05e42017-08-11 20:37:22 -070079 state = State.ACTIVE;
slowr13fa5b02017-08-08 16:32:31 -070080 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
slowr60d4d102017-08-16 18:33:58 -0700102 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -0700103 public Timer getTimer() {
104 return timer;
105 }
106
slowr60d4d102017-08-16 18:33:58 -0700107 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -0700108 public void setTimer(Timer timer) {
109 this.timer.cancel();
110 this.timer.purge();
111 this.timer = timer;
112 }
113
slowr60d4d102017-08-16 18:33:58 -0700114 @JsonProperty("MMEUES1APID")
slowr13fa5b02017-08-08 16:32:31 -0700115 public MMEUES1APID getMmeS1apId() {
116 return mmeS1apId;
117 }
118
slowr60d4d102017-08-16 18:33:58 -0700119 @JsonProperty("MMEUES1APID")
slowr13fa5b02017-08-08 16:32:31 -0700120 public void setMmeS1apId(MMEUES1APID mmeS1apId) {
121 this.mmeS1apId = mmeS1apId;
122 }
123
slowr60d4d102017-08-16 18:33:58 -0700124 @JsonProperty("ENBUES1APID")
slowr13fa5b02017-08-08 16:32:31 -0700125 public ENBUES1APID getEnbS1apId() {
126 return enbS1apId;
127 }
128
slowr60d4d102017-08-16 18:33:58 -0700129 @JsonProperty("ENBUES1APID")
slowr13fa5b02017-08-08 16:32:31 -0700130 public void setEnbS1apId(ENBUES1APID enbS1apId) {
131 this.enbS1apId = enbS1apId;
132 }
133
slowr60d4d102017-08-16 18:33:58 -0700134 @JsonProperty("CRNTI")
slowr13fa5b02017-08-08 16:32:31 -0700135 public CRNTI getRanId() {
136 return ranId;
137 }
138
slowr60d4d102017-08-16 18:33:58 -0700139 @JsonProperty("CRNTI")
slowr13fa5b02017-08-08 16:32:31 -0700140 public void setRanId(CRNTI ranId) {
141 this.ranId = ranId;
142 }
143
slowr60d4d102017-08-16 18:33:58 -0700144 @JsonProperty("IMSI")
slowr13fa5b02017-08-08 16:32:31 -0700145 public String getImsi() {
146 return imsi;
147 }
148
slowr60d4d102017-08-16 18:33:58 -0700149 @JsonProperty("IMSI")
slowr13fa5b02017-08-08 16:32:31 -0700150 public void setImsi(String imsi) {
151 this.imsi = imsi;
152 }
153
slowr60d4d102017-08-16 18:33:58 -0700154 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -0700155 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
slowr60d4d102017-08-16 18:33:58 -0700193 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -0700194 public RXSigMeasConfig getMeasConfig() {
195 return measConfig;
196 }
197
slowr60d4d102017-08-16 18:33:58 -0700198 @JsonProperty("MeasurementConfiguration")
slowr13fa5b02017-08-08 16:32:31 -0700199 public void setMeasConfig(RXSigMeasConfig measConfig) {
200 this.measConfig = measConfig;
201 }
202
slowr60d4d102017-08-16 18:33:58 -0700203 @JsonProperty("Capability")
slowr13fa5b02017-08-08 16:32:31 -0700204 public UECapabilityInfo getCapability() {
205 return capability;
206 }
207
slowr60d4d102017-08-16 18:33:58 -0700208 @JsonProperty("Capability")
slowr13fa5b02017-08-08 16:32:31 -0700209 public void setCapability(UECapabilityInfo capability) {
210 this.capability = capability;
211 }
212
slowr60d4d102017-08-16 18:33:58 -0700213 @JsonProperty("State")
slowr67d05e42017-08-11 20:37:22 -0700214 public State getState() {
215 return state;
slowr13fa5b02017-08-08 16:32:31 -0700216 }
217
slowr60d4d102017-08-16 18:33:58 -0700218 @JsonProperty("State")
slowr67d05e42017-08-11 20:37:22 -0700219 public void setState(State state) {
220 this.state = state;
slowr13fa5b02017-08-08 16:32:31 -0700221 }
222
223 @Override
224 public String toString() {
slowr60d4d102017-08-16 18:33:58 -0700225 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 '}';
slowr13fa5b02017-08-08 16:32:31 -0700235 }
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
slowr67d05e42017-08-11 20:37:22 -0700254 public enum State {
slowr13fa5b02017-08-08 16:32:31 -0700255 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}