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 | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 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; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.Link; |
| 23 | import org.onosproject.net.flow.TrafficSelector; |
| 24 | import org.onosproject.net.flow.TrafficTreatment; |
| 25 | import org.onosproject.net.intent.constraint.LinkTypeConstraint; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 26 | |
Sho SHIMIZU | d7d1800 | 2015-01-21 14:37:14 -0800 | [diff] [blame] | 27 | import java.util.Collections; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 28 | import java.util.List; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 29 | |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 30 | import static com.google.common.base.Preconditions.checkArgument; |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 31 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Abstraction of point-to-point connectivity. |
| 35 | */ |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 36 | public final class PointToPointIntent extends ConnectivityIntent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 37 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 38 | private final ConnectPoint ingressPoint; |
| 39 | private final ConnectPoint egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Creates a new point-to-point intent with the supplied ingress/egress |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 43 | * ports and constraints. |
| 44 | * |
| 45 | * @param appId application identifier |
| 46 | * @param key key of the intent |
| 47 | * @param selector traffic selector |
| 48 | * @param treatment treatment |
| 49 | * @param ingressPoint ingress port |
| 50 | * @param egressPoint egress port |
| 51 | * @param constraints optional list of constraints |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame^] | 52 | * @param priority priority to use for flows generated by this intent |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 53 | * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null. |
| 54 | */ |
| 55 | public PointToPointIntent(ApplicationId appId, |
| 56 | Key key, |
| 57 | TrafficSelector selector, |
| 58 | TrafficTreatment treatment, |
| 59 | ConnectPoint ingressPoint, |
| 60 | ConnectPoint egressPoint, |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame^] | 61 | List<Constraint> constraints, |
| 62 | int priority) { |
| 63 | super(appId, key, Collections.emptyList(), selector, treatment, constraints, |
| 64 | priority); |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 65 | |
| 66 | checkNotNull(ingressPoint); |
| 67 | checkNotNull(egressPoint); |
| 68 | checkArgument(!ingressPoint.equals(egressPoint), |
| 69 | "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint); |
| 70 | |
| 71 | this.ingressPoint = ingressPoint; |
| 72 | this.egressPoint = egressPoint; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Creates a new point-to-point intent with the supplied ingress/egress |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 77 | * 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] | 78 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 79 | * @param appId application identifier |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 80 | * @param selector traffic selector |
| 81 | * @param treatment treatment |
| 82 | * @param ingressPoint ingress port |
| 83 | * @param egressPoint egress port |
| 84 | * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 85 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 86 | public PointToPointIntent(ApplicationId appId, TrafficSelector selector, |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 87 | TrafficTreatment treatment, |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 88 | ConnectPoint ingressPoint, |
| 89 | ConnectPoint egressPoint) { |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 90 | this(appId, null, selector, treatment, ingressPoint, egressPoint, |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame^] | 91 | ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)), |
| 92 | DEFAULT_INTENT_PRIORITY); |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Creates a new point-to-point intent with the supplied ingress/egress |
| 97 | * ports and constraints. |
| 98 | * |
| 99 | * @param appId application identifier |
| 100 | * @param selector traffic selector |
| 101 | * @param treatment treatment |
| 102 | * @param ingressPoint ingress port |
| 103 | * @param egressPoint egress port |
| 104 | * @param constraints optional list of constraints |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame^] | 105 | * @param priority priority to use for flows generated by this intent |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 106 | * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null. |
| 107 | */ |
| 108 | public PointToPointIntent(ApplicationId appId, TrafficSelector selector, |
| 109 | TrafficTreatment treatment, |
| 110 | ConnectPoint ingressPoint, |
| 111 | ConnectPoint egressPoint, |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame^] | 112 | List<Constraint> constraints, |
| 113 | int priority) { |
| 114 | super(appId, null, Collections.emptyList(), selector, treatment, |
| 115 | constraints, priority); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 116 | |
| 117 | checkNotNull(ingressPoint); |
| 118 | checkNotNull(egressPoint); |
| 119 | checkArgument(!ingressPoint.equals(egressPoint), |
| 120 | "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint); |
| 121 | |
| 122 | this.ingressPoint = ingressPoint; |
| 123 | this.egressPoint = egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Constructor for serializer. |
| 128 | */ |
| 129 | protected PointToPointIntent() { |
| 130 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 131 | this.ingressPoint = null; |
| 132 | this.egressPoint = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Returns the port on which the ingress traffic should be connected to |
| 137 | * the egress. |
| 138 | * |
| 139 | * @return ingress port |
| 140 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 141 | public ConnectPoint ingressPoint() { |
| 142 | return ingressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Returns the port on which the traffic should egress. |
| 147 | * |
| 148 | * @return egress port |
| 149 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 150 | public ConnectPoint egressPoint() { |
| 151 | return egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 155 | public String toString() { |
| 156 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 157 | .add("id", id()) |
Ray Milkey | c357381 | 2015-02-09 09:18:34 -0800 | [diff] [blame] | 158 | .add("key", key()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 159 | .add("appId", appId()) |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame^] | 160 | .add("priority", priority()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 161 | .add("resources", resources()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 162 | .add("selector", selector()) |
| 163 | .add("treatment", treatment()) |
| 164 | .add("ingress", ingressPoint) |
| 165 | .add("egress", egressPoint) |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 166 | .add("constraints", constraints()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 167 | .toString(); |
| 168 | } |
| 169 | |
| 170 | } |