blob: 5e1eacc7d041a53147c5c79585e2a368e270ea23 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
weibitf32383b2014-10-22 10:17:31 -070017
Brian O'Connorabafb502014-12-02 22:26:20 -080018import org.onosproject.core.ApplicationId;
19import org.onosproject.net.ConnectPoint;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070020import org.onosproject.net.OchSignal;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.Path;
weibitf32383b2014-10-22 10:17:31 -070022
Ray Milkeye076c792015-03-24 09:38:30 -070023import com.google.common.base.MoreObjects;
24import com.google.common.collect.ImmutableSet;
weibitf32383b2014-10-22 10:17:31 -070025
Ray Milkeyebc5d222015-03-18 15:45:36 -070026import static com.google.common.base.Preconditions.checkNotNull;
27
Ray Milkeybd4f0112015-03-02 17:07:09 -080028public final class OpticalPathIntent extends Intent {
Brian O'Connor086724e2014-10-23 15:47:32 -070029
30 private final ConnectPoint src;
31 private final ConnectPoint dst;
weibitf32383b2014-10-22 10:17:31 -070032 private final Path path;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070033 private final OchSignal lambda;
weibitf32383b2014-10-22 10:17:31 -070034
Ray Milkeye076c792015-03-24 09:38:30 -070035 private OpticalPathIntent(ApplicationId appId,
36 Key key,
37 ConnectPoint src,
38 ConnectPoint dst,
39 Path path,
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070040 OchSignal lambda,
Ray Milkeye076c792015-03-24 09:38:30 -070041 int priority) {
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070042 super(appId, key, ImmutableSet.copyOf(path.links()), priority);
Ray Milkeyebc5d222015-03-18 15:45:36 -070043 this.src = checkNotNull(src);
44 this.dst = checkNotNull(dst);
45 this.path = checkNotNull(path);
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070046 this.lambda = checkNotNull(lambda);
weibitf32383b2014-10-22 10:17:31 -070047 }
48
weibit9e622ac2014-10-23 13:45:44 -070049 protected OpticalPathIntent() {
Brian O'Connor086724e2014-10-23 15:47:32 -070050 this.src = null;
51 this.dst = null;
weibitf32383b2014-10-22 10:17:31 -070052 this.path = null;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070053 this.lambda = null;
weibitf32383b2014-10-22 10:17:31 -070054 }
55
Ray Milkeye076c792015-03-24 09:38:30 -070056 /**
57 * Returns a new optical connectivity intent builder.
58 *
59 * @return host to host intent builder
60 */
61 public static Builder builder() {
62 return new Builder();
63 }
64
65
66 /**
67 * Builder for optical path intents.
68 */
69 public static class Builder extends Intent.Builder {
70 private ConnectPoint src;
71 private ConnectPoint dst;
72 private Path path;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070073 private OchSignal lambda;
Ray Milkeye076c792015-03-24 09:38:30 -070074 Key key;
75
76 @Override
77 public Builder appId(ApplicationId appId) {
78 return (Builder) super.appId(appId);
79 }
80
81 @Override
82 public Builder key(Key key) {
83 return (Builder) super.key(key);
84 }
85
86 @Override
87 public Builder priority(int priority) {
88 return (Builder) super.priority(priority);
89 }
90
91 /**
92 * Sets the source for the intent that will be built.
93 *
94 * @param src source to use for built intent
95 * @return this builder
96 */
97 public Builder src(ConnectPoint src) {
98 this.src = src;
99 return this;
100 }
101
102 /**
103 * Sets the destination for the intent that will be built.
104 *
105 * @param dst dest to use for built intent
106 * @return this builder
107 */
108 public Builder dst(ConnectPoint dst) {
109 this.dst = dst;
110 return this;
111 }
112
113 /**
114 * Sets the path for the intent that will be built.
115 *
116 * @param path path to use for built intent
117 * @return this builder
118 */
119 public Builder path(Path path) {
120 this.path = path;
121 return this;
122 }
123
124 /**
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700125 * Sets the optical channel (lambda) for the intent that will be built.
126 *
127 * @param lambda the optical channel
128 * @return this builder
129 */
130 public Builder lambda(OchSignal lambda) {
131 this.lambda = lambda;
132 return this;
133 }
134
135 /**
Ray Milkeye076c792015-03-24 09:38:30 -0700136 * Builds an optical path intent from the accumulated parameters.
137 *
138 * @return optical path intent
139 */
140 public OpticalPathIntent build() {
141
142 return new OpticalPathIntent(
143 appId,
144 key,
145 src,
146 dst,
147 path,
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700148 lambda,
Ray Milkeye076c792015-03-24 09:38:30 -0700149 priority
150 );
151 }
152 }
153
154
Brian O'Connor086724e2014-10-23 15:47:32 -0700155 public ConnectPoint src() {
156 return src;
157 }
158
159 public ConnectPoint dst() {
160 return dst;
161 }
162
weibitf32383b2014-10-22 10:17:31 -0700163 public Path path() {
164 return path;
165 }
weibitf32383b2014-10-22 10:17:31 -0700166
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700167 public OchSignal lambda() {
168 return lambda;
169 }
170
weibitf32383b2014-10-22 10:17:31 -0700171 @Override
weibitf32383b2014-10-22 10:17:31 -0700172 public String toString() {
173 return MoreObjects.toStringHelper(getClass())
174 .add("id", id())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800175 .add("appId", appId())
Ray Milkeyebc5d222015-03-18 15:45:36 -0700176 .add("key", key())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800177 .add("resources", resources())
Brian O'Connor086724e2014-10-23 15:47:32 -0700178 .add("ingressPort", src)
179 .add("egressPort", dst)
weibitf32383b2014-10-22 10:17:31 -0700180 .add("path", path)
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700181 .add("lambda", lambda)
weibitf32383b2014-10-22 10:17:31 -0700182 .toString();
183 }
weibitf32383b2014-10-22 10:17:31 -0700184}