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; |
| 19 | import com.google.common.collect.Sets; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 20 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.net.ConnectPoint; |
| 23 | import org.onosproject.net.flow.TrafficSelector; |
| 24 | import org.onosproject.net.flow.TrafficTreatment; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 25 | |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 26 | import java.util.Collections; |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 27 | import java.util.Set; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 28 | import java.util.List; |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 29 | |
| 30 | import static com.google.common.base.Preconditions.checkArgument; |
| 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 single source, multiple destination connectivity intent. |
| 35 | */ |
| 36 | public class SinglePointToMultiPointIntent extends ConnectivityIntent { |
| 37 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 38 | private final ConnectPoint ingressPoint; |
| 39 | private final Set<ConnectPoint> egressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Creates a new single-to-multi point connectivity intent. |
| 43 | * |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 44 | * @param appId application identifier |
| 45 | * @param selector traffic selector |
| 46 | * @param treatment treatment |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 47 | * @param ingressPoint port on which traffic will ingress |
| 48 | * @param egressPoints set of ports on which traffic will egress |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 49 | * @throws NullPointerException if {@code ingressPoint} or |
| 50 | * {@code egressPoints} is null |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 51 | * @throws IllegalArgumentException if the size of {@code egressPoints} is |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 52 | * not more than 1 |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 53 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 54 | public SinglePointToMultiPointIntent(ApplicationId appId, |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 55 | TrafficSelector selector, TrafficTreatment treatment, |
| 56 | ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints) { |
| 57 | this(appId, selector, treatment, ingressPoint, egressPoints, Collections.emptyList()); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Creates a new single-to-multi point connectivity intent. |
| 62 | * |
| 63 | * @param appId application identifier |
| 64 | * @param selector traffic selector |
| 65 | * @param treatment treatment |
| 66 | * @param ingressPoint port on which traffic will ingress |
| 67 | * @param egressPoints set of ports on which traffic will egress |
| 68 | * @param constraints constraints to apply to the intent |
| 69 | * @throws NullPointerException if {@code ingressPoint} or |
| 70 | * {@code egressPoints} is null |
| 71 | * @throws IllegalArgumentException if the size of {@code egressPoints} is |
| 72 | * not more than 1 |
| 73 | */ |
| 74 | public SinglePointToMultiPointIntent(ApplicationId appId, |
| 75 | TrafficSelector selector, TrafficTreatment treatment, |
| 76 | ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints, |
| 77 | List<Constraint> constraints) { |
Sho SHIMIZU | d7d1800 | 2015-01-21 14:37:14 -0800 | [diff] [blame] | 78 | super(appId, Collections.emptyList(), selector, treatment, constraints); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 79 | checkNotNull(egressPoints); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 80 | checkNotNull(ingressPoint); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 81 | checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty"); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 82 | checkArgument(!egressPoints.contains(ingressPoint), |
| 83 | "Set of egresses should not contain ingress (ingress: %s)", ingressPoint); |
| 84 | |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 85 | this.ingressPoint = checkNotNull(ingressPoint); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 86 | this.egressPoints = Sets.newHashSet(egressPoints); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Constructor for serializer. |
| 91 | */ |
| 92 | protected SinglePointToMultiPointIntent() { |
| 93 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 94 | this.ingressPoint = null; |
| 95 | this.egressPoints = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /** |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 99 | * Returns the port on which the ingress traffic should be connected to the |
| 100 | * egress. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 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 set of ports on which the traffic should egress. |
| 110 | * |
| 111 | * @return set of egress ports |
| 112 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 113 | public Set<ConnectPoint> egressPoints() { |
| 114 | return egressPoints; |
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()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 122 | .add("resources", resources()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 123 | .add("selector", selector()) |
| 124 | .add("treatment", treatment()) |
| 125 | .add("ingress", ingressPoint) |
| 126 | .add("egress", egressPoints) |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 127 | .add("constraints", constraints()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 128 | .toString(); |
| 129 | } |
| 130 | |
| 131 | } |