Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 16 | package org.onlab.onos.calendar; |
| 17 | |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 18 | import java.net.URI; |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 19 | import org.onlab.onos.net.ConnectPoint; |
| 20 | import org.onlab.onos.net.DeviceId; |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame^] | 21 | import org.onlab.onos.net.intent.IntentService; |
| 22 | import org.onlab.rest.BaseResource; |
| 23 | import javax.ws.rs.POST; |
| 24 | import javax.ws.rs.DELETE; |
| 25 | import javax.ws.rs.PathParam; |
| 26 | import javax.ws.rs.core.Response; |
| 27 | import org.onlab.onos.core.ApplicationId; |
| 28 | import org.onlab.onos.core.CoreService; |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 29 | import org.onlab.onos.net.flow.DefaultTrafficSelector; |
| 30 | import org.onlab.onos.net.flow.TrafficSelector; |
| 31 | import org.onlab.onos.net.flow.TrafficTreatment; |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame^] | 32 | import org.onlab.onos.net.intent.PointToPointIntent; |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 33 | import org.onlab.packet.Ethernet; |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 34 | import static org.onlab.onos.net.PortNumber.portNumber; |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 35 | import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder; |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 36 | |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame^] | 37 | import static org.slf4j.LoggerFactory.getLogger; |
| 38 | import org.slf4j.Logger; |
| 39 | |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Web resource for triggering calendared intents. |
| 42 | */ |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame^] | 43 | @javax.ws.rs.Path("intent") |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 44 | public class BandwidthCalendarResource extends BaseResource { |
| 45 | |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame^] | 46 | private static final Logger log = getLogger(BandwidthCalendarResource.class); |
| 47 | |
| 48 | @javax.ws.rs.Path("/{src}/{dst}/{srcPort}/{dstPort}/{bandwidth}") |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 49 | @POST |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 50 | public Response createIntent(@PathParam("src") String src, |
| 51 | @PathParam("dst") String dst, |
| 52 | @PathParam("srcPort") String srcPort, |
| 53 | @PathParam("dstPort") String dstPort, |
| 54 | @PathParam("bandwidth") String bandwidth) { |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame^] | 55 | |
| 56 | log.info("Receiving Create Intent request..."); |
| 57 | log.info("Path Constraints: Src = {} SrcPort = {} Dest = {} DestPort = {} BW = {}", |
| 58 | src, srcPort, dst, dstPort, bandwidth); |
| 59 | |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 60 | IntentService service = get(IntentService.class); |
| 61 | |
| 62 | ConnectPoint srcPoint = new ConnectPoint(deviceId(src), portNumber(srcPort)); |
| 63 | ConnectPoint dstPoint = new ConnectPoint(deviceId(dst), portNumber(dstPort)); |
| 64 | |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 65 | TrafficSelector selector = buildTrafficSelector(); |
| 66 | TrafficTreatment treatment = builder().build(); |
| 67 | |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame^] | 68 | PointToPointIntent intentP2P = |
| 69 | new PointToPointIntent(appId(), selector, treatment, |
| 70 | srcPoint, dstPoint); |
| 71 | service.submit(intentP2P); |
| 72 | log.info("Submitted Calendar App intent: src = " + src + "dest = " + dst |
| 73 | + "srcPort = " + srcPort + "destPort" + dstPort + "intentID = " + intentP2P.id().toString()); |
| 74 | String reply = intentP2P.id().toString() + "\n"; |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 75 | |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame^] | 76 | return Response.ok(reply).build(); |
| 77 | } |
| 78 | |
| 79 | @javax.ws.rs.Path("/cancellation/{intentId}") |
| 80 | @DELETE |
| 81 | public Response withdrawIntent(@PathParam("intentId") String intentId) { |
| 82 | |
| 83 | log.info("Receiving Teardown request..."); |
| 84 | log.info("Withdraw intentId = {} ", intentId); |
| 85 | |
| 86 | String reply = "ok\n"; |
| 87 | return Response.ok(reply).build(); |
| 88 | } |
| 89 | |
| 90 | @javax.ws.rs.Path("/modification/{intentId}/{bandwidth}") |
| 91 | @POST |
| 92 | public Response modifyBandwidth(@PathParam("intentId") String intentId, |
| 93 | @PathParam("bandwidth") String bandwidth) { |
| 94 | |
| 95 | log.info("Receiving Modify request..."); |
| 96 | log.info("Modify bw for intentId = {} with new bandwidth = {}", intentId, bandwidth); |
| 97 | |
| 98 | String reply = "ok\n"; |
| 99 | return Response.ok(reply).build(); |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 102 | private TrafficSelector buildTrafficSelector() { |
| 103 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
| 104 | Short ethType = Ethernet.TYPE_IPV4; |
| 105 | |
| 106 | selectorBuilder.matchEthType(ethType); |
| 107 | |
| 108 | return selectorBuilder.build(); |
| 109 | } |
| 110 | |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 111 | private DeviceId deviceId(String dpid) { |
| 112 | return DeviceId.deviceId(URI.create("of:" + dpid)); |
| 113 | } |
| 114 | |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 115 | protected ApplicationId appId() { |
| 116 | return get(CoreService.class).registerApplication("org.onlab.onos.calendar"); |
| 117 | } |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 118 | } |