blob: e91144cbcbe59e63e121a6c6ed37ccc07078ce49 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -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 */
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;
Ray Milkeyb7f0f642016-01-22 16:08:14 -080034 private final boolean isExpected;
35
36 public static final boolean EXPECTED = true;
37 public static final boolean NOT_EXPECTED = false;
38
39 /**
40 * Creates a link description using the supplied information.
41 *
42 * @param src link source
43 * @param dst link destination
44 * @param type link type
45 * @param isExpected is the link expected to be part of this configuration
46 * @param annotations optional key/value annotations
47 */
48 public DefaultLinkDescription(ConnectPoint src, ConnectPoint dst,
49 Link.Type type,
50 boolean isExpected,
51 SparseAnnotations... annotations) {
52 super(annotations);
53 this.src = src;
54 this.dst = dst;
55 this.type = type;
56 this.isExpected = isExpected;
57 }
tom4c6606f2014-09-07 11:11:21 -070058
59 /**
60 * Creates a link description using the supplied information.
61 *
Thomas Vachuska57126fe2014-11-11 17:13:24 -080062 * @param src link source
63 * @param dst link destination
64 * @param type link type
tomf5d85d42014-10-02 05:27:56 -070065 * @param annotations optional key/value annotations
tom4c6606f2014-09-07 11:11:21 -070066 */
tomf5d85d42014-10-02 05:27:56 -070067 public DefaultLinkDescription(ConnectPoint src, ConnectPoint dst,
Ray Milkeyb7f0f642016-01-22 16:08:14 -080068 Link.Type type,
69 SparseAnnotations... annotations) {
70 this(src, dst, type, EXPECTED, annotations);
tom4c6606f2014-09-07 11:11:21 -070071 }
72
73 @Override
74 public ConnectPoint src() {
75 return src;
76 }
77
78 @Override
79 public ConnectPoint dst() {
80 return dst;
81 }
82
tomeadbb462014-09-07 16:10:19 -070083 @Override
84 public Link.Type type() {
tomd176fc42014-09-08 00:12:30 -070085 return type;
tomeadbb462014-09-07 16:10:19 -070086 }
87
alshabibdfc7afb2014-10-21 20:13:27 -070088 @Override
Ray Milkeyb7f0f642016-01-22 16:08:14 -080089 public boolean isExpected() {
90 return isExpected;
91 }
92
93 @Override
alshabibdfc7afb2014-10-21 20:13:27 -070094 public String toString() {
Thomas Vachuska57126fe2014-11-11 17:13:24 -080095 return MoreObjects.toStringHelper(this)
96 .add("src", src())
97 .add("dst", dst())
Pavel Likin9d49f542015-12-13 15:04:55 +030098 .add("type", type())
Ray Milkeyb7f0f642016-01-22 16:08:14 -080099 .add("isExpected", isExpected())
Pavel Likin9d49f542015-12-13 15:04:55 +0300100 .add("annotations", annotations())
101 .toString();
alshabibdfc7afb2014-10-21 20:13:27 -0700102 }
103
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -0800104 @Override
105 public int hashCode() {
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800106 return Objects.hashCode(super.hashCode(), src, dst, type, isExpected);
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -0800107 }
108
109 @Override
110 public boolean equals(Object object) {
111 if (object != null && getClass() == object.getClass()) {
112 if (!super.equals(object)) {
113 return false;
114 }
115 DefaultLinkDescription that = (DefaultLinkDescription) object;
116 return Objects.equal(this.src, that.src)
117 && Objects.equal(this.dst, that.dst)
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800118 && Objects.equal(this.type, that.type)
119 && Objects.equal(this.isExpected, that.isExpected);
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -0800120 }
121 return false;
122 }
123
tom4c6606f2014-09-07 11:11:21 -0700124}