blob: a995758be5d76debc08e7c64c1b7f88b373ba4f3 [file] [log] [blame]
Hongtao Yin36f79aa2015-02-14 03:51:39 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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
Ray Milkeyebc5d222015-03-18 15:45:36 -070021import org.onosproject.core.ApplicationId;
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
25
26import com.google.common.base.MoreObjects;
27
Hongtao Yin36f79aa2015-02-14 03:51:39 -080028import static com.google.common.base.Preconditions.checkNotNull;
29
30/**
31 * Abstraction of bidirectional connectivity between two points in the network.
32 */
33public final class TwoWayP2PIntent extends ConnectivityIntent {
34
35 private final ConnectPoint one;
36 private final ConnectPoint two;
37
Hongtao Yin36f79aa2015-02-14 03:51:39 -080038
39 /**
40 * Creates a new host-to-host intent with the supplied host pair.
41 *
42 * @param appId application identifier
Ray Milkeyebc5d222015-03-18 15:45:36 -070043 * @param key intent key
Hongtao Yin36f79aa2015-02-14 03:51:39 -080044 * @param one first host
45 * @param two second host
46 * @param selector action
47 * @param treatment ingress port
48 * @param constraints optional prioritized list of path selection constraints
Ray Milkey50a9b722015-03-12 10:38:55 -070049 * @param priority priority to use for flows generated by this intent
Hongtao Yin36f79aa2015-02-14 03:51:39 -080050 * @throws NullPointerException if {@code one} or {@code two} is null.
51 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070052 private TwoWayP2PIntent(ApplicationId appId, Key key,
Hongtao Yin36f79aa2015-02-14 03:51:39 -080053 ConnectPoint one, ConnectPoint two,
54 TrafficSelector selector,
55 TrafficTreatment treatment,
Ray Milkey50a9b722015-03-12 10:38:55 -070056 List<Constraint> constraints,
57 int priority) {
Ray Milkeyc24cde32015-03-10 18:20:18 -070058 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
Ray Milkey50a9b722015-03-12 10:38:55 -070059 priority);
Hongtao Yin36f79aa2015-02-14 03:51:39 -080060
61 // TODO: consider whether the case one and two are same is allowed
62 this.one = checkNotNull(one);
63 this.two = checkNotNull(two);
64
65 }
66
Ray Milkeyebc5d222015-03-18 15:45:36 -070067 /**
68 * Returns a new two way intent builder.
69 *
70 * @return two way intent builder
71 */
72 public static Builder builder() {
73 return new Builder();
Hongtao Yin36f79aa2015-02-14 03:51:39 -080074 }
75
Ray Milkeyebc5d222015-03-18 15:45:36 -070076 /**
77 * Builder of a point to point intent.
78 */
79 public static final class Builder extends ConnectivityIntent.Builder {
80 ConnectPoint one;
81 ConnectPoint two;
82
83 private Builder() {
84 // Hide constructor
85 }
86
87 @Override
88 public Builder appId(ApplicationId appId) {
89 return (Builder) super.appId(appId);
90 }
91
92 @Override
93 public Builder key(Key key) {
94 return (Builder) super.key(key);
95 }
96
97 @Override
98 public Builder selector(TrafficSelector selector) {
99 return (Builder) super.selector(selector);
100 }
101
102 @Override
103 public Builder treatment(TrafficTreatment treatment) {
104 return (Builder) super.treatment(treatment);
105 }
106
107 @Override
108 public Builder constraints(List<Constraint> constraints) {
109 return (Builder) super.constraints(constraints);
110 }
111
112 @Override
113 public Builder priority(int priority) {
114 return (Builder) super.priority(priority);
115 }
116
117 /**
118 * Sets the first connection point of the two way intent that will be built.
119 *
120 * @param one first connect point
121 * @return this builder
122 */
123 public Builder one(ConnectPoint one) {
124 this.one = one;
125 return this;
126 }
127
128 /**
129 * Sets the second connection point of the two way intent that will be built.
130 *
131 * @param two second connect point
132 * @return this builder
133 */
134 public Builder two(ConnectPoint two) {
135 this.two = two;
136 return this;
137 }
138
139 /**
140 * Builds a point to point intent from the accumulated parameters.
141 *
142 * @return point to point intent
143 */
144 public TwoWayP2PIntent build() {
145
146 return new TwoWayP2PIntent(
147 appId,
148 key,
149 one,
150 two,
151 selector,
152 treatment,
153 constraints,
154 priority
155 );
156 }
Hongtao Yin36f79aa2015-02-14 03:51:39 -0800157 }
158
159 /**
160 * Returns identifier of the first host.
161 *
162 * @return first host identifier
163 */
164 public ConnectPoint one() {
165 return one;
166 }
167
168 /**
169 * Returns identifier of the second host.
170 *
171 * @return second host identifier
172 */
173 public ConnectPoint two() {
174 return two;
175 }
176
177 @Override
178 public String toString() {
179 return MoreObjects.toStringHelper(getClass())
180 .add("id", id())
181 .add("key", key())
182 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700183 .add("priority", priority())
Hongtao Yin36f79aa2015-02-14 03:51:39 -0800184 .add("resources", resources())
185 .add("selector", selector())
186 .add("treatment", treatment())
187 .add("constraints", constraints())
188 .add("one", one)
189 .add("two", two)
190 .toString();
191 }
192
193}