blob: 2f20449ee9a5da430e9c3118d73cbe3192ff71ac [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 */
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) {
Ray Milkey5b3717e2015-02-05 11:44:08 -080057 this(appId, null, selector, treatment, ingressPoint, egressPoints, Collections.emptyList());
Michele Santuari4a338072014-11-05 18:38:55 +010058 }
59
60 /**
61 * Creates a new single-to-multi point connectivity intent.
62 *
63 * @param appId application identifier
Ray Milkey5b3717e2015-02-05 11:44:08 -080064 * @param key intent key
Michele Santuari4a338072014-11-05 18:38:55 +010065 * @param selector traffic selector
66 * @param treatment treatment
67 * @param ingressPoint port on which traffic will ingress
68 * @param egressPoints set of ports on which traffic will egress
69 * @param constraints constraints to apply to the intent
70 * @throws NullPointerException if {@code ingressPoint} or
71 * {@code egressPoints} is null
72 * @throws IllegalArgumentException if the size of {@code egressPoints} is
73 * not more than 1
74 */
75 public SinglePointToMultiPointIntent(ApplicationId appId,
Ray Milkey5b3717e2015-02-05 11:44:08 -080076 Key key,
Michele Santuari4a338072014-11-05 18:38:55 +010077 TrafficSelector selector, TrafficTreatment treatment,
78 ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints,
79 List<Constraint> constraints) {
Ray Milkey5b3717e2015-02-05 11:44:08 -080080 super(appId, key, Collections.emptyList(), selector, treatment, constraints);
tom85258ee2014-10-07 00:10:02 -070081 checkNotNull(egressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080082 checkNotNull(ingressPoint);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070083 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080084 checkArgument(!egressPoints.contains(ingressPoint),
85 "Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
86
Michele Santuari4a338072014-11-05 18:38:55 +010087 this.ingressPoint = checkNotNull(ingressPoint);
tom85258ee2014-10-07 00:10:02 -070088 this.egressPoints = Sets.newHashSet(egressPoints);
Brian O'Connorb876bf12014-10-02 14:59:37 -070089 }
90
91 /**
92 * Constructor for serializer.
93 */
94 protected SinglePointToMultiPointIntent() {
95 super();
tom85258ee2014-10-07 00:10:02 -070096 this.ingressPoint = null;
97 this.egressPoints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070098 }
99
100 /**
Michele Santuari4a338072014-11-05 18:38:55 +0100101 * Returns the port on which the ingress traffic should be connected to the
102 * egress.
Brian O'Connorb876bf12014-10-02 14:59:37 -0700103 *
104 * @return ingress port
105 */
tom85258ee2014-10-07 00:10:02 -0700106 public ConnectPoint ingressPoint() {
107 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700108 }
109
110 /**
111 * Returns the set of ports on which the traffic should egress.
112 *
113 * @return set of egress ports
114 */
tom85258ee2014-10-07 00:10:02 -0700115 public Set<ConnectPoint> egressPoints() {
116 return egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700117 }
118
119 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700120 public String toString() {
121 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700122 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800123 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700124 .add("appId", appId())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800125 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700126 .add("selector", selector())
127 .add("treatment", treatment())
128 .add("ingress", ingressPoint)
129 .add("egress", egressPoints)
Michele Santuari4a338072014-11-05 18:38:55 +0100130 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700131 .toString();
132 }
133
134}