blob: 425269586aded5d91fb874faacd434b45d492673 [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.link;
tom4c6606f2014-09-07 11:11:21 -070017
alshabibdfc7afb2014-10-21 20:13:27 -070018import com.google.common.base.MoreObjects;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.net.AbstractDescription;
20import org.onosproject.net.ConnectPoint;
21import org.onosproject.net.Link;
22import org.onosproject.net.SparseAnnotations;
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -080023import com.google.common.base.Objects;
tom4c6606f2014-09-07 11:11:21 -070024
25/**
26 * Default implementation of immutable link description entity.
27 */
tomf5d85d42014-10-02 05:27:56 -070028public class DefaultLinkDescription extends AbstractDescription
29 implements LinkDescription {
tom4c6606f2014-09-07 11:11:21 -070030
tomeadbb462014-09-07 16:10:19 -070031 private final ConnectPoint src;
32 private final ConnectPoint dst;
33 private final Link.Type type;
tom4c6606f2014-09-07 11:11:21 -070034
35 /**
36 * Creates a link description using the supplied information.
37 *
Thomas Vachuska57126fe2014-11-11 17:13:24 -080038 * @param src link source
39 * @param dst link destination
40 * @param type link type
tomf5d85d42014-10-02 05:27:56 -070041 * @param annotations optional key/value annotations
tom4c6606f2014-09-07 11:11:21 -070042 */
tomf5d85d42014-10-02 05:27:56 -070043 public DefaultLinkDescription(ConnectPoint src, ConnectPoint dst,
44 Link.Type type, SparseAnnotations... annotations) {
45 super(annotations);
tom4c6606f2014-09-07 11:11:21 -070046 this.src = src;
47 this.dst = dst;
tomeadbb462014-09-07 16:10:19 -070048 this.type = type;
tom4c6606f2014-09-07 11:11:21 -070049 }
50
51 @Override
52 public ConnectPoint src() {
53 return src;
54 }
55
56 @Override
57 public ConnectPoint dst() {
58 return dst;
59 }
60
tomeadbb462014-09-07 16:10:19 -070061 @Override
62 public Link.Type type() {
tomd176fc42014-09-08 00:12:30 -070063 return type;
tomeadbb462014-09-07 16:10:19 -070064 }
65
alshabibdfc7afb2014-10-21 20:13:27 -070066 @Override
67 public String toString() {
Thomas Vachuska57126fe2014-11-11 17:13:24 -080068 return MoreObjects.toStringHelper(this)
69 .add("src", src())
70 .add("dst", dst())
Pavel Likin9d49f542015-12-13 15:04:55 +030071 .add("type", type())
72 .add("annotations", annotations())
73 .toString();
alshabibdfc7afb2014-10-21 20:13:27 -070074 }
75
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -080076 @Override
77 public int hashCode() {
78 return Objects.hashCode(super.hashCode(), src, dst, type);
79 }
80
81 @Override
82 public boolean equals(Object object) {
83 if (object != null && getClass() == object.getClass()) {
84 if (!super.equals(object)) {
85 return false;
86 }
87 DefaultLinkDescription that = (DefaultLinkDescription) object;
88 return Objects.equal(this.src, that.src)
89 && Objects.equal(this.dst, that.dst)
90 && Objects.equal(this.type, that.type);
91 }
92 return false;
93 }
94
tom4c6606f2014-09-07 11:11:21 -070095}