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