blob: 4a786f05c2b522dfe696d74e3056a0d463022995 [file] [log] [blame]
Ray Milkey17481412015-12-09 09:16:26 -08001/*
Brian O'Connord6a135a2017-08-03 22:46:05 -07002 * Copyright 2016-present Open Networking Foundation
Ray Milkey17481412015-12-09 09:16:26 -08003 *
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 */
alshabib36a4d732016-06-01 16:03:59 -070016package org.opencord.olt.rest;
Ray Milkey17481412015-12-09 09:16:26 -080017
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010018import org.onosproject.net.ConnectPoint;
19import org.onosproject.net.DeviceId;
20import org.onosproject.net.PortNumber;
21import org.onosproject.rest.AbstractWebResource;
22import org.opencord.olt.AccessDeviceService;
Amit Ghosh31939522018-08-16 13:28:21 +010023import org.opencord.olt.AccessSubscriberId;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010024
Ray Milkey17481412015-12-09 09:16:26 -080025import javax.ws.rs.DELETE;
26import javax.ws.rs.POST;
27import javax.ws.rs.Path;
28import javax.ws.rs.PathParam;
29import javax.ws.rs.Produces;
30import javax.ws.rs.core.MediaType;
31import javax.ws.rs.core.Response;
32
Amit Ghosh31939522018-08-16 13:28:21 +010033import static javax.ws.rs.core.Response.Status.NOT_FOUND;
34
Ray Milkey17481412015-12-09 09:16:26 -080035/**
36 * OLT REST APIs.
37 */
38
39@Path("oltapp")
40public class OltWebResource extends AbstractWebResource {
41
42 /**
43 * Provision a subscriber.
44 *
Jian Lid8bca082016-01-22 16:46:58 -080045 * @param device device id
46 * @param port port number
Ray Milkey17481412015-12-09 09:16:26 -080047 * @return 200 OK
48 */
49 @POST
50 @Produces(MediaType.APPLICATION_JSON)
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010051 @Path("{device}/{port}")
Ray Milkey17481412015-12-09 09:16:26 -080052 public Response provisionSubscriber(
53 @PathParam("device")String device,
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010054 @PathParam("port")long port) {
Ray Milkey17481412015-12-09 09:16:26 -080055 AccessDeviceService service = get(AccessDeviceService.class);
56 DeviceId deviceId = DeviceId.deviceId(device);
57 PortNumber portNumber = PortNumber.portNumber(port);
Ray Milkey17481412015-12-09 09:16:26 -080058 ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010059 service.provisionSubscriber(connectPoint);
Ray Milkey17481412015-12-09 09:16:26 -080060 return ok("").build();
61 }
62
63 /**
64 * Remove the provisioning for a subscriber.
Jian Lid8bca082016-01-22 16:46:58 -080065 *
66 * @param device device id
67 * @param port port number
Jian Lic39f08d2016-05-10 11:48:19 -070068 * @return 204 NO CONTENT
Ray Milkey17481412015-12-09 09:16:26 -080069 */
70 @DELETE
Ray Milkey17481412015-12-09 09:16:26 -080071 @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 Lic39f08d2016-05-10 11:48:19 -070080 return Response.noContent().build();
Ray Milkey17481412015-12-09 09:16:26 -080081 }
Amit Ghosh31939522018-08-16 13:28:21 +010082
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 Milkey17481412015-12-09 09:16:26 -0800121}