2 * Copyright 2015 Open Networking Laboratory
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 package org.onosproject.bgpio.types;
\r
18 import java.util.Objects;
\r
19 import org.jboss.netty.buffer.ChannelBuffer;
\r
20 import org.slf4j.Logger;
\r
21 import org.slf4j.LoggerFactory;
\r
23 import com.google.common.base.MoreObjects;
\r
26 * Provides MultiProtocolExtnCapabilityTlv.
\r
28 public class MultiProtocolExtnCapabilityTlv implements BgpValueType {
\r
32 +-------+-------+-------+-------+
\r
33 | AFI | Res | SAFI |
\r
34 +-------+-------+-------+-------+
\r
36 Multiprotocol Extensions CAPABILITY TLV format
\r
37 REFERENCE : RFC 4760
\r
39 protected static final Logger log = LoggerFactory
\r
40 .getLogger(MultiProtocolExtnCapabilityTlv.class);
\r
42 public static final byte TYPE = 1;
\r
43 public static final byte LENGTH = 4;
\r
45 private final short afi;
\r
46 private final byte res;
\r
47 private final byte safi;
\r
50 * Constructor to initialize variables.
\r
51 * @param afi Address Family Identifiers
\r
52 * @param res reserved field
\r
53 * @param safi Subsequent Address Family Identifier
\r
55 public MultiProtocolExtnCapabilityTlv(short afi, byte res, byte safi) {
\r
62 * Returns object of MultiProtocolExtnCapabilityTlv.
\r
63 * @param afi Address Family Identifiers
\r
64 * @param res reserved field
\r
65 * @param safi Subsequent Address Family Identifier
\r
66 * @return object of MultiProtocolExtnCapabilityTlv
\r
68 public static MultiProtocolExtnCapabilityTlv of(short afi, byte res,
\r
70 return new MultiProtocolExtnCapabilityTlv(afi, res, safi);
\r
74 * Returns afi Address Family Identifiers value.
\r
75 * @return afi Address Family Identifiers value
\r
77 public short getAFI() {
\r
82 * Returns res reserved field value.
\r
83 * @return res reserved field value
\r
85 public byte getRes() {
\r
90 * Returns safi Subsequent Address Family Identifier value.
\r
91 * @return safi Subsequent Address Family Identifier value
\r
93 public byte getSAFI() {
\r
98 public short getType() {
\r
103 public int hashCode() {
\r
104 return Objects.hash(afi, res, safi);
\r
108 public boolean equals(Object obj) {
\r
112 if (obj instanceof MultiProtocolExtnCapabilityTlv) {
\r
113 MultiProtocolExtnCapabilityTlv other = (MultiProtocolExtnCapabilityTlv) obj;
\r
114 return Objects.equals(this.afi, other.afi)
\r
115 && Objects.equals(this.res, other.res)
\r
116 && Objects.equals(this.safi, other.safi);
\r
122 public int write(ChannelBuffer cb) {
\r
123 int iLenStartIndex = cb.writerIndex();
\r
124 cb.writeByte(TYPE);
\r
125 cb.writeByte(LENGTH);
\r
128 cb.writeShort(afi);
\r
134 cb.writeByte(safi);
\r
136 return cb.writerIndex() - iLenStartIndex;
\r
140 * Reads from channel buffer and returns object of MultiprotocolCapabilityTlv.
\r
141 * @param cb of type channel buffer
\r
142 * @return object of MultiProtocolExtnCapabilityTlv
\r
144 public static BgpValueType read(ChannelBuffer cb) {
\r
145 short afi = cb.readShort();
\r
146 byte res = cb.readByte();
\r
147 byte safi = cb.readByte();
\r
148 return new MultiProtocolExtnCapabilityTlv(afi, res, safi);
\r
152 public String toString() {
\r
153 return MoreObjects.toStringHelper(getClass())
\r
155 .add("Length", LENGTH)
\r
157 .add("Reserved", res)
\r
158 .add("SAFI", safi).toString();
\r
162 public int compareTo(Object o) {
\r
163 // TODO Auto-generated method stub
\r