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