Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 19 | package org.onlab.onos.calendar; |
| 20 | |
| 21 | import org.onlab.onos.net.ConnectPoint; |
| 22 | import org.onlab.onos.net.DeviceId; |
| 23 | import org.onlab.onos.net.intent.IntentService; |
| 24 | import org.onlab.rest.BaseResource; |
| 25 | |
| 26 | import javax.ws.rs.POST; |
| 27 | import javax.ws.rs.Path; |
| 28 | import javax.ws.rs.PathParam; |
| 29 | import javax.ws.rs.core.Response; |
| 30 | import java.net.URI; |
| 31 | |
| 32 | import static org.onlab.onos.net.PortNumber.portNumber; |
| 33 | |
| 34 | /** |
| 35 | * Web resource for triggering calendared intents. |
| 36 | */ |
| 37 | @Path("intent") |
| 38 | public class BandwidthCalendarResource extends BaseResource { |
| 39 | |
| 40 | @POST |
| 41 | @Path("{src}/{dst}/{srcPort}/{dstPort}/{bandwidth}") |
| 42 | public Response createIntent(@PathParam("src") String src, |
| 43 | @PathParam("dst") String dst, |
| 44 | @PathParam("srcPort") String srcPort, |
| 45 | @PathParam("dstPort") String dstPort, |
| 46 | @PathParam("bandwidth") String bandwidth) { |
| 47 | // TODO: implement calls to intent framework |
| 48 | IntentService service = get(IntentService.class); |
| 49 | |
| 50 | ConnectPoint srcPoint = new ConnectPoint(deviceId(src), portNumber(srcPort)); |
| 51 | ConnectPoint dstPoint = new ConnectPoint(deviceId(dst), portNumber(dstPort)); |
| 52 | |
| 53 | return Response.ok("Yo! We got src=" + srcPoint + "; dst=" + dstPoint + |
| 54 | "; bw=" + bandwidth + "; intent service " + service).build(); |
| 55 | } |
| 56 | |
| 57 | private DeviceId deviceId(String dpid) { |
| 58 | return DeviceId.deviceId(URI.create("of:" + dpid)); |
| 59 | } |
| 60 | |
| 61 | } |