blob: b72ada523328d879fd20e2b177c8f7e09c3b8a8c [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'Connorb5dcc512015-03-24 17:28:00 -070018import com.google.common.base.MoreObjects;
19import com.google.common.collect.ImmutableSet;
Ray Milkeyebc5d222015-03-18 15:45:36 -070020import org.onosproject.core.ApplicationId;
21import org.onosproject.net.HostId;
22import org.onosproject.net.flow.TrafficSelector;
23import org.onosproject.net.flow.TrafficTreatment;
24
Brian O'Connorb5dcc512015-03-24 17:28:00 -070025import java.util.List;
Ray Milkeyebc5d222015-03-18 15:45:36 -070026
toma1d16b62014-10-02 23:45:11 -070027import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connor66630c82014-10-02 21:08:19 -070028
29/**
tomf5c9d922014-10-03 15:22:03 -070030 * Abstraction of end-station to end-station bidirectional connectivity.
Brian O'Connor66630c82014-10-02 21:08:19 -070031 */
Ray Milkeye6684082014-10-16 16:59:47 -070032public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070033
tomf5c9d922014-10-03 15:22:03 -070034 private final HostId one;
35 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070036
37 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070038 * Returns a new host to host intent builder.
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080039 *
Ray Milkeyebc5d222015-03-18 15:45:36 -070040 * @return host to host intent builder
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080041 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070042 public static Builder builder() {
43 return new Builder();
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080044 }
45
46 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070047 * Builder of a host to host intent.
Brian O'Connor66630c82014-10-02 21:08:19 -070048 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070049 public static final class Builder extends ConnectivityIntent.Builder {
50 HostId one;
51 HostId two;
52
53 private Builder() {
54 // Hide constructor
55 }
56
57 @Override
58 public Builder appId(ApplicationId appId) {
59 return (Builder) super.appId(appId);
60 }
61
62 @Override
63 public Builder key(Key key) {
64 return (Builder) super.key(key);
65 }
66
67 @Override
68 public Builder selector(TrafficSelector selector) {
69 return (Builder) super.selector(selector);
70 }
71
72 @Override
73 public Builder treatment(TrafficTreatment treatment) {
74 return (Builder) super.treatment(treatment);
75 }
76
77 @Override
78 public Builder constraints(List<Constraint> constraints) {
79 return (Builder) super.constraints(constraints);
80 }
81
82 @Override
83 public Builder priority(int priority) {
84 return (Builder) super.priority(priority);
85 }
86
87 /**
88 * Sets the first host of the intent that will be built.
89 *
90 * @param one first host
91 * @return this builder
92 */
93 public Builder one(HostId one) {
94 this.one = one;
95 return this;
96 }
97
98 /**
99 * Sets the second host of the intent that will be built.
100 *
101 * @param two second host
102 * @return this builder
103 */
104 public Builder two(HostId two) {
105 this.two = two;
106 return this;
107 }
108
109 /**
110 * Builds a host to host intent from the accumulated parameters.
111 *
112 * @return point to point intent
113 */
114 public HostToHostIntent build() {
115
116 return new HostToHostIntent(
117 appId,
118 key,
119 one,
120 two,
121 selector,
122 treatment,
123 constraints,
124 priority
125 );
126 }
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800127 }
128
Ray Milkeyebc5d222015-03-18 15:45:36 -0700129
Ray Milkey5b3717e2015-02-05 11:44:08 -0800130 /**
131 * Creates a new host-to-host intent with the supplied host pair.
132 *
133 * @param appId application identifier
134 * @param key intent key
135 * @param one first host
136 * @param two second host
137 * @param selector action
138 * @param treatment ingress port
139 * @param constraints optional prioritized list of path selection constraints
Ray Milkey50a9b722015-03-12 10:38:55 -0700140 * @param priority priority to use for flows generated by this intent
Ray Milkey5b3717e2015-02-05 11:44:08 -0800141 * @throws NullPointerException if {@code one} or {@code two} is null.
142 */
Ray Milkeyebc5d222015-03-18 15:45:36 -0700143 private HostToHostIntent(ApplicationId appId, Key key,
Ray Milkey5b3717e2015-02-05 11:44:08 -0800144 HostId one, HostId two,
145 TrafficSelector selector,
146 TrafficTreatment treatment,
Ray Milkey50a9b722015-03-12 10:38:55 -0700147 List<Constraint> constraints,
148 int priority) {
Brian O'Connorb5dcc512015-03-24 17:28:00 -0700149 super(appId, key, ImmutableSet.of(one, two), selector, treatment,
Ray Milkey50a9b722015-03-12 10:38:55 -0700150 constraints, priority);
Sho SHIMIZU2e660802014-11-21 14:55:32 -0800151
152 // TODO: consider whether the case one and two are same is allowed
tomf5c9d922014-10-03 15:22:03 -0700153 this.one = checkNotNull(one);
154 this.two = checkNotNull(two);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800155
Brian O'Connor66630c82014-10-02 21:08:19 -0700156 }
157
158 /**
tomf5c9d922014-10-03 15:22:03 -0700159 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700160 *
tomf5c9d922014-10-03 15:22:03 -0700161 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700162 */
tomf5c9d922014-10-03 15:22:03 -0700163 public HostId one() {
164 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -0700165 }
166
167 /**
tomf5c9d922014-10-03 15:22:03 -0700168 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700169 *
tomf5c9d922014-10-03 15:22:03 -0700170 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700171 */
tomf5c9d922014-10-03 15:22:03 -0700172 public HostId two() {
173 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -0700174 }
175
176 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -0700177 public String toString() {
178 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700179 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800180 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700181 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700182 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800183 .add("resources", resources())
tom85258ee2014-10-07 00:10:02 -0700184 .add("selector", selector())
185 .add("treatment", treatment())
Ray Milkey460f4022014-11-05 15:41:43 -0800186 .add("constraints", constraints())
tomf5c9d922014-10-03 15:22:03 -0700187 .add("one", one)
188 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -0700189 .toString();
190 }
191
192}