blob: 60dc9f343cbf9cc1b5cff56813fe88864b5c1b5b [file] [log] [blame]
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001/*
2 * Copyright 2016 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.tetopology.management.api.node;
17
18import com.google.common.base.MoreObjects.ToStringHelper;
19import com.google.common.base.Objects;
20
21/**
22 * Representation of a TE tunnel termination point key.
23 */
24public class TtpKey extends TeNodeKey {
25 private final long ttpId;
26
27 /**
28 * Creates a TE tunnel termination point key.
29 *
30 * @param providerId provider identifier
31 * @param clientId client identifier
32 * @param topologyId topology identifier
33 * @param teNodeId TE node identifier
34 * @param ttpId tunnel termination point identifier
35 */
36 public TtpKey(long providerId, long clientId, long topologyId,
37 long teNodeId, long ttpId) {
38 super(providerId, clientId, topologyId, teNodeId);
39 this.ttpId = ttpId;
40 }
41
42 /**
43 * Creates a TE tunnel termination point key based on a given TE node
44 * key and a tunnel termination point identifier.
45 *
46 * @param teNodeKey TE node key
47 * @param ttpId tunnel termination point id
48 */
49 public TtpKey(TeNodeKey teNodeKey, long ttpId) {
50 super(teNodeKey.providerId(), teNodeKey.clientId(),
51 teNodeKey.topologyId(), teNodeKey.teNodeId());
52 this.ttpId = ttpId;
53 }
54
55 /**
56 * Returns the TE node key.
57 *
58 * @return the TE node key
59 */
60 public TeNodeKey teNodekey() {
61 return new TeNodeKey(providerId(), clientId(), topologyId(), teNodeId());
62 }
63
64 /**
65 * Returns the tunnel termination point identifier.
66 *
67 * @return the tunnel termination point id
68 */
69 public long ttpId() {
70 return ttpId;
71 }
72
73 @Override
74 public int hashCode() {
75 return Objects.hashCode(super.hashCode(), ttpId);
76 }
77
78 @Override
79 public boolean equals(Object object) {
80 if (this == object) {
81 return true;
82 }
83 if (object instanceof TtpKey) {
84 if (!super.equals(object)) {
85 return false;
86 }
87 TtpKey that = (TtpKey) object;
88 return Objects.equal(ttpId, that.ttpId);
89 }
90 return false;
91 }
92
93 /**
94 * Returns ToStringHelper with an additional tunnel termination point
95 * identifier.
96 *
97 * @return toStringHelper
98 */
99 protected ToStringHelper toTtpKeyStringHelper() {
100 return toTeNodeKeyStringHelper().add("ttpId", ttpId);
101 }
102
103 @Override
104 public String toString() {
105 return toTtpKeyStringHelper().toString();
106 }
107
108}