Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.link; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 17 | |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.net.AbstractDescription; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.Link; |
| 22 | import org.onosproject.net.SparseAnnotations; |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 23 | import com.google.common.base.Objects; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Default implementation of immutable link description entity. |
| 27 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 28 | public class DefaultLinkDescription extends AbstractDescription |
| 29 | implements LinkDescription { |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 30 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 31 | private final ConnectPoint src; |
| 32 | private final ConnectPoint dst; |
| 33 | private final Link.Type type; |
Ray Milkey | b7f0f64 | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 34 | 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 | } |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * Creates a link description using the supplied information. |
| 61 | * |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 62 | * @param src link source |
| 63 | * @param dst link destination |
| 64 | * @param type link type |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 65 | * @param annotations optional key/value annotations |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 66 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 67 | public DefaultLinkDescription(ConnectPoint src, ConnectPoint dst, |
Ray Milkey | b7f0f64 | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 68 | Link.Type type, |
| 69 | SparseAnnotations... annotations) { |
| 70 | this(src, dst, type, EXPECTED, annotations); |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public ConnectPoint src() { |
| 75 | return src; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public ConnectPoint dst() { |
| 80 | return dst; |
| 81 | } |
| 82 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 83 | @Override |
| 84 | public Link.Type type() { |
tom | d176fc4 | 2014-09-08 00:12:30 -0700 | [diff] [blame] | 85 | return type; |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 86 | } |
| 87 | |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 88 | @Override |
Ray Milkey | b7f0f64 | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 89 | public boolean isExpected() { |
| 90 | return isExpected; |
| 91 | } |
| 92 | |
| 93 | @Override |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 94 | public String toString() { |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 95 | return MoreObjects.toStringHelper(this) |
| 96 | .add("src", src()) |
| 97 | .add("dst", dst()) |
Pavel Likin | 9d49f54 | 2015-12-13 15:04:55 +0300 | [diff] [blame] | 98 | .add("type", type()) |
Ray Milkey | b7f0f64 | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 99 | .add("isExpected", isExpected()) |
Pavel Likin | 9d49f54 | 2015-12-13 15:04:55 +0300 | [diff] [blame] | 100 | .add("annotations", annotations()) |
| 101 | .toString(); |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 102 | } |
| 103 | |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 104 | @Override |
| 105 | public int hashCode() { |
Ray Milkey | b7f0f64 | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 106 | return Objects.hashCode(super.hashCode(), src, dst, type, isExpected); |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 107 | } |
| 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 Milkey | b7f0f64 | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 118 | && Objects.equal(this.type, that.type) |
| 119 | && Objects.equal(this.isExpected, that.isExpected); |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 120 | } |
| 121 | return false; |
| 122 | } |
| 123 | |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 124 | } |