blob: 64c4fd8410566155265e9ba83838a35042256b0c [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) {
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080059 this(appId, selector, treatment, ingressPoints, egressPoint, Collections.emptyList());
Brian O'Connorb876bf12014-10-02 14:59:37 -070060 }
61
62 /**
Ray Milkey460f4022014-11-05 15:41:43 -080063 * Creates a new multi-to-single point connectivity intent for the specified
64 * traffic selector and treatment.
65 *
66 * @param appId application identifier
67 * @param selector traffic selector
68 * @param treatment treatment
69 * @param ingressPoints set of ports from which ingress traffic originates
70 * @param egressPoint port to which traffic will egress
71 * @param constraints constraints to apply to the intent
72 * @throws NullPointerException if {@code ingressPoints} or
73 * {@code egressPoint} is null.
74 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
75 * not more than 1
76 */
77 public MultiPointToSinglePointIntent(ApplicationId appId,
Ray Milkey5b3717e2015-02-05 11:44:08 -080078 Key key,
Ray Milkey460f4022014-11-05 15:41:43 -080079 TrafficSelector selector,
80 TrafficTreatment treatment,
81 Set<ConnectPoint> ingressPoints,
82 ConnectPoint egressPoint,
83 List<Constraint> constraints) {
Ray Milkey5b3717e2015-02-05 11:44:08 -080084 super(appId, key, Collections.emptyList(), selector, treatment, constraints);
Ray Milkey460f4022014-11-05 15:41:43 -080085
86 checkNotNull(ingressPoints);
87 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080088 checkNotNull(egressPoint);
89 checkArgument(!ingressPoints.contains(egressPoint),
90 "Set of ingresses should not contain egress (egress: %s)", egressPoint);
Ray Milkey460f4022014-11-05 15:41:43 -080091
92 this.ingressPoints = Sets.newHashSet(ingressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080093 this.egressPoint = egressPoint;
Ray Milkey460f4022014-11-05 15:41:43 -080094 }
95
96 /**
Ray Milkey5b3717e2015-02-05 11:44:08 -080097 * Creates a new multi-to-single point connectivity intent for the specified
98 * traffic selector and treatment.
99 *
100 * @param appId application identifier
101 * @param selector traffic selector
102 * @param treatment treatment
103 * @param ingressPoints set of ports from which ingress traffic originates
104 * @param egressPoint port to which traffic will egress
105 * @param constraints constraints to apply to the intent
106 * @throws NullPointerException if {@code ingressPoints} or
107 * {@code egressPoint} is null.
108 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
109 * not more than 1
110 */
111 public MultiPointToSinglePointIntent(ApplicationId appId,
112 TrafficSelector selector,
113 TrafficTreatment treatment,
114 Set<ConnectPoint> ingressPoints,
115 ConnectPoint egressPoint,
116 List<Constraint> constraints) {
117 this(appId, null, selector, treatment, ingressPoints, egressPoint, constraints);
118 }
119
120 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700121 * Constructor for serializer.
122 */
123 protected MultiPointToSinglePointIntent() {
124 super();
tom85258ee2014-10-07 00:10:02 -0700125 this.ingressPoints = null;
126 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700127 }
128
129 /**
130 * Returns the set of ports on which ingress traffic should be connected to
131 * the egress port.
132 *
133 * @return set of ingress ports
134 */
tom85258ee2014-10-07 00:10:02 -0700135 public Set<ConnectPoint> ingressPoints() {
136 return ingressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700137 }
138
139 /**
140 * Returns the port on which the traffic should egress.
141 *
142 * @return egress port
143 */
tom85258ee2014-10-07 00:10:02 -0700144 public ConnectPoint egressPoint() {
145 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700146 }
147
148 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700149 public String toString() {
150 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700151 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800152 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700153 .add("appId", appId())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800154 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700155 .add("selector", selector())
156 .add("treatment", treatment())
157 .add("ingress", ingressPoints())
158 .add("egress", egressPoint())
Ray Milkey460f4022014-11-05 15:41:43 -0800159 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700160 .toString();
161 }
162}