wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 1 | package org.onosproject.net.tunnel; |
| 2 | |
| 3 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 4 | |
| 5 | import java.util.Objects; |
| 6 | import java.util.Optional; |
| 7 | |
| 8 | import org.onosproject.net.AbstractModel; |
| 9 | import org.onosproject.net.Annotations; |
| 10 | import org.onosproject.net.ElementId; |
| 11 | import org.onosproject.net.PortNumber; |
| 12 | import org.onosproject.net.provider.ProviderId; |
| 13 | |
| 14 | /** |
| 15 | * Default label model implementation. |
| 16 | */ |
| 17 | public class DefaultLabel extends AbstractModel implements Label { |
| 18 | private final Optional<ElementId> elementId; |
| 19 | private final Optional<PortNumber> portNumber; |
| 20 | private final Optional<Label> parentLabel; |
| 21 | private final Type type; |
| 22 | private final LabelId id; |
| 23 | private final boolean isGlobal; |
| 24 | |
| 25 | /** |
| 26 | * Creates a label attributed to the specified provider (may be null). |
| 27 | * if provider is null, which means the label is not managed by the SB. |
| 28 | * |
wei wei | a668122 | 2015-04-21 14:58:22 -0500 | [diff] [blame] | 29 | * @param providerId tunnelProvider Id |
| 30 | * @param elementId parent network element |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 31 | * @param number port number |
| 32 | * @param parentLabel parent port or parent label |
| 33 | * @param type port type |
| 34 | * @param id LabelId |
| 35 | * @param isGlobal indicator whether the label is global significant or not |
| 36 | * @param annotations optional key/value annotations |
| 37 | */ |
| 38 | public DefaultLabel(ProviderId providerId, Optional<ElementId> elementId, |
| 39 | Optional<PortNumber> number, Optional<Label> parentLabel, |
| 40 | Type type, LabelId id, boolean isGlobal, Annotations... annotations) { |
| 41 | super(providerId, annotations); |
| 42 | this.elementId = elementId; |
| 43 | this.portNumber = number; |
| 44 | this.parentLabel = parentLabel; |
| 45 | this.id = id; |
| 46 | this.type = type; |
| 47 | this.isGlobal = isGlobal; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public LabelId id() { |
| 52 | return id; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public Optional<ElementId> elementId() { |
| 57 | return elementId; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public Optional<PortNumber> portNumber() { |
| 62 | return portNumber; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public Optional<Label> parentLabel() { |
| 67 | return parentLabel; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public boolean isGlobal() { |
| 72 | return isGlobal; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public Type type() { |
| 77 | return type; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public int hashCode() { |
| 82 | return Objects.hash(elementId, portNumber, parentLabel, id); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public boolean equals(Object obj) { |
| 87 | if (this == obj) { |
| 88 | return true; |
| 89 | } |
| 90 | if (obj instanceof DefaultLabel) { |
| 91 | final DefaultLabel other = (DefaultLabel) obj; |
| 92 | return Objects.equals(this.id, other.id) && |
| 93 | Objects.equals(this.type, other.type) && |
| 94 | Objects.equals(this.isGlobal, other.isGlobal) && |
| 95 | Objects.equals(this.elementId, other.elementId) && |
| 96 | Objects.equals(this.portNumber, other.portNumber) && |
| 97 | Objects.equals(this.parentLabel, other.parentLabel); |
| 98 | } |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public String toString() { |
| 104 | return toStringHelper(this) |
| 105 | .add("elementId", elementId) |
| 106 | .add("portNumber", portNumber) |
| 107 | .add("parentLabel", parentLabel) |
| 108 | .add("type", type) |
| 109 | .add("id", id) |
| 110 | .add("isGlobal", isGlobal) |
| 111 | .toString(); |
| 112 | } |
| 113 | |
| 114 | } |