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 | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 25 | */ |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 26 | public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst, |
| 27 | Type type) { |
| 28 | super(providerId); |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 29 | this.src = src; |
| 30 | this.dst = dst; |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 31 | this.type = type; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public ConnectPoint src() { |
| 36 | return src; |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public ConnectPoint dst() { |
| 41 | return dst; |
| 42 | } |
| 43 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 44 | @Override |
| 45 | public Type type() { |
| 46 | return type; |
| 47 | } |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 48 | |
| 49 | @Override |
| 50 | public int hashCode() { |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 51 | return Objects.hash(src, dst, type); |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public boolean equals(Object obj) { |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 56 | if (obj instanceof DefaultLink) { |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 57 | final DefaultLink other = (DefaultLink) obj; |
| 58 | return Objects.equals(this.src, other.src) && |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 59 | Objects.equals(this.dst, other.dst) && |
| 60 | Objects.equals(this.type, other.type); |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 61 | } |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public String toString() { |
| 67 | return toStringHelper(this) |
| 68 | .add("src", src) |
| 69 | .add("dst", dst) |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 70 | .add("type", type) |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 71 | .toString(); |
| 72 | } |
| 73 | |
| 74 | } |