blob: a63de3bb152930600d08d28001946511e3b4935a [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;
tom4c6606f2014-09-07 11:11:21 -070023
24/**
25 * Default infrastructure link model implementation.
26 */
tomeadbb462014-09-07 16:10:19 -070027public class DefaultLink extends AbstractModel implements Link {
tom4c6606f2014-09-07 11:11:21 -070028
tomeadbb462014-09-07 16:10:19 -070029 private final ConnectPoint src;
30 private final ConnectPoint dst;
31 private final Type type;
tom4c6606f2014-09-07 11:11:21 -070032
33 /**
tom97937552014-09-11 10:48:42 -070034 * Creates an infrastructure link using the supplied information.
tom4c6606f2014-09-07 11:11:21 -070035 *
tomeadbb462014-09-07 16:10:19 -070036 * @param providerId provider identity
37 * @param src link source
38 * @param dst link destination
39 * @param type link type
tomf5d85d42014-10-02 05:27:56 -070040 * @param annotations optional key/value annotations
tom4c6606f2014-09-07 11:11:21 -070041 */
tomeadbb462014-09-07 16:10:19 -070042 public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst,
tomf5d85d42014-10-02 05:27:56 -070043 Type type, Annotations... annotations) {
44 super(providerId, annotations);
tom4c6606f2014-09-07 11:11:21 -070045 this.src = src;
46 this.dst = dst;
tomeadbb462014-09-07 16:10:19 -070047 this.type = type;
tom4c6606f2014-09-07 11:11:21 -070048 }
49
50 @Override
51 public ConnectPoint src() {
52 return src;
53 }
54
55 @Override
56 public ConnectPoint dst() {
57 return dst;
58 }
59
tomeadbb462014-09-07 16:10:19 -070060 @Override
61 public Type type() {
62 return type;
63 }
tom4c6606f2014-09-07 11:11:21 -070064
65 @Override
66 public int hashCode() {
tomeadbb462014-09-07 16:10:19 -070067 return Objects.hash(src, dst, type);
tom4c6606f2014-09-07 11:11:21 -070068 }
69
70 @Override
71 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070072 if (this == obj) {
73 return true;
74 }
tomeadbb462014-09-07 16:10:19 -070075 if (obj instanceof DefaultLink) {
tom4c6606f2014-09-07 11:11:21 -070076 final DefaultLink other = (DefaultLink) obj;
77 return Objects.equals(this.src, other.src) &&
tomeadbb462014-09-07 16:10:19 -070078 Objects.equals(this.dst, other.dst) &&
79 Objects.equals(this.type, other.type);
tom4c6606f2014-09-07 11:11:21 -070080 }
81 return false;
82 }
83
84 @Override
85 public String toString() {
86 return toStringHelper(this)
87 .add("src", src)
88 .add("dst", dst)
tomeadbb462014-09-07 16:10:19 -070089 .add("type", type)
tom4c6606f2014-09-07 11:11:21 -070090 .toString();
91 }
92
93}