blob: bd4219ad368a1e4465efe90283a15a38c1365d5e [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;
20import com.google.common.collect.ImmutableSet;
Ray Milkeyebc5d222015-03-18 15:45:36 -070021import org.onosproject.core.ApplicationId;
22import org.onosproject.net.HostId;
23import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
25
Brian O'Connorb5dcc512015-03-24 17:28:00 -070026import java.util.List;
Ray Milkeyebc5d222015-03-18 15:45:36 -070027
toma1d16b62014-10-02 23:45:11 -070028import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connor66630c82014-10-02 21:08:19 -070029
30/**
tomf5c9d922014-10-03 15:22:03 -070031 * Abstraction of end-station to end-station bidirectional connectivity.
Brian O'Connor66630c82014-10-02 21:08:19 -070032 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040033@Beta
Ray Milkeye6684082014-10-16 16:59:47 -070034public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070035
tomf5c9d922014-10-03 15:22:03 -070036 private final HostId one;
37 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070038
39 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070040 * Returns a new host to host intent builder.
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080041 *
Ray Milkeyebc5d222015-03-18 15:45:36 -070042 * @return host to host intent builder
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080043 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070044 public static Builder builder() {
45 return new Builder();
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080046 }
47
48 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070049 * Builder of a host to host intent.
Brian O'Connor66630c82014-10-02 21:08:19 -070050 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070051 public static final class Builder extends ConnectivityIntent.Builder {
52 HostId one;
53 HostId two;
54
55 private Builder() {
56 // Hide constructor
57 }
58
59 @Override
60 public Builder appId(ApplicationId appId) {
61 return (Builder) super.appId(appId);
62 }
63
64 @Override
65 public Builder key(Key key) {
66 return (Builder) super.key(key);
67 }
68
69 @Override
70 public Builder selector(TrafficSelector selector) {
71 return (Builder) super.selector(selector);
72 }
73
74 @Override
75 public Builder treatment(TrafficTreatment treatment) {
76 return (Builder) super.treatment(treatment);
77 }
78
79 @Override
80 public Builder constraints(List<Constraint> constraints) {
81 return (Builder) super.constraints(constraints);
82 }
83
84 @Override
85 public Builder priority(int priority) {
86 return (Builder) super.priority(priority);
87 }
88
89 /**
90 * Sets the first host of the intent that will be built.
91 *
92 * @param one first host
93 * @return this builder
94 */
95 public Builder one(HostId one) {
96 this.one = one;
97 return this;
98 }
99
100 /**
101 * Sets the second host of the intent that will be built.
102 *
103 * @param two second host
104 * @return this builder
105 */
106 public Builder two(HostId two) {
107 this.two = two;
108 return this;
109 }
110
111 /**
112 * Builds a host to host intent from the accumulated parameters.
113 *
114 * @return point to point intent
115 */
116 public HostToHostIntent build() {
117
118 return new HostToHostIntent(
119 appId,
120 key,
121 one,
122 two,
123 selector,
124 treatment,
125 constraints,
126 priority
127 );
128 }
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800129 }
130
Ray Milkeyebc5d222015-03-18 15:45:36 -0700131
Ray Milkey5b3717e2015-02-05 11:44:08 -0800132 /**
133 * Creates a new host-to-host intent with the supplied host pair.
134 *
135 * @param appId application identifier
136 * @param key intent key
137 * @param one first host
138 * @param two second host
139 * @param selector action
140 * @param treatment ingress port
141 * @param constraints optional prioritized list of path selection constraints
Ray Milkey50a9b722015-03-12 10:38:55 -0700142 * @param priority priority to use for flows generated by this intent
Ray Milkey5b3717e2015-02-05 11:44:08 -0800143 * @throws NullPointerException if {@code one} or {@code two} is null.
144 */
Ray Milkeyebc5d222015-03-18 15:45:36 -0700145 private HostToHostIntent(ApplicationId appId, Key key,
Ray Milkey5b3717e2015-02-05 11:44:08 -0800146 HostId one, HostId two,
147 TrafficSelector selector,
148 TrafficTreatment treatment,
Ray Milkey50a9b722015-03-12 10:38:55 -0700149 List<Constraint> constraints,
150 int priority) {
Brian O'Connorb5dcc512015-03-24 17:28:00 -0700151 super(appId, key, ImmutableSet.of(one, two), selector, treatment,
Ray Milkey50a9b722015-03-12 10:38:55 -0700152 constraints, priority);
Sho SHIMIZU2e660802014-11-21 14:55:32 -0800153
154 // TODO: consider whether the case one and two are same is allowed
tomf5c9d922014-10-03 15:22:03 -0700155 this.one = checkNotNull(one);
156 this.two = checkNotNull(two);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800157
Brian O'Connor66630c82014-10-02 21:08:19 -0700158 }
159
160 /**
tomf5c9d922014-10-03 15:22:03 -0700161 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700162 *
tomf5c9d922014-10-03 15:22:03 -0700163 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700164 */
tomf5c9d922014-10-03 15:22:03 -0700165 public HostId one() {
166 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -0700167 }
168
169 /**
tomf5c9d922014-10-03 15:22:03 -0700170 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700171 *
tomf5c9d922014-10-03 15:22:03 -0700172 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700173 */
tomf5c9d922014-10-03 15:22:03 -0700174 public HostId two() {
175 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -0700176 }
177
178 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -0700179 public String toString() {
180 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700181 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800182 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700183 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700184 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800185 .add("resources", resources())
tom85258ee2014-10-07 00:10:02 -0700186 .add("selector", selector())
187 .add("treatment", treatment())
Ray Milkey460f4022014-11-05 15:41:43 -0800188 .add("constraints", constraints())
tomf5c9d922014-10-03 15:22:03 -0700189 .add("one", one)
190 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -0700191 .toString();
192 }
193
194}