blob: 6ebd52d95c03efe0aa42ec70b055580877235608 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
tom4c6606f2014-09-07 11:11:21 -070016package org.onlab.onos.net;
17
tomeadbb462014-09-07 16:10:19 -070018import org.onlab.onos.net.provider.ProviderId;
tom4c6606f2014-09-07 11:11:21 -070019
20import java.util.Objects;
21
tomeadbb462014-09-07 16:10:19 -070022import static com.google.common.base.MoreObjects.toStringHelper;
Thomas Vachuska57126fe2014-11-11 17:13:24 -080023import static org.onlab.onos.net.Link.State.ACTIVE;
tom4c6606f2014-09-07 11:11:21 -070024
25/**
26 * Default infrastructure link model implementation.
27 */
tomeadbb462014-09-07 16:10:19 -070028public class DefaultLink extends AbstractModel implements Link {
tom4c6606f2014-09-07 11:11:21 -070029
tomeadbb462014-09-07 16:10:19 -070030 private final ConnectPoint src;
31 private final ConnectPoint dst;
32 private final Type type;
Thomas Vachuska57126fe2014-11-11 17:13:24 -080033 private final State state;
34 private final boolean isDurable;
tom4c6606f2014-09-07 11:11:21 -070035
36 /**
Thomas Vachuska57126fe2014-11-11 17:13:24 -080037 * Creates an active infrastructure link using the supplied information.
tom4c6606f2014-09-07 11:11:21 -070038 *
Thomas Vachuska57126fe2014-11-11 17:13:24 -080039 * @param providerId provider identity
40 * @param src link source
41 * @param dst link destination
42 * @param type link type
tomf5d85d42014-10-02 05:27:56 -070043 * @param annotations optional key/value annotations
tom4c6606f2014-09-07 11:11:21 -070044 */
tomeadbb462014-09-07 16:10:19 -070045 public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst,
tomf5d85d42014-10-02 05:27:56 -070046 Type type, Annotations... annotations) {
Thomas Vachuska57126fe2014-11-11 17:13:24 -080047 this(providerId, src, dst, type, ACTIVE, false, annotations);
48 }
49
50 /**
51 * Creates an infrastructure link using the supplied information.
52 * Links marked as durable will remain in the inventory when a vanish
53 * message is received and instead will be marked as inactive.
54 *
55 * @param providerId provider identity
56 * @param src link source
57 * @param dst link destination
58 * @param type link type
59 * @param state link state
60 * @param isDurable indicates if the link is to be considered durable
61 * @param annotations optional key/value annotations
62 */
63 public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst,
64 Type type, State state,
65 boolean isDurable, Annotations... annotations) {
tomf5d85d42014-10-02 05:27:56 -070066 super(providerId, annotations);
tom4c6606f2014-09-07 11:11:21 -070067 this.src = src;
68 this.dst = dst;
tomeadbb462014-09-07 16:10:19 -070069 this.type = type;
Thomas Vachuska57126fe2014-11-11 17:13:24 -080070 this.state = state;
71 this.isDurable = isDurable;
tom4c6606f2014-09-07 11:11:21 -070072 }
73
74 @Override
75 public ConnectPoint src() {
76 return src;
77 }
78
79 @Override
80 public ConnectPoint dst() {
81 return dst;
82 }
83
tomeadbb462014-09-07 16:10:19 -070084 @Override
85 public Type type() {
86 return type;
87 }
tom4c6606f2014-09-07 11:11:21 -070088
89 @Override
Thomas Vachuska57126fe2014-11-11 17:13:24 -080090 public State state() {
91 return state;
92 }
93
94 @Override
95 public boolean isDurable() {
96 return isDurable;
97 }
98
99 // Note: Durability & state are purposefully omitted form equality & hashCode.
100
101 @Override
tom4c6606f2014-09-07 11:11:21 -0700102 public int hashCode() {
tomeadbb462014-09-07 16:10:19 -0700103 return Objects.hash(src, dst, type);
tom4c6606f2014-09-07 11:11:21 -0700104 }
105
106 @Override
107 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -0700108 if (this == obj) {
109 return true;
110 }
tomeadbb462014-09-07 16:10:19 -0700111 if (obj instanceof DefaultLink) {
tom4c6606f2014-09-07 11:11:21 -0700112 final DefaultLink other = (DefaultLink) obj;
113 return Objects.equals(this.src, other.src) &&
tomeadbb462014-09-07 16:10:19 -0700114 Objects.equals(this.dst, other.dst) &&
115 Objects.equals(this.type, other.type);
tom4c6606f2014-09-07 11:11:21 -0700116 }
117 return false;
118 }
119
120 @Override
121 public String toString() {
122 return toStringHelper(this)
123 .add("src", src)
124 .add("dst", dst)
tomeadbb462014-09-07 16:10:19 -0700125 .add("type", type)
Thomas Vachuska57126fe2014-11-11 17:13:24 -0800126 .add("state", state)
127 .add("durable", isDurable)
tom4c6606f2014-09-07 11:11:21 -0700128 .toString();
129 }
130
131}