Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | d6a135a | 2017-08-03 22:46:05 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [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 | */ |
alshabib | 36a4d73 | 2016-06-01 16:03:59 -0700 | [diff] [blame] | 16 | package org.opencord.olt.rest; |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 17 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 18 | import org.onlab.packet.VlanId; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 19 | import org.onosproject.net.ConnectPoint; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.net.PortNumber; |
| 22 | import org.onosproject.rest.AbstractWebResource; |
| 23 | import org.opencord.olt.AccessDeviceService; |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 24 | import org.opencord.olt.AccessSubscriberId; |
Andrea Campanella | 5111823 | 2021-07-01 17:18:02 +0200 | [diff] [blame] | 25 | import org.slf4j.Logger; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 26 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 27 | import java.util.Optional; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 28 | import javax.ws.rs.Consumes; |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 29 | import javax.ws.rs.DELETE; |
| 30 | import javax.ws.rs.POST; |
| 31 | import javax.ws.rs.Path; |
| 32 | import javax.ws.rs.PathParam; |
| 33 | import javax.ws.rs.Produces; |
| 34 | import javax.ws.rs.core.MediaType; |
| 35 | import javax.ws.rs.core.Response; |
| 36 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 37 | import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; |
Andrea Campanella | 5111823 | 2021-07-01 17:18:02 +0200 | [diff] [blame] | 38 | import static org.slf4j.LoggerFactory.getLogger; |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 39 | |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 40 | /** |
| 41 | * OLT REST APIs. |
| 42 | */ |
| 43 | |
| 44 | @Path("oltapp") |
| 45 | public class OltWebResource extends AbstractWebResource { |
| 46 | |
Andrea Campanella | 5111823 | 2021-07-01 17:18:02 +0200 | [diff] [blame] | 47 | private final Logger log = getLogger(getClass()); |
| 48 | |
| 49 | |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 50 | /** |
| 51 | * Provision a subscriber. |
| 52 | * |
Jian Li | d8bca08 | 2016-01-22 16:46:58 -0800 | [diff] [blame] | 53 | * @param device device id |
| 54 | * @param port port number |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 55 | * @return 200 OK or 500 Internal Server Error |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 56 | */ |
| 57 | @POST |
| 58 | @Produces(MediaType.APPLICATION_JSON) |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 59 | @Path("{device}/{port}") |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 60 | public Response provisionSubscriber( |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 61 | @PathParam("device") String device, |
| 62 | @PathParam("port") long port) { |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 63 | AccessDeviceService service = get(AccessDeviceService.class); |
| 64 | DeviceId deviceId = DeviceId.deviceId(device); |
| 65 | PortNumber portNumber = PortNumber.portNumber(port); |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 66 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 67 | try { |
| 68 | service.provisionSubscriber(connectPoint); |
| 69 | } catch (Exception e) { |
Andrea Campanella | 5111823 | 2021-07-01 17:18:02 +0200 | [diff] [blame] | 70 | log.error("Can't provision subscriber {} due to exception", connectPoint, e); |
| 71 | return Response.status(INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 72 | } |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 73 | return ok("").build(); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Remove the provisioning for a subscriber. |
Jian Li | d8bca08 | 2016-01-22 16:46:58 -0800 | [diff] [blame] | 78 | * |
| 79 | * @param device device id |
| 80 | * @param port port number |
Jian Li | c39f08d | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 81 | * @return 204 NO CONTENT |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 82 | */ |
| 83 | @DELETE |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 84 | @Path("{device}/{port}") |
| 85 | public Response removeSubscriber( |
| 86 | @PathParam("device")String device, |
| 87 | @PathParam("port")long port) { |
| 88 | AccessDeviceService service = get(AccessDeviceService.class); |
| 89 | DeviceId deviceId = DeviceId.deviceId(device); |
| 90 | PortNumber portNumber = PortNumber.portNumber(port); |
| 91 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber); |
Andrea Campanella | 5111823 | 2021-07-01 17:18:02 +0200 | [diff] [blame] | 92 | try { |
| 93 | service.removeSubscriber(connectPoint); |
| 94 | } catch (Exception e) { |
| 95 | log.error("Can't remove subscriber {} due to exception", connectPoint, e); |
| 96 | return Response.status(INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); |
| 97 | } |
Jian Li | c39f08d | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 98 | return Response.noContent().build(); |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 99 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * Provision service for a subscriber. |
| 103 | * |
| 104 | * @param portName Name of the port on which the subscriber is connected |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 105 | * @return 200 OK or 204 NO CONTENT |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 106 | */ |
| 107 | @POST |
| 108 | @Produces(MediaType.APPLICATION_JSON) |
| 109 | @Path("services/{portName}") |
| 110 | public Response provisionServices( |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 111 | @PathParam("portName") String portName) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 112 | AccessDeviceService service = get(AccessDeviceService.class); |
| 113 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 114 | Optional<VlanId> emptyVlan = Optional.empty(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 115 | Optional<Integer> emptyTpId = Optional.empty(); |
| 116 | if (service.provisionSubscriber(new AccessSubscriberId(portName), emptyVlan, emptyVlan, emptyTpId)) { |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 117 | return ok("").build(); |
| 118 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 119 | return Response.noContent().build(); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Provision service with particular tags for a subscriber. |
| 124 | * |
| 125 | * @param portName Name of the port on which the subscriber is connected |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 126 | * @param sTagVal additional outer tag on this port |
| 127 | * @param cTagVal additional innter tag on this port |
| 128 | * @param tpIdVal technology profile id |
| 129 | * @return 200 OK or 204 NO CONTENT |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 130 | */ |
| 131 | @POST |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 132 | @Consumes(MediaType.APPLICATION_JSON) |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 133 | @Produces(MediaType.APPLICATION_JSON) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 134 | @Path("services/{portName}/{sTag}/{cTag}/{tpId}") |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 135 | public Response provisionAdditionalVlans( |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 136 | @PathParam("portName") String portName, |
| 137 | @PathParam("sTag") String sTagVal, |
| 138 | @PathParam("cTag") String cTagVal, |
| 139 | @PathParam("tpId") String tpIdVal) { |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 140 | AccessDeviceService service = get(AccessDeviceService.class); |
| 141 | VlanId cTag = VlanId.vlanId(cTagVal); |
| 142 | VlanId sTag = VlanId.vlanId(sTagVal); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 143 | Integer tpId = Integer.valueOf(tpIdVal); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 144 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 145 | if (service.provisionSubscriber(new AccessSubscriberId(portName), Optional.of(sTag), |
| 146 | Optional.of(cTag), Optional.of(tpId))) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 147 | return ok("").build(); |
| 148 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 149 | return Response.noContent().build(); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Removes services for a subscriber. |
| 154 | * |
| 155 | * @param portName Name of the port on which the subscriber is connected |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 156 | * @return 200 OK or 204 NO CONTENT |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 157 | */ |
| 158 | @DELETE |
| 159 | @Produces(MediaType.APPLICATION_JSON) |
| 160 | @Path("services/{portName}") |
| 161 | public Response deleteServices( |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 162 | @PathParam("portName") String portName) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 163 | AccessDeviceService service = get(AccessDeviceService.class); |
| 164 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 165 | Optional<VlanId> emptyVlan = Optional.empty(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 166 | Optional<Integer> emptyTpId = Optional.empty(); |
| 167 | if (service.removeSubscriber(new AccessSubscriberId(portName), emptyVlan, emptyVlan, emptyTpId)) { |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 168 | return ok("").build(); |
| 169 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 170 | return Response.noContent().build(); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Removes additional vlans of a particular subscriber. |
| 175 | * |
| 176 | * @param portName Name of the port on which the subscriber is connected |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 177 | * @param sTagVal additional outer tag on this port which needs to be removed |
| 178 | * @param cTagVal additional inner tag on this port which needs to be removed |
| 179 | * @param tpIdVal additional technology profile id |
| 180 | * @return 200 OK or 204 NO CONTENT |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 181 | */ |
| 182 | @DELETE |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 183 | @Consumes(MediaType.APPLICATION_JSON) |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 184 | @Produces(MediaType.APPLICATION_JSON) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 185 | @Path("services/{portName}/{sTag}/{cTag}/{tpId}") |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 186 | public Response removeAdditionalVlans( |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 187 | @PathParam("portName") String portName, |
| 188 | @PathParam("sTag") String sTagVal, |
| 189 | @PathParam("cTag") String cTagVal, |
| 190 | @PathParam("tpId") String tpIdVal) { |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 191 | AccessDeviceService service = get(AccessDeviceService.class); |
| 192 | VlanId cTag = VlanId.vlanId(cTagVal); |
| 193 | VlanId sTag = VlanId.vlanId(sTagVal); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 194 | Integer tpId = Integer.valueOf(tpIdVal); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 195 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 196 | if (service.removeSubscriber(new AccessSubscriberId(portName), Optional.of(sTag), |
| 197 | Optional.of(cTag), Optional.of(tpId))) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 198 | return ok("").build(); |
| 199 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 200 | return Response.noContent().build(); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 201 | } |
| 202 | |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 203 | } |