blob: 92dd83b5de203ce1b0204deea2fd338ebe3799b6 [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'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
andreac0085112015-11-24 18:01:45 -0800117
118
Ray Milkeyebc5d222015-03-18 15:45:36 -0700119 /**
120 * Builds a host to host intent from the accumulated parameters.
121 *
122 * @return point to point intent
123 */
124 public HostToHostIntent build() {
125
HIGUCHI Yuta584107a2015-10-27 18:12:44 -0700126 List<Constraint> theConstraints = constraints;
127 // If not-OPTICAL constraint hasn't been specified, add them
128 if (!constraints.contains(NOT_OPTICAL)) {
129 theConstraints = ImmutableList.<Constraint>builder()
130 .add(NOT_OPTICAL)
131 .addAll(constraints)
132 .build();
133 }
134
Ray Milkeyebc5d222015-03-18 15:45:36 -0700135 return new HostToHostIntent(
136 appId,
137 key,
138 one,
139 two,
140 selector,
141 treatment,
HIGUCHI Yuta584107a2015-10-27 18:12:44 -0700142 theConstraints,
Ray Milkeyebc5d222015-03-18 15:45:36 -0700143 priority
144 );
145 }
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800146 }
147
Ray Milkeyebc5d222015-03-18 15:45:36 -0700148
Ray Milkey5b3717e2015-02-05 11:44:08 -0800149 /**
150 * Creates a new host-to-host intent with the supplied host pair.
151 *
152 * @param appId application identifier
153 * @param key intent key
154 * @param one first host
155 * @param two second host
156 * @param selector action
157 * @param treatment ingress port
158 * @param constraints optional prioritized list of path selection constraints
Ray Milkey50a9b722015-03-12 10:38:55 -0700159 * @param priority priority to use for flows generated by this intent
Ray Milkey5b3717e2015-02-05 11:44:08 -0800160 * @throws NullPointerException if {@code one} or {@code two} is null.
161 */
Ray Milkeyebc5d222015-03-18 15:45:36 -0700162 private HostToHostIntent(ApplicationId appId, Key key,
Ray Milkey5b3717e2015-02-05 11:44:08 -0800163 HostId one, HostId two,
164 TrafficSelector selector,
165 TrafficTreatment treatment,
Ray Milkey50a9b722015-03-12 10:38:55 -0700166 List<Constraint> constraints,
167 int priority) {
Brian O'Connorb5dcc512015-03-24 17:28:00 -0700168 super(appId, key, ImmutableSet.of(one, two), selector, treatment,
Ray Milkey50a9b722015-03-12 10:38:55 -0700169 constraints, priority);
Sho SHIMIZU2e660802014-11-21 14:55:32 -0800170
171 // TODO: consider whether the case one and two are same is allowed
tomf5c9d922014-10-03 15:22:03 -0700172 this.one = checkNotNull(one);
173 this.two = checkNotNull(two);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800174
Brian O'Connor66630c82014-10-02 21:08:19 -0700175 }
176
177 /**
tomf5c9d922014-10-03 15:22:03 -0700178 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700179 *
tomf5c9d922014-10-03 15:22:03 -0700180 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700181 */
tomf5c9d922014-10-03 15:22:03 -0700182 public HostId one() {
183 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -0700184 }
185
186 /**
tomf5c9d922014-10-03 15:22:03 -0700187 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700188 *
tomf5c9d922014-10-03 15:22:03 -0700189 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700190 */
tomf5c9d922014-10-03 15:22:03 -0700191 public HostId two() {
192 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -0700193 }
194
195 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -0700196 public String toString() {
197 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700198 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800199 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700200 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700201 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800202 .add("resources", resources())
tom85258ee2014-10-07 00:10:02 -0700203 .add("selector", selector())
204 .add("treatment", treatment())
Ray Milkey460f4022014-11-05 15:41:43 -0800205 .add("constraints", constraints())
tomf5c9d922014-10-03 15:22:03 -0700206 .add("one", one)
207 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -0700208 .toString();
209 }
210
211}