blob: 1631b099b9498ad13c9a274ec00e41d858dd2272 [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;
Ray Milkey17481412015-12-09 09:16:26 -080027import javax.ws.rs.DELETE;
28import javax.ws.rs.POST;
29import javax.ws.rs.Path;
30import javax.ws.rs.PathParam;
31import javax.ws.rs.Produces;
32import javax.ws.rs.core.MediaType;
33import javax.ws.rs.core.Response;
34
Amit Ghosh31939522018-08-16 13:28:21 +010035import static javax.ws.rs.core.Response.Status.NOT_FOUND;
36
Ray Milkey17481412015-12-09 09:16:26 -080037/**
38 * OLT REST APIs.
39 */
40
41@Path("oltapp")
42public class OltWebResource extends AbstractWebResource {
43
44 /**
45 * Provision a subscriber.
46 *
Jian Lid8bca082016-01-22 16:46:58 -080047 * @param device device id
48 * @param port port number
Ray Milkey17481412015-12-09 09:16:26 -080049 * @return 200 OK
50 */
51 @POST
52 @Produces(MediaType.APPLICATION_JSON)
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010053 @Path("{device}/{port}")
Ray Milkey17481412015-12-09 09:16:26 -080054 public Response provisionSubscriber(
55 @PathParam("device")String device,
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010056 @PathParam("port")long port) {
Ray Milkey17481412015-12-09 09:16:26 -080057 AccessDeviceService service = get(AccessDeviceService.class);
58 DeviceId deviceId = DeviceId.deviceId(device);
59 PortNumber portNumber = PortNumber.portNumber(port);
Ray Milkey17481412015-12-09 09:16:26 -080060 ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010061 service.provisionSubscriber(connectPoint);
Ray Milkey17481412015-12-09 09:16:26 -080062 return ok("").build();
63 }
64
65 /**
66 * Remove the provisioning for a subscriber.
Jian Lid8bca082016-01-22 16:46:58 -080067 *
68 * @param device device id
69 * @param port port number
Jian Lic39f08d2016-05-10 11:48:19 -070070 * @return 204 NO CONTENT
Ray Milkey17481412015-12-09 09:16:26 -080071 */
72 @DELETE
Ray Milkey17481412015-12-09 09:16:26 -080073 @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 Lic39f08d2016-05-10 11:48:19 -070082 return Response.noContent().build();
Ray Milkey17481412015-12-09 09:16:26 -080083 }
Amit Ghosh31939522018-08-16 13:28:21 +010084
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 Ghoshe1d3f092018-10-09 19:44:33 +010098 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 Ghosh31939522018-08-16 13:28:21 +0100125 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 Ghoshe1d3f092018-10-09 19:44:33 +0100143 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 Ghosh31939522018-08-16 13:28:21 +0100170 return ok("").build();
171 }
172 return Response.status(NOT_FOUND).build();
173 }
174
Ray Milkey17481412015-12-09 09:16:26 -0800175}