blob: 8c806bd04b5eebb4c600a573d3b8cbfad44b495e [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;
Michele Santuari4a338072014-11-05 18:38:55 +010020
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070021import org.onlab.onos.core.ApplicationId;
Brian O'Connorb876bf12014-10-02 14:59:37 -070022import org.onlab.onos.net.ConnectPoint;
23import org.onlab.onos.net.flow.TrafficSelector;
24import org.onlab.onos.net.flow.TrafficTreatment;
25
Michele Santuari4a338072014-11-05 18:38:55 +010026import java.util.Collections;
toma1d16b62014-10-02 23:45:11 -070027import java.util.Set;
Michele Santuari4a338072014-11-05 18:38:55 +010028import java.util.List;
toma1d16b62014-10-02 23:45:11 -070029
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 *
Michele Santuari4a338072014-11-05 18:38:55 +010044 * @param appId application identifier
45 * @param selector traffic selector
46 * @param treatment treatment
tom85258ee2014-10-07 00:10:02 -070047 * @param ingressPoint port on which traffic will ingress
48 * @param egressPoints set of ports on which traffic will egress
Michele Santuari4a338072014-11-05 18:38:55 +010049 * @throws NullPointerException if {@code ingressPoint} or
50 * {@code egressPoints} is null
tom85258ee2014-10-07 00:10:02 -070051 * @throws IllegalArgumentException if the size of {@code egressPoints} is
Michele Santuari4a338072014-11-05 18:38:55 +010052 * 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,
Michele Santuari4a338072014-11-05 18:38:55 +010055 TrafficSelector selector, TrafficTreatment treatment,
56 ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints) {
57 this(appId, selector, treatment, ingressPoint, egressPoints, Collections.emptyList());
58 }
59
60 /**
61 * Creates a new single-to-multi point connectivity intent.
62 *
63 * @param appId application identifier
64 * @param selector traffic selector
65 * @param treatment treatment
66 * @param ingressPoint port on which traffic will ingress
67 * @param egressPoints set of ports on which traffic will egress
68 * @param constraints constraints to apply to the intent
69 * @throws NullPointerException if {@code ingressPoint} or
70 * {@code egressPoints} is null
71 * @throws IllegalArgumentException if the size of {@code egressPoints} is
72 * not more than 1
73 */
74 public SinglePointToMultiPointIntent(ApplicationId appId,
75 TrafficSelector selector, TrafficTreatment treatment,
76 ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints,
77 List<Constraint> constraints) {
Brian O'Connor520c0522014-11-23 23:50:47 -080078 super(appId, null, selector, treatment, constraints);
tom85258ee2014-10-07 00:10:02 -070079 checkNotNull(egressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080080 checkNotNull(ingressPoint);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070081 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080082 checkArgument(!egressPoints.contains(ingressPoint),
83 "Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
84
Michele Santuari4a338072014-11-05 18:38:55 +010085 this.ingressPoint = checkNotNull(ingressPoint);
tom85258ee2014-10-07 00:10:02 -070086 this.egressPoints = Sets.newHashSet(egressPoints);
Brian O'Connorb876bf12014-10-02 14:59:37 -070087 }
88
89 /**
90 * Constructor for serializer.
91 */
92 protected SinglePointToMultiPointIntent() {
93 super();
tom85258ee2014-10-07 00:10:02 -070094 this.ingressPoint = null;
95 this.egressPoints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070096 }
97
98 /**
Michele Santuari4a338072014-11-05 18:38:55 +010099 * Returns the port on which the ingress traffic should be connected to the
100 * egress.
Brian O'Connorb876bf12014-10-02 14:59:37 -0700101 *
102 * @return ingress port
103 */
tom85258ee2014-10-07 00:10:02 -0700104 public ConnectPoint ingressPoint() {
105 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700106 }
107
108 /**
109 * Returns the set of ports on which the traffic should egress.
110 *
111 * @return set of egress ports
112 */
tom85258ee2014-10-07 00:10:02 -0700113 public Set<ConnectPoint> egressPoints() {
114 return egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700115 }
116
117 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700118 public String toString() {
119 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700120 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700121 .add("appId", appId())
122 .add("selector", selector())
123 .add("treatment", treatment())
124 .add("ingress", ingressPoint)
125 .add("egress", egressPoints)
Michele Santuari4a338072014-11-05 18:38:55 +0100126 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700127 .toString();
128 }
129
130}