blob: 754d4339123765201d2ccbb2ff6550c0e14efe7b [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
weibitf32383b2014-10-22 10:17:31 -070017
Ray Milkeye076c792015-03-24 09:38:30 -070018import java.util.Collection;
19
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.core.ApplicationId;
21import org.onosproject.net.ConnectPoint;
22import org.onosproject.net.Link;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.net.Path;
weibitf32383b2014-10-22 10:17:31 -070024
Ray Milkeye076c792015-03-24 09:38:30 -070025import com.google.common.base.MoreObjects;
26import com.google.common.collect.ImmutableSet;
weibitf32383b2014-10-22 10:17:31 -070027
Ray Milkeyebc5d222015-03-18 15:45:36 -070028import static com.google.common.base.Preconditions.checkNotNull;
29
Ray Milkeybd4f0112015-03-02 17:07:09 -080030public final class OpticalPathIntent extends Intent {
Brian O'Connor086724e2014-10-23 15:47:32 -070031
32 private final ConnectPoint src;
33 private final ConnectPoint dst;
weibitf32383b2014-10-22 10:17:31 -070034 private final Path path;
Brian O'Connor086724e2014-10-23 15:47:32 -070035
weibitf32383b2014-10-22 10:17:31 -070036
Ray Milkeye076c792015-03-24 09:38:30 -070037 private OpticalPathIntent(ApplicationId appId,
38 Key key,
39 ConnectPoint src,
40 ConnectPoint dst,
41 Path path,
42 int priority) {
43 super(appId,
44 key,
45 ImmutableSet.copyOf(path.links()),
46 priority);
Ray Milkeyebc5d222015-03-18 15:45:36 -070047 this.src = checkNotNull(src);
48 this.dst = checkNotNull(dst);
49 this.path = checkNotNull(path);
weibitf32383b2014-10-22 10:17:31 -070050 }
51
weibit9e622ac2014-10-23 13:45:44 -070052 protected OpticalPathIntent() {
Brian O'Connor086724e2014-10-23 15:47:32 -070053 this.src = null;
54 this.dst = null;
weibitf32383b2014-10-22 10:17:31 -070055 this.path = null;
56 }
57
Ray Milkeye076c792015-03-24 09:38:30 -070058 /**
59 * Returns a new optical connectivity intent builder.
60 *
61 * @return host to host intent builder
62 */
63 public static Builder builder() {
64 return new Builder();
65 }
66
67
68 /**
69 * Builder for optical path intents.
70 */
71 public static class Builder extends Intent.Builder {
72 private ConnectPoint src;
73 private ConnectPoint dst;
74 private Path path;
75 Key key;
76
77 @Override
78 public Builder appId(ApplicationId appId) {
79 return (Builder) super.appId(appId);
80 }
81
82 @Override
83 public Builder key(Key key) {
84 return (Builder) super.key(key);
85 }
86
87 @Override
88 public Builder priority(int priority) {
89 return (Builder) super.priority(priority);
90 }
91
92 /**
93 * Sets the source for the intent that will be built.
94 *
95 * @param src source to use for built intent
96 * @return this builder
97 */
98 public Builder src(ConnectPoint src) {
99 this.src = src;
100 return this;
101 }
102
103 /**
104 * Sets the destination for the intent that will be built.
105 *
106 * @param dst dest to use for built intent
107 * @return this builder
108 */
109 public Builder dst(ConnectPoint dst) {
110 this.dst = dst;
111 return this;
112 }
113
114 /**
115 * Sets the path for the intent that will be built.
116 *
117 * @param path path to use for built intent
118 * @return this builder
119 */
120 public Builder path(Path path) {
121 this.path = path;
122 return this;
123 }
124
125 /**
126 * Builds an optical path intent from the accumulated parameters.
127 *
128 * @return optical path intent
129 */
130 public OpticalPathIntent build() {
131
132 return new OpticalPathIntent(
133 appId,
134 key,
135 src,
136 dst,
137 path,
138 priority
139 );
140 }
141 }
142
143
Brian O'Connor086724e2014-10-23 15:47:32 -0700144 public ConnectPoint src() {
145 return src;
146 }
147
148 public ConnectPoint dst() {
149 return dst;
150 }
151
weibitf32383b2014-10-22 10:17:31 -0700152 public Path path() {
153 return path;
154 }
weibitf32383b2014-10-22 10:17:31 -0700155
weibitf32383b2014-10-22 10:17:31 -0700156 @Override
weibit7e583462014-10-23 10:14:05 -0700157 public boolean isInstallable() {
weibitf32383b2014-10-22 10:17:31 -0700158 return true;
159 }
160
161 @Override
weibitf32383b2014-10-22 10:17:31 -0700162 public String toString() {
163 return MoreObjects.toStringHelper(getClass())
164 .add("id", id())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800165 .add("appId", appId())
Ray Milkeyebc5d222015-03-18 15:45:36 -0700166 .add("key", key())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800167 .add("resources", resources())
Brian O'Connor086724e2014-10-23 15:47:32 -0700168 .add("ingressPort", src)
169 .add("egressPort", dst)
weibitf32383b2014-10-22 10:17:31 -0700170 .add("path", path)
171 .toString();
172 }
173
Praseed Balakrishnan00dd1f92014-11-19 17:12:36 -0800174
weibitf32383b2014-10-22 10:17:31 -0700175 public Collection<Link> requiredLinks() {
176 return path.links();
177 }
178}