blob: 7b19b181a0b4a701eb6d6baa176c5edd4c0f0def [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;
Andrea Campanella51118232021-07-01 17:18:02 +020025import org.slf4j.Logger;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010026
Amit Ghoshe1d3f092018-10-09 19:44:33 +010027import java.util.Optional;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000028import javax.ws.rs.Consumes;
Ray Milkey17481412015-12-09 09:16:26 -080029import javax.ws.rs.DELETE;
30import javax.ws.rs.POST;
31import javax.ws.rs.Path;
32import javax.ws.rs.PathParam;
33import javax.ws.rs.Produces;
34import javax.ws.rs.core.MediaType;
35import javax.ws.rs.core.Response;
36
Andrea Campanellacbbb7952019-11-25 06:38:41 +000037import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
Andrea Campanella51118232021-07-01 17:18:02 +020038import static org.slf4j.LoggerFactory.getLogger;
Amit Ghosh31939522018-08-16 13:28:21 +010039
Ray Milkey17481412015-12-09 09:16:26 -080040/**
41 * OLT REST APIs.
42 */
43
44@Path("oltapp")
45public class OltWebResource extends AbstractWebResource {
46
Andrea Campanella51118232021-07-01 17:18:02 +020047 private final Logger log = getLogger(getClass());
48
49
Ray Milkey17481412015-12-09 09:16:26 -080050 /**
51 * Provision a subscriber.
52 *
Jian Lid8bca082016-01-22 16:46:58 -080053 * @param device device id
54 * @param port port number
Andrea Campanellacbbb7952019-11-25 06:38:41 +000055 * @return 200 OK or 500 Internal Server Error
Ray Milkey17481412015-12-09 09:16:26 -080056 */
57 @POST
58 @Produces(MediaType.APPLICATION_JSON)
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010059 @Path("{device}/{port}")
Ray Milkey17481412015-12-09 09:16:26 -080060 public Response provisionSubscriber(
Andrea Campanellacbbb7952019-11-25 06:38:41 +000061 @PathParam("device") String device,
62 @PathParam("port") long port) {
Ray Milkey17481412015-12-09 09:16:26 -080063 AccessDeviceService service = get(AccessDeviceService.class);
64 DeviceId deviceId = DeviceId.deviceId(device);
65 PortNumber portNumber = PortNumber.portNumber(port);
Ray Milkey17481412015-12-09 09:16:26 -080066 ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber);
Andrea Campanellacbbb7952019-11-25 06:38:41 +000067 try {
68 service.provisionSubscriber(connectPoint);
69 } catch (Exception e) {
Andrea Campanella51118232021-07-01 17:18:02 +020070 log.error("Can't provision subscriber {} due to exception", connectPoint, e);
71 return Response.status(INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
Andrea Campanellacbbb7952019-11-25 06:38:41 +000072 }
Ray Milkey17481412015-12-09 09:16:26 -080073 return ok("").build();
74 }
75
76 /**
77 * Remove the provisioning for a subscriber.
Jian Lid8bca082016-01-22 16:46:58 -080078 *
79 * @param device device id
80 * @param port port number
Jian Lic39f08d2016-05-10 11:48:19 -070081 * @return 204 NO CONTENT
Ray Milkey17481412015-12-09 09:16:26 -080082 */
83 @DELETE
Ray Milkey17481412015-12-09 09:16:26 -080084 @Path("{device}/{port}")
85 public Response removeSubscriber(
86 @PathParam("device")String device,
87 @PathParam("port")long port) {
88 AccessDeviceService service = get(AccessDeviceService.class);
89 DeviceId deviceId = DeviceId.deviceId(device);
90 PortNumber portNumber = PortNumber.portNumber(port);
91 ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber);
Andrea Campanella51118232021-07-01 17:18:02 +020092 try {
93 service.removeSubscriber(connectPoint);
94 } catch (Exception e) {
95 log.error("Can't remove subscriber {} due to exception", connectPoint, e);
96 return Response.status(INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
97 }
Jian Lic39f08d2016-05-10 11:48:19 -070098 return Response.noContent().build();
Ray Milkey17481412015-12-09 09:16:26 -080099 }
Amit Ghosh31939522018-08-16 13:28:21 +0100100
101 /**
102 * Provision service for a subscriber.
103 *
104 * @param portName Name of the port on which the subscriber is connected
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000105 * @return 200 OK or 204 NO CONTENT
Amit Ghosh31939522018-08-16 13:28:21 +0100106 */
107 @POST
108 @Produces(MediaType.APPLICATION_JSON)
109 @Path("services/{portName}")
110 public Response provisionServices(
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000111 @PathParam("portName") String portName) {
Amit Ghosh31939522018-08-16 13:28:21 +0100112 AccessDeviceService service = get(AccessDeviceService.class);
113
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100114 Optional<VlanId> emptyVlan = Optional.empty();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000115 Optional<Integer> emptyTpId = Optional.empty();
116 if (service.provisionSubscriber(new AccessSubscriberId(portName), emptyVlan, emptyVlan, emptyTpId)) {
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100117 return ok("").build();
118 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000119 return Response.noContent().build();
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100120 }
121
122 /**
123 * Provision service with particular tags for a subscriber.
124 *
125 * @param portName Name of the port on which the subscriber is connected
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000126 * @param sTagVal additional outer tag on this port
127 * @param cTagVal additional innter tag on this port
128 * @param tpIdVal technology profile id
129 * @return 200 OK or 204 NO CONTENT
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100130 */
131 @POST
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000132 @Consumes(MediaType.APPLICATION_JSON)
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100133 @Produces(MediaType.APPLICATION_JSON)
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000134 @Path("services/{portName}/{sTag}/{cTag}/{tpId}")
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100135 public Response provisionAdditionalVlans(
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000136 @PathParam("portName") String portName,
137 @PathParam("sTag") String sTagVal,
138 @PathParam("cTag") String cTagVal,
139 @PathParam("tpId") String tpIdVal) {
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100140 AccessDeviceService service = get(AccessDeviceService.class);
141 VlanId cTag = VlanId.vlanId(cTagVal);
142 VlanId sTag = VlanId.vlanId(sTagVal);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000143 Integer tpId = Integer.valueOf(tpIdVal);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100144
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000145 if (service.provisionSubscriber(new AccessSubscriberId(portName), Optional.of(sTag),
146 Optional.of(cTag), Optional.of(tpId))) {
Amit Ghosh31939522018-08-16 13:28:21 +0100147 return ok("").build();
148 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000149 return Response.noContent().build();
Amit Ghosh31939522018-08-16 13:28:21 +0100150 }
151
152 /**
153 * Removes services for a subscriber.
154 *
155 * @param portName Name of the port on which the subscriber is connected
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000156 * @return 200 OK or 204 NO CONTENT
Amit Ghosh31939522018-08-16 13:28:21 +0100157 */
158 @DELETE
159 @Produces(MediaType.APPLICATION_JSON)
160 @Path("services/{portName}")
161 public Response deleteServices(
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000162 @PathParam("portName") String portName) {
Amit Ghosh31939522018-08-16 13:28:21 +0100163 AccessDeviceService service = get(AccessDeviceService.class);
164
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100165 Optional<VlanId> emptyVlan = Optional.empty();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000166 Optional<Integer> emptyTpId = Optional.empty();
167 if (service.removeSubscriber(new AccessSubscriberId(portName), emptyVlan, emptyVlan, emptyTpId)) {
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100168 return ok("").build();
169 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000170 return Response.noContent().build();
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100171 }
172
173 /**
174 * Removes additional vlans of a particular subscriber.
175 *
176 * @param portName Name of the port on which the subscriber is connected
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000177 * @param sTagVal additional outer tag on this port which needs to be removed
178 * @param cTagVal additional inner tag on this port which needs to be removed
179 * @param tpIdVal additional technology profile id
180 * @return 200 OK or 204 NO CONTENT
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100181 */
182 @DELETE
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000183 @Consumes(MediaType.APPLICATION_JSON)
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100184 @Produces(MediaType.APPLICATION_JSON)
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000185 @Path("services/{portName}/{sTag}/{cTag}/{tpId}")
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100186 public Response removeAdditionalVlans(
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000187 @PathParam("portName") String portName,
188 @PathParam("sTag") String sTagVal,
189 @PathParam("cTag") String cTagVal,
190 @PathParam("tpId") String tpIdVal) {
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100191 AccessDeviceService service = get(AccessDeviceService.class);
192 VlanId cTag = VlanId.vlanId(cTagVal);
193 VlanId sTag = VlanId.vlanId(sTagVal);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000194 Integer tpId = Integer.valueOf(tpIdVal);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100195
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000196 if (service.removeSubscriber(new AccessSubscriberId(portName), Optional.of(sTag),
197 Optional.of(cTag), Optional.of(tpId))) {
Amit Ghosh31939522018-08-16 13:28:21 +0100198 return ok("").build();
199 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000200 return Response.noContent().build();
Amit Ghosh31939522018-08-16 13:28:21 +0100201 }
202
Ray Milkey17481412015-12-09 09:16:26 -0800203}