1 package org.onosproject.pcepio.types;
3 import java.util.Objects;
5 import org.jboss.netty.buffer.ChannelBuffer;
6 import org.onosproject.pcepio.protocol.PcepNai;
8 import com.google.common.base.MoreObjects;
11 * Provides Pcep Nai Unnumbered Adjacency Ipv4.
13 public class PcepNaiUnnumberedAdjacencyIpv4 implements PcepNai {
15 * draft-ietf-pce-segment-routing-03 section 5.3.2.
17 public static final byte ST_TYPE = 0x05;
19 private final int localNodeId;
20 private final int localInterfaceId;
21 private final int remoteNodeId;
22 private final int remoteInterfaceId;
25 * Constructor to initialize all the member variables.
27 * @param localNodeId local node id
28 * @param localInterfaceId local interface id
29 * @param remoteNodeId remote node id
30 * @param remoteInterfaceId remote interface id
32 public PcepNaiUnnumberedAdjacencyIpv4(int localNodeId, int localInterfaceId, int remoteNodeId,
33 int remoteInterfaceId) {
34 this.localNodeId = localNodeId;
35 this.localInterfaceId = localInterfaceId;
36 this.remoteNodeId = remoteNodeId;
37 this.remoteInterfaceId = remoteInterfaceId;
41 * Returns PCEP Nai Unnumbered Adjacency Ipv4 object.
43 * @param localNodeId local node id
44 * @param localInterfaceId local interface if
45 * @param remoteNodeId remote node id
46 * @param remoteInterfaceId remote interface id
47 * @return PCEP Nai Unnumbered Adjacency Ipv4 object
49 public static PcepNaiUnnumberedAdjacencyIpv4 of(int localNodeId, int localInterfaceId, int remoteNodeId,
50 int remoteInterfaceId) {
51 return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
55 public byte getType() {
60 public int write(ChannelBuffer bb) {
61 int iLenStartIndex = bb.writerIndex();
62 bb.writeInt(localNodeId);
63 bb.writeInt(localInterfaceId);
64 bb.writeInt(remoteNodeId);
65 bb.writeInt(remoteInterfaceId);
66 return bb.writerIndex() - iLenStartIndex;
70 * Reads from channel buffer and return object of PcepNAIUnnumberedAdjacencyIpv4.
72 * @param bb of type channel buffer
73 * @return object of PcepNAIUnnumberedAdjacencyIpv4
75 public static PcepNaiUnnumberedAdjacencyIpv4 read(ChannelBuffer bb) {
79 int remoteInterfaceId;
80 localNodeId = bb.readInt();
81 localInterfaceId = bb.readInt();
82 remoteNodeId = bb.readInt();
83 remoteInterfaceId = bb.readInt();
84 return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
88 public int hashCode() {
89 return Objects.hash(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
93 public boolean equals(Object obj) {
97 if (obj instanceof PcepNaiUnnumberedAdjacencyIpv4) {
98 PcepNaiUnnumberedAdjacencyIpv4 other = (PcepNaiUnnumberedAdjacencyIpv4) obj;
99 return Objects.equals(this.localNodeId, other.localNodeId)
100 && Objects.equals(this.localInterfaceId, other.localInterfaceId)
101 && Objects.equals(this.remoteNodeId, other.remoteNodeId)
102 && Objects.equals(this.remoteInterfaceId, other.remoteInterfaceId);
108 public String toString() {
109 return MoreObjects.toStringHelper(getClass())
110 .add("localNodeId", localNodeId)
111 .add("localInterfaceId", localInterfaceId)
112 .add("remoteNodeId", remoteNodeId)
113 .add("remoteInterfaceId", remoteInterfaceId)