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; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 18 | import org.onosproject.net.provider.ProviderId; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 19 | |
| 20 | import java.util.Objects; |
| 21 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import static org.onosproject.net.Link.State.ACTIVE; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Default infrastructure link model implementation. |
| 27 | */ |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 28 | public class DefaultLink extends AbstractModel implements Link { |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 29 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 30 | private final ConnectPoint src; |
| 31 | private final ConnectPoint dst; |
| 32 | private final Type type; |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 33 | private final State state; |
| 34 | private final boolean isDurable; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 37 | * Creates an active infrastructure link using the supplied information. |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 38 | * |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 39 | * @param providerId provider identity |
| 40 | * @param src link source |
| 41 | * @param dst link destination |
| 42 | * @param type link type |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 43 | * @param annotations optional key/value annotations |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 44 | */ |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 45 | public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 46 | Type type, Annotations... annotations) { |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 47 | this(providerId, src, dst, type, ACTIVE, false, annotations); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Creates an infrastructure link using the supplied information. |
| 52 | * Links marked as durable will remain in the inventory when a vanish |
| 53 | * message is received and instead will be marked as inactive. |
| 54 | * |
| 55 | * @param providerId provider identity |
| 56 | * @param src link source |
| 57 | * @param dst link destination |
| 58 | * @param type link type |
| 59 | * @param state link state |
| 60 | * @param isDurable indicates if the link is to be considered durable |
| 61 | * @param annotations optional key/value annotations |
| 62 | */ |
| 63 | public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst, |
| 64 | Type type, State state, |
| 65 | boolean isDurable, Annotations... annotations) { |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 66 | super(providerId, annotations); |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 67 | this.src = src; |
| 68 | this.dst = dst; |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 69 | this.type = type; |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 70 | this.state = state; |
| 71 | this.isDurable = isDurable; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public ConnectPoint src() { |
| 76 | return src; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public ConnectPoint dst() { |
| 81 | return dst; |
| 82 | } |
| 83 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 84 | @Override |
| 85 | public Type type() { |
| 86 | return type; |
| 87 | } |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 88 | |
| 89 | @Override |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 90 | public State state() { |
| 91 | return state; |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public boolean isDurable() { |
| 96 | return isDurable; |
| 97 | } |
| 98 | |
| 99 | // Note: Durability & state are purposefully omitted form equality & hashCode. |
| 100 | |
| 101 | @Override |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 102 | public int hashCode() { |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 103 | return Objects.hash(src, dst, type); |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public boolean equals(Object obj) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 108 | if (this == obj) { |
| 109 | return true; |
| 110 | } |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 111 | if (obj instanceof DefaultLink) { |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 112 | final DefaultLink other = (DefaultLink) obj; |
| 113 | return Objects.equals(this.src, other.src) && |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 114 | Objects.equals(this.dst, other.dst) && |
| 115 | Objects.equals(this.type, other.type); |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 116 | } |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public String toString() { |
| 122 | return toStringHelper(this) |
| 123 | .add("src", src) |
| 124 | .add("dst", dst) |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 125 | .add("type", type) |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 126 | .add("state", state) |
| 127 | .add("durable", isDurable) |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 128 | .toString(); |
| 129 | } |
| 130 | |
| 131 | } |