blob: 157397a4b33d3523430330fa16349e98742ad530 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 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
Sho SHIMIZUd7d18002015-01-21 14:37:14 -080018import java.util.Collections;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080019import java.util.List;
20
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
26import com.google.common.base.MoreObjects;
27
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 */
Ray Milkeye6684082014-10-16 16:59:47 -070033public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070034
tomf5c9d922014-10-03 15:22:03 -070035 private final HostId one;
36 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070037
38 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070039 * Returns a new host to host intent builder.
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080040 *
Ray Milkeyebc5d222015-03-18 15:45:36 -070041 * @return host to host intent builder
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080042 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070043 public static Builder builder() {
44 return new Builder();
Thomas Vachuska6dd018f2014-12-04 15:04:26 -080045 }
46
47 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070048 * Builder of a host to host intent.
Brian O'Connor66630c82014-10-02 21:08:19 -070049 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070050 public static final class Builder extends ConnectivityIntent.Builder {
51 HostId one;
52 HostId two;
53
54 private Builder() {
55 // Hide constructor
56 }
57
58 @Override
59 public Builder appId(ApplicationId appId) {
60 return (Builder) super.appId(appId);
61 }
62
63 @Override
64 public Builder key(Key key) {
65 return (Builder) super.key(key);
66 }
67
68 @Override
69 public Builder selector(TrafficSelector selector) {
70 return (Builder) super.selector(selector);
71 }
72
73 @Override
74 public Builder treatment(TrafficTreatment treatment) {
75 return (Builder) super.treatment(treatment);
76 }
77
78 @Override
79 public Builder constraints(List<Constraint> constraints) {
80 return (Builder) super.constraints(constraints);
81 }
82
83 @Override
84 public Builder priority(int priority) {
85 return (Builder) super.priority(priority);
86 }
87
88 /**
89 * Sets the first host of the intent that will be built.
90 *
91 * @param one first host
92 * @return this builder
93 */
94 public Builder one(HostId one) {
95 this.one = one;
96 return this;
97 }
98
99 /**
100 * Sets the second host of the intent that will be built.
101 *
102 * @param two second host
103 * @return this builder
104 */
105 public Builder two(HostId two) {
106 this.two = two;
107 return this;
108 }
109
110 /**
111 * Builds a host to host intent from the accumulated parameters.
112 *
113 * @return point to point intent
114 */
115 public HostToHostIntent build() {
116
117 return new HostToHostIntent(
118 appId,
119 key,
120 one,
121 two,
122 selector,
123 treatment,
124 constraints,
125 priority
126 );
127 }
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800128 }
129
Ray Milkeyebc5d222015-03-18 15:45:36 -0700130
Ray Milkey5b3717e2015-02-05 11:44:08 -0800131 /**
132 * Creates a new host-to-host intent with the supplied host pair.
133 *
134 * @param appId application identifier
135 * @param key intent key
136 * @param one first host
137 * @param two second host
138 * @param selector action
139 * @param treatment ingress port
140 * @param constraints optional prioritized list of path selection constraints
Ray Milkey50a9b722015-03-12 10:38:55 -0700141 * @param priority priority to use for flows generated by this intent
Ray Milkey5b3717e2015-02-05 11:44:08 -0800142 * @throws NullPointerException if {@code one} or {@code two} is null.
143 */
Ray Milkeyebc5d222015-03-18 15:45:36 -0700144 private HostToHostIntent(ApplicationId appId, Key key,
Ray Milkey5b3717e2015-02-05 11:44:08 -0800145 HostId one, HostId two,
146 TrafficSelector selector,
147 TrafficTreatment treatment,
Ray Milkey50a9b722015-03-12 10:38:55 -0700148 List<Constraint> constraints,
149 int priority) {
150 super(appId, key, Collections.emptyList(), selector, treatment,
151 constraints, priority);
Sho SHIMIZU2e660802014-11-21 14:55:32 -0800152
153 // TODO: consider whether the case one and two are same is allowed
tomf5c9d922014-10-03 15:22:03 -0700154 this.one = checkNotNull(one);
155 this.two = checkNotNull(two);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800156
Brian O'Connor66630c82014-10-02 21:08:19 -0700157 }
158
159 /**
tomf5c9d922014-10-03 15:22:03 -0700160 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700161 *
tomf5c9d922014-10-03 15:22:03 -0700162 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700163 */
tomf5c9d922014-10-03 15:22:03 -0700164 public HostId one() {
165 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -0700166 }
167
168 /**
tomf5c9d922014-10-03 15:22:03 -0700169 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -0700170 *
tomf5c9d922014-10-03 15:22:03 -0700171 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -0700172 */
tomf5c9d922014-10-03 15:22:03 -0700173 public HostId two() {
174 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -0700175 }
176
177 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -0700178 public String toString() {
179 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700180 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800181 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700182 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700183 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800184 .add("resources", resources())
tom85258ee2014-10-07 00:10:02 -0700185 .add("selector", selector())
186 .add("treatment", treatment())
Ray Milkey460f4022014-11-05 15:41:43 -0800187 .add("constraints", constraints())
tomf5c9d922014-10-03 15:22:03 -0700188 .add("one", one)
189 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -0700190 .toString();
191 }
192
193}