slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /* |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 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 | package org.onosproject.xran.rest; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import com.google.common.collect.Lists; |
| 21 | import org.apache.commons.lang.exception.ExceptionUtils; |
| 22 | import org.onosproject.rest.AbstractWebResource; |
| 23 | import org.onosproject.xran.XranStore; |
| 24 | import org.onosproject.xran.annotations.Patch; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 25 | import org.onosproject.xran.codecs.ber.types.BerInteger; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 26 | import org.onosproject.xran.controller.XranController; |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 27 | import org.onosproject.xran.entities.RnibCell; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 28 | import org.onosproject.xran.entities.RnibLink; |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 29 | import org.onosproject.xran.entities.RnibUe; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 33 | import javax.ws.rs.DefaultValue; |
| 34 | import javax.ws.rs.GET; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 35 | import javax.ws.rs.Path; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 36 | import javax.ws.rs.QueryParam; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 37 | import javax.ws.rs.Consumes; |
| 38 | import javax.ws.rs.Produces; |
| 39 | import javax.ws.rs.POST; |
| 40 | import javax.ws.rs.PathParam; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 41 | import javax.ws.rs.core.MediaType; |
| 42 | import javax.ws.rs.core.Response; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 43 | import java.io.InputStream; |
| 44 | import java.util.List; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 45 | import java.util.Optional; |
| 46 | import java.util.concurrent.SynchronousQueue; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 47 | import java.util.concurrent.TimeUnit; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Link web resource. |
| 51 | */ |
| 52 | @Path("links") |
| 53 | public class LinkWebResource extends AbstractWebResource { |
| 54 | |
| 55 | private static final Logger log = |
| 56 | LoggerFactory.getLogger(LinkWebResource.class); |
| 57 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 58 | public LinkWebResource() { |
| 59 | |
| 60 | } |
| 61 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 62 | /** |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 63 | * List all the links originating or terminating at cell/UE OR list the link connecting between cell and UE. |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 64 | * |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 65 | * @param eciHex EutranCellIdentifier in binary |
| 66 | * @param ue UE ID |
| 67 | * @return Response |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 68 | */ |
| 69 | @GET |
| 70 | @Produces(MediaType.APPLICATION_JSON) |
| 71 | public Response getLinksBetween(@DefaultValue("") @QueryParam("cell") String eciHex, |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 72 | @DefaultValue("-1") @QueryParam("ue") long ue) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 73 | List<RnibLink> list = Lists.newArrayList(); |
| 74 | if (!eciHex.isEmpty() && ue != -1) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 75 | RnibLink link = get(XranStore.class).getlinkbetweencellidueid(eciHex, ue); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 76 | if (link != null) { |
| 77 | list.add(link); |
| 78 | } |
| 79 | } else if (!eciHex.isEmpty()) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 80 | list.addAll(get(XranStore.class).getlinksbycellid(eciHex)); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 81 | } else if (ue != -1) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 82 | list.addAll(get(XranStore.class).getlinksbyueid(ue)); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 83 | } else { |
| 84 | list.addAll(get(XranStore.class).getLinks()); |
| 85 | } |
| 86 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 87 | if (list.size() > 0) { |
| 88 | try { |
| 89 | JsonNode jsonNode = mapper().valueToTree(list); |
| 90 | |
| 91 | return ResponseHelper.getResponse( |
| 92 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 93 | ResponseHelper.StatusCode.OK, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 94 | 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(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 103 | ResponseHelper.StatusCode.INTERNAL_SERVER_ERROR, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 104 | "Exception", |
| 105 | fullStackTrace |
| 106 | ); |
| 107 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 108 | } |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 109 | |
| 110 | return ResponseHelper.getResponse( |
| 111 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 112 | ResponseHelper.StatusCode.NOT_FOUND, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 113 | "Not Found", |
| 114 | "Specified links not found" |
| 115 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /** |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 119 | * Modify the link. |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 120 | * |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 121 | * @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 |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 125 | */ |
| 126 | @Patch |
| 127 | @Path("{src},{dst}") |
| 128 | @Consumes(MediaType.APPLICATION_JSON) |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 129 | @Produces(MediaType.APPLICATION_JSON) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 130 | public Response patchLinks(@PathParam("src") String src, @PathParam("dst") long dst, InputStream stream) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 131 | RnibLink link = get(XranStore.class).getlinkbetweencellidueid(src, dst); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 132 | if (link != null) { |
| 133 | try { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 134 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 135 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 136 | // Modify link based on Type |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 137 | JsonNode type = jsonTree.path("type"); |
| 138 | if (!type.isMissingNode()) { |
| 139 | RnibLink.Type anEnum = RnibLink.Type.getEnum(type.asText()); |
| 140 | return handleTypeChange(link, anEnum); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 141 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 142 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 143 | // Modify link based on traffic percent |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 144 | JsonNode trafficpercent = jsonTree.path("trafficpercent"); |
| 145 | if (!trafficpercent.isMissingNode()) { |
| 146 | return handleTrafficChange(link, trafficpercent); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 147 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 148 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 149 | // Modify link based on RRMConf |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 150 | JsonNode rrmConf = jsonTree.path("RRMConf"); |
| 151 | if (!rrmConf.isMissingNode()) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 152 | return handleRrmChange(link, rrmConf); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 153 | } |
| 154 | |
slowr | d19a83b | 2017-08-17 08:57:46 -0700 | [diff] [blame] | 155 | return ResponseHelper.getResponse( |
| 156 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 157 | ResponseHelper.StatusCode.NOT_IMPLEMENTED, |
slowr | d19a83b | 2017-08-17 08:57:46 -0700 | [diff] [blame] | 158 | "Not Implemented", |
| 159 | "The command you specified is not implemented or doesn't exist. We support " + |
| 160 | "type/RRMConf/traficpercent commands." |
| 161 | ); |
| 162 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 163 | } catch (Exception e) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 164 | String fullStackTrace = ExceptionUtils.getFullStackTrace(e); |
| 165 | log.error(fullStackTrace); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 166 | e.printStackTrace(); |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 167 | |
| 168 | return ResponseHelper.getResponse( |
| 169 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 170 | ResponseHelper.StatusCode.INTERNAL_SERVER_ERROR, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 171 | "Exception", |
| 172 | fullStackTrace |
| 173 | ); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 174 | } |
| 175 | } |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 176 | |
| 177 | return ResponseHelper.getResponse( |
| 178 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 179 | ResponseHelper.StatusCode.NOT_FOUND, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 180 | "Not Found", |
| 181 | "Link not found use POST request" |
| 182 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /** |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 186 | * Create link based on Type of the link. |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 187 | * |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 188 | * @param src CELL ECI in binary |
| 189 | * @param dst UE ID |
| 190 | * @param stream LinkType |
| 191 | * @return Response |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 192 | */ |
| 193 | @POST |
| 194 | @Path("{src},{dst}") |
| 195 | @Consumes(MediaType.APPLICATION_JSON) |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 196 | @Produces(MediaType.APPLICATION_JSON) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 197 | public Response postLinks(@PathParam("src") String src, @PathParam("dst") long dst, InputStream stream) { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 198 | RnibCell cell = get(XranStore.class).getCell(src); |
| 199 | RnibUe ue = get(XranStore.class).getUe(dst); |
| 200 | |
| 201 | if (cell == null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 202 | return ResponseHelper.getResponse( |
| 203 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 204 | ResponseHelper.StatusCode.NOT_FOUND, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 205 | "Not Found", |
| 206 | "Cell " + src + " was not found" |
| 207 | ); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | if (ue == null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 211 | return ResponseHelper.getResponse( |
| 212 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 213 | ResponseHelper.StatusCode.NOT_FOUND, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 214 | "Not Found", |
| 215 | "Ue with " + dst + " was not found" |
| 216 | ); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 217 | } |
| 218 | |
slowr | c86750e | 2017-08-22 17:26:47 -0700 | [diff] [blame] | 219 | if (get(XranStore.class).getLink(cell.getEcgi(), ue.getId()) != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 220 | return ResponseHelper.getResponse( |
| 221 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 222 | ResponseHelper.StatusCode.BAD_REQUEST, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 223 | "Bad Request", |
| 224 | "Link already exists use PATCH to modify" |
| 225 | ); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 226 | } |
| 227 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 228 | try { |
| 229 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
| 230 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 231 | JsonNode type = jsonTree.path("type"); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 232 | |
slowr | 077957a | 2017-08-16 11:54:22 -0700 | [diff] [blame] | 233 | RnibLink link = new RnibLink(cell, ue); |
| 234 | // store it as non-serving when creating link |
| 235 | get(XranStore.class).storeLink(link); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 236 | if (!type.isMissingNode()) { |
slowr | 077957a | 2017-08-16 11:54:22 -0700 | [diff] [blame] | 237 | return handleTypeChange(link, RnibLink.Type.getEnum(type.asText())); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 238 | } |
slowr | 077957a | 2017-08-16 11:54:22 -0700 | [diff] [blame] | 239 | |
| 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()) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 247 | return handleRrmChange(link, rrmConf); |
slowr | 077957a | 2017-08-16 11:54:22 -0700 | [diff] [blame] | 248 | } |
| 249 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 250 | } catch (Exception e) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 251 | String fullStackTrace = ExceptionUtils.getFullStackTrace(e); |
| 252 | log.error(fullStackTrace); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 253 | e.printStackTrace(); |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 254 | |
| 255 | return ResponseHelper.getResponse( |
| 256 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 257 | ResponseHelper.StatusCode.INTERNAL_SERVER_ERROR, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 258 | "Exception", |
| 259 | fullStackTrace |
| 260 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 261 | } |
| 262 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 263 | return ResponseHelper.getResponse( |
| 264 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 265 | ResponseHelper.StatusCode.BAD_REQUEST, |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 266 | "Bad Request", |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 267 | "The command you specified is not implemented " + |
| 268 | "or doesn't exist. We support " + |
slowr | d19a83b | 2017-08-17 08:57:46 -0700 | [diff] [blame] | 269 | "type/RRMConf/traficpercent commands." |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 270 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 271 | } |
| 272 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 273 | |
| 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 { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 284 | final SynchronousQueue<String>[] queue = new SynchronousQueue[1]; |
| 285 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 286 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 287 | if (newType.equals(RnibLink.Type.SERVING_PRIMARY)) { |
slowr | 077957a | 2017-08-16 11:54:22 -0700 | [diff] [blame] | 288 | switch (link.getType()) { |
| 289 | case SERVING_PRIMARY: { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 290 | return ResponseHelper.getResponse( |
| 291 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 292 | ResponseHelper.StatusCode.BAD_REQUEST, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 293 | "Bad Request", |
| 294 | "Link is already a primary link" |
| 295 | ); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 296 | } |
slowr | 077957a | 2017-08-16 11:54:22 -0700 | [diff] [blame] | 297 | case SERVING_SECONDARY_CA: |
| 298 | case SERVING_SECONDARY_DC: |
| 299 | case NON_SERVING: { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 300 | List<RnibLink> linksByUeId = get(XranStore.class) |
| 301 | .getlinksbyueid(link.getLinkId().getUeId()); |
slowr | 077957a | 2017-08-16 11:54:22 -0700 | [diff] [blame] | 302 | |
| 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()); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 308 | String poll = queue[0].poll(get(XranController.class) |
| 309 | .getNorthboundTimeout(), TimeUnit.MILLISECONDS); |
slowr | 077957a | 2017-08-16 11:54:22 -0700 | [diff] [blame] | 310 | |
| 311 | if (poll != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 312 | return ResponseHelper.getResponse( |
| 313 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 314 | ResponseHelper.StatusCode.OK, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 315 | "Handoff Response", |
| 316 | poll |
| 317 | ); |
slowr | 077957a | 2017-08-16 11:54:22 -0700 | [diff] [blame] | 318 | } else { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 319 | return ResponseHelper.getResponse( |
| 320 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 321 | ResponseHelper.StatusCode.REQUEST_TIMEOUT, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 322 | "Handoff Timeout", |
| 323 | "eNodeB did not send a HOComplete/HOFailure on time" |
| 324 | ); |
slowr | 077957a | 2017-08-16 11:54:22 -0700 | [diff] [blame] | 325 | } |
| 326 | } else { |
| 327 | link.setType(RnibLink.Type.SERVING_PRIMARY); |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 328 | return ResponseHelper.getResponse( |
| 329 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 330 | ResponseHelper.StatusCode.OK, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 331 | "OK", |
| 332 | "Link set to primary" |
| 333 | ); |
slowr | 077957a | 2017-08-16 11:54:22 -0700 | [diff] [blame] | 334 | } |
| 335 | } |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 336 | default: |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 337 | } |
| 338 | } else if (newType.equals(RnibLink.Type.NON_SERVING)) { |
| 339 | switch (link.getType()) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 340 | case NON_SERVING: { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 341 | return ResponseHelper.getResponse( |
| 342 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 343 | ResponseHelper.StatusCode.BAD_REQUEST, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 344 | "Bad Request", |
| 345 | "Link is already a primary link" |
| 346 | ); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 347 | } |
| 348 | case SERVING_PRIMARY: { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 349 | return ResponseHelper.getResponse( |
| 350 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 351 | ResponseHelper.StatusCode.BAD_REQUEST, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 352 | "Bad Request", |
| 353 | "Cannot modify a primary link" |
| 354 | ); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 355 | } |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 356 | case SERVING_SECONDARY_CA: |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 357 | case SERVING_SECONDARY_DC: { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 358 | if (get(XranController.class).sendScellDelete(link)) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 359 | return ResponseHelper.getResponse( |
| 360 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 361 | ResponseHelper.StatusCode.OK, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 362 | "OK", |
| 363 | "Link set to non-serving" |
| 364 | ); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 365 | } else { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 366 | return ResponseHelper.getResponse( |
| 367 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 368 | ResponseHelper.StatusCode.NOT_FOUND, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 369 | "Not Found", |
| 370 | "Could not find cell config report to construct Scell Delete" |
| 371 | ); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 372 | } |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 373 | } |
| 374 | default: |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 375 | } |
| 376 | } else if (newType.equals(RnibLink.Type.SERVING_SECONDARY_CA)) { |
| 377 | switch (link.getType()) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 378 | case SERVING_PRIMARY: { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 379 | return ResponseHelper.getResponse( |
| 380 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 381 | ResponseHelper.StatusCode.BAD_REQUEST, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 382 | "Bad Request", |
| 383 | "Cannot modify a primary link" |
| 384 | ); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 385 | } |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 386 | case SERVING_SECONDARY_DC: |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 387 | case NON_SERVING: { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 388 | queue[0] = get(XranController.class).sendScellAdd(link); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 389 | String poll = queue[0].poll(get(XranController.class) |
| 390 | .getNorthboundTimeout(), TimeUnit.MILLISECONDS); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 391 | if (poll != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 392 | return ResponseHelper.getResponse( |
| 393 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 394 | ResponseHelper.StatusCode.OK, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 395 | "ScellAdd Response", |
| 396 | poll |
| 397 | ); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 398 | } else { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 399 | return ResponseHelper.getResponse( |
| 400 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 401 | ResponseHelper.StatusCode.REQUEST_TIMEOUT, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 402 | "ScellAdd Timeout", |
| 403 | "eNodeB did not send a ScellAddStatus on time" |
| 404 | ); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 405 | } |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 406 | } |
| 407 | case SERVING_SECONDARY_CA: { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 408 | return ResponseHelper.getResponse( |
| 409 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 410 | ResponseHelper.StatusCode.BAD_REQUEST, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 411 | "Bad Request", |
| 412 | "Link is already a secondary CA link" |
| 413 | ); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 414 | } |
| 415 | default: |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 419 | return ResponseHelper.getResponse( |
| 420 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 421 | ResponseHelper.StatusCode.BAD_REQUEST, |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 422 | "Bad Request", |
| 423 | "The command you specified is not implemented or doesn't exist." |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 424 | ); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 425 | } |
| 426 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 427 | /** |
| 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 | */ |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 434 | 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 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 445 | return ResponseHelper.getResponse( |
| 446 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 447 | ResponseHelper.StatusCode.OK, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 448 | "OK", |
| 449 | "Traffic Percent changed" |
| 450 | ); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 451 | } |
| 452 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 453 | /** |
| 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 { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 462 | final SynchronousQueue<String>[] queue = new SynchronousQueue[1]; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 463 | get(XranStore.class).modifylinkrrmconf(link, rrmConf); |
| 464 | boolean isxicic = link.getLinkId().getCell().getVersion() <= 3; |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 465 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 466 | queue[0] = get(XranController.class).sendmodifiedrrmconf(link.getRrmParameters(), |
| 467 | isxicic); |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 468 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 469 | if (isxicic) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 470 | return ResponseHelper.getResponse( |
| 471 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 472 | ResponseHelper.StatusCode.OK, |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 473 | "OK", |
| 474 | "xICIC was sent successfully" |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 475 | ); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 476 | } else { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 477 | String poll = queue[0].poll(get(XranController.class).getNorthboundTimeout(), TimeUnit.MILLISECONDS); |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 478 | |
| 479 | if (poll != null) { |
| 480 | return ResponseHelper.getResponse( |
| 481 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 482 | ResponseHelper.StatusCode.OK, |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 483 | "RRMConfig Response", |
| 484 | poll |
| 485 | ); |
| 486 | } else { |
| 487 | return ResponseHelper.getResponse( |
| 488 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 489 | ResponseHelper.StatusCode.REQUEST_TIMEOUT, |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 490 | "RRMConfig Timeout", |
| 491 | "eNodeB did not send a RRMConfingStatus on time" |
| 492 | ); |
| 493 | } |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 496 | } |