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;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import com.google.common.base.MoreObjects;
27 * Provides Implementation of Link Local/Remote IdentifiersTlv.
29 public class LinkLocalRemoteIdentifiersTlv implements BGPValueType {
30 private static final Logger log = LoggerFactory.getLogger(LinkLocalRemoteIdentifiersTlv.class);
31 public static final short TYPE = 258;
32 private static final int LENGTH = 8;
34 private final int linkLocalIdentifer;
35 private final int linkRemoteIdentifer;
38 * Constructor to initialize parameters.
40 * @param linkLocalIdentifer link local Identifer
41 * @param linkRemoteIdentifer link remote Identifer
43 public LinkLocalRemoteIdentifiersTlv(int linkLocalIdentifer, int linkRemoteIdentifer) {
44 this.linkLocalIdentifer = linkLocalIdentifer;
45 this.linkRemoteIdentifer = linkRemoteIdentifer;
49 * Returns link remote Identifer.
51 * @return link remote Identifer
53 public int getLinkRemoteIdentifier() {
54 return linkRemoteIdentifer;
58 * Returns link local Identifer.
60 * @return link local Identifer
62 public int getLinkLocalIdentifier() {
63 return linkLocalIdentifer;
67 public short getType() {
72 public int hashCode() {
73 return Objects.hash(linkLocalIdentifer, linkRemoteIdentifer);
77 public boolean equals(Object obj) {
81 if (obj instanceof LinkLocalRemoteIdentifiersTlv) {
82 LinkLocalRemoteIdentifiersTlv other = (LinkLocalRemoteIdentifiersTlv) obj;
83 return Objects.equals(this.linkLocalIdentifer, other.linkLocalIdentifer)
84 && Objects.equals(this.linkRemoteIdentifer, other.linkRemoteIdentifer);
90 public int write(ChannelBuffer cb) {
91 int iLenStartIndex = cb.writerIndex();
93 cb.writeShort(LENGTH);
94 cb.writeInt(linkLocalIdentifer);
95 cb.writeInt(linkRemoteIdentifer);
96 return cb.writerIndex() - iLenStartIndex;
100 * Reads the channel buffer and returns object of LinkLocalRemoteIdentifiersTlv.
102 * @param cb channelBuffer
103 * @return object of LinkLocalRemoteIdentifiersTlv
105 public static LinkLocalRemoteIdentifiersTlv read(ChannelBuffer cb) {
106 int linkLocalIdentifer = cb.readInt();
107 int linkRemoteIdentifer = cb.readInt();
108 return LinkLocalRemoteIdentifiersTlv.of(linkLocalIdentifer, linkRemoteIdentifer);
112 * Returns object of this class with specified link local identifer and link remote identifer.
114 * @param linkLocalIdentifer link local identifier
115 * @param linkRemoteIdentifer link remote identifier
116 * @return object of LinkLocalRemoteIdentifiersTlv
118 public static LinkLocalRemoteIdentifiersTlv of(final int linkLocalIdentifer, final int linkRemoteIdentifer) {
119 return new LinkLocalRemoteIdentifiersTlv(linkLocalIdentifer, linkRemoteIdentifer);
123 public String toString() {
124 return MoreObjects.toStringHelper(getClass())
126 .add("LENGTH", LENGTH)
127 .add("linkLocalIdentifer", linkLocalIdentifer)
128 .add("linkRemoteIdentifer", linkRemoteIdentifer)