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