blob: 420d7b4802037ce11a26e73c14e3d53f3aa0f3ca [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
slowr577f3222017-08-28 10:49:08 -07002 * Copyright 2016-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 */
16package org.onosproject.xran.rest;
17
18import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.node.ObjectNode;
20import com.google.common.collect.Lists;
21import org.apache.commons.lang.exception.ExceptionUtils;
22import org.onosproject.rest.AbstractWebResource;
23import org.onosproject.xran.XranStore;
24import org.onosproject.xran.annotations.Patch;
slowr577f3222017-08-28 10:49:08 -070025import org.onosproject.xran.codecs.ber.types.BerInteger;
slowr67d05e42017-08-11 20:37:22 -070026import org.onosproject.xran.controller.XranController;
slowr89c2ac12017-08-15 16:20:06 -070027import org.onosproject.xran.entities.RnibCell;
slowr13fa5b02017-08-08 16:32:31 -070028import org.onosproject.xran.entities.RnibLink;
slowr89c2ac12017-08-15 16:20:06 -070029import org.onosproject.xran.entities.RnibUe;
slowr13fa5b02017-08-08 16:32:31 -070030import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
slowr60d4d102017-08-16 18:33:58 -070033import javax.ws.rs.DefaultValue;
34import javax.ws.rs.GET;
slowr60d4d102017-08-16 18:33:58 -070035import javax.ws.rs.Path;
slowr60d4d102017-08-16 18:33:58 -070036import javax.ws.rs.QueryParam;
slowr577f3222017-08-28 10:49:08 -070037import javax.ws.rs.Consumes;
38import javax.ws.rs.Produces;
39import javax.ws.rs.POST;
40import javax.ws.rs.PathParam;
slowr13fa5b02017-08-08 16:32:31 -070041import javax.ws.rs.core.MediaType;
42import javax.ws.rs.core.Response;
slowr13fa5b02017-08-08 16:32:31 -070043import java.io.InputStream;
44import java.util.List;
slowr67d05e42017-08-11 20:37:22 -070045import java.util.Optional;
46import java.util.concurrent.SynchronousQueue;
slowr8ddc2b12017-08-14 14:13:38 -070047import java.util.concurrent.TimeUnit;
slowr13fa5b02017-08-08 16:32:31 -070048
49/**
50 * Link web resource.
51 */
52@Path("links")
53public class LinkWebResource extends AbstractWebResource {
54
55 private static final Logger log =
56 LoggerFactory.getLogger(LinkWebResource.class);
57
slowr60d4d102017-08-16 18:33:58 -070058 public LinkWebResource() {
59
60 }
61
slowr13fa5b02017-08-08 16:32:31 -070062 /**
slowr577f3222017-08-28 10:49:08 -070063 * List all the links originating or terminating at cell/UE OR list the link connecting between cell and UE.
slowr13fa5b02017-08-08 16:32:31 -070064 *
slowr577f3222017-08-28 10:49:08 -070065 * @param eciHex EutranCellIdentifier in binary
66 * @param ue UE ID
67 * @return Response
slowr13fa5b02017-08-08 16:32:31 -070068 */
69 @GET
70 @Produces(MediaType.APPLICATION_JSON)
71 public Response getLinksBetween(@DefaultValue("") @QueryParam("cell") String eciHex,
slowr8ddc2b12017-08-14 14:13:38 -070072 @DefaultValue("-1") @QueryParam("ue") long ue) {
slowr13fa5b02017-08-08 16:32:31 -070073 List<RnibLink> list = Lists.newArrayList();
74 if (!eciHex.isEmpty() && ue != -1) {
slowr577f3222017-08-28 10:49:08 -070075 RnibLink link = get(XranStore.class).getlinkbetweencellidueid(eciHex, ue);
slowr13fa5b02017-08-08 16:32:31 -070076 if (link != null) {
77 list.add(link);
78 }
79 } else if (!eciHex.isEmpty()) {
slowr577f3222017-08-28 10:49:08 -070080 list.addAll(get(XranStore.class).getlinksbycellid(eciHex));
slowr13fa5b02017-08-08 16:32:31 -070081 } else if (ue != -1) {
slowr577f3222017-08-28 10:49:08 -070082 list.addAll(get(XranStore.class).getlinksbyueid(ue));
slowr13fa5b02017-08-08 16:32:31 -070083 } else {
84 list.addAll(get(XranStore.class).getLinks());
85 }
86
slowr60d4d102017-08-16 18:33:58 -070087 if (list.size() > 0) {
88 try {
89 JsonNode jsonNode = mapper().valueToTree(list);
90
91 return ResponseHelper.getResponse(
92 mapper(),
slowr577f3222017-08-28 10:49:08 -070093 ResponseHelper.StatusCode.OK,
slowr60d4d102017-08-16 18:33:58 -070094 jsonNode
95 );
96 } catch (Exception e) {
97 String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
98 log.error(fullStackTrace);
99 e.printStackTrace();
100
101 return ResponseHelper.getResponse(
102 mapper(),
slowr577f3222017-08-28 10:49:08 -0700103 ResponseHelper.StatusCode.INTERNAL_SERVER_ERROR,
slowr60d4d102017-08-16 18:33:58 -0700104 "Exception",
105 fullStackTrace
106 );
107 }
slowr13fa5b02017-08-08 16:32:31 -0700108 }
slowr60d4d102017-08-16 18:33:58 -0700109
110 return ResponseHelper.getResponse(
111 mapper(),
slowr577f3222017-08-28 10:49:08 -0700112 ResponseHelper.StatusCode.NOT_FOUND,
slowr60d4d102017-08-16 18:33:58 -0700113 "Not Found",
114 "Specified links not found"
115 );
slowr13fa5b02017-08-08 16:32:31 -0700116 }
117
118 /**
slowr577f3222017-08-28 10:49:08 -0700119 * Modify the link.
slowr13fa5b02017-08-08 16:32:31 -0700120 *
slowr577f3222017-08-28 10:49:08 -0700121 * @param src CELL ECI in binary
122 * @param dst UE ID
123 * @param stream Parameter on basis of which link is to be modified
124 * @return Response
slowr13fa5b02017-08-08 16:32:31 -0700125 */
126 @Patch
127 @Path("{src},{dst}")
128 @Consumes(MediaType.APPLICATION_JSON)
slowr60d4d102017-08-16 18:33:58 -0700129 @Produces(MediaType.APPLICATION_JSON)
slowr13fa5b02017-08-08 16:32:31 -0700130 public Response patchLinks(@PathParam("src") String src, @PathParam("dst") long dst, InputStream stream) {
slowr577f3222017-08-28 10:49:08 -0700131 RnibLink link = get(XranStore.class).getlinkbetweencellidueid(src, dst);
slowr8ddc2b12017-08-14 14:13:38 -0700132 if (link != null) {
133 try {
slowr67d05e42017-08-11 20:37:22 -0700134 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
slowr13fa5b02017-08-08 16:32:31 -0700135
slowr577f3222017-08-28 10:49:08 -0700136 // Modify link based on Type
slowr89c2ac12017-08-15 16:20:06 -0700137 JsonNode type = jsonTree.path("type");
138 if (!type.isMissingNode()) {
139 RnibLink.Type anEnum = RnibLink.Type.getEnum(type.asText());
140 return handleTypeChange(link, anEnum);
slowr67d05e42017-08-11 20:37:22 -0700141 }
slowr13fa5b02017-08-08 16:32:31 -0700142
slowr577f3222017-08-28 10:49:08 -0700143 // Modify link based on traffic percent
slowr89c2ac12017-08-15 16:20:06 -0700144 JsonNode trafficpercent = jsonTree.path("trafficpercent");
145 if (!trafficpercent.isMissingNode()) {
146 return handleTrafficChange(link, trafficpercent);
slowr67d05e42017-08-11 20:37:22 -0700147 }
slowr13fa5b02017-08-08 16:32:31 -0700148
slowr577f3222017-08-28 10:49:08 -0700149 // Modify link based on RRMConf
slowr89c2ac12017-08-15 16:20:06 -0700150 JsonNode rrmConf = jsonTree.path("RRMConf");
151 if (!rrmConf.isMissingNode()) {
slowr577f3222017-08-28 10:49:08 -0700152 return handleRrmChange(link, rrmConf);
slowr8ddc2b12017-08-14 14:13:38 -0700153 }
154
slowrd19a83b2017-08-17 08:57:46 -0700155 return ResponseHelper.getResponse(
156 mapper(),
slowr577f3222017-08-28 10:49:08 -0700157 ResponseHelper.StatusCode.NOT_IMPLEMENTED,
slowrd19a83b2017-08-17 08:57:46 -0700158 "Not Implemented",
159 "The command you specified is not implemented or doesn't exist. We support " +
160 "type/RRMConf/traficpercent commands."
161 );
162
slowr8ddc2b12017-08-14 14:13:38 -0700163 } catch (Exception e) {
slowr60d4d102017-08-16 18:33:58 -0700164 String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
165 log.error(fullStackTrace);
slowr8ddc2b12017-08-14 14:13:38 -0700166 e.printStackTrace();
slowr60d4d102017-08-16 18:33:58 -0700167
168 return ResponseHelper.getResponse(
169 mapper(),
slowr577f3222017-08-28 10:49:08 -0700170 ResponseHelper.StatusCode.INTERNAL_SERVER_ERROR,
slowr60d4d102017-08-16 18:33:58 -0700171 "Exception",
172 fullStackTrace
173 );
slowr8ddc2b12017-08-14 14:13:38 -0700174 }
175 }
slowr60d4d102017-08-16 18:33:58 -0700176
177 return ResponseHelper.getResponse(
178 mapper(),
slowr577f3222017-08-28 10:49:08 -0700179 ResponseHelper.StatusCode.NOT_FOUND,
slowr60d4d102017-08-16 18:33:58 -0700180 "Not Found",
181 "Link not found use POST request"
182 );
slowr13fa5b02017-08-08 16:32:31 -0700183 }
184
185 /**
slowr577f3222017-08-28 10:49:08 -0700186 * Create link based on Type of the link.
slowr13fa5b02017-08-08 16:32:31 -0700187 *
slowr577f3222017-08-28 10:49:08 -0700188 * @param src CELL ECI in binary
189 * @param dst UE ID
190 * @param stream LinkType
191 * @return Response
slowr13fa5b02017-08-08 16:32:31 -0700192 */
193 @POST
194 @Path("{src},{dst}")
195 @Consumes(MediaType.APPLICATION_JSON)
slowr60d4d102017-08-16 18:33:58 -0700196 @Produces(MediaType.APPLICATION_JSON)
slowr13fa5b02017-08-08 16:32:31 -0700197 public Response postLinks(@PathParam("src") String src, @PathParam("dst") long dst, InputStream stream) {
slowr89c2ac12017-08-15 16:20:06 -0700198 RnibCell cell = get(XranStore.class).getCell(src);
199 RnibUe ue = get(XranStore.class).getUe(dst);
200
201 if (cell == null) {
slowr60d4d102017-08-16 18:33:58 -0700202 return ResponseHelper.getResponse(
203 mapper(),
slowr577f3222017-08-28 10:49:08 -0700204 ResponseHelper.StatusCode.NOT_FOUND,
slowr60d4d102017-08-16 18:33:58 -0700205 "Not Found",
206 "Cell " + src + " was not found"
207 );
slowr89c2ac12017-08-15 16:20:06 -0700208 }
209
210 if (ue == null) {
slowr60d4d102017-08-16 18:33:58 -0700211 return ResponseHelper.getResponse(
212 mapper(),
slowr577f3222017-08-28 10:49:08 -0700213 ResponseHelper.StatusCode.NOT_FOUND,
slowr60d4d102017-08-16 18:33:58 -0700214 "Not Found",
215 "Ue with " + dst + " was not found"
216 );
slowr89c2ac12017-08-15 16:20:06 -0700217 }
218
slowrc86750e2017-08-22 17:26:47 -0700219 if (get(XranStore.class).getLink(cell.getEcgi(), ue.getId()) != null) {
slowr60d4d102017-08-16 18:33:58 -0700220 return ResponseHelper.getResponse(
221 mapper(),
slowr577f3222017-08-28 10:49:08 -0700222 ResponseHelper.StatusCode.BAD_REQUEST,
slowr60d4d102017-08-16 18:33:58 -0700223 "Bad Request",
224 "Link already exists use PATCH to modify"
225 );
slowr89c2ac12017-08-15 16:20:06 -0700226 }
227
slowr13fa5b02017-08-08 16:32:31 -0700228 try {
229 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
230
slowr89c2ac12017-08-15 16:20:06 -0700231 JsonNode type = jsonTree.path("type");
slowr13fa5b02017-08-08 16:32:31 -0700232
slowr077957a2017-08-16 11:54:22 -0700233 RnibLink link = new RnibLink(cell, ue);
234 // store it as non-serving when creating link
235 get(XranStore.class).storeLink(link);
slowr89c2ac12017-08-15 16:20:06 -0700236 if (!type.isMissingNode()) {
slowr077957a2017-08-16 11:54:22 -0700237 return handleTypeChange(link, RnibLink.Type.getEnum(type.asText()));
slowr13fa5b02017-08-08 16:32:31 -0700238 }
slowr077957a2017-08-16 11:54:22 -0700239
240 JsonNode trafficpercent = jsonTree.path("trafficpercent");
241 if (!trafficpercent.isMissingNode()) {
242 return handleTrafficChange(link, trafficpercent);
243 }
244
245 JsonNode rrmConf = jsonTree.path("RRMConf");
246 if (!rrmConf.isMissingNode()) {
slowr577f3222017-08-28 10:49:08 -0700247 return handleRrmChange(link, rrmConf);
slowr077957a2017-08-16 11:54:22 -0700248 }
249
slowr13fa5b02017-08-08 16:32:31 -0700250 } catch (Exception e) {
slowr60d4d102017-08-16 18:33:58 -0700251 String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
252 log.error(fullStackTrace);
slowr13fa5b02017-08-08 16:32:31 -0700253 e.printStackTrace();
slowr60d4d102017-08-16 18:33:58 -0700254
255 return ResponseHelper.getResponse(
256 mapper(),
slowr577f3222017-08-28 10:49:08 -0700257 ResponseHelper.StatusCode.INTERNAL_SERVER_ERROR,
slowr60d4d102017-08-16 18:33:58 -0700258 "Exception",
259 fullStackTrace
260 );
slowr13fa5b02017-08-08 16:32:31 -0700261 }
262
slowr60d4d102017-08-16 18:33:58 -0700263 return ResponseHelper.getResponse(
264 mapper(),
slowr577f3222017-08-28 10:49:08 -0700265 ResponseHelper.StatusCode.BAD_REQUEST,
slowr73b4eae2017-08-17 16:09:09 -0700266 "Bad Request",
slowr577f3222017-08-28 10:49:08 -0700267 "The command you specified is not implemented " +
268 "or doesn't exist. We support " +
slowrd19a83b2017-08-17 08:57:46 -0700269 "type/RRMConf/traficpercent commands."
slowr60d4d102017-08-16 18:33:58 -0700270 );
slowr13fa5b02017-08-08 16:32:31 -0700271 }
272
slowr577f3222017-08-28 10:49:08 -0700273
274 /**
275 * Change link based on type of the link.
276 *
277 * @param link Link
278 * @param newType LinkType
279 * @return Response
280 * @throws InterruptedException Interrupted queue
281 */
282 private Response handleTypeChange(RnibLink link, RnibLink.Type newType)
283 throws InterruptedException {
slowr89c2ac12017-08-15 16:20:06 -0700284 final SynchronousQueue<String>[] queue = new SynchronousQueue[1];
285
slowr577f3222017-08-28 10:49:08 -0700286
slowr89c2ac12017-08-15 16:20:06 -0700287 if (newType.equals(RnibLink.Type.SERVING_PRIMARY)) {
slowr077957a2017-08-16 11:54:22 -0700288 switch (link.getType()) {
289 case SERVING_PRIMARY: {
slowr60d4d102017-08-16 18:33:58 -0700290 return ResponseHelper.getResponse(
291 mapper(),
slowr577f3222017-08-28 10:49:08 -0700292 ResponseHelper.StatusCode.BAD_REQUEST,
slowr60d4d102017-08-16 18:33:58 -0700293 "Bad Request",
294 "Link is already a primary link"
295 );
slowr89c2ac12017-08-15 16:20:06 -0700296 }
slowr077957a2017-08-16 11:54:22 -0700297 case SERVING_SECONDARY_CA:
298 case SERVING_SECONDARY_DC:
299 case NON_SERVING: {
slowr577f3222017-08-28 10:49:08 -0700300 List<RnibLink> linksByUeId = get(XranStore.class)
301 .getlinksbyueid(link.getLinkId().getUeId());
slowr077957a2017-08-16 11:54:22 -0700302
303 Optional<RnibLink> primary = linksByUeId.stream()
304 .filter(l -> l.getType().equals(RnibLink.Type.SERVING_PRIMARY))
305 .findFirst();
306 if (primary.isPresent()) {
307 queue[0] = get(XranController.class).sendHORequest(link, primary.get());
slowr577f3222017-08-28 10:49:08 -0700308 String poll = queue[0].poll(get(XranController.class)
309 .getNorthboundTimeout(), TimeUnit.MILLISECONDS);
slowr077957a2017-08-16 11:54:22 -0700310
311 if (poll != null) {
slowr60d4d102017-08-16 18:33:58 -0700312 return ResponseHelper.getResponse(
313 mapper(),
slowr577f3222017-08-28 10:49:08 -0700314 ResponseHelper.StatusCode.OK,
slowr60d4d102017-08-16 18:33:58 -0700315 "Handoff Response",
316 poll
317 );
slowr077957a2017-08-16 11:54:22 -0700318 } else {
slowr60d4d102017-08-16 18:33:58 -0700319 return ResponseHelper.getResponse(
320 mapper(),
slowr577f3222017-08-28 10:49:08 -0700321 ResponseHelper.StatusCode.REQUEST_TIMEOUT,
slowr60d4d102017-08-16 18:33:58 -0700322 "Handoff Timeout",
323 "eNodeB did not send a HOComplete/HOFailure on time"
324 );
slowr077957a2017-08-16 11:54:22 -0700325 }
326 } else {
327 link.setType(RnibLink.Type.SERVING_PRIMARY);
slowr60d4d102017-08-16 18:33:58 -0700328 return ResponseHelper.getResponse(
329 mapper(),
slowr577f3222017-08-28 10:49:08 -0700330 ResponseHelper.StatusCode.OK,
slowr60d4d102017-08-16 18:33:58 -0700331 "OK",
332 "Link set to primary"
333 );
slowr077957a2017-08-16 11:54:22 -0700334 }
335 }
slowr577f3222017-08-28 10:49:08 -0700336 default:
slowr89c2ac12017-08-15 16:20:06 -0700337 }
338 } else if (newType.equals(RnibLink.Type.NON_SERVING)) {
339 switch (link.getType()) {
slowr577f3222017-08-28 10:49:08 -0700340 case NON_SERVING: {
slowr60d4d102017-08-16 18:33:58 -0700341 return ResponseHelper.getResponse(
342 mapper(),
slowr577f3222017-08-28 10:49:08 -0700343 ResponseHelper.StatusCode.BAD_REQUEST,
slowr60d4d102017-08-16 18:33:58 -0700344 "Bad Request",
345 "Link is already a primary link"
346 );
slowr577f3222017-08-28 10:49:08 -0700347 }
348 case SERVING_PRIMARY: {
slowr60d4d102017-08-16 18:33:58 -0700349 return ResponseHelper.getResponse(
350 mapper(),
slowr577f3222017-08-28 10:49:08 -0700351 ResponseHelper.StatusCode.BAD_REQUEST,
slowr60d4d102017-08-16 18:33:58 -0700352 "Bad Request",
353 "Cannot modify a primary link"
354 );
slowr577f3222017-08-28 10:49:08 -0700355 }
slowr89c2ac12017-08-15 16:20:06 -0700356 case SERVING_SECONDARY_CA:
slowr577f3222017-08-28 10:49:08 -0700357 case SERVING_SECONDARY_DC: {
slowr89c2ac12017-08-15 16:20:06 -0700358 if (get(XranController.class).sendScellDelete(link)) {
slowr60d4d102017-08-16 18:33:58 -0700359 return ResponseHelper.getResponse(
360 mapper(),
slowr577f3222017-08-28 10:49:08 -0700361 ResponseHelper.StatusCode.OK,
slowr60d4d102017-08-16 18:33:58 -0700362 "OK",
363 "Link set to non-serving"
364 );
slowr89c2ac12017-08-15 16:20:06 -0700365 } else {
slowr60d4d102017-08-16 18:33:58 -0700366 return ResponseHelper.getResponse(
367 mapper(),
slowr577f3222017-08-28 10:49:08 -0700368 ResponseHelper.StatusCode.NOT_FOUND,
slowr60d4d102017-08-16 18:33:58 -0700369 "Not Found",
370 "Could not find cell config report to construct Scell Delete"
371 );
slowr89c2ac12017-08-15 16:20:06 -0700372 }
slowr577f3222017-08-28 10:49:08 -0700373 }
374 default:
slowr89c2ac12017-08-15 16:20:06 -0700375 }
376 } else if (newType.equals(RnibLink.Type.SERVING_SECONDARY_CA)) {
377 switch (link.getType()) {
slowr577f3222017-08-28 10:49:08 -0700378 case SERVING_PRIMARY: {
slowr60d4d102017-08-16 18:33:58 -0700379 return ResponseHelper.getResponse(
380 mapper(),
slowr577f3222017-08-28 10:49:08 -0700381 ResponseHelper.StatusCode.BAD_REQUEST,
slowr60d4d102017-08-16 18:33:58 -0700382 "Bad Request",
383 "Cannot modify a primary link"
384 );
slowr577f3222017-08-28 10:49:08 -0700385 }
slowr89c2ac12017-08-15 16:20:06 -0700386 case SERVING_SECONDARY_DC:
slowr577f3222017-08-28 10:49:08 -0700387 case NON_SERVING: {
slowr89c2ac12017-08-15 16:20:06 -0700388 queue[0] = get(XranController.class).sendScellAdd(link);
slowr577f3222017-08-28 10:49:08 -0700389 String poll = queue[0].poll(get(XranController.class)
390 .getNorthboundTimeout(), TimeUnit.MILLISECONDS);
slowr89c2ac12017-08-15 16:20:06 -0700391 if (poll != null) {
slowr60d4d102017-08-16 18:33:58 -0700392 return ResponseHelper.getResponse(
393 mapper(),
slowr577f3222017-08-28 10:49:08 -0700394 ResponseHelper.StatusCode.OK,
slowr60d4d102017-08-16 18:33:58 -0700395 "ScellAdd Response",
396 poll
397 );
slowr89c2ac12017-08-15 16:20:06 -0700398 } else {
slowr60d4d102017-08-16 18:33:58 -0700399 return ResponseHelper.getResponse(
400 mapper(),
slowr577f3222017-08-28 10:49:08 -0700401 ResponseHelper.StatusCode.REQUEST_TIMEOUT,
slowr60d4d102017-08-16 18:33:58 -0700402 "ScellAdd Timeout",
403 "eNodeB did not send a ScellAddStatus on time"
404 );
slowr89c2ac12017-08-15 16:20:06 -0700405 }
slowr577f3222017-08-28 10:49:08 -0700406 }
407 case SERVING_SECONDARY_CA: {
slowr60d4d102017-08-16 18:33:58 -0700408 return ResponseHelper.getResponse(
409 mapper(),
slowr577f3222017-08-28 10:49:08 -0700410 ResponseHelper.StatusCode.BAD_REQUEST,
slowr60d4d102017-08-16 18:33:58 -0700411 "Bad Request",
412 "Link is already a secondary CA link"
413 );
slowr577f3222017-08-28 10:49:08 -0700414 }
415 default:
slowr89c2ac12017-08-15 16:20:06 -0700416 }
417 }
418
slowr60d4d102017-08-16 18:33:58 -0700419 return ResponseHelper.getResponse(
420 mapper(),
slowr577f3222017-08-28 10:49:08 -0700421 ResponseHelper.StatusCode.BAD_REQUEST,
slowr73b4eae2017-08-17 16:09:09 -0700422 "Bad Request",
423 "The command you specified is not implemented or doesn't exist."
slowr60d4d102017-08-16 18:33:58 -0700424 );
slowr89c2ac12017-08-15 16:20:06 -0700425 }
426
slowr577f3222017-08-28 10:49:08 -0700427 /**
428 * Modify link based on the traffic percent.
429 *
430 * @param link Link
431 * @param trafficpercent Traffic Percent of the link to be modified
432 * @return Response
433 */
slowr89c2ac12017-08-15 16:20:06 -0700434 private Response handleTrafficChange(RnibLink link, JsonNode trafficpercent) {
435 JsonNode jsonNode = trafficpercent.path("traffic-percent-dl");
436 if (!jsonNode.isMissingNode()) {
437 link.getTrafficPercent().setTrafficPercentDl(new BerInteger(jsonNode.asInt()));
438 }
439
440 jsonNode = trafficpercent.path("traffic-percent-ul");
441 if (!jsonNode.isMissingNode()) {
442 link.getTrafficPercent().setTrafficPercentUl(new BerInteger(jsonNode.asInt()));
443 }
444
slowr60d4d102017-08-16 18:33:58 -0700445 return ResponseHelper.getResponse(
446 mapper(),
slowr577f3222017-08-28 10:49:08 -0700447 ResponseHelper.StatusCode.OK,
slowr60d4d102017-08-16 18:33:58 -0700448 "OK",
449 "Traffic Percent changed"
450 );
slowr89c2ac12017-08-15 16:20:06 -0700451 }
452
slowr577f3222017-08-28 10:49:08 -0700453 /**
454 * Modify link based on RRMConf parameters.
455 *
456 * @param link Link
457 * @param rrmConf RRMConfig of the Link to be modified
458 * @return Response
459 * @throws InterruptedException Interrupted queue
460 */
461 private Response handleRrmChange(RnibLink link, JsonNode rrmConf) throws InterruptedException {
slowr89c2ac12017-08-15 16:20:06 -0700462 final SynchronousQueue<String>[] queue = new SynchronousQueue[1];
slowr577f3222017-08-28 10:49:08 -0700463 get(XranStore.class).modifylinkrrmconf(link, rrmConf);
464 boolean isxicic = link.getLinkId().getCell().getVersion() <= 3;
slowr89c2ac12017-08-15 16:20:06 -0700465
slowr577f3222017-08-28 10:49:08 -0700466 queue[0] = get(XranController.class).sendmodifiedrrmconf(link.getRrmParameters(),
467 isxicic);
slowr73b4eae2017-08-17 16:09:09 -0700468
slowr577f3222017-08-28 10:49:08 -0700469 if (isxicic) {
slowr60d4d102017-08-16 18:33:58 -0700470 return ResponseHelper.getResponse(
471 mapper(),
slowr577f3222017-08-28 10:49:08 -0700472 ResponseHelper.StatusCode.OK,
slowr73b4eae2017-08-17 16:09:09 -0700473 "OK",
474 "xICIC was sent successfully"
slowr60d4d102017-08-16 18:33:58 -0700475 );
slowr89c2ac12017-08-15 16:20:06 -0700476 } else {
slowr577f3222017-08-28 10:49:08 -0700477 String poll = queue[0].poll(get(XranController.class).getNorthboundTimeout(), TimeUnit.MILLISECONDS);
slowr73b4eae2017-08-17 16:09:09 -0700478
479 if (poll != null) {
480 return ResponseHelper.getResponse(
481 mapper(),
slowr577f3222017-08-28 10:49:08 -0700482 ResponseHelper.StatusCode.OK,
slowr73b4eae2017-08-17 16:09:09 -0700483 "RRMConfig Response",
484 poll
485 );
486 } else {
487 return ResponseHelper.getResponse(
488 mapper(),
slowr577f3222017-08-28 10:49:08 -0700489 ResponseHelper.StatusCode.REQUEST_TIMEOUT,
slowr73b4eae2017-08-17 16:09:09 -0700490 "RRMConfig Timeout",
491 "eNodeB did not send a RRMConfingStatus on time"
492 );
493 }
slowr89c2ac12017-08-15 16:20:06 -0700494 }
495 }
slowr13fa5b02017-08-08 16:32:31 -0700496}