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 | 85258ee | 2014-10-07 00:10:02 -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 | 85258ee | 2014-10-07 00:10:02 -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 multiple source to single destination connectivity intent. |
| 35 | */ |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 36 | public final class MultiPointToSinglePointIntent 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 Set<ConnectPoint> ingressPoints; |
| 39 | private final ConnectPoint egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Creates a new multi-to-single point connectivity intent for the specified |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 43 | * traffic selector and treatment. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 44 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 45 | * @param appId application identifier |
| 46 | * @param selector traffic selector |
| 47 | * @param treatment treatment |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 48 | * @param ingressPoints set of ports from which ingress traffic originates |
| 49 | * @param egressPoint port to which traffic will egress |
| 50 | * @throws NullPointerException if {@code ingressPoints} or |
| 51 | * {@code egressPoint} is null. |
| 52 | * @throws IllegalArgumentException if the size of {@code ingressPoints} is |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 53 | * not more than 1 |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 54 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 55 | public MultiPointToSinglePointIntent(ApplicationId appId, |
| 56 | TrafficSelector selector, |
| 57 | TrafficTreatment treatment, |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 58 | Set<ConnectPoint> ingressPoints, |
| 59 | ConnectPoint egressPoint) { |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 60 | super(id(MultiPointToSinglePointIntent.class, selector, treatment, |
| 61 | ingressPoints, egressPoint), appId, null, selector, treatment); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 62 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 63 | checkNotNull(ingressPoints); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 64 | checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty"); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 65 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 66 | this.ingressPoints = Sets.newHashSet(ingressPoints); |
| 67 | this.egressPoint = checkNotNull(egressPoint); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Constructor for serializer. |
| 72 | */ |
| 73 | protected MultiPointToSinglePointIntent() { |
| 74 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 75 | this.ingressPoints = null; |
| 76 | this.egressPoint = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the set of ports on which ingress traffic should be connected to |
| 81 | * the egress port. |
| 82 | * |
| 83 | * @return set of ingress ports |
| 84 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 85 | public Set<ConnectPoint> ingressPoints() { |
| 86 | return ingressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns the port on which the traffic should egress. |
| 91 | * |
| 92 | * @return egress port |
| 93 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 94 | public ConnectPoint egressPoint() { |
| 95 | return egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 99 | public String toString() { |
| 100 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 101 | .add("id", id()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 102 | .add("appId", appId()) |
| 103 | .add("selector", selector()) |
| 104 | .add("treatment", treatment()) |
| 105 | .add("ingress", ingressPoints()) |
| 106 | .add("egress", egressPoint()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 107 | .toString(); |
| 108 | } |
| 109 | } |