blob: 721ff176ce04fa286481e208917f64e16dde6bdb [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
tom85258ee2014-10-07 00:10:02 -070018import com.google.common.base.MoreObjects;
19import com.google.common.collect.Sets;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.core.ApplicationId;
21import org.onosproject.net.ConnectPoint;
22import org.onosproject.net.flow.TrafficSelector;
23import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorb876bf12014-10-02 14:59:37 -070024
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080025import java.util.Collections;
Ray Milkey460f4022014-11-05 15:41:43 -080026import java.util.List;
tom85258ee2014-10-07 00:10:02 -070027import java.util.Set;
28
29import static com.google.common.base.Preconditions.checkArgument;
30import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070031
32/**
33 * Abstraction of multiple source to single destination connectivity intent.
34 */
Ray Milkeye6684082014-10-16 16:59:47 -070035public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070036
tom85258ee2014-10-07 00:10:02 -070037 private final Set<ConnectPoint> ingressPoints;
38 private final ConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070039
40 /**
41 * Creates a new multi-to-single point connectivity intent for the specified
Thomas Vachuskac96058a2014-10-20 23:00:16 -070042 * traffic selector and treatment.
Brian O'Connorb876bf12014-10-02 14:59:37 -070043 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070044 * @param appId application identifier
45 * @param selector traffic selector
46 * @param treatment treatment
tom85258ee2014-10-07 00:10:02 -070047 * @param ingressPoints set of ports from which ingress traffic originates
48 * @param egressPoint port to which traffic will egress
49 * @throws NullPointerException if {@code ingressPoints} or
50 * {@code egressPoint} is null.
51 * @throws IllegalArgumentException if the size of {@code ingressPoints} 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 MultiPointToSinglePointIntent(ApplicationId appId,
55 TrafficSelector selector,
56 TrafficTreatment treatment,
tom85258ee2014-10-07 00:10:02 -070057 Set<ConnectPoint> ingressPoints,
58 ConnectPoint egressPoint) {
Ray Milkeyc24cde32015-03-10 18:20:18 -070059 this(appId, selector, treatment, ingressPoints, egressPoint,
60 Collections.emptyList(), DEFAULT_INTENT_PRIORITY);
Brian O'Connorb876bf12014-10-02 14:59:37 -070061 }
62
63 /**
Ray Milkey460f4022014-11-05 15:41:43 -080064 * Creates a new multi-to-single point connectivity intent for the specified
65 * traffic selector and treatment.
66 *
67 * @param appId application identifier
Jonathan Hartd0ba2172015-02-11 13:54:33 -080068 * @param key intent key
Ray Milkey460f4022014-11-05 15:41:43 -080069 * @param selector traffic selector
70 * @param treatment treatment
71 * @param ingressPoints set of ports from which ingress traffic originates
72 * @param egressPoint port to which traffic will egress
73 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070074 * @param priority priority to use for flows generated by this intent
Ray Milkey460f4022014-11-05 15:41:43 -080075 * @throws NullPointerException if {@code ingressPoints} or
76 * {@code egressPoint} is null.
77 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
78 * not more than 1
79 */
80 public MultiPointToSinglePointIntent(ApplicationId appId,
Ray Milkey5b3717e2015-02-05 11:44:08 -080081 Key key,
Ray Milkey460f4022014-11-05 15:41:43 -080082 TrafficSelector selector,
83 TrafficTreatment treatment,
84 Set<ConnectPoint> ingressPoints,
85 ConnectPoint egressPoint,
Ray Milkeyc24cde32015-03-10 18:20:18 -070086 List<Constraint> constraints,
87 int priority) {
88 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
89 priority);
Ray Milkey460f4022014-11-05 15:41:43 -080090
91 checkNotNull(ingressPoints);
92 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080093 checkNotNull(egressPoint);
94 checkArgument(!ingressPoints.contains(egressPoint),
95 "Set of ingresses should not contain egress (egress: %s)", egressPoint);
Ray Milkey460f4022014-11-05 15:41:43 -080096
97 this.ingressPoints = Sets.newHashSet(ingressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080098 this.egressPoint = egressPoint;
Ray Milkey460f4022014-11-05 15:41:43 -080099 }
100
101 /**
Ray Milkey5b3717e2015-02-05 11:44:08 -0800102 * Creates a new multi-to-single point connectivity intent for the specified
103 * traffic selector and treatment.
104 *
105 * @param appId application identifier
106 * @param selector traffic selector
107 * @param treatment treatment
108 * @param ingressPoints set of ports from which ingress traffic originates
109 * @param egressPoint port to which traffic will egress
110 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -0700111 * @param priority priority to use for flows generated by this intent
Ray Milkey5b3717e2015-02-05 11:44:08 -0800112 * @throws NullPointerException if {@code ingressPoints} or
113 * {@code egressPoint} is null.
114 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
115 * not more than 1
116 */
117 public MultiPointToSinglePointIntent(ApplicationId appId,
118 TrafficSelector selector,
119 TrafficTreatment treatment,
120 Set<ConnectPoint> ingressPoints,
121 ConnectPoint egressPoint,
Ray Milkeyc24cde32015-03-10 18:20:18 -0700122 List<Constraint> constraints,
123 int priority) {
124 this(appId, null, selector, treatment, ingressPoints, egressPoint,
125 constraints, priority);
Ray Milkey5b3717e2015-02-05 11:44:08 -0800126 }
127
128 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700129 * Constructor for serializer.
130 */
131 protected MultiPointToSinglePointIntent() {
132 super();
tom85258ee2014-10-07 00:10:02 -0700133 this.ingressPoints = null;
134 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700135 }
136
137 /**
138 * Returns the set of ports on which ingress traffic should be connected to
139 * the egress port.
140 *
141 * @return set of ingress ports
142 */
tom85258ee2014-10-07 00:10:02 -0700143 public Set<ConnectPoint> ingressPoints() {
144 return ingressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700145 }
146
147 /**
148 * Returns the port on which the traffic should egress.
149 *
150 * @return egress port
151 */
tom85258ee2014-10-07 00:10:02 -0700152 public ConnectPoint egressPoint() {
153 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700154 }
155
156 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700157 public String toString() {
158 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700159 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800160 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700161 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700162 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800163 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700164 .add("selector", selector())
165 .add("treatment", treatment())
166 .add("ingress", ingressPoints())
167 .add("egress", egressPoint())
Ray Milkey460f4022014-11-05 15:41:43 -0800168 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700169 .toString();
170 }
171}