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.
17 package org.onosproject.pcepio.types;
19 import java.util.Objects;
21 import org.jboss.netty.buffer.ChannelBuffer;
22 import org.onosproject.pcepio.protocol.PcepVersion;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.google.common.base.MoreObjects;
29 * NexthopIPv6addressTlv provides Ipv4 address of next hop.
31 public class NexthopIPv4addressTlv implements PcepValueType {
34 Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01
37 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
38 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 | Type=TBD | Length = 8 |
40 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 | nexthop IPv4 address |
42 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 NEXTHOP-IPV4-ADDRESS TLV
47 protected static final Logger log = LoggerFactory.getLogger(NexthopIPv4addressTlv.class);
49 public static final short TYPE = 2; //to be defined
50 //Length is header + value
51 public static final short LENGTH = 8;
52 public static final short VALUE_LENGTH = 4;
54 private final int rawValue;
57 * Constructor to initialize next hop IPv4 address.
59 * @param rawValue next hop IPv4 address
61 public NexthopIPv4addressTlv(int rawValue) {
62 this.rawValue = rawValue;
66 * Return next hop IPv4 address tlv.
68 * @param raw of next hop IPv4 address
69 * @return object of NexthopIPv4addressTlv
71 public static NexthopIPv4addressTlv of(final int raw) {
72 return new NexthopIPv4addressTlv(raw);
76 * Returns next hop IPv4 address.
78 * @return next hop IPv4 address
85 public PcepVersion getVersion() {
86 return PcepVersion.PCEP_1;
90 public short getType() {
95 public short getLength() {
100 public int hashCode() {
101 return Objects.hash(rawValue);
105 public boolean equals(Object obj) {
109 if (obj instanceof NexthopIPv4addressTlv) {
110 NexthopIPv4addressTlv other = (NexthopIPv4addressTlv) obj;
111 return Objects.equals(this.rawValue, other.rawValue);
117 public int write(ChannelBuffer c) {
118 int iStartIndex = c.writerIndex();
120 c.writeShort(LENGTH);
121 c.writeInt(rawValue);
122 return c.writerIndex() - iStartIndex;
126 * Reads the channel buffer and returns object of NexthopIPv4addressTlv.
128 * @param c type of channel buffer
129 * @return object of NexthopIPv4addressTlv
131 public static NexthopIPv4addressTlv read(ChannelBuffer c) {
132 return NexthopIPv4addressTlv.of(c.readInt());
136 public String toString() {
137 return MoreObjects.toStringHelper(getClass())
139 .add("Length", LENGTH)
140 .add("Ipv4Address ", rawValue)