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 | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 18 | import org.onosproject.net.ConnectPoint; |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | import org.onosproject.net.PortNumber; |
| 21 | import org.onosproject.rest.AbstractWebResource; |
| 22 | import org.opencord.olt.AccessDeviceService; |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame^] | 23 | import org.opencord.olt.AccessSubscriberId; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 24 | |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 25 | import javax.ws.rs.DELETE; |
| 26 | import javax.ws.rs.POST; |
| 27 | import javax.ws.rs.Path; |
| 28 | import javax.ws.rs.PathParam; |
| 29 | import javax.ws.rs.Produces; |
| 30 | import javax.ws.rs.core.MediaType; |
| 31 | import javax.ws.rs.core.Response; |
| 32 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame^] | 33 | import static javax.ws.rs.core.Response.Status.NOT_FOUND; |
| 34 | |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 35 | /** |
| 36 | * OLT REST APIs. |
| 37 | */ |
| 38 | |
| 39 | @Path("oltapp") |
| 40 | public class OltWebResource extends AbstractWebResource { |
| 41 | |
| 42 | /** |
| 43 | * Provision a subscriber. |
| 44 | * |
Jian Li | d8bca08 | 2016-01-22 16:46:58 -0800 | [diff] [blame] | 45 | * @param device device id |
| 46 | * @param port port number |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 47 | * @return 200 OK |
| 48 | */ |
| 49 | @POST |
| 50 | @Produces(MediaType.APPLICATION_JSON) |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 51 | @Path("{device}/{port}") |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 52 | public Response provisionSubscriber( |
| 53 | @PathParam("device")String device, |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 54 | @PathParam("port")long port) { |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 55 | AccessDeviceService service = get(AccessDeviceService.class); |
| 56 | DeviceId deviceId = DeviceId.deviceId(device); |
| 57 | PortNumber portNumber = PortNumber.portNumber(port); |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 58 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 59 | service.provisionSubscriber(connectPoint); |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 60 | return ok("").build(); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Remove the provisioning for a subscriber. |
Jian Li | d8bca08 | 2016-01-22 16:46:58 -0800 | [diff] [blame] | 65 | * |
| 66 | * @param device device id |
| 67 | * @param port port number |
Jian Li | c39f08d | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 68 | * @return 204 NO CONTENT |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 69 | */ |
| 70 | @DELETE |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 71 | @Path("{device}/{port}") |
| 72 | public Response removeSubscriber( |
| 73 | @PathParam("device")String device, |
| 74 | @PathParam("port")long port) { |
| 75 | AccessDeviceService service = get(AccessDeviceService.class); |
| 76 | DeviceId deviceId = DeviceId.deviceId(device); |
| 77 | PortNumber portNumber = PortNumber.portNumber(port); |
| 78 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber); |
| 79 | service.removeSubscriber(connectPoint); |
Jian Li | c39f08d | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 80 | return Response.noContent().build(); |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 81 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame^] | 82 | |
| 83 | /** |
| 84 | * Provision service for a subscriber. |
| 85 | * |
| 86 | * @param portName Name of the port on which the subscriber is connected |
| 87 | * @return 200 OK or 404 NOT_FOUND |
| 88 | */ |
| 89 | @POST |
| 90 | @Produces(MediaType.APPLICATION_JSON) |
| 91 | @Path("services/{portName}") |
| 92 | public Response provisionServices( |
| 93 | @PathParam("portName")String portName) { |
| 94 | AccessDeviceService service = get(AccessDeviceService.class); |
| 95 | |
| 96 | if (service.provisionSubscriber(new AccessSubscriberId(portName))) { |
| 97 | return ok("").build(); |
| 98 | } |
| 99 | return Response.status(NOT_FOUND).build(); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Removes services for a subscriber. |
| 104 | * |
| 105 | * @param portName Name of the port on which the subscriber is connected |
| 106 | * @return 200 OK or 404 NOT_FOUND |
| 107 | */ |
| 108 | @DELETE |
| 109 | @Produces(MediaType.APPLICATION_JSON) |
| 110 | @Path("services/{portName}") |
| 111 | public Response deleteServices( |
| 112 | @PathParam("portName")String portName) { |
| 113 | AccessDeviceService service = get(AccessDeviceService.class); |
| 114 | |
| 115 | if (service.removeSubscriber(new AccessSubscriberId(portName))) { |
| 116 | return ok("").build(); |
| 117 | } |
| 118 | return Response.status(NOT_FOUND).build(); |
| 119 | } |
| 120 | |
Ray Milkey | 1748141 | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 121 | } |