2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.pcepio.types;
18 import java.util.Objects;
20 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.onosproject.pcepio.protocol.PcepVersion;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import com.google.common.base.MoreObjects;
28 * Provides Local and remote Link Identifiers.
30 public class LinkLocalRemoteIdentifiersTlv implements PcepValueType {
34 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 | Link Local Identifier |
39 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 | Link Remote Identifier |
41 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 protected static final Logger log = LoggerFactory.getLogger(LinkLocalRemoteIdentifiersTlv.class);
46 public static final short TYPE = 4;
47 public static final short LENGTH = 8;
48 private final int iLinkLocalIdentifier;
49 private final int iLinkRemoteIdentifier;
52 * Constructor to initialize iLinkLocalIdentifier , iLinkRemoteIdentifier.
54 * @param iLinkLocalIdentifier Link Local identifier
55 * @param iLinkRemoteIdentifier Link Remote identifier
57 public LinkLocalRemoteIdentifiersTlv(int iLinkLocalIdentifier, int iLinkRemoteIdentifier) {
58 this.iLinkLocalIdentifier = iLinkLocalIdentifier;
59 this.iLinkRemoteIdentifier = iLinkRemoteIdentifier;
63 * Retruns an object of Link Local Remote Identifiers Tlv.
65 * @param iLinkLocalIdentifier Link Local identifier
66 * @param iLinkRemoteIdentifier Link Remote identifier
67 * @return object of LinkLocalRemoteIdentifiersTlv
69 public static LinkLocalRemoteIdentifiersTlv of(int iLinkLocalIdentifier, int iLinkRemoteIdentifier) {
70 return new LinkLocalRemoteIdentifiersTlv(iLinkLocalIdentifier, iLinkRemoteIdentifier);
74 * Returns Link-Local-Identifier.
76 * @return iLinkLocalIdentifier Link Local Identifier
78 public int getLinkLocalIdentifier() {
79 return iLinkLocalIdentifier;
83 * Returns Link-Remote-Identifier.
85 * @return iLinkRemoteIdentifier Link Remote Identifier.
87 public int getLinkRemoteIdentifier() {
88 return iLinkRemoteIdentifier;
92 public PcepVersion getVersion() {
93 return PcepVersion.PCEP_1;
97 public short getLength() {
102 public short getType() {
107 public int hashCode() {
108 return Objects.hash(iLinkLocalIdentifier, iLinkRemoteIdentifier);
112 public boolean equals(Object obj) {
116 if (obj instanceof LinkLocalRemoteIdentifiersTlv) {
117 LinkLocalRemoteIdentifiersTlv other = (LinkLocalRemoteIdentifiersTlv) obj;
118 return Objects.equals(iLinkLocalIdentifier, other.iLinkLocalIdentifier)
119 && Objects.equals(iLinkRemoteIdentifier, other.iLinkRemoteIdentifier);
125 public int write(ChannelBuffer c) {
126 int iStartIndex = c.writerIndex();
128 c.writeShort(LENGTH);
129 c.writeInt(iLinkLocalIdentifier);
130 c.writeInt(iLinkRemoteIdentifier);
131 return c.writerIndex() - iStartIndex;
135 * Reads the channel buffer and returns object of LinkLocalRemoteIdentifiersTlv.
137 * @param c input channel buffer
138 * @return object of LinkLocalRemoteIdentifiersTlv
140 public static PcepValueType read(ChannelBuffer c) {
141 int iLinkLocalIdentifier = c.readInt();
142 int iLinkRemoteIdentifier = c.readInt();
143 return new LinkLocalRemoteIdentifiersTlv(iLinkLocalIdentifier, iLinkRemoteIdentifier);
147 public String toString() {
148 return MoreObjects.toStringHelper(getClass())
150 .add("Length", LENGTH)
151 .add("LinkLocalIdentifier", iLinkLocalIdentifier)
152 .add("LinkRemoteIdentifier", iLinkRemoteIdentifier)