blob: af7f2a2fba4dd30de1397826369ebe9a5d471189 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
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 Vachuska140d5852014-10-16 12:17:45 -070019package org.onlab.onos.calendar;
20
21import org.onlab.onos.net.ConnectPoint;
22import org.onlab.onos.net.DeviceId;
23import org.onlab.onos.net.intent.IntentService;
24import org.onlab.rest.BaseResource;
25
26import javax.ws.rs.POST;
27import javax.ws.rs.Path;
28import javax.ws.rs.PathParam;
29import javax.ws.rs.core.Response;
30import java.net.URI;
31
32import static org.onlab.onos.net.PortNumber.portNumber;
33
34/**
35 * Web resource for triggering calendared intents.
36 */
37@Path("intent")
38public 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}