Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 19 | package org.onlab.onos.net.intent; |
| 20 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 21 | import com.google.common.base.MoreObjects; |
| 22 | import com.google.common.collect.Sets; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 23 | import org.onlab.onos.core.ApplicationId; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 24 | import org.onlab.onos.net.ConnectPoint; |
| 25 | import org.onlab.onos.net.flow.TrafficSelector; |
| 26 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 27 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 28 | import java.util.Set; |
| 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 | * |
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 port on which traffic will ingress |
| 48 | * @param egressPoints set of ports on which traffic will egress |
| 49 | * @throws NullPointerException if {@code ingressPoint} or |
| 50 | * {@code egressPoints} is null |
| 51 | * @throws IllegalArgumentException if the size of {@code egressPoints} is |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [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, |
| 55 | TrafficSelector selector, |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 56 | TrafficTreatment treatment, |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 57 | ConnectPoint ingressPoint, |
| 58 | Set<ConnectPoint> egressPoints) { |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 59 | super(id(SinglePointToMultiPointIntent.class, selector, treatment, |
| 60 | ingressPoint, egressPoints), appId, null, selector, treatment); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 61 | checkNotNull(egressPoints); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 62 | checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty"); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 63 | this.ingressPoint = checkNotNull(ingressPoint); |
| 64 | this.egressPoints = Sets.newHashSet(egressPoints); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Constructor for serializer. |
| 69 | */ |
| 70 | protected SinglePointToMultiPointIntent() { |
| 71 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 72 | this.ingressPoint = null; |
| 73 | this.egressPoints = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the port on which the ingress traffic should be connected to the egress. |
| 78 | * |
| 79 | * @return ingress port |
| 80 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 81 | public ConnectPoint ingressPoint() { |
| 82 | return ingressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns the set of ports on which the traffic should egress. |
| 87 | * |
| 88 | * @return set of egress ports |
| 89 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 90 | public Set<ConnectPoint> egressPoints() { |
| 91 | return egressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 95 | public String toString() { |
| 96 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 97 | .add("id", id()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 98 | .add("appId", appId()) |
| 99 | .add("selector", selector()) |
| 100 | .add("treatment", treatment()) |
| 101 | .add("ingress", ingressPoint) |
| 102 | .add("egress", egressPoints) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 103 | .toString(); |
| 104 | } |
| 105 | |
| 106 | } |