Michele Santuari | 38dd82e | 2017-01-04 09:23:49 +0100 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Michele Santuari | 38dd82e | 2017-01-04 09:23:49 +0100 | [diff] [blame] | 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.net.domain; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.collect.ImmutableList; |
| 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.net.FilteredConnectPoint; |
| 23 | import org.onosproject.net.NetworkResource; |
| 24 | import org.onosproject.net.flow.TrafficTreatment; |
| 25 | import org.onosproject.net.intent.Constraint; |
| 26 | import org.onosproject.net.intent.Intent; |
| 27 | import org.onosproject.net.intent.Key; |
| 28 | |
| 29 | import java.util.Collection; |
| 30 | import java.util.List; |
| 31 | import java.util.Set; |
| 32 | |
| 33 | import static com.google.common.base.Preconditions.checkArgument; |
| 34 | import static com.google.common.base.Preconditions.checkNotNull; |
| 35 | |
| 36 | /** |
| 37 | * Intents targeting a domain network. |
| 38 | */ |
| 39 | @Beta |
| 40 | public abstract class DomainIntent extends Intent { |
| 41 | |
| 42 | private final Set<FilteredConnectPoint> filteredIngressPoints; |
| 43 | private final Set<FilteredConnectPoint> filteredEgressPoints; |
| 44 | private final TrafficTreatment treatment; |
| 45 | private final List<Constraint> constraints; |
| 46 | |
| 47 | |
| 48 | /** |
| 49 | * @param appId application identifier |
| 50 | * @param key explicit key to use for intent |
| 51 | * @param resources required network resources (optional) |
| 52 | * @param priority intent priority |
| 53 | * @param filteredIngressPoints filtered ingress points |
| 54 | * @param filteredEgressPoints filtered egress points |
| 55 | * @param treatment action to be applied at the egress |
| 56 | * @param constraints constraints of the intent |
| 57 | * @throws NullPointerException if {@code filteredIngressPoints} or |
| 58 | * {@code filteredEgressPoints} or {@code appId} |
| 59 | * or {@code constraints} is null. |
| 60 | * @throws IllegalArgumentException if {@code filteredIngressPoints} or {@code filteredEgressPoints} is empty. |
| 61 | */ |
| 62 | public DomainIntent(ApplicationId appId, Key key, |
| 63 | Collection<NetworkResource> resources, |
| 64 | int priority, |
| 65 | Set<FilteredConnectPoint> filteredIngressPoints, |
| 66 | Set<FilteredConnectPoint> filteredEgressPoints, |
| 67 | TrafficTreatment treatment, |
| 68 | List<Constraint> constraints) { |
Ray Milkey | 39f78b6 | 2018-01-05 15:17:37 -0800 | [diff] [blame] | 69 | super(appId, key, resources, priority, null); |
Michele Santuari | 38dd82e | 2017-01-04 09:23:49 +0100 | [diff] [blame] | 70 | |
| 71 | checkNotNull(filteredIngressPoints, "Ingress points cannot be null"); |
| 72 | checkArgument(!filteredIngressPoints.isEmpty(), "Ingress point cannot be empty"); |
| 73 | checkNotNull(filteredEgressPoints, "Egress points cannot be null"); |
| 74 | checkArgument(!filteredEgressPoints.isEmpty(), "Egress point cannot be empty"); |
| 75 | this.filteredIngressPoints = filteredIngressPoints; |
| 76 | this.filteredEgressPoints = filteredEgressPoints; |
| 77 | this.treatment = treatment; |
| 78 | this.constraints = checkNotNull(constraints, "Constraints cannot be null"); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Constructor for serializer. |
| 83 | */ |
| 84 | protected DomainIntent() { |
| 85 | super(); |
| 86 | filteredIngressPoints = null; |
| 87 | filteredEgressPoints = null; |
| 88 | treatment = null; |
| 89 | constraints = null; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Abstract builder for connectivity intents. |
| 94 | */ |
| 95 | public abstract static class Builder extends Intent.Builder { |
| 96 | protected List<Constraint> constraints = ImmutableList.of(); |
| 97 | protected TrafficTreatment treatment; |
| 98 | |
| 99 | /** |
| 100 | * Creates a new empty builder. |
| 101 | */ |
| 102 | protected Builder() { |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public Builder appId(ApplicationId appId) { |
| 107 | return (Builder) super.appId(appId); |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public Builder key(Key key) { |
| 112 | return (Builder) super.key(key); |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public Builder priority(int priority) { |
| 117 | return (Builder) super.priority(priority); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Sets the traffic treatment for the intent that will be built. |
| 122 | * |
| 123 | * @param treatment treatment to use for built intent |
| 124 | * @return this builder |
| 125 | */ |
| 126 | public Builder treatment(TrafficTreatment treatment) { |
| 127 | this.treatment = treatment; |
| 128 | return this; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Sets the constraints for the intent that will be built. |
| 133 | * |
| 134 | * @param constraints constraints to use for built intent |
| 135 | * @return this builder |
| 136 | */ |
| 137 | public Builder constraints(List<Constraint> constraints) { |
| 138 | this.constraints = ImmutableList.copyOf(constraints); |
| 139 | return this; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public boolean isInstallable() { |
| 145 | return true; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Returns the filtered connected points on which the ingress traffic |
| 150 | * should be connected to the egress. |
| 151 | * |
| 152 | * @return filtered ingress connect points |
| 153 | */ |
| 154 | public Set<FilteredConnectPoint> filteredIngressPoints() { |
| 155 | return filteredIngressPoints; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Returns the filtered connected points on which the traffic should egress. |
| 160 | * |
| 161 | * @return filtered egress connect points |
| 162 | */ |
| 163 | public Set<FilteredConnectPoint> filteredEgressPoints() { |
| 164 | return filteredEgressPoints; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Returns the action applied to the traffic at the egress. |
| 169 | * |
| 170 | * @return applied action |
| 171 | */ |
| 172 | public TrafficTreatment treatment() { |
| 173 | return treatment; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Returns the set of connectivity constraints. |
| 178 | * |
| 179 | * @return list of intent constraints |
| 180 | */ |
| 181 | public List<Constraint> constraints() { |
| 182 | return constraints; |
| 183 | } |
| 184 | |
| 185 | } |