Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 17 | |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 18 | import java.util.Collection; |
| 19 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.Link; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.net.Path; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 24 | |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 25 | import com.google.common.base.MoreObjects; |
| 26 | import com.google.common.collect.ImmutableSet; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 27 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 28 | import static com.google.common.base.Preconditions.checkNotNull; |
| 29 | |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 30 | public final class OpticalPathIntent extends Intent { |
Brian O'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 31 | |
| 32 | private final ConnectPoint src; |
| 33 | private final ConnectPoint dst; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 34 | private final Path path; |
Brian O'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 35 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 36 | |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 37 | 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 Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 47 | this.src = checkNotNull(src); |
| 48 | this.dst = checkNotNull(dst); |
| 49 | this.path = checkNotNull(path); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 50 | } |
| 51 | |
weibit | 9e622ac | 2014-10-23 13:45:44 -0700 | [diff] [blame] | 52 | protected OpticalPathIntent() { |
Brian O'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 53 | this.src = null; |
| 54 | this.dst = null; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 55 | this.path = null; |
| 56 | } |
| 57 | |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 58 | /** |
| 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'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 144 | public ConnectPoint src() { |
| 145 | return src; |
| 146 | } |
| 147 | |
| 148 | public ConnectPoint dst() { |
| 149 | return dst; |
| 150 | } |
| 151 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 152 | public Path path() { |
| 153 | return path; |
| 154 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 155 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 156 | @Override |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 157 | public String toString() { |
| 158 | return MoreObjects.toStringHelper(getClass()) |
| 159 | .add("id", id()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 160 | .add("appId", appId()) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 161 | .add("key", key()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 162 | .add("resources", resources()) |
Brian O'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 163 | .add("ingressPort", src) |
| 164 | .add("egressPort", dst) |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 165 | .add("path", path) |
| 166 | .toString(); |
| 167 | } |
| 168 | |
Praseed Balakrishnan | 00dd1f9 | 2014-11-19 17:12:36 -0800 | [diff] [blame] | 169 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 170 | public Collection<Link> requiredLinks() { |
| 171 | return path.links(); |
| 172 | } |
| 173 | } |