blob: c1645152051db4b5dabc75d8d45c5209e767f906 [file] [log] [blame]
wei wei89ddc322015-03-22 16:29:04 -05001package org.onosproject.net.tunnel;
2
3import static com.google.common.base.MoreObjects.toStringHelper;
4
5import java.util.Objects;
6import java.util.Optional;
7
8import org.onosproject.net.AbstractModel;
9import org.onosproject.net.Annotations;
10import org.onosproject.net.ElementId;
11import org.onosproject.net.PortNumber;
12import org.onosproject.net.provider.ProviderId;
13
14/**
15 * Default label model implementation.
16 */
17public 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 weia6681222015-04-21 14:58:22 -050029 * @param providerId tunnelProvider Id
30 * @param elementId parent network element
wei wei89ddc322015-03-22 16:29:04 -050031 * @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}