blob: 3fb2e7ddde04b011e33885348a323e0420af6734 [file] [log] [blame]
wei wei89ddc322015-03-22 16:29:04 -05001package org.onosproject.net.tunnel;
2
jcc4a20a5f2015-04-30 15:43:39 +08003import static com.google.common.base.Preconditions.checkNotNull;
wei wei89ddc322015-03-22 16:29:04 -05004import static com.google.common.base.MoreObjects.toStringHelper;
5
6import java.util.Objects;
7import java.util.Optional;
8
9import org.onosproject.net.AbstractModel;
10import org.onosproject.net.Annotations;
11import org.onosproject.net.ElementId;
12import org.onosproject.net.PortNumber;
13import org.onosproject.net.provider.ProviderId;
14
15/**
jcc4a20a5f2015-04-30 15:43:39 +080016 * Default optical tunnel point model implementation.
wei wei89ddc322015-03-22 16:29:04 -050017 */
jcc4a20a5f2015-04-30 15:43:39 +080018public class DefaultOpticalTunnelEndPoint extends AbstractModel implements OpticalTunnelEndPoint {
wei wei89ddc322015-03-22 16:29:04 -050019 private final Optional<ElementId> elementId;
20 private final Optional<PortNumber> portNumber;
jcc4a20a5f2015-04-30 15:43:39 +080021 private final Optional<OpticalTunnelEndPoint> parentPoint;
wei wei89ddc322015-03-22 16:29:04 -050022 private final Type type;
jcc4a20a5f2015-04-30 15:43:39 +080023 private final OpticalLogicId id;
wei wei89ddc322015-03-22 16:29:04 -050024 private final boolean isGlobal;
25
26 /**
jcc4a20a5f2015-04-30 15:43:39 +080027 * Creates a optical tunnel point attributed to the specified provider (may be null).
28 * if provider is null, which means the optical tunnel point is not managed by the SB.
wei wei89ddc322015-03-22 16:29:04 -050029 *
wei weia6681222015-04-21 14:58:22 -050030 * @param providerId tunnelProvider Id
31 * @param elementId parent network element
wei wei89ddc322015-03-22 16:29:04 -050032 * @param number port number
jcc4a20a5f2015-04-30 15:43:39 +080033 * @param parentPoint parent port or parent label
wei wei89ddc322015-03-22 16:29:04 -050034 * @param type port type
35 * @param id LabelId
36 * @param isGlobal indicator whether the label is global significant or not
37 * @param annotations optional key/value annotations
38 */
jcc4a20a5f2015-04-30 15:43:39 +080039 public DefaultOpticalTunnelEndPoint(ProviderId providerId, Optional<ElementId> elementId,
40 Optional<PortNumber> number, Optional<OpticalTunnelEndPoint> parentPoint,
41 Type type, OpticalLogicId id, boolean isGlobal, Annotations... annotations) {
wei wei89ddc322015-03-22 16:29:04 -050042 super(providerId, annotations);
jcc4a20a5f2015-04-30 15:43:39 +080043 checkNotNull(type, "type cannot be null");
44 checkNotNull(id, "id cannot be null");
45 checkNotNull(isGlobal, "isGlobal cannot be null");
wei wei89ddc322015-03-22 16:29:04 -050046 this.elementId = elementId;
47 this.portNumber = number;
jcc4a20a5f2015-04-30 15:43:39 +080048 this.parentPoint = parentPoint;
wei wei89ddc322015-03-22 16:29:04 -050049 this.id = id;
50 this.type = type;
51 this.isGlobal = isGlobal;
52 }
53
54 @Override
jcc4a20a5f2015-04-30 15:43:39 +080055 public OpticalLogicId id() {
wei wei89ddc322015-03-22 16:29:04 -050056 return id;
57 }
58
59 @Override
60 public Optional<ElementId> elementId() {
61 return elementId;
62 }
63
64 @Override
65 public Optional<PortNumber> portNumber() {
66 return portNumber;
67 }
68
69 @Override
jcc4a20a5f2015-04-30 15:43:39 +080070 public Optional<OpticalTunnelEndPoint> parentPoint() {
71 return parentPoint;
wei wei89ddc322015-03-22 16:29:04 -050072 }
73
74 @Override
75 public boolean isGlobal() {
76 return isGlobal;
77 }
78
79 @Override
80 public Type type() {
81 return type;
82 }
83
84 @Override
85 public int hashCode() {
jcc4a20a5f2015-04-30 15:43:39 +080086 return Objects.hash(elementId, portNumber, parentPoint, id);
wei wei89ddc322015-03-22 16:29:04 -050087 }
88
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj) {
92 return true;
93 }
jcc4a20a5f2015-04-30 15:43:39 +080094 if (obj instanceof DefaultOpticalTunnelEndPoint) {
95 final DefaultOpticalTunnelEndPoint other = (DefaultOpticalTunnelEndPoint) obj;
wei wei89ddc322015-03-22 16:29:04 -050096 return Objects.equals(this.id, other.id) &&
97 Objects.equals(this.type, other.type) &&
98 Objects.equals(this.isGlobal, other.isGlobal) &&
99 Objects.equals(this.elementId, other.elementId) &&
100 Objects.equals(this.portNumber, other.portNumber) &&
jcc4a20a5f2015-04-30 15:43:39 +0800101 Objects.equals(this.parentPoint, other.parentPoint);
wei wei89ddc322015-03-22 16:29:04 -0500102 }
103 return false;
104 }
105
106 @Override
107 public String toString() {
108 return toStringHelper(this)
109 .add("elementId", elementId)
110 .add("portNumber", portNumber)
jcc4a20a5f2015-04-30 15:43:39 +0800111 .add("parentPoint", parentPoint)
wei wei89ddc322015-03-22 16:29:04 -0500112 .add("type", type)
113 .add("id", id)
114 .add("isGlobal", isGlobal)
115 .toString();
116 }
117
118}