blob: ff42dcd33d68b64293c097af1c4c1dcae11f07fb [file] [log] [blame]
Brian Stanke0e5c94e2016-03-08 11:20:04 -05001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Brian Stanke0e5c94e2016-03-08 11:20:04 -05003 *
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
17package org.onosproject.incubator.net.virtual;
18
19import org.onosproject.incubator.net.tunnel.TunnelId;
20import org.onosproject.net.ConnectPoint;
21import org.onosproject.net.DefaultAnnotations;
22import org.onosproject.net.DefaultLink;
23import org.onosproject.net.provider.ProviderId;
24
25import java.util.Objects;
26
27import static com.google.common.base.MoreObjects.toStringHelper;
Brian Stanke9a108972016-04-11 15:25:17 -040028import static com.google.common.base.Preconditions.checkNotNull;
Brian Stanke0e5c94e2016-03-08 11:20:04 -050029
30/**
31 * Default representation of a virtual link.
32 */
33public final class DefaultVirtualLink extends DefaultLink implements VirtualLink {
34
Brian Stanke9a108972016-04-11 15:25:17 -040035 private static final String VIRTUAL = "virtualLink";
36 public static final ProviderId PID = new ProviderId(VIRTUAL, VIRTUAL);
Brian Stanke0e5c94e2016-03-08 11:20:04 -050037
38 private final NetworkId networkId;
39 private final TunnelId tunnelId;
40
41 /**
Brian Stanke9a108972016-04-11 15:25:17 -040042 * Private constructor for a default virtual link.
Brian Stanke0e5c94e2016-03-08 11:20:04 -050043 *
44 * @param networkId network identifier
45 * @param src source connection point
46 * @param dst destination connection point
47 * @param tunnelId tunnel identifier
48 */
Brian Stanke9a108972016-04-11 15:25:17 -040049 private DefaultVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) {
Brian Stanke0e5c94e2016-03-08 11:20:04 -050050 super(PID, src, dst, Type.VIRTUAL, DefaultAnnotations.builder().build());
51 this.networkId = networkId;
52 this.tunnelId = tunnelId;
53 }
54
55 @Override
56 public NetworkId networkId() {
57 return networkId;
58 }
59
60 /**
61 * Returns the tunnel identifier.
62 *
63 * @return tunnel identifier.
64 */
65 public TunnelId tunnelId() {
66 return tunnelId;
67 }
68
69 @Override
70 public int hashCode() {
71 return Objects.hash(networkId, tunnelId);
72 }
73
74 @Override
75 public boolean equals(Object obj) {
76 if (this == obj) {
77 return true;
78 }
79 if (obj instanceof DefaultVirtualLink) {
80 DefaultVirtualLink that = (DefaultVirtualLink) obj;
81 return super.equals(that) &&
82 Objects.equals(this.networkId, that.networkId) &&
83 Objects.equals(this.tunnelId, that.tunnelId);
84 }
85 return false;
86 }
87
88 @Override
89 public String toString() {
90 return toStringHelper(this).add("networkId", networkId).add("tunnelId", tunnelId).toString();
91 }
Brian Stanke9a108972016-04-11 15:25:17 -040092
93 /**
94 * Creates a new default virtual link builder.
95 *
96 * @return default virtual link builder
97 */
98 public static Builder builder() {
99 return new Builder();
100 }
101
102 /**
103 * Builder for DefaultVirtualLink objects.
104 */
105 public static final class Builder extends DefaultLink.Builder {
106 private NetworkId networkId;
107 private ConnectPoint src;
108 private ConnectPoint dst;
109 private TunnelId tunnelId;
110
111 private Builder() {
112 // Hide constructor
113 }
114
115 /**
116 * Sets the network identifier to be used by the builder.
117 *
118 * @param networkId network identifier
119 * @return self
120 */
121 public Builder networkId(NetworkId networkId) {
122 this.networkId = networkId;
123 return this;
124 }
125
126 /**
127 * Sets the source connect point to be used by the builder.
128 *
129 * @param src source connect point
130 * @return self
131 */
132 public Builder src(ConnectPoint src) {
133 this.src = src;
134 return this;
135 }
136
137 /**
138 * Sets the destination connect point to be used by the builder.
139 *
140 * @param dst new destination connect point
141 * @return self
142 */
143 public Builder dst(ConnectPoint dst) {
144 this.dst = dst;
145 return this;
146 }
147
148 /**
149 * Sets the tunnel identifier to be used by the builder.
150 *
151 * @param tunnelId tunnel identifier
152 * @return self
153 */
154 public Builder tunnelId(TunnelId tunnelId) {
155 this.tunnelId = tunnelId;
156 return this;
157 }
158
159 /**
160 * Builds a default virtual link object from the accumulated parameters.
161 *
162 * @return default virtual link object
163 */
164 public DefaultVirtualLink build() {
165 checkNotNull(src, "Source connect point cannot be null");
166 checkNotNull(dst, "Destination connect point cannot be null");
167 checkNotNull(networkId, "Network Id cannot be null");
168
169 return new DefaultVirtualLink(networkId, src, dst, tunnelId);
170 }
171 }
Brian Stanke0e5c94e2016-03-08 11:20:04 -0500172}