Yuta HIGUCHI | a255bb4 | 2016-11-03 16:04:08 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Yuta HIGUCHI | a255bb4 | 2016-11-03 16:04:08 -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 | */ |
| 16 | package org.onosproject.net.intent; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | import java.util.Collection; |
| 20 | |
| 21 | import javax.annotation.concurrent.Immutable; |
| 22 | |
| 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.onosproject.net.NetworkResource; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 26 | import org.onosproject.net.ResourceGroup; |
Yuta HIGUCHI | a255bb4 | 2016-11-03 16:04:08 -0700 | [diff] [blame] | 27 | import org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription; |
| 28 | |
| 29 | import com.google.common.annotations.Beta; |
| 30 | import com.google.common.base.MoreObjects; |
| 31 | import com.google.common.collect.ImmutableList; |
| 32 | |
| 33 | /** |
| 34 | * Installable Intent for the ProtectionEndpoint (head/tail). |
| 35 | */ |
| 36 | @Immutable |
| 37 | @Beta |
| 38 | public class ProtectionEndpointIntent extends Intent { |
| 39 | |
| 40 | private final DeviceId deviceId; |
| 41 | private final ProtectedTransportEndpointDescription description; |
| 42 | |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 43 | /** |
| 44 | * Creates a ProtectionEndpointIntent by specific resource and description. |
| 45 | * |
| 46 | * @param appId application identification |
| 47 | * @param key intent key |
| 48 | * @param resources network resource to be set |
| 49 | * @param priority priority to use for flows from this intent |
| 50 | * @param deviceId target device id |
| 51 | * @param description protected transport endpoint description of the intent |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 52 | * @param resourceGroup resource group for this intent |
| 53 | */ |
| 54 | protected ProtectionEndpointIntent(ApplicationId appId, Key key, |
| 55 | Collection<NetworkResource> resources, |
| 56 | int priority, |
| 57 | DeviceId deviceId, |
| 58 | ProtectedTransportEndpointDescription description, |
| 59 | ResourceGroup resourceGroup) { |
| 60 | super(appId, key, resources, priority, resourceGroup); |
Yuta HIGUCHI | a255bb4 | 2016-11-03 16:04:08 -0700 | [diff] [blame] | 61 | |
| 62 | this.deviceId = checkNotNull(deviceId); |
| 63 | this.description = checkNotNull(description); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Returns the identifier of the device to be configured. |
| 68 | * |
| 69 | * @return the deviceId |
| 70 | */ |
| 71 | public DeviceId deviceId() { |
| 72 | return deviceId; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Returns the description of this protection endpoint. |
| 77 | * |
| 78 | * @return the description |
| 79 | */ |
| 80 | public ProtectedTransportEndpointDescription description() { |
| 81 | return description; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public boolean isInstallable() { |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public String toString() { |
| 91 | return MoreObjects.toStringHelper(getClass()) |
| 92 | .add("id", id()) |
| 93 | .add("key", key()) |
| 94 | .add("appId", appId()) |
| 95 | .add("priority", priority()) |
| 96 | .add("resources", resources()) |
| 97 | .add("deviceId", deviceId) |
| 98 | .add("description", description) |
| 99 | .toString(); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Returns a new {@link ProtectionEndpointIntent} builder. |
| 104 | * |
| 105 | * @return the builder |
| 106 | */ |
| 107 | public static Builder builder() { |
| 108 | return new Builder(); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Builder for {@link ProtectionEndpointIntent}. |
| 113 | */ |
| 114 | public static class Builder extends Intent.Builder { |
| 115 | |
| 116 | private DeviceId deviceId; |
| 117 | private ProtectedTransportEndpointDescription description; |
| 118 | |
| 119 | /** |
| 120 | * Creates a new empty builder. |
| 121 | */ |
| 122 | protected Builder() { |
| 123 | resources = ImmutableList.of(); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Creates a new builder pre-populated with the information in the given |
| 128 | * intent. |
| 129 | * |
| 130 | * @param intent initial intent |
| 131 | */ |
| 132 | protected Builder(ProtectionEndpointIntent intent) { |
| 133 | super(intent); |
| 134 | } |
| 135 | |
| 136 | // TODO remove these overrides |
| 137 | @Override |
| 138 | public Builder key(Key key) { |
| 139 | super.key(key); |
| 140 | return this; |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public Builder appId(ApplicationId appId) { |
| 145 | super.appId(appId); |
| 146 | return this; |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public Builder resources(Collection<NetworkResource> resources) { |
| 151 | super.resources(resources); |
| 152 | return this; |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public Builder priority(int priority) { |
| 157 | super.priority(priority); |
| 158 | return this; |
| 159 | } |
| 160 | |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 161 | @Override |
| 162 | public Builder resourceGroup(ResourceGroup resourceGroup) { |
| 163 | return (Builder) super.resourceGroup(resourceGroup); |
| 164 | } |
| 165 | |
Yuta HIGUCHI | a255bb4 | 2016-11-03 16:04:08 -0700 | [diff] [blame] | 166 | public Builder deviceId(DeviceId deviceId) { |
| 167 | this.deviceId = deviceId; |
| 168 | return this; |
| 169 | } |
| 170 | |
| 171 | public Builder description(ProtectedTransportEndpointDescription description) { |
| 172 | this.description = description; |
| 173 | return this; |
| 174 | } |
| 175 | |
| 176 | public ProtectionEndpointIntent build() { |
| 177 | checkNotNull(key, "Key inherited from origin Intent expected."); |
| 178 | return new ProtectionEndpointIntent(appId, |
| 179 | key, |
| 180 | resources, |
| 181 | priority, |
| 182 | deviceId, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 183 | description, |
| 184 | resourceGroup); |
Yuta HIGUCHI | a255bb4 | 2016-11-03 16:04:08 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | } |
| 188 | |
| 189 | |
| 190 | |
| 191 | /* |
| 192 | * For serialization. |
| 193 | */ |
| 194 | @SuppressWarnings("unused") |
| 195 | private ProtectionEndpointIntent() { |
| 196 | this.deviceId = null; |
| 197 | this.description = null; |
| 198 | } |
| 199 | } |