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 IPv4 Neighbor Address .
30 public class IPv4NeighborAddressTlv implements PcepValueType {
32 /* Reference :[RFC5305]/3.3
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 | IPv4 Neighbor Address |
39 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 protected static final Logger log = LoggerFactory.getLogger(IPv4NeighborAddressTlv.class);
44 public static final short TYPE = 8;
45 public static final short LENGTH = 4;
47 private final int rawValue;
50 * Constructor to initialize rawValue.
52 * @param rawValue IPv4-Neighbor-Address-Tlv
54 public IPv4NeighborAddressTlv(int rawValue) {
55 log.debug("IPv4NeighborAddressTlv");
56 this.rawValue = rawValue;
60 * Returns newly created IPv4NeighborAddressTlv object.
62 * @param raw value of IPv4-Neighbor-Address
63 * @return object of IPv4NeighborAddressTlv
65 public static IPv4NeighborAddressTlv of(final int raw) {
66 return new IPv4NeighborAddressTlv(raw);
70 * Returns value of IPv4 Neighbor Address.
72 * @return rawValue IPv4 Neighbor Address
79 public PcepVersion getVersion() {
80 return PcepVersion.PCEP_1;
84 public short getType() {
89 public short getLength() {
94 public int hashCode() {
95 return Objects.hash(rawValue);
99 public boolean equals(Object obj) {
103 if (obj instanceof IPv4NeighborAddressTlv) {
104 IPv4NeighborAddressTlv other = (IPv4NeighborAddressTlv) obj;
105 return Objects.equals(rawValue, other.rawValue);
111 public int write(ChannelBuffer c) {
112 int iLenStartIndex = c.writerIndex();
114 c.writeShort(LENGTH);
115 c.writeInt(rawValue);
116 return c.writerIndex() - iLenStartIndex;
120 * Reads the channel buffer and returns object of IPv4-Neighbor-Address-Tlv.
122 * @param c input channel buffer
123 * @return object of IPv4-Neighbor-Address-Tlv
125 public static IPv4NeighborAddressTlv read(ChannelBuffer c) {
126 return IPv4NeighborAddressTlv.of(c.readInt());
130 public String toString() {
131 return MoreObjects.toStringHelper(getClass())
133 .add("Length", LENGTH)
134 .add("Value", rawValue)