blob: d6ad8f91e4954af65f34c4e1b9977455904bf6df [file] [log] [blame]
Yuta HIGUCHI4d0f89a2016-09-14 15:40:39 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Yuta HIGUCHI4d0f89a2016-09-14 15:40:39 -07003 *
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 */
16package org.onosproject.net.behaviour.protection;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.List;
21
22import javax.annotation.concurrent.Immutable;
23
24import org.onosproject.net.DeviceId;
25
26import com.google.common.annotations.Beta;
27import com.google.common.base.MoreObjects;
28import com.google.common.collect.ImmutableList;
29
30/**
31 * Configuration for a protected transport entity endpoint.
32 */
33@Beta
34@Immutable
35public 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 HIGUCHIdcfa31a2016-12-09 19:37:41 -0800116 * @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 HIGUCHI4d0f89a2016-09-14 15:40:39 -0700132 * @param fingerprint opaque fingerprint object. must be serializable.
133 * @return {@link TransportEndpointDescription}
134 */
135 public static final ProtectedTransportEndpointDescription
136 of(List<TransportEndpointDescription> paths,
Yuta HIGUCHIdcfa31a2016-12-09 19:37:41 -0800137 DeviceId peer,
Yuta HIGUCHI4d0f89a2016-09-14 15:40:39 -0700138 String fingerprint) {
Yuta HIGUCHIdcfa31a2016-12-09 19:37:41 -0800139 return new ProtectedTransportEndpointDescription(paths, peer, fingerprint);
Yuta HIGUCHI4d0f89a2016-09-14 15:40:39 -0700140 }
141}