blob: efe96e2ea0f0ba82b78a871b071337c5ddaf7b05 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorb876bf12014-10-02 14:59:37 -070016package org.onlab.onos.net.intent;
17
toma1d16b62014-10-02 23:45:11 -070018import com.google.common.base.MoreObjects;
19import com.google.common.collect.Sets;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070020import org.onlab.onos.core.ApplicationId;
Brian O'Connorb876bf12014-10-02 14:59:37 -070021import org.onlab.onos.net.ConnectPoint;
22import org.onlab.onos.net.flow.TrafficSelector;
23import org.onlab.onos.net.flow.TrafficTreatment;
24
toma1d16b62014-10-02 23:45:11 -070025import java.util.Set;
26
27import static com.google.common.base.Preconditions.checkArgument;
28import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070029
30/**
31 * Abstraction of single source, multiple destination connectivity intent.
32 */
33public class SinglePointToMultiPointIntent extends ConnectivityIntent {
34
tom85258ee2014-10-07 00:10:02 -070035 private final ConnectPoint ingressPoint;
36 private final Set<ConnectPoint> egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070037
38 /**
39 * Creates a new single-to-multi point connectivity intent.
40 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070041 * @param appId application identifier
tom85258ee2014-10-07 00:10:02 -070042 * @param selector traffic selector
43 * @param treatment treatment
44 * @param ingressPoint port on which traffic will ingress
45 * @param egressPoints set of ports on which traffic will egress
46 * @throws NullPointerException if {@code ingressPoint} or
47 * {@code egressPoints} is null
48 * @throws IllegalArgumentException if the size of {@code egressPoints} is
toma1d16b62014-10-02 23:45:11 -070049 * not more than 1
Brian O'Connorb876bf12014-10-02 14:59:37 -070050 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070051 public SinglePointToMultiPointIntent(ApplicationId appId,
52 TrafficSelector selector,
toma1d16b62014-10-02 23:45:11 -070053 TrafficTreatment treatment,
tom85258ee2014-10-07 00:10:02 -070054 ConnectPoint ingressPoint,
55 Set<ConnectPoint> egressPoints) {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070056 super(id(SinglePointToMultiPointIntent.class, selector, treatment,
57 ingressPoint, egressPoints), appId, null, selector, treatment);
tom85258ee2014-10-07 00:10:02 -070058 checkNotNull(egressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080059 checkNotNull(ingressPoint);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070060 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080061 checkArgument(!egressPoints.contains(ingressPoint),
62 "Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
63
64 this.ingressPoint = ingressPoint;
tom85258ee2014-10-07 00:10:02 -070065 this.egressPoints = Sets.newHashSet(egressPoints);
Brian O'Connorb876bf12014-10-02 14:59:37 -070066 }
67
68 /**
69 * Constructor for serializer.
70 */
71 protected SinglePointToMultiPointIntent() {
72 super();
tom85258ee2014-10-07 00:10:02 -070073 this.ingressPoint = null;
74 this.egressPoints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070075 }
76
77 /**
78 * Returns the port on which the ingress traffic should be connected to the egress.
79 *
80 * @return ingress port
81 */
tom85258ee2014-10-07 00:10:02 -070082 public ConnectPoint ingressPoint() {
83 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070084 }
85
86 /**
87 * Returns the set of ports on which the traffic should egress.
88 *
89 * @return set of egress ports
90 */
tom85258ee2014-10-07 00:10:02 -070091 public Set<ConnectPoint> egressPoints() {
92 return egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070093 }
94
95 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -070096 public String toString() {
97 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -070098 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -070099 .add("appId", appId())
100 .add("selector", selector())
101 .add("treatment", treatment())
102 .add("ingress", ingressPoint)
103 .add("egress", egressPoints)
Brian O'Connorb876bf12014-10-02 14:59:37 -0700104 .toString();
105 }
106
107}