Thomas Vachuska | bf916ea | 2015-05-20 18:24:34 -0700 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.incubator.net.tunnel; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 17 | |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 19 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | import java.util.Optional; |
| 23 | |
| 24 | import org.onosproject.net.AbstractModel; |
| 25 | import org.onosproject.net.Annotations; |
| 26 | import org.onosproject.net.ElementId; |
| 27 | import org.onosproject.net.PortNumber; |
| 28 | import org.onosproject.net.provider.ProviderId; |
| 29 | |
| 30 | /** |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 31 | * Default optical tunnel point model implementation. |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 32 | */ |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 33 | public class DefaultOpticalTunnelEndPoint extends AbstractModel implements OpticalTunnelEndPoint { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 34 | private final Optional<ElementId> elementId; |
| 35 | private final Optional<PortNumber> portNumber; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 36 | private final Optional<OpticalTunnelEndPoint> parentPoint; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 37 | private final Type type; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 38 | private final OpticalLogicId id; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 39 | private final boolean isGlobal; |
| 40 | |
| 41 | /** |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 42 | * 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 wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 44 | * |
wei wei | a668122 | 2015-04-21 14:58:22 -0500 | [diff] [blame] | 45 | * @param providerId tunnelProvider Id |
| 46 | * @param elementId parent network element |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 47 | * @param number port number |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 48 | * @param parentPoint parent port or parent label |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 49 | * @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 | */ |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 54 | public DefaultOpticalTunnelEndPoint(ProviderId providerId, Optional<ElementId> elementId, |
| 55 | Optional<PortNumber> number, Optional<OpticalTunnelEndPoint> parentPoint, |
| 56 | Type type, OpticalLogicId id, boolean isGlobal, Annotations... annotations) { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 57 | super(providerId, annotations); |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 58 | checkNotNull(type, "type cannot be null"); |
| 59 | checkNotNull(id, "id cannot be null"); |
| 60 | checkNotNull(isGlobal, "isGlobal cannot be null"); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 61 | this.elementId = elementId; |
| 62 | this.portNumber = number; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 63 | this.parentPoint = parentPoint; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 64 | this.id = id; |
| 65 | this.type = type; |
| 66 | this.isGlobal = isGlobal; |
| 67 | } |
| 68 | |
| 69 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 70 | public OpticalLogicId id() { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 71 | 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 |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 85 | public Optional<OpticalTunnelEndPoint> parentPoint() { |
| 86 | return parentPoint; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 87 | } |
| 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() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 101 | return Objects.hash(elementId, portNumber, parentPoint, id); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public boolean equals(Object obj) { |
| 106 | if (this == obj) { |
| 107 | return true; |
| 108 | } |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 109 | if (obj instanceof DefaultOpticalTunnelEndPoint) { |
| 110 | final DefaultOpticalTunnelEndPoint other = (DefaultOpticalTunnelEndPoint) obj; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 111 | 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) && |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 116 | Objects.equals(this.parentPoint, other.parentPoint); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 117 | } |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public String toString() { |
| 123 | return toStringHelper(this) |
| 124 | .add("elementId", elementId) |
| 125 | .add("portNumber", portNumber) |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 126 | .add("parentPoint", parentPoint) |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 127 | .add("type", type) |
| 128 | .add("id", id) |
| 129 | .add("isGlobal", isGlobal) |
| 130 | .toString(); |
| 131 | } |
| 132 | |
| 133 | } |