tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net; |
| 2 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 3 | import org.onlab.onos.net.provider.ProviderId; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 4 | |
| 5 | import java.util.Objects; |
| 6 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 7 | import static com.google.common.base.MoreObjects.toStringHelper; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 8 | |
| 9 | /** |
| 10 | * Default infrastructure link model implementation. |
| 11 | */ |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 12 | public class DefaultLink extends AbstractModel implements Link { |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 13 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 14 | private final ConnectPoint src; |
| 15 | private final ConnectPoint dst; |
| 16 | private final Type type; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 17 | |
| 18 | /** |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 19 | * Creates an infrastructure link using the supplied information. |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 20 | * |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 21 | * @param providerId provider identity |
| 22 | * @param src link source |
| 23 | * @param dst link destination |
| 24 | * @param type link type |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 25 | * @param annotations optional key/value annotations |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 26 | */ |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 27 | public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 28 | Type type, Annotations... annotations) { |
| 29 | super(providerId, annotations); |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 30 | this.src = src; |
| 31 | this.dst = dst; |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 32 | this.type = type; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public ConnectPoint src() { |
| 37 | return src; |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public ConnectPoint dst() { |
| 42 | return dst; |
| 43 | } |
| 44 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 45 | @Override |
| 46 | public Type type() { |
| 47 | return type; |
| 48 | } |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 49 | |
| 50 | @Override |
| 51 | public int hashCode() { |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 52 | return Objects.hash(src, dst, type); |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public boolean equals(Object obj) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 57 | if (this == obj) { |
| 58 | return true; |
| 59 | } |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 60 | if (obj instanceof DefaultLink) { |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 61 | final DefaultLink other = (DefaultLink) obj; |
| 62 | return Objects.equals(this.src, other.src) && |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 63 | Objects.equals(this.dst, other.dst) && |
| 64 | Objects.equals(this.type, other.type); |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 65 | } |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public String toString() { |
| 71 | return toStringHelper(this) |
| 72 | .add("src", src) |
| 73 | .add("dst", dst) |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 74 | .add("type", type) |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 75 | .toString(); |
| 76 | } |
| 77 | |
| 78 | } |