blob: 6e205e11aaa0494483c3b13333830c10989625da [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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
Sho SHIMIZUd7d18002015-01-21 14:37:14 -080018import java.util.Collections;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080019import java.util.List;
Brian O'Connorb876bf12014-10-02 14:59:37 -070020
Brian O'Connor9476fa12015-06-25 15:17:17 -040021import com.google.common.annotations.Beta;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070022import org.onosproject.core.ApplicationId;
23import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
26
27import com.google.common.base.MoreObjects;
28
Sho SHIMIZU2e660802014-11-21 14:55:32 -080029import static com.google.common.base.Preconditions.checkArgument;
toma1d16b62014-10-02 23:45:11 -070030import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070031
32/**
33 * Abstraction of point-to-point connectivity.
34 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040035@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080036public final class PointToPointIntent 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 ConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070040
41 /**
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070042 * Returns a new point to point intent builder. The application id,
43 * ingress point and egress point are required fields. If they are
44 * not set by calls to the appropriate methods, an exception will
45 * be thrown.
46 *
47 * @return point to point builder
48 */
49 public static PointToPointIntent.Builder builder() {
50 return new Builder();
51 }
52
53 /**
54 * Builder of a point to point intent.
55 */
56 public static final class Builder extends ConnectivityIntent.Builder {
57 ConnectPoint ingressPoint;
58 ConnectPoint egressPoint;
59
60 private Builder() {
61 // Hide constructor
62 }
63
64 @Override
65 public Builder appId(ApplicationId appId) {
66 return (Builder) super.appId(appId);
67 }
68
69 @Override
70 public Builder key(Key key) {
71 return (Builder) super.key(key);
72 }
73
74 @Override
75 public Builder selector(TrafficSelector selector) {
76 return (Builder) super.selector(selector);
77 }
78
79 @Override
80 public Builder treatment(TrafficTreatment treatment) {
81 return (Builder) super.treatment(treatment);
82 }
83
84 @Override
85 public Builder constraints(List<Constraint> constraints) {
86 return (Builder) super.constraints(constraints);
87 }
88
89 @Override
90 public Builder priority(int priority) {
91 return (Builder) super.priority(priority);
92 }
93
94 /**
95 * Sets the ingress point of the point to point intent that will be built.
96 *
97 * @param ingressPoint ingress connect point
98 * @return this builder
99 */
100 public Builder ingressPoint(ConnectPoint ingressPoint) {
101 this.ingressPoint = ingressPoint;
102 return this;
103 }
104
105 /**
106 * Sets the egress point of the point to point intent that will be built.
107 *
108 * @param egressPoint egress connect point
109 * @return this builder
110 */
111 public Builder egressPoint(ConnectPoint egressPoint) {
112 this.egressPoint = egressPoint;
113 return this;
114 }
115
116 /**
117 * Builds a point to point intent from the accumulated parameters.
118 *
119 * @return point to point intent
120 */
121 public PointToPointIntent build() {
122
123 return new PointToPointIntent(
124 appId,
125 key,
126 selector,
127 treatment,
128 ingressPoint,
129 egressPoint,
130 constraints,
131 priority
132 );
133 }
134 }
135
136
137
138 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700139 * Creates a new point-to-point intent with the supplied ingress/egress
Ray Milkey5b3717e2015-02-05 11:44:08 -0800140 * ports and constraints.
141 *
142 * @param appId application identifier
143 * @param key key of the intent
144 * @param selector traffic selector
145 * @param treatment treatment
146 * @param ingressPoint ingress port
147 * @param egressPoint egress port
148 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -0700149 * @param priority priority to use for flows generated by this intent
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700150 * @throws NullPointerException if {@code ingressPoint} or
151 * {@code egressPoints} or {@code appId} is null.
Ray Milkey5b3717e2015-02-05 11:44:08 -0800152 */
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700153 private PointToPointIntent(ApplicationId appId,
Ray Milkey5b3717e2015-02-05 11:44:08 -0800154 Key key,
155 TrafficSelector selector,
156 TrafficTreatment treatment,
157 ConnectPoint ingressPoint,
158 ConnectPoint egressPoint,
Ray Milkeyc24cde32015-03-10 18:20:18 -0700159 List<Constraint> constraints,
160 int priority) {
161 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
162 priority);
Ray Milkey5b3717e2015-02-05 11:44:08 -0800163
Ray Milkey5b3717e2015-02-05 11:44:08 -0800164 checkArgument(!ingressPoint.equals(egressPoint),
165 "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
166
Ray Milkeyebc5d222015-03-18 15:45:36 -0700167 this.ingressPoint = checkNotNull(ingressPoint);
168 this.egressPoint = checkNotNull(egressPoint);
Ray Milkey5b3717e2015-02-05 11:44:08 -0800169 }
170
171 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700172 * Constructor for serializer.
173 */
174 protected PointToPointIntent() {
175 super();
tom85258ee2014-10-07 00:10:02 -0700176 this.ingressPoint = null;
177 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700178 }
179
180 /**
181 * Returns the port on which the ingress traffic should be connected to
182 * the egress.
183 *
184 * @return ingress port
185 */
tom85258ee2014-10-07 00:10:02 -0700186 public ConnectPoint ingressPoint() {
187 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700188 }
189
190 /**
191 * Returns the port on which the traffic should egress.
192 *
193 * @return egress port
194 */
tom85258ee2014-10-07 00:10:02 -0700195 public ConnectPoint egressPoint() {
196 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700197 }
198
199 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700200 public String toString() {
201 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700202 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800203 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700204 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700205 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800206 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700207 .add("selector", selector())
208 .add("treatment", treatment())
209 .add("ingress", ingressPoint)
210 .add("egress", egressPoint)
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800211 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700212 .toString();
213 }
214
215}