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.bgpio.types;
18 import java.util.Objects;
20 import org.jboss.netty.buffer.ChannelBuffer;
22 import com.google.common.base.MoreObjects;
25 * Provides Implementation of Link Local/Remote IdentifiersTlv.
27 public class LinkLocalRemoteIdentifiersTlv implements BgpValueType {
28 public static final short TYPE = 258;
29 private static final int LENGTH = 8;
31 private final int linkLocalIdentifer;
32 private final int linkRemoteIdentifer;
35 * Constructor to initialize parameters.
37 * @param linkLocalIdentifer link local Identifer
38 * @param linkRemoteIdentifer link remote Identifer
40 public LinkLocalRemoteIdentifiersTlv(int linkLocalIdentifer, int linkRemoteIdentifer) {
41 this.linkLocalIdentifer = linkLocalIdentifer;
42 this.linkRemoteIdentifer = linkRemoteIdentifer;
46 * Returns link remote Identifer.
48 * @return link remote Identifer
50 public int getLinkRemoteIdentifier() {
51 return linkRemoteIdentifer;
55 * Returns link local Identifer.
57 * @return link local Identifer
59 public int getLinkLocalIdentifier() {
60 return linkLocalIdentifer;
64 public short getType() {
69 public int hashCode() {
70 return Objects.hash(linkLocalIdentifer, linkRemoteIdentifer);
74 public boolean equals(Object obj) {
78 if (obj instanceof LinkLocalRemoteIdentifiersTlv) {
79 LinkLocalRemoteIdentifiersTlv other = (LinkLocalRemoteIdentifiersTlv) obj;
80 return Objects.equals(this.linkLocalIdentifer, other.linkLocalIdentifer)
81 && Objects.equals(this.linkRemoteIdentifer, other.linkRemoteIdentifer);
87 public int write(ChannelBuffer cb) {
88 int iLenStartIndex = cb.writerIndex();
90 cb.writeShort(LENGTH);
91 cb.writeInt(linkLocalIdentifer);
92 cb.writeInt(linkRemoteIdentifer);
93 return cb.writerIndex() - iLenStartIndex;
97 * Reads the channel buffer and returns object of LinkLocalRemoteIdentifiersTlv.
99 * @param cb channelBuffer
100 * @return object of LinkLocalRemoteIdentifiersTlv
102 public static LinkLocalRemoteIdentifiersTlv read(ChannelBuffer cb) {
103 int linkLocalIdentifer = cb.readInt();
104 int linkRemoteIdentifer = cb.readInt();
105 return LinkLocalRemoteIdentifiersTlv.of(linkLocalIdentifer, linkRemoteIdentifer);
109 * Returns object of this class with specified link local identifer and link remote identifer.
111 * @param linkLocalIdentifer link local identifier
112 * @param linkRemoteIdentifer link remote identifier
113 * @return object of LinkLocalRemoteIdentifiersTlv
115 public static LinkLocalRemoteIdentifiersTlv of(final int linkLocalIdentifer, final int linkRemoteIdentifer) {
116 return new LinkLocalRemoteIdentifiersTlv(linkLocalIdentifer, linkRemoteIdentifer);
120 public int compareTo(Object o) {
121 if (this.equals(o)) {
124 int result = ((Integer) (this.linkLocalIdentifer))
125 .compareTo((Integer) (((LinkLocalRemoteIdentifiersTlv) o).linkLocalIdentifer));
129 return ((Integer) (this.linkRemoteIdentifer))
130 .compareTo((Integer) (((LinkLocalRemoteIdentifiersTlv) o).linkRemoteIdentifer));
134 public String toString() {
135 return MoreObjects.toStringHelper(getClass())
137 .add("LENGTH", LENGTH)
138 .add("linkLocalIdentifer", linkLocalIdentifer)
139 .add("linkRemoteIdentifer", linkRemoteIdentifer)