blob: 11bdcb816532080364c595a68f106a60c2ec4fe5 [file] [log] [blame]
Hongtao Yin36f79aa2015-02-14 03:51:39 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Hongtao Yin36f79aa2015-02-14 03:51:39 -08003 *
4 * 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
7 *
8 * 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.
15 */
16package org.onosproject.net.intent;
17
Hongtao Yin36f79aa2015-02-14 03:51:39 -080018import java.util.Collections;
19import java.util.List;
20
Brian O'Connor9476fa12015-06-25 15:17:17 -040021import com.google.common.annotations.Beta;
Ray Milkeyebc5d222015-03-18 15:45:36 -070022import org.onosproject.core.ApplicationId;
23import org.onosproject.net.ConnectPoint;
Luca Prete670ac5d2017-02-03 15:55:43 -080024import org.onosproject.net.ResourceGroup;
Ray Milkeyebc5d222015-03-18 15:45:36 -070025import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
27
28import com.google.common.base.MoreObjects;
29
Hongtao Yin36f79aa2015-02-14 03:51:39 -080030import static com.google.common.base.Preconditions.checkNotNull;
31
32/**
33 * Abstraction of bidirectional connectivity between two points in the network.
34 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040035@Beta
Hongtao Yin36f79aa2015-02-14 03:51:39 -080036public final class TwoWayP2PIntent extends ConnectivityIntent {
37
38 private final ConnectPoint one;
39 private final ConnectPoint two;
40
Hongtao Yin36f79aa2015-02-14 03:51:39 -080041
42 /**
43 * Creates a new host-to-host intent with the supplied host pair.
44 *
45 * @param appId application identifier
Ray Milkeyebc5d222015-03-18 15:45:36 -070046 * @param key intent key
Hongtao Yin36f79aa2015-02-14 03:51:39 -080047 * @param one first host
48 * @param two second host
49 * @param selector action
50 * @param treatment ingress port
51 * @param constraints optional prioritized list of path selection constraints
Ray Milkey50a9b722015-03-12 10:38:55 -070052 * @param priority priority to use for flows generated by this intent
Luca Prete670ac5d2017-02-03 15:55:43 -080053 * @param resourceGroup resource group for this intent
Hongtao Yin36f79aa2015-02-14 03:51:39 -080054 * @throws NullPointerException if {@code one} or {@code two} is null.
55 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070056 private TwoWayP2PIntent(ApplicationId appId, Key key,
Luca Prete670ac5d2017-02-03 15:55:43 -080057 ConnectPoint one, ConnectPoint two,
58 TrafficSelector selector,
59 TrafficTreatment treatment,
60 List<Constraint> constraints,
61 int priority,
62 ResourceGroup resourceGroup) {
Ray Milkeyc24cde32015-03-10 18:20:18 -070063 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -080064 priority, resourceGroup);
Hongtao Yin36f79aa2015-02-14 03:51:39 -080065
66 // TODO: consider whether the case one and two are same is allowed
67 this.one = checkNotNull(one);
68 this.two = checkNotNull(two);
69
70 }
71
Ray Milkeyebc5d222015-03-18 15:45:36 -070072 /**
73 * Returns a new two way intent builder.
74 *
75 * @return two way intent builder
76 */
77 public static Builder builder() {
78 return new Builder();
Hongtao Yin36f79aa2015-02-14 03:51:39 -080079 }
80
Ray Milkeyebc5d222015-03-18 15:45:36 -070081 /**
82 * Builder of a point to point intent.
83 */
84 public static final class Builder extends ConnectivityIntent.Builder {
85 ConnectPoint one;
86 ConnectPoint two;
87
88 private Builder() {
89 // Hide constructor
90 }
91
92 @Override
93 public Builder appId(ApplicationId appId) {
94 return (Builder) super.appId(appId);
95 }
96
97 @Override
98 public Builder key(Key key) {
99 return (Builder) super.key(key);
100 }
101
102 @Override
103 public Builder selector(TrafficSelector selector) {
104 return (Builder) super.selector(selector);
105 }
106
107 @Override
108 public Builder treatment(TrafficTreatment treatment) {
109 return (Builder) super.treatment(treatment);
110 }
111
112 @Override
113 public Builder constraints(List<Constraint> constraints) {
114 return (Builder) super.constraints(constraints);
115 }
116
117 @Override
118 public Builder priority(int priority) {
119 return (Builder) super.priority(priority);
120 }
121
Luca Prete670ac5d2017-02-03 15:55:43 -0800122 @Override
123 public Builder resourceGroup(ResourceGroup resourceGroup) {
124 return (Builder) super.resourceGroup(resourceGroup);
125 }
126
Ray Milkeyebc5d222015-03-18 15:45:36 -0700127 /**
128 * Sets the first connection point of the two way intent that will be built.
129 *
130 * @param one first connect point
131 * @return this builder
132 */
133 public Builder one(ConnectPoint one) {
134 this.one = one;
135 return this;
136 }
137
138 /**
139 * Sets the second connection point of the two way intent that will be built.
140 *
141 * @param two second connect point
142 * @return this builder
143 */
144 public Builder two(ConnectPoint two) {
145 this.two = two;
146 return this;
147 }
148
149 /**
150 * Builds a point to point intent from the accumulated parameters.
151 *
152 * @return point to point intent
153 */
154 public TwoWayP2PIntent build() {
155
156 return new TwoWayP2PIntent(
157 appId,
158 key,
159 one,
160 two,
161 selector,
162 treatment,
163 constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800164 priority,
165 resourceGroup
Ray Milkeyebc5d222015-03-18 15:45:36 -0700166 );
167 }
Hongtao Yin36f79aa2015-02-14 03:51:39 -0800168 }
169
170 /**
171 * Returns identifier of the first host.
172 *
173 * @return first host identifier
174 */
175 public ConnectPoint one() {
176 return one;
177 }
178
179 /**
180 * Returns identifier of the second host.
181 *
182 * @return second host identifier
183 */
184 public ConnectPoint two() {
185 return two;
186 }
187
188 @Override
189 public String toString() {
190 return MoreObjects.toStringHelper(getClass())
191 .add("id", id())
192 .add("key", key())
193 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700194 .add("priority", priority())
Hongtao Yin36f79aa2015-02-14 03:51:39 -0800195 .add("resources", resources())
196 .add("selector", selector())
197 .add("treatment", treatment())
198 .add("constraints", constraints())
Luca Prete670ac5d2017-02-03 15:55:43 -0800199 .add("resourceGroup", resourceGroup())
Hongtao Yin36f79aa2015-02-14 03:51:39 -0800200 .add("one", one)
201 .add("two", two)
202 .toString();
203 }
204
205}