Ray Milkey | 30d3f8b | 2015-12-09 09:16:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | */ |
| 16 | package org.onosproject.olt.rest; |
| 17 | |
| 18 | import javax.ws.rs.DELETE; |
| 19 | import javax.ws.rs.POST; |
| 20 | import javax.ws.rs.Path; |
| 21 | import javax.ws.rs.PathParam; |
| 22 | import javax.ws.rs.Produces; |
| 23 | import javax.ws.rs.core.MediaType; |
| 24 | import javax.ws.rs.core.Response; |
| 25 | |
| 26 | import org.onlab.packet.VlanId; |
| 27 | import org.onosproject.net.ConnectPoint; |
| 28 | import org.onosproject.net.DeviceId; |
| 29 | import org.onosproject.net.PortNumber; |
| 30 | import org.onosproject.olt.AccessDeviceService; |
| 31 | import org.onosproject.rest.AbstractWebResource; |
| 32 | |
| 33 | /** |
| 34 | * OLT REST APIs. |
| 35 | */ |
| 36 | |
| 37 | @Path("oltapp") |
| 38 | public class OltWebResource extends AbstractWebResource { |
| 39 | |
| 40 | /** |
| 41 | * Provision a subscriber. |
| 42 | * |
| 43 | * @return 200 OK |
| 44 | */ |
| 45 | @POST |
| 46 | @Produces(MediaType.APPLICATION_JSON) |
| 47 | @Path("{device}/{port}/{vlan}") |
| 48 | public Response provisionSubscriber( |
| 49 | @PathParam("device")String device, |
| 50 | @PathParam("port")long port, |
| 51 | @PathParam("vlan")short vlan) { |
| 52 | AccessDeviceService service = get(AccessDeviceService.class); |
| 53 | DeviceId deviceId = DeviceId.deviceId(device); |
| 54 | PortNumber portNumber = PortNumber.portNumber(port); |
| 55 | VlanId vlanId = VlanId.vlanId(vlan); |
| 56 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber); |
| 57 | service.provisionSubscriber(connectPoint, vlanId); |
| 58 | return ok("").build(); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Remove the provisioning for a subscriber. |
| 63 | */ |
| 64 | @DELETE |
| 65 | @Produces(MediaType.APPLICATION_JSON) |
| 66 | @Path("{device}/{port}") |
| 67 | public Response removeSubscriber( |
| 68 | @PathParam("device")String device, |
| 69 | @PathParam("port")long port) { |
| 70 | AccessDeviceService service = get(AccessDeviceService.class); |
| 71 | DeviceId deviceId = DeviceId.deviceId(device); |
| 72 | PortNumber portNumber = PortNumber.portNumber(port); |
| 73 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber); |
| 74 | service.removeSubscriber(connectPoint); |
| 75 | return ok("").build(); |
| 76 | } |
| 77 | } |