blob: c14672411f914a52a287154d651129a419fc46f5 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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'Connor66630c82014-10-02 21:08:19 -070017
Brian O'Connor9476fa12015-06-25 15:17:17 -040018import com.google.common.annotations.Beta;
Brian O'Connorb5dcc512015-03-24 17:28:00 -070019import com.google.common.base.MoreObjects;
HIGUCHI Yuta584107a2015-10-27 18:12:44 -070020import com.google.common.collect.ImmutableList;
Brian O'Connorb5dcc512015-03-24 17:28:00 -070021import com.google.common.collect.ImmutableSet;
HIGUCHI Yuta584107a2015-10-27 18:12:44 -070022
Ray Milkeyebc5d222015-03-18 15:45:36 -070023import org.onosproject.core.ApplicationId;
24import org.onosproject.net.HostId;
HIGUCHI Yuta584107a2015-10-27 18:12:44 -070025import org.onosproject.net.Link;
Ray Milkeyebc5d222015-03-18 15:45:36 -070026import org.onosproject.net.flow.TrafficSelector;
27import org.onosproject.net.flow.TrafficTreatment;
HIGUCHI Yuta584107a2015-10-27 18:12:44 -070028import org.onosproject.net.intent.constraint.LinkTypeConstraint;
Ray Milkeyebc5d222015-03-18 15:45:36 -070029
Brian O'Connorb5dcc512015-03-24 17:28:00 -070030import java.util.List;
Ray Milkeyebc5d222015-03-18 15:45:36 -070031
toma1d16b62014-10-02 23:45:11 -070032import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connor66630c82014-10-02 21:08:19 -070033
34/**
tomf5c9d922014-10-03 15:22:03 -070035 * Abstraction of end-station to end-station bidirectional connectivity.
Brian O'Connor66630c82014-10-02 21:08:19 -070036 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040037@Beta
Ray Milkeye6684082014-10-16 16:59:47 -070038public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070039
HIGUCHI Yuta584107a2015-10-27 18:12:44 -070040 static final LinkTypeConstraint NOT_OPTICAL = new LinkTypeConstraint(false, Link.Type.OPTICAL);
41
tomf5c9d922014-10-03 15:22:03 -070042 private final HostId one;
43 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070044
45 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070046 * Returns a new host to host intent builder.
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080047 *
Ray Milkeyebc5d222015-03-18 15:45:36 -070048 * @return host to host intent builder
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080049 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070050 public static Builder builder() {
51 return new Builder();
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080052 }
53
54 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070055 * Builder of a host to host intent.
Brian O'Connor66630c82014-10-02 21:08:19 -070056 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070057 public static final class Builder extends ConnectivityIntent.Builder {
58 HostId one;
59 HostId two;
60
61 private Builder() {
62 // Hide constructor
63 }
64
65 @Override
66 public Builder appId(ApplicationId appId) {
67 return (Builder) super.appId(appId);
68 }
69
70 @Override
71 public Builder key(Key key) {
72 return (Builder) super.key(key);
73 }
74
75 @Override
76 public Builder selector(TrafficSelector selector) {
77 return (Builder) super.selector(selector);
78 }
79
80 @Override
81 public Builder treatment(TrafficTreatment treatment) {
82 return (Builder) super.treatment(treatment);
83 }
84
85 @Override
86 public Builder constraints(List<Constraint> constraints) {
87 return (Builder) super.constraints(constraints);
88 }
89
90 @Override
91 public Builder priority(int priority) {
92 return (Builder) super.priority(priority);
93 }
94
95 /**
96 * Sets the first host of the intent that will be built.
97 *
98 * @param one first host
99 * @return this builder
100 */
101 public Builder one(HostId one) {
102 this.one = one;
103 return this;
104 }
105
106 /**
107 * Sets the second host of the intent that will be built.
108 *
109 * @param two second host
110 * @return this builder
111 */
112 public Builder two(HostId two) {
113 this.two = two;
114 return this;
115 }
116
117 /**
118 * Builds a host to host intent from the accumulated parameters.
119 *
120 * @return point to point intent
121 */
122 public HostToHostIntent build() {
123
HIGUCHI Yuta584107a2015-10-27 18:12:44 -0700124 List<Constraint> theConstraints = constraints;
125 // If not-OPTICAL constraint hasn't been specified, add them
126 if (!constraints.contains(NOT_OPTICAL)) {
127 theConstraints = ImmutableList.<Constraint>builder()
128 .add(NOT_OPTICAL)
129 .addAll(constraints)
130 .build();
131 }
132
Ray Milkeyebc5d222015-03-18 15:45:36 -0700133 return new HostToHostIntent(
134 appId,
135 key,
136 one,
137 two,
138 selector,
139 treatment,
HIGUCHI Yuta584107a2015-10-27 18:12:44 -0700140 theConstraints,
Ray Milkeyebc5d222015-03-18 15:45:36 -0700141 priority
142 );
143 }
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800144 }
145
Ray Milkeyebc5d222015-03-18 15:45:36 -0700146
Ray Milkey5b3717e2015-02-05 11:44:08 -0800147 /**
148 * Creates a new host-to-host intent with the supplied host pair.
149 *
150 * @param appId application identifier
151 * @param key intent key
152 * @param one first host
153 * @param two second host
154 * @param selector action
155 * @param treatment ingress port
156 * @param constraints optional prioritized list of path selection constraints
Ray Milkey50a9b722015-03-12 10:38:55 -0700157 * @param priority priority to use for flows generated by this intent
Ray Milkey5b3717e2015-02-05 11:44:08 -0800158 * @throws NullPointerException if {@code one} or {@code two} is null.
159 */
Ray Milkeyebc5d222015-03-18 15:45:36 -0700160 private HostToHostIntent(ApplicationId appId, Key key,
Ray Milkey5b3717e2015-02-05 11:44:08 -0800161 HostId one, HostId two,
162 TrafficSelector selector,
163 TrafficTreatment treatment,
Ray Milkey50a9b722015-03-12 10:38:55 -0700164 List<Constraint> constraints,
165 int priority) {
Brian O'Connorb5dcc512015-03-24 17:28:00 -0700166 super(appId, key, ImmutableSet.of(one, two), selector, treatment,
Ray Milkey50a9b722015-03-12 10:38:55 -0700167 constraints, priority);
Sho SHIMIZU2e660802014-11-21 14:55:32 -0800168
169 // TODO: consider whether the case one and two are same is allowed
tomf5c9d922014-10-03 15:22:03 -0700170 this.one = checkNotNull(one);
171 this.two = checkNotNull(two);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800172
Brian O'Connor66630c82014-10-02 21:08:19 -0700173 }
174
175 /**
tomf5c9d922014-10-03 15:22:03 -0700176 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700177 *
tomf5c9d922014-10-03 15:22:03 -0700178 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700179 */
tomf5c9d922014-10-03 15:22:03 -0700180 public HostId one() {
181 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -0700182 }
183
184 /**
tomf5c9d922014-10-03 15:22:03 -0700185 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700186 *
tomf5c9d922014-10-03 15:22:03 -0700187 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700188 */
tomf5c9d922014-10-03 15:22:03 -0700189 public HostId two() {
190 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -0700191 }
192
193 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -0700194 public String toString() {
195 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700196 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800197 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700198 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700199 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800200 .add("resources", resources())
tom85258ee2014-10-07 00:10:02 -0700201 .add("selector", selector())
202 .add("treatment", treatment())
Ray Milkey460f4022014-11-05 15:41:43 -0800203 .add("constraints", constraints())
tomf5c9d922014-10-03 15:22:03 -0700204 .add("one", one)
205 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -0700206 .toString();
207 }
208
209}