blob: 54af4ac944c823e897af06ba49209b930b3b259f [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 Ghoshe1d3f092018-10-09 19:44:33 +010018import org.onlab.packet.VlanId;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010019import org.onosproject.net.ConnectPoint;
20import org.onosproject.net.DeviceId;
21import org.onosproject.net.PortNumber;
22import org.onosproject.rest.AbstractWebResource;
23import org.opencord.olt.AccessDeviceService;
Amit Ghosh31939522018-08-16 13:28:21 +010024import org.opencord.olt.AccessSubscriberId;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010025
Amit Ghoshe1d3f092018-10-09 19:44:33 +010026import java.util.Optional;
Gamze Abaka1b7816e2019-11-25 06:38:41 +000027import javax.ws.rs.Consumes;
Ray Milkey17481412015-12-09 09:16:26 -080028import javax.ws.rs.DELETE;
29import javax.ws.rs.POST;
30import javax.ws.rs.Path;
31import javax.ws.rs.PathParam;
32import javax.ws.rs.Produces;
33import javax.ws.rs.core.MediaType;
34import javax.ws.rs.core.Response;
35
Gamze Abaka1b7816e2019-11-25 06:38:41 +000036import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
Amit Ghosh31939522018-08-16 13:28:21 +010037
Ray Milkey17481412015-12-09 09:16:26 -080038/**
39 * OLT REST APIs.
40 */
41
42@Path("oltapp")
43public class OltWebResource extends AbstractWebResource {
44
45 /**
46 * Provision a subscriber.
47 *
Jian Lid8bca082016-01-22 16:46:58 -080048 * @param device device id
49 * @param port port number
Gamze Abaka1b7816e2019-11-25 06:38:41 +000050 * @return 200 OK or 500 Internal Server Error
Ray Milkey17481412015-12-09 09:16:26 -080051 */
52 @POST
53 @Produces(MediaType.APPLICATION_JSON)
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010054 @Path("{device}/{port}")
Ray Milkey17481412015-12-09 09:16:26 -080055 public Response provisionSubscriber(
Gamze Abaka1b7816e2019-11-25 06:38:41 +000056 @PathParam("device") String device,
57 @PathParam("port") long port) {
Ray Milkey17481412015-12-09 09:16:26 -080058 AccessDeviceService service = get(AccessDeviceService.class);
59 DeviceId deviceId = DeviceId.deviceId(device);
60 PortNumber portNumber = PortNumber.portNumber(port);
Ray Milkey17481412015-12-09 09:16:26 -080061 ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber);
Gamze Abaka1b7816e2019-11-25 06:38:41 +000062 try {
63 service.provisionSubscriber(connectPoint);
64 } catch (Exception e) {
65 return Response.status(INTERNAL_SERVER_ERROR).build();
66 }
Ray Milkey17481412015-12-09 09:16:26 -080067 return ok("").build();
68 }
69
70 /**
71 * Remove the provisioning for a subscriber.
Jian Lid8bca082016-01-22 16:46:58 -080072 *
73 * @param device device id
74 * @param port port number
Jian Lic39f08d2016-05-10 11:48:19 -070075 * @return 204 NO CONTENT
Ray Milkey17481412015-12-09 09:16:26 -080076 */
77 @DELETE
Ray Milkey17481412015-12-09 09:16:26 -080078 @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 Lic39f08d2016-05-10 11:48:19 -070087 return Response.noContent().build();
Ray Milkey17481412015-12-09 09:16:26 -080088 }
Amit Ghosh31939522018-08-16 13:28:21 +010089
90 /**
91 * Provision service for a subscriber.
92 *
93 * @param portName Name of the port on which the subscriber is connected
Gamze Abaka1b7816e2019-11-25 06:38:41 +000094 * @return 200 OK or 204 NO CONTENT
Amit Ghosh31939522018-08-16 13:28:21 +010095 */
96 @POST
97 @Produces(MediaType.APPLICATION_JSON)
98 @Path("services/{portName}")
99 public Response provisionServices(
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000100 @PathParam("portName") String portName) {
Amit Ghosh31939522018-08-16 13:28:21 +0100101 AccessDeviceService service = get(AccessDeviceService.class);
102
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100103 Optional<VlanId> emptyVlan = Optional.empty();
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000104 Optional<Integer> emptyTpId = Optional.empty();
105 if (service.provisionSubscriber(new AccessSubscriberId(portName), emptyVlan, emptyVlan, emptyTpId)) {
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100106 return ok("").build();
107 }
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000108 return Response.noContent().build();
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100109 }
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
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000115 * @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 Ghoshe1d3f092018-10-09 19:44:33 +0100119 */
120 @POST
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000121 @Consumes(MediaType.APPLICATION_JSON)
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100122 @Produces(MediaType.APPLICATION_JSON)
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000123 @Path("services/{portName}/{sTag}/{cTag}/{tpId}")
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100124 public Response provisionAdditionalVlans(
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000125 @PathParam("portName") String portName,
126 @PathParam("sTag") String sTagVal,
127 @PathParam("cTag") String cTagVal,
128 @PathParam("tpId") String tpIdVal) {
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100129 AccessDeviceService service = get(AccessDeviceService.class);
130 VlanId cTag = VlanId.vlanId(cTagVal);
131 VlanId sTag = VlanId.vlanId(sTagVal);
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000132 Integer tpId = Integer.valueOf(tpIdVal);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100133
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000134 if (service.provisionSubscriber(new AccessSubscriberId(portName), Optional.of(sTag),
135 Optional.of(cTag), Optional.of(tpId))) {
Amit Ghosh31939522018-08-16 13:28:21 +0100136 return ok("").build();
137 }
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000138 return Response.noContent().build();
Amit Ghosh31939522018-08-16 13:28:21 +0100139 }
140
141 /**
142 * Removes services for a subscriber.
143 *
144 * @param portName Name of the port on which the subscriber is connected
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000145 * @return 200 OK or 204 NO CONTENT
Amit Ghosh31939522018-08-16 13:28:21 +0100146 */
147 @DELETE
148 @Produces(MediaType.APPLICATION_JSON)
149 @Path("services/{portName}")
150 public Response deleteServices(
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000151 @PathParam("portName") String portName) {
Amit Ghosh31939522018-08-16 13:28:21 +0100152 AccessDeviceService service = get(AccessDeviceService.class);
153
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100154 Optional<VlanId> emptyVlan = Optional.empty();
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000155 Optional<Integer> emptyTpId = Optional.empty();
156 if (service.removeSubscriber(new AccessSubscriberId(portName), emptyVlan, emptyVlan, emptyTpId)) {
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100157 return ok("").build();
158 }
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000159 return Response.noContent().build();
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100160 }
161
162 /**
163 * Removes additional vlans of a particular subscriber.
164 *
165 * @param portName Name of the port on which the subscriber is connected
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000166 * @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 Ghoshe1d3f092018-10-09 19:44:33 +0100170 */
171 @DELETE
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000172 @Consumes(MediaType.APPLICATION_JSON)
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100173 @Produces(MediaType.APPLICATION_JSON)
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000174 @Path("services/{portName}/{sTag}/{cTag}/{tpId}")
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100175 public Response removeAdditionalVlans(
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000176 @PathParam("portName") String portName,
177 @PathParam("sTag") String sTagVal,
178 @PathParam("cTag") String cTagVal,
179 @PathParam("tpId") String tpIdVal) {
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100180 AccessDeviceService service = get(AccessDeviceService.class);
181 VlanId cTag = VlanId.vlanId(cTagVal);
182 VlanId sTag = VlanId.vlanId(sTagVal);
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000183 Integer tpId = Integer.valueOf(tpIdVal);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100184
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000185 if (service.removeSubscriber(new AccessSubscriberId(portName), Optional.of(sTag),
186 Optional.of(cTag), Optional.of(tpId))) {
Amit Ghosh31939522018-08-16 13:28:21 +0100187 return ok("").build();
188 }
Gamze Abaka1b7816e2019-11-25 06:38:41 +0000189 return Response.noContent().build();
Amit Ghosh31939522018-08-16 13:28:21 +0100190 }
191
Ray Milkey17481412015-12-09 09:16:26 -0800192}