Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -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 | 83e090e | 2014-10-22 14:25:35 -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 | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.intent; |
| 17 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableList; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 20 | import org.onlab.onos.core.ApplicationId; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 21 | import org.onlab.onos.net.ConnectPoint; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 22 | import org.onlab.onos.net.Link; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 23 | import org.onlab.onos.net.flow.TrafficSelector; |
| 24 | import org.onlab.onos.net.flow.TrafficTreatment; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 25 | import org.onlab.onos.net.intent.constraint.LinkTypeConstraint; |
| 26 | |
| 27 | import java.util.List; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 28 | |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 29 | import static com.google.common.base.Preconditions.checkArgument; |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 30 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Abstraction of point-to-point connectivity. |
| 34 | */ |
| 35 | public class PointToPointIntent extends ConnectivityIntent { |
| 36 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 37 | private final ConnectPoint ingressPoint; |
| 38 | private final ConnectPoint egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Creates a new point-to-point intent with the supplied ingress/egress |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 42 | * ports and with built-in link type constraint to avoid optical links. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 43 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 44 | * @param appId application identifier |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 45 | * @param selector traffic selector |
| 46 | * @param treatment treatment |
| 47 | * @param ingressPoint ingress port |
| 48 | * @param egressPoint egress port |
| 49 | * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 50 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 51 | public PointToPointIntent(ApplicationId appId, TrafficSelector selector, |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 52 | TrafficTreatment treatment, |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 53 | ConnectPoint ingressPoint, |
| 54 | ConnectPoint egressPoint) { |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 55 | this(appId, selector, treatment, ingressPoint, egressPoint, |
| 56 | ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL))); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Creates a new point-to-point intent with the supplied ingress/egress |
| 61 | * ports and constraints. |
| 62 | * |
| 63 | * @param appId application identifier |
| 64 | * @param selector traffic selector |
| 65 | * @param treatment treatment |
| 66 | * @param ingressPoint ingress port |
| 67 | * @param egressPoint egress port |
| 68 | * @param constraints optional list of constraints |
| 69 | * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null. |
| 70 | */ |
| 71 | public PointToPointIntent(ApplicationId appId, TrafficSelector selector, |
| 72 | TrafficTreatment treatment, |
| 73 | ConnectPoint ingressPoint, |
| 74 | ConnectPoint egressPoint, |
| 75 | List<Constraint> constraints) { |
| 76 | super(id(PointToPointIntent.class, selector, treatment, |
| 77 | ingressPoint, egressPoint, constraints), |
| 78 | appId, null, selector, treatment, constraints); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 79 | |
| 80 | checkNotNull(ingressPoint); |
| 81 | checkNotNull(egressPoint); |
| 82 | checkArgument(!ingressPoint.equals(egressPoint), |
| 83 | "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint); |
| 84 | |
| 85 | this.ingressPoint = ingressPoint; |
| 86 | this.egressPoint = egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Constructor for serializer. |
| 91 | */ |
| 92 | protected PointToPointIntent() { |
| 93 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 94 | this.ingressPoint = null; |
| 95 | this.egressPoint = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Returns the port on which the ingress traffic should be connected to |
| 100 | * the egress. |
| 101 | * |
| 102 | * @return ingress port |
| 103 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 104 | public ConnectPoint ingressPoint() { |
| 105 | return ingressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns the port on which the traffic should egress. |
| 110 | * |
| 111 | * @return egress port |
| 112 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 113 | public ConnectPoint egressPoint() { |
| 114 | return egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 118 | public String toString() { |
| 119 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 120 | .add("id", id()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 121 | .add("appId", appId()) |
| 122 | .add("selector", selector()) |
| 123 | .add("treatment", treatment()) |
| 124 | .add("ingress", ingressPoint) |
| 125 | .add("egress", egressPoint) |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 126 | .add("constraints", constraints()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 127 | .toString(); |
| 128 | } |
| 129 | |
| 130 | } |