blob: a7505ae7f5101b3b4b7d59fe6b6cd939e319bd51 [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;
Luca Prete670ac5d2017-02-03 15:55:43 -080026import org.onosproject.net.ResourceGroup;
Ray Milkeyebc5d222015-03-18 15:45:36 -070027import org.onosproject.net.flow.TrafficSelector;
28import org.onosproject.net.flow.TrafficTreatment;
HIGUCHI Yuta584107a2015-10-27 18:12:44 -070029import org.onosproject.net.intent.constraint.LinkTypeConstraint;
Ray Milkeyebc5d222015-03-18 15:45:36 -070030
Brian O'Connorb5dcc512015-03-24 17:28:00 -070031import java.util.List;
Ray Milkeyebc5d222015-03-18 15:45:36 -070032
toma1d16b62014-10-02 23:45:11 -070033import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connor66630c82014-10-02 21:08:19 -070034
35/**
tomf5c9d922014-10-03 15:22:03 -070036 * Abstraction of end-station to end-station bidirectional connectivity.
Brian O'Connor66630c82014-10-02 21:08:19 -070037 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040038@Beta
Ray Milkeye6684082014-10-16 16:59:47 -070039public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070040
HIGUCHI Yuta584107a2015-10-27 18:12:44 -070041 static final LinkTypeConstraint NOT_OPTICAL = new LinkTypeConstraint(false, Link.Type.OPTICAL);
42
tomf5c9d922014-10-03 15:22:03 -070043 private final HostId one;
44 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070045
46 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070047 * Returns a new host to host intent builder.
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080048 *
Ray Milkeyebc5d222015-03-18 15:45:36 -070049 * @return host to host intent builder
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080050 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070051 public static Builder builder() {
52 return new Builder();
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080053 }
54
55 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070056 * Builder of a host to host intent.
Brian O'Connor66630c82014-10-02 21:08:19 -070057 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070058 public static final class Builder extends ConnectivityIntent.Builder {
59 HostId one;
60 HostId two;
61
62 private Builder() {
63 // Hide constructor
64 }
65
66 @Override
67 public Builder appId(ApplicationId appId) {
68 return (Builder) super.appId(appId);
69 }
70
71 @Override
72 public Builder key(Key key) {
73 return (Builder) super.key(key);
74 }
75
76 @Override
77 public Builder selector(TrafficSelector selector) {
78 return (Builder) super.selector(selector);
79 }
80
81 @Override
82 public Builder treatment(TrafficTreatment treatment) {
83 return (Builder) super.treatment(treatment);
84 }
85
86 @Override
87 public Builder constraints(List<Constraint> constraints) {
88 return (Builder) super.constraints(constraints);
89 }
90
91 @Override
92 public Builder priority(int priority) {
93 return (Builder) super.priority(priority);
94 }
95
Luca Prete670ac5d2017-02-03 15:55:43 -080096 @Override
97 public Builder resourceGroup(ResourceGroup resourceGroup) {
98 return (Builder) super.resourceGroup(resourceGroup);
99 }
100
Ray Milkeyebc5d222015-03-18 15:45:36 -0700101 /**
102 * Sets the first host of the intent that will be built.
103 *
104 * @param one first host
105 * @return this builder
106 */
107 public Builder one(HostId one) {
108 this.one = one;
109 return this;
110 }
111
112 /**
113 * Sets the second host of the intent that will be built.
114 *
115 * @param two second host
116 * @return this builder
117 */
118 public Builder two(HostId two) {
119 this.two = two;
120 return this;
121 }
122
123 /**
124 * Builds a host to host intent from the accumulated parameters.
125 *
126 * @return point to point intent
127 */
128 public HostToHostIntent build() {
129
HIGUCHI Yuta584107a2015-10-27 18:12:44 -0700130 List<Constraint> theConstraints = constraints;
131 // If not-OPTICAL constraint hasn't been specified, add them
132 if (!constraints.contains(NOT_OPTICAL)) {
133 theConstraints = ImmutableList.<Constraint>builder()
134 .add(NOT_OPTICAL)
135 .addAll(constraints)
136 .build();
137 }
138
Ray Milkeyebc5d222015-03-18 15:45:36 -0700139 return new HostToHostIntent(
140 appId,
141 key,
142 one,
143 two,
144 selector,
145 treatment,
HIGUCHI Yuta584107a2015-10-27 18:12:44 -0700146 theConstraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800147 priority,
148 resourceGroup
Ray Milkeyebc5d222015-03-18 15:45:36 -0700149 );
150 }
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800151 }
152
Ray Milkey5b3717e2015-02-05 11:44:08 -0800153 /**
154 * Creates a new host-to-host intent with the supplied host pair.
155 *
156 * @param appId application identifier
157 * @param key intent key
158 * @param one first host
159 * @param two second host
160 * @param selector action
161 * @param treatment ingress port
162 * @param constraints optional prioritized list of path selection constraints
Ray Milkey50a9b722015-03-12 10:38:55 -0700163 * @param priority priority to use for flows generated by this intent
Luca Prete670ac5d2017-02-03 15:55:43 -0800164 * @param resourceGroup resource group for this intent
Ray Milkey5b3717e2015-02-05 11:44:08 -0800165 * @throws NullPointerException if {@code one} or {@code two} is null.
166 */
Ray Milkeyebc5d222015-03-18 15:45:36 -0700167 private HostToHostIntent(ApplicationId appId, Key key,
Luca Prete670ac5d2017-02-03 15:55:43 -0800168 HostId one, HostId two,
169 TrafficSelector selector,
170 TrafficTreatment treatment,
171 List<Constraint> constraints,
172 int priority,
173 ResourceGroup resourceGroup) {
Brian O'Connorb5dcc512015-03-24 17:28:00 -0700174 super(appId, key, ImmutableSet.of(one, two), selector, treatment,
Luca Prete670ac5d2017-02-03 15:55:43 -0800175 constraints, priority, resourceGroup);
Sho SHIMIZU2e660802014-11-21 14:55:32 -0800176
177 // TODO: consider whether the case one and two are same is allowed
tomf5c9d922014-10-03 15:22:03 -0700178 this.one = checkNotNull(one);
179 this.two = checkNotNull(two);
Brian O'Connor66630c82014-10-02 21:08:19 -0700180 }
181
182 /**
tomf5c9d922014-10-03 15:22:03 -0700183 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700184 *
tomf5c9d922014-10-03 15:22:03 -0700185 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700186 */
tomf5c9d922014-10-03 15:22:03 -0700187 public HostId one() {
188 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -0700189 }
190
191 /**
tomf5c9d922014-10-03 15:22:03 -0700192 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700193 *
tomf5c9d922014-10-03 15:22:03 -0700194 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700195 */
tomf5c9d922014-10-03 15:22:03 -0700196 public HostId two() {
197 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -0700198 }
199
200 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -0700201 public String toString() {
202 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700203 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800204 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700205 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700206 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800207 .add("resources", resources())
tom85258ee2014-10-07 00:10:02 -0700208 .add("selector", selector())
209 .add("treatment", treatment())
Ray Milkey460f4022014-11-05 15:41:43 -0800210 .add("constraints", constraints())
Luca Prete670ac5d2017-02-03 15:55:43 -0800211 .add("resourceGroup", resourceGroup())
tomf5c9d922014-10-03 15:22:03 -0700212 .add("one", one)
213 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -0700214 .toString();
215 }
216
217}