blob: f08c1d710cc7afb2e450c8e778da7d09091dd77e [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
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'Connorb876bf12014-10-02 14:59:37 -070019package org.onlab.onos.net.intent;
20
toma1d16b62014-10-02 23:45:11 -070021import com.google.common.base.MoreObjects;
22import com.google.common.collect.Sets;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070023import org.onlab.onos.core.ApplicationId;
Brian O'Connorb876bf12014-10-02 14:59:37 -070024import org.onlab.onos.net.ConnectPoint;
25import org.onlab.onos.net.flow.TrafficSelector;
26import org.onlab.onos.net.flow.TrafficTreatment;
27
toma1d16b62014-10-02 23:45:11 -070028import java.util.Set;
29
30import static com.google.common.base.Preconditions.checkArgument;
31import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070032
33/**
34 * Abstraction of single source, multiple destination connectivity intent.
35 */
36public class SinglePointToMultiPointIntent extends ConnectivityIntent {
37
tom85258ee2014-10-07 00:10:02 -070038 private final ConnectPoint ingressPoint;
39 private final Set<ConnectPoint> egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070040
41 /**
42 * Creates a new single-to-multi point connectivity intent.
43 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070044 * @param appId application identifier
tom85258ee2014-10-07 00:10:02 -070045 * @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
toma1d16b62014-10-02 23:45:11 -070052 * not more than 1
Brian O'Connorb876bf12014-10-02 14:59:37 -070053 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070054 public SinglePointToMultiPointIntent(ApplicationId appId,
55 TrafficSelector selector,
toma1d16b62014-10-02 23:45:11 -070056 TrafficTreatment treatment,
tom85258ee2014-10-07 00:10:02 -070057 ConnectPoint ingressPoint,
58 Set<ConnectPoint> egressPoints) {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070059 super(id(SinglePointToMultiPointIntent.class, selector, treatment,
60 ingressPoint, egressPoints), appId, null, selector, treatment);
tom85258ee2014-10-07 00:10:02 -070061 checkNotNull(egressPoints);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070062 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
tom85258ee2014-10-07 00:10:02 -070063 this.ingressPoint = checkNotNull(ingressPoint);
64 this.egressPoints = Sets.newHashSet(egressPoints);
Brian O'Connorb876bf12014-10-02 14:59:37 -070065 }
66
67 /**
68 * Constructor for serializer.
69 */
70 protected SinglePointToMultiPointIntent() {
71 super();
tom85258ee2014-10-07 00:10:02 -070072 this.ingressPoint = null;
73 this.egressPoints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070074 }
75
76 /**
77 * Returns the port on which the ingress traffic should be connected to the egress.
78 *
79 * @return ingress port
80 */
tom85258ee2014-10-07 00:10:02 -070081 public ConnectPoint ingressPoint() {
82 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070083 }
84
85 /**
86 * Returns the set of ports on which the traffic should egress.
87 *
88 * @return set of egress ports
89 */
tom85258ee2014-10-07 00:10:02 -070090 public Set<ConnectPoint> egressPoints() {
91 return egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070092 }
93
94 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -070095 public String toString() {
96 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -070097 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -070098 .add("appId", appId())
99 .add("selector", selector())
100 .add("treatment", treatment())
101 .add("ingress", ingressPoint)
102 .add("egress", egressPoints)
Brian O'Connorb876bf12014-10-02 14:59:37 -0700103 .toString();
104 }
105
106}