blob: 8c8cbb051c1d00138bdc00c47304e6ac2b5baa3c [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
tom85258ee2014-10-07 00:10:02 -070018import com.google.common.base.MoreObjects;
19import com.google.common.collect.Sets;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070020import org.onlab.onos.core.ApplicationId;
Brian O'Connorb876bf12014-10-02 14:59:37 -070021import org.onlab.onos.net.ConnectPoint;
22import org.onlab.onos.net.flow.TrafficSelector;
23import org.onlab.onos.net.flow.TrafficTreatment;
24
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,
78 TrafficSelector selector,
79 TrafficTreatment treatment,
80 Set<ConnectPoint> ingressPoints,
81 ConnectPoint egressPoint,
82 List<Constraint> constraints) {
83 super(id(MultiPointToSinglePointIntent.class, selector, treatment,
84 ingressPoints, egressPoint), appId, null, selector, treatment,
85 constraints);
86
87 checkNotNull(ingressPoints);
88 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
89
90 this.ingressPoints = Sets.newHashSet(ingressPoints);
91 this.egressPoint = checkNotNull(egressPoint);
92 }
93
94 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -070095 * Constructor for serializer.
96 */
97 protected MultiPointToSinglePointIntent() {
98 super();
tom85258ee2014-10-07 00:10:02 -070099 this.ingressPoints = null;
100 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700101 }
102
103 /**
104 * Returns the set of ports on which ingress traffic should be connected to
105 * the egress port.
106 *
107 * @return set of ingress ports
108 */
tom85258ee2014-10-07 00:10:02 -0700109 public Set<ConnectPoint> ingressPoints() {
110 return ingressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700111 }
112
113 /**
114 * Returns the port on which the traffic should egress.
115 *
116 * @return egress port
117 */
tom85258ee2014-10-07 00:10:02 -0700118 public ConnectPoint egressPoint() {
119 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700120 }
121
122 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700123 public String toString() {
124 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700125 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700126 .add("appId", appId())
127 .add("selector", selector())
128 .add("treatment", treatment())
129 .add("ingress", ingressPoints())
130 .add("egress", egressPoint())
Ray Milkey460f4022014-11-05 15:41:43 -0800131 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700132 .toString();
133 }
134}