blob: 2a478917554b287b47320762543ade16b82ba881 [file] [log] [blame]
Hongtao Yin36f79aa2015-02-14 03:51:39 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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;
24import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
26
27import com.google.common.base.MoreObjects;
28
Hongtao Yin36f79aa2015-02-14 03:51:39 -080029import static com.google.common.base.Preconditions.checkNotNull;
30
31/**
32 * Abstraction of bidirectional connectivity between two points in the network.
33 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040034@Beta
Hongtao Yin36f79aa2015-02-14 03:51:39 -080035public final class TwoWayP2PIntent extends ConnectivityIntent {
36
37 private final ConnectPoint one;
38 private final ConnectPoint two;
39
Hongtao Yin36f79aa2015-02-14 03:51:39 -080040
41 /**
42 * Creates a new host-to-host intent with the supplied host pair.
43 *
44 * @param appId application identifier
Ray Milkeyebc5d222015-03-18 15:45:36 -070045 * @param key intent key
Hongtao Yin36f79aa2015-02-14 03:51:39 -080046 * @param one first host
47 * @param two second host
48 * @param selector action
49 * @param treatment ingress port
50 * @param constraints optional prioritized list of path selection constraints
Ray Milkey50a9b722015-03-12 10:38:55 -070051 * @param priority priority to use for flows generated by this intent
Hongtao Yin36f79aa2015-02-14 03:51:39 -080052 * @throws NullPointerException if {@code one} or {@code two} is null.
53 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070054 private TwoWayP2PIntent(ApplicationId appId, Key key,
Hongtao Yin36f79aa2015-02-14 03:51:39 -080055 ConnectPoint one, ConnectPoint two,
56 TrafficSelector selector,
57 TrafficTreatment treatment,
Ray Milkey50a9b722015-03-12 10:38:55 -070058 List<Constraint> constraints,
59 int priority) {
Ray Milkeyc24cde32015-03-10 18:20:18 -070060 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
Ray Milkey50a9b722015-03-12 10:38:55 -070061 priority);
Hongtao Yin36f79aa2015-02-14 03:51:39 -080062
63 // TODO: consider whether the case one and two are same is allowed
64 this.one = checkNotNull(one);
65 this.two = checkNotNull(two);
66
67 }
68
Ray Milkeyebc5d222015-03-18 15:45:36 -070069 /**
70 * Returns a new two way intent builder.
71 *
72 * @return two way intent builder
73 */
74 public static Builder builder() {
75 return new Builder();
Hongtao Yin36f79aa2015-02-14 03:51:39 -080076 }
77
Ray Milkeyebc5d222015-03-18 15:45:36 -070078 /**
79 * Builder of a point to point intent.
80 */
81 public static final class Builder extends ConnectivityIntent.Builder {
82 ConnectPoint one;
83 ConnectPoint two;
84
85 private Builder() {
86 // Hide constructor
87 }
88
89 @Override
90 public Builder appId(ApplicationId appId) {
91 return (Builder) super.appId(appId);
92 }
93
94 @Override
95 public Builder key(Key key) {
96 return (Builder) super.key(key);
97 }
98
99 @Override
100 public Builder selector(TrafficSelector selector) {
101 return (Builder) super.selector(selector);
102 }
103
104 @Override
105 public Builder treatment(TrafficTreatment treatment) {
106 return (Builder) super.treatment(treatment);
107 }
108
109 @Override
110 public Builder constraints(List<Constraint> constraints) {
111 return (Builder) super.constraints(constraints);
112 }
113
114 @Override
115 public Builder priority(int priority) {
116 return (Builder) super.priority(priority);
117 }
118
119 /**
120 * Sets the first connection point of the two way intent that will be built.
121 *
122 * @param one first connect point
123 * @return this builder
124 */
125 public Builder one(ConnectPoint one) {
126 this.one = one;
127 return this;
128 }
129
130 /**
131 * Sets the second connection point of the two way intent that will be built.
132 *
133 * @param two second connect point
134 * @return this builder
135 */
136 public Builder two(ConnectPoint two) {
137 this.two = two;
138 return this;
139 }
140
141 /**
142 * Builds a point to point intent from the accumulated parameters.
143 *
144 * @return point to point intent
145 */
146 public TwoWayP2PIntent build() {
147
148 return new TwoWayP2PIntent(
149 appId,
150 key,
151 one,
152 two,
153 selector,
154 treatment,
155 constraints,
156 priority
157 );
158 }
Hongtao Yin36f79aa2015-02-14 03:51:39 -0800159 }
160
161 /**
162 * Returns identifier of the first host.
163 *
164 * @return first host identifier
165 */
166 public ConnectPoint one() {
167 return one;
168 }
169
170 /**
171 * Returns identifier of the second host.
172 *
173 * @return second host identifier
174 */
175 public ConnectPoint two() {
176 return two;
177 }
178
179 @Override
180 public String toString() {
181 return MoreObjects.toStringHelper(getClass())
182 .add("id", id())
183 .add("key", key())
184 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700185 .add("priority", priority())
Hongtao Yin36f79aa2015-02-14 03:51:39 -0800186 .add("resources", resources())
187 .add("selector", selector())
188 .add("treatment", treatment())
189 .add("constraints", constraints())
190 .add("one", one)
191 .add("two", two)
192 .toString();
193 }
194
195}