Yuta HIGUCHI | 4d0f89a | 2016-09-14 15:40:39 -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 | 4d0f89a | 2016-09-14 15:40:39 -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.behaviour.protection; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
| 20 | import java.util.List; |
| 21 | |
| 22 | import javax.annotation.concurrent.Immutable; |
| 23 | |
| 24 | import org.onosproject.net.DeviceId; |
| 25 | |
| 26 | import com.google.common.annotations.Beta; |
| 27 | import com.google.common.base.MoreObjects; |
| 28 | import com.google.common.collect.ImmutableList; |
| 29 | |
| 30 | /** |
| 31 | * Configuration for a protected transport entity endpoint. |
| 32 | */ |
| 33 | @Beta |
| 34 | @Immutable |
| 35 | public class ProtectedTransportEndpointDescription { |
| 36 | |
| 37 | /** |
| 38 | * List of underlying transport entity endpoints in priority order. |
| 39 | */ |
| 40 | private final List<TransportEndpointDescription> paths; |
| 41 | |
| 42 | /** |
| 43 | * DeviceId of remote peer of this endpoint. |
| 44 | */ |
| 45 | private final DeviceId peer; |
| 46 | |
| 47 | // Note: Do we need opaque configuration? |
| 48 | // ⇨ For device specific configuration, |
| 49 | // NO, it should be expressed as org.onosproject.net.config.Config |
| 50 | // For information needed for caller to correlate Intent to description, |
| 51 | // use fingerprint |
| 52 | /** |
| 53 | * Caller specified fingerprint to identify this protected transport entity. |
| 54 | * <p> |
| 55 | * Virtual port corresponding to this description, |
| 56 | * should have annotations {@link ProtectionConfigBehaviour#FINGERPRINT} |
| 57 | * with the value specified by this field. |
| 58 | */ |
| 59 | private final String fingerprint; |
| 60 | |
| 61 | |
| 62 | /** |
| 63 | * Constructor. |
| 64 | * |
| 65 | * @param paths {@link TransportEndpointDescription}s |
| 66 | * @param peer remote peer of this endpoint |
| 67 | * @param fingerprint to identify this protected transport entity. |
| 68 | */ |
| 69 | protected ProtectedTransportEndpointDescription(List<TransportEndpointDescription> paths, |
| 70 | DeviceId peer, |
| 71 | String fingerprint) { |
| 72 | this.paths = ImmutableList.copyOf(paths); |
| 73 | this.peer = checkNotNull(peer); |
| 74 | this.fingerprint = checkNotNull(fingerprint); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Returns List of underlying transport entity endpoints in priority order. |
| 79 | * |
| 80 | * @return the transport entity endpoint descriptions |
| 81 | */ |
| 82 | public List<TransportEndpointDescription> paths() { |
| 83 | return paths; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Returns DeviceId of remote peer of this endpoint. |
| 88 | * @return the peer |
| 89 | */ |
| 90 | public DeviceId peer() { |
| 91 | return peer; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Returns fingerprint to identify this protected transport entity. |
| 96 | * |
| 97 | * @return the fingerprint |
| 98 | */ |
| 99 | public String fingerprint() { |
| 100 | return fingerprint; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public String toString() { |
| 105 | return MoreObjects.toStringHelper(this) |
| 106 | .add("paths", paths) |
| 107 | .add("peer", peer) |
| 108 | .add("fingerprint", fingerprint) |
| 109 | .toString(); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Creates a {@link ProtectedTransportEndpointDescription}. |
| 114 | * |
| 115 | * @param paths {@link TransportEndpointDescription}s forming protection |
Yuta HIGUCHI | dcfa31a | 2016-12-09 19:37:41 -0800 | [diff] [blame] | 116 | * @param peer DeviceId of remote peer of this endpoint. |
| 117 | * @param fingerprint opaque fingerprint object. must be serializable. |
| 118 | * @return {@link TransportEndpointDescription} |
| 119 | */ |
| 120 | public static final ProtectedTransportEndpointDescription |
| 121 | buildDescription(List<TransportEndpointDescription> paths, |
| 122 | DeviceId peer, |
| 123 | String fingerprint) { |
| 124 | return new ProtectedTransportEndpointDescription(paths, peer, fingerprint); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Creates a {@link ProtectedTransportEndpointDescription}. |
| 129 | * |
| 130 | * @param paths {@link TransportEndpointDescription}s forming protection |
| 131 | * @param peer DeviceId of remote peer of this endpoint. |
Yuta HIGUCHI | 4d0f89a | 2016-09-14 15:40:39 -0700 | [diff] [blame] | 132 | * @param fingerprint opaque fingerprint object. must be serializable. |
| 133 | * @return {@link TransportEndpointDescription} |
| 134 | */ |
| 135 | public static final ProtectedTransportEndpointDescription |
| 136 | of(List<TransportEndpointDescription> paths, |
Yuta HIGUCHI | dcfa31a | 2016-12-09 19:37:41 -0800 | [diff] [blame] | 137 | DeviceId peer, |
Yuta HIGUCHI | 4d0f89a | 2016-09-14 15:40:39 -0700 | [diff] [blame] | 138 | String fingerprint) { |
Yuta HIGUCHI | dcfa31a | 2016-12-09 19:37:41 -0800 | [diff] [blame] | 139 | return new ProtectedTransportEndpointDescription(paths, peer, fingerprint); |
Yuta HIGUCHI | 4d0f89a | 2016-09-14 15:40:39 -0700 | [diff] [blame] | 140 | } |
| 141 | } |