blob: 5f80d9a9886d8cef834a888e84f657fdb8e2b9de [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
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
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070021import org.onosproject.core.ApplicationId;
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
25
26import com.google.common.base.MoreObjects;
27
Sho SHIMIZU2e660802014-11-21 14:55:32 -080028import static com.google.common.base.Preconditions.checkArgument;
toma1d16b62014-10-02 23:45:11 -070029import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070030
31/**
32 * Abstraction of point-to-point connectivity.
33 */
Ray Milkeybd4f0112015-03-02 17:07:09 -080034public final class PointToPointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070035
tom85258ee2014-10-07 00:10:02 -070036 private final ConnectPoint ingressPoint;
37 private final ConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070038
39 /**
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070040 * Returns a new point to point intent builder. The application id,
41 * ingress point and egress point are required fields. If they are
42 * not set by calls to the appropriate methods, an exception will
43 * be thrown.
44 *
45 * @return point to point builder
46 */
47 public static PointToPointIntent.Builder builder() {
48 return new Builder();
49 }
50
51 /**
52 * Builder of a point to point intent.
53 */
54 public static final class Builder extends ConnectivityIntent.Builder {
55 ConnectPoint ingressPoint;
56 ConnectPoint egressPoint;
57
58 private Builder() {
59 // Hide constructor
60 }
61
62 @Override
63 public Builder appId(ApplicationId appId) {
64 return (Builder) super.appId(appId);
65 }
66
67 @Override
68 public Builder key(Key key) {
69 return (Builder) super.key(key);
70 }
71
72 @Override
73 public Builder selector(TrafficSelector selector) {
74 return (Builder) super.selector(selector);
75 }
76
77 @Override
78 public Builder treatment(TrafficTreatment treatment) {
79 return (Builder) super.treatment(treatment);
80 }
81
82 @Override
83 public Builder constraints(List<Constraint> constraints) {
84 return (Builder) super.constraints(constraints);
85 }
86
87 @Override
88 public Builder priority(int priority) {
89 return (Builder) super.priority(priority);
90 }
91
92 /**
93 * Sets the ingress point of the point to point intent that will be built.
94 *
95 * @param ingressPoint ingress connect point
96 * @return this builder
97 */
98 public Builder ingressPoint(ConnectPoint ingressPoint) {
99 this.ingressPoint = ingressPoint;
100 return this;
101 }
102
103 /**
104 * Sets the egress point of the point to point intent that will be built.
105 *
106 * @param egressPoint egress connect point
107 * @return this builder
108 */
109 public Builder egressPoint(ConnectPoint egressPoint) {
110 this.egressPoint = egressPoint;
111 return this;
112 }
113
114 /**
115 * Builds a point to point intent from the accumulated parameters.
116 *
117 * @return point to point intent
118 */
119 public PointToPointIntent build() {
120
121 return new PointToPointIntent(
122 appId,
123 key,
124 selector,
125 treatment,
126 ingressPoint,
127 egressPoint,
128 constraints,
129 priority
130 );
131 }
132 }
133
134
135
136 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700137 * Creates a new point-to-point intent with the supplied ingress/egress
Ray Milkey5b3717e2015-02-05 11:44:08 -0800138 * ports and constraints.
139 *
140 * @param appId application identifier
141 * @param key key of the intent
142 * @param selector traffic selector
143 * @param treatment treatment
144 * @param ingressPoint ingress port
145 * @param egressPoint egress port
146 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -0700147 * @param priority priority to use for flows generated by this intent
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700148 * @throws NullPointerException if {@code ingressPoint} or
149 * {@code egressPoints} or {@code appId} is null.
Ray Milkey5b3717e2015-02-05 11:44:08 -0800150 */
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700151 private PointToPointIntent(ApplicationId appId,
Ray Milkey5b3717e2015-02-05 11:44:08 -0800152 Key key,
153 TrafficSelector selector,
154 TrafficTreatment treatment,
155 ConnectPoint ingressPoint,
156 ConnectPoint egressPoint,
Ray Milkeyc24cde32015-03-10 18:20:18 -0700157 List<Constraint> constraints,
158 int priority) {
159 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
160 priority);
Ray Milkey5b3717e2015-02-05 11:44:08 -0800161
162 checkNotNull(ingressPoint);
163 checkNotNull(egressPoint);
164 checkArgument(!ingressPoint.equals(egressPoint),
165 "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
166
167 this.ingressPoint = ingressPoint;
168 this.egressPoint = egressPoint;
169 }
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}