blob: 129c4a6bd265f7fa8b4f4fa7c9e145b080e6b1d7 [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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
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
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.core.ApplicationId;
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorb876bf12014-10-02 14:59:37 -070025
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 */
Ray Milkeybd4f0112015-03-02 17:07:09 -080036public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070037
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) {
Ray Milkeyc24cde32015-03-10 18:20:18 -070057 this(appId, null, selector, treatment, ingressPoint, egressPoints,
58 Collections.emptyList(),
59 DEFAULT_INTENT_PRIORITY);
Michele Santuari4a338072014-11-05 18:38:55 +010060 }
61
62 /**
63 * Creates a new single-to-multi point connectivity intent.
64 *
65 * @param appId application identifier
Ray Milkey5b3717e2015-02-05 11:44:08 -080066 * @param key intent key
Michele Santuari4a338072014-11-05 18:38:55 +010067 * @param selector traffic selector
68 * @param treatment treatment
69 * @param ingressPoint port on which traffic will ingress
70 * @param egressPoints set of ports on which traffic will egress
71 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070072 * @param priority priority to use for flows generated by this intent
Michele Santuari4a338072014-11-05 18:38:55 +010073 * @throws NullPointerException if {@code ingressPoint} or
74 * {@code egressPoints} is null
75 * @throws IllegalArgumentException if the size of {@code egressPoints} is
76 * not more than 1
77 */
78 public SinglePointToMultiPointIntent(ApplicationId appId,
Ray Milkey5b3717e2015-02-05 11:44:08 -080079 Key key,
Michele Santuari4a338072014-11-05 18:38:55 +010080 TrafficSelector selector, TrafficTreatment treatment,
81 ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints,
Ray Milkeyc24cde32015-03-10 18:20:18 -070082 List<Constraint> constraints,
83 int priority) {
84 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
85 priority);
tom85258ee2014-10-07 00:10:02 -070086 checkNotNull(egressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080087 checkNotNull(ingressPoint);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070088 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080089 checkArgument(!egressPoints.contains(ingressPoint),
90 "Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
91
Michele Santuari4a338072014-11-05 18:38:55 +010092 this.ingressPoint = checkNotNull(ingressPoint);
tom85258ee2014-10-07 00:10:02 -070093 this.egressPoints = Sets.newHashSet(egressPoints);
Brian O'Connorb876bf12014-10-02 14:59:37 -070094 }
95
96 /**
97 * Constructor for serializer.
98 */
99 protected SinglePointToMultiPointIntent() {
100 super();
tom85258ee2014-10-07 00:10:02 -0700101 this.ingressPoint = null;
102 this.egressPoints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700103 }
104
105 /**
Michele Santuari4a338072014-11-05 18:38:55 +0100106 * Returns the port on which the ingress traffic should be connected to the
107 * egress.
Brian O'Connorb876bf12014-10-02 14:59:37 -0700108 *
109 * @return ingress port
110 */
tom85258ee2014-10-07 00:10:02 -0700111 public ConnectPoint ingressPoint() {
112 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700113 }
114
115 /**
116 * Returns the set of ports on which the traffic should egress.
117 *
118 * @return set of egress ports
119 */
tom85258ee2014-10-07 00:10:02 -0700120 public Set<ConnectPoint> egressPoints() {
121 return egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700122 }
123
124 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700125 public String toString() {
126 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700127 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800128 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700129 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700130 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800131 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700132 .add("selector", selector())
133 .add("treatment", treatment())
134 .add("ingress", ingressPoint)
135 .add("egress", egressPoints)
Michele Santuari4a338072014-11-05 18:38:55 +0100136 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700137 .toString();
138 }
139
140}