blob: 777dfd7113ec5353f7c34c847df8a730c2e3ff19 [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 javax.annotation.concurrent.Immutable;
21
22import org.onosproject.net.FilteredConnectPoint;
23
24import com.google.common.annotations.Beta;
25import com.google.common.base.MoreObjects;
26
27/**
28 * Configuration for a underlying path endpoint, forming protected path.
29 */
30@Beta
31@Immutable
32public class TransportEndpointDescription {
33
34 // TODO is there a better field name for this?
35 // Only VLAN selector expected in practice for now.
36 private final FilteredConnectPoint output;
37
38 /**
39 * True if this endpoint is administratively enabled, false otherwise.
40 */
41 private final boolean enabled;
42
43 // Do we need opaque config per path/flow?
44 // ⇨ No it should probably be expressed as org.onosproject.net.config.Config
45
46 protected TransportEndpointDescription(FilteredConnectPoint output,
47 boolean enabled) {
48 this.output = checkNotNull(output);
49 this.enabled = enabled;
50 }
51
52 /**
53 * @return the output
54 */
55 public FilteredConnectPoint output() {
56 return output;
57 }
58
59 /**
60 * Returns administrative state.
61 *
62 * @return the enabled
63 */
64 public boolean isEnabled() {
65 return enabled;
66 }
67
68 @Override
69 public String toString() {
70 return MoreObjects.toStringHelper(this)
71 .add("output", output)
72 .add("enabled", enabled)
73 .toString();
74 }
75
76
77 /**
78 * Returns {@link TransportEndpointDescription} builder.
79 *
80 * @return the builder
81 */
82 public static Builder builder() {
83 return new Builder();
84 }
85
86 public static class Builder {
87 private FilteredConnectPoint output;
88 private boolean enabled = true;
89
90 /**
91 * Copies all the fields from {@code src}.
92 *
93 * @param src object to copy from
94 * @return this
95 */
96 public Builder copyFrom(TransportEndpointDescription src) {
97 this.output = src.output();
98 this.enabled = src.isEnabled();
99 return this;
100 }
101
102 /**
103 * Sets output configuration.
104 *
105 * @param output configuration to set
106 * @return this
107 */
108 public Builder withOutput(FilteredConnectPoint output) {
109 this.output = output;
110 return this;
111 }
112
113 /**
114 * Sets enabled state.
115 *
116 * @param enabled state to set
117 * @return this
118 */
119 public Builder withEnabled(boolean enabled) {
120 this.enabled = enabled;
121 return this;
122 }
123
124 /**
125 * Builds {@link TransportEndpointDescription}.
126 *
127 * @return {@link TransportEndpointDescription}
128 */
129 public TransportEndpointDescription build() {
130 checkNotNull(output, "output field is mandatory");
131 return new TransportEndpointDescription(output, enabled);
132 }
133 }
134}