blob: c6e41196905e7ed33c9b48e5e275e2e7a130b414 [file] [log] [blame]
Thomas Vachuskabf916ea2015-05-20 18:24:34 -07001/*
2 * Copyright 2015 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 */
16package org.onosproject.incubator.net.tunnel;
wei wei89ddc322015-03-22 16:29:04 -050017
jcc4a20a5f2015-04-30 15:43:39 +080018import static com.google.common.base.Preconditions.checkNotNull;
wei wei89ddc322015-03-22 16:29:04 -050019import static com.google.common.base.MoreObjects.toStringHelper;
20
21import java.util.Objects;
22import java.util.Optional;
23
24import org.onosproject.net.AbstractModel;
25import org.onosproject.net.Annotations;
26import org.onosproject.net.ElementId;
27import org.onosproject.net.PortNumber;
28import org.onosproject.net.provider.ProviderId;
29
30/**
jcc4a20a5f2015-04-30 15:43:39 +080031 * Default optical tunnel point model implementation.
wei wei89ddc322015-03-22 16:29:04 -050032 */
jcc4a20a5f2015-04-30 15:43:39 +080033public class DefaultOpticalTunnelEndPoint extends AbstractModel implements OpticalTunnelEndPoint {
wei wei89ddc322015-03-22 16:29:04 -050034 private final Optional<ElementId> elementId;
35 private final Optional<PortNumber> portNumber;
jcc4a20a5f2015-04-30 15:43:39 +080036 private final Optional<OpticalTunnelEndPoint> parentPoint;
wei wei89ddc322015-03-22 16:29:04 -050037 private final Type type;
jcc4a20a5f2015-04-30 15:43:39 +080038 private final OpticalLogicId id;
wei wei89ddc322015-03-22 16:29:04 -050039 private final boolean isGlobal;
40
41 /**
jcc4a20a5f2015-04-30 15:43:39 +080042 * Creates a optical tunnel point attributed to the specified provider (may be null).
43 * if provider is null, which means the optical tunnel point is not managed by the SB.
wei wei89ddc322015-03-22 16:29:04 -050044 *
wei weia6681222015-04-21 14:58:22 -050045 * @param providerId tunnelProvider Id
46 * @param elementId parent network element
wei wei89ddc322015-03-22 16:29:04 -050047 * @param number port number
jcc4a20a5f2015-04-30 15:43:39 +080048 * @param parentPoint parent port or parent label
wei wei89ddc322015-03-22 16:29:04 -050049 * @param type port type
50 * @param id LabelId
51 * @param isGlobal indicator whether the label is global significant or not
52 * @param annotations optional key/value annotations
53 */
jcc4a20a5f2015-04-30 15:43:39 +080054 public DefaultOpticalTunnelEndPoint(ProviderId providerId, Optional<ElementId> elementId,
55 Optional<PortNumber> number, Optional<OpticalTunnelEndPoint> parentPoint,
56 Type type, OpticalLogicId id, boolean isGlobal, Annotations... annotations) {
wei wei89ddc322015-03-22 16:29:04 -050057 super(providerId, annotations);
jcc4a20a5f2015-04-30 15:43:39 +080058 checkNotNull(type, "type cannot be null");
59 checkNotNull(id, "id cannot be null");
60 checkNotNull(isGlobal, "isGlobal cannot be null");
wei wei89ddc322015-03-22 16:29:04 -050061 this.elementId = elementId;
62 this.portNumber = number;
jcc4a20a5f2015-04-30 15:43:39 +080063 this.parentPoint = parentPoint;
wei wei89ddc322015-03-22 16:29:04 -050064 this.id = id;
65 this.type = type;
66 this.isGlobal = isGlobal;
67 }
68
69 @Override
jcc4a20a5f2015-04-30 15:43:39 +080070 public OpticalLogicId id() {
wei wei89ddc322015-03-22 16:29:04 -050071 return id;
72 }
73
74 @Override
75 public Optional<ElementId> elementId() {
76 return elementId;
77 }
78
79 @Override
80 public Optional<PortNumber> portNumber() {
81 return portNumber;
82 }
83
84 @Override
jcc4a20a5f2015-04-30 15:43:39 +080085 public Optional<OpticalTunnelEndPoint> parentPoint() {
86 return parentPoint;
wei wei89ddc322015-03-22 16:29:04 -050087 }
88
89 @Override
90 public boolean isGlobal() {
91 return isGlobal;
92 }
93
94 @Override
95 public Type type() {
96 return type;
97 }
98
99 @Override
100 public int hashCode() {
jcc4a20a5f2015-04-30 15:43:39 +0800101 return Objects.hash(elementId, portNumber, parentPoint, id);
wei wei89ddc322015-03-22 16:29:04 -0500102 }
103
104 @Override
105 public boolean equals(Object obj) {
106 if (this == obj) {
107 return true;
108 }
jcc4a20a5f2015-04-30 15:43:39 +0800109 if (obj instanceof DefaultOpticalTunnelEndPoint) {
110 final DefaultOpticalTunnelEndPoint other = (DefaultOpticalTunnelEndPoint) obj;
wei wei89ddc322015-03-22 16:29:04 -0500111 return Objects.equals(this.id, other.id) &&
112 Objects.equals(this.type, other.type) &&
113 Objects.equals(this.isGlobal, other.isGlobal) &&
114 Objects.equals(this.elementId, other.elementId) &&
115 Objects.equals(this.portNumber, other.portNumber) &&
jcc4a20a5f2015-04-30 15:43:39 +0800116 Objects.equals(this.parentPoint, other.parentPoint);
wei wei89ddc322015-03-22 16:29:04 -0500117 }
118 return false;
119 }
120
121 @Override
122 public String toString() {
123 return toStringHelper(this)
124 .add("elementId", elementId)
125 .add("portNumber", portNumber)
jcc4a20a5f2015-04-30 15:43:39 +0800126 .add("parentPoint", parentPoint)
wei wei89ddc322015-03-22 16:29:04 -0500127 .add("type", type)
128 .add("id", id)
129 .add("isGlobal", isGlobal)
130 .toString();
131 }
132
133}