blob: 79099b56b4e167f8b1202df290c544d939f67dd7 [file] [log] [blame]
bharat saraswalf7364db2015-08-11 13:39:31 +05301package org.onosproject.pcepio.types;
2
3import java.util.Objects;
4
5import org.jboss.netty.buffer.ChannelBuffer;
6import org.onosproject.pcepio.protocol.PcepNai;
7
8import com.google.common.base.MoreObjects;
9
10public class PcepNaiUnnumberedAdjacencyIpv4 implements PcepNai {
11 /**
12 * draft-ietf-pce-segment-routing-03 section 5.3.2.
13 */
14 public static final byte ST_TYPE = 0x05;
15
16 private final int localNodeId;
17 private final int localInterfaceId;
18 private final int remoteNodeId;
19 private final int remoteInterfaceId;
20
21 /**
22 * Constructor to initialize all the member variables.
23 *
24 * @param localNodeId local node id
25 * @param localInterfaceId local interface id
26 * @param remoteNodeId remote node id
27 * @param remoteInterfaceId remote interface id
28 */
29 public PcepNaiUnnumberedAdjacencyIpv4(int localNodeId, int localInterfaceId, int remoteNodeId,
30 int remoteInterfaceId) {
31 this.localNodeId = localNodeId;
32 this.localInterfaceId = localInterfaceId;
33 this.remoteNodeId = remoteNodeId;
34 this.remoteInterfaceId = remoteInterfaceId;
35 }
36
37 /**
38 * Returns PCEP Nai Unnumbered Adjacency Ipv4 object.
39 *
40 * @param localNodeId local node id
41 * @param localInterfaceId local interface if
42 * @param remoteNodeId remote node id
43 * @param remoteInterfaceId remote interface id
44 * @return PCEP Nai Unnumbered Adjacency Ipv4 object
45 */
46 public static PcepNaiUnnumberedAdjacencyIpv4 of(int localNodeId, int localInterfaceId, int remoteNodeId,
47 int remoteInterfaceId) {
48 return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
49 }
50
51 @Override
52 public byte getType() {
53 return ST_TYPE;
54 }
55
56 @Override
57 public int write(ChannelBuffer bb) {
58 int iLenStartIndex = bb.writerIndex();
59 bb.writeInt(localNodeId);
60 bb.writeInt(localInterfaceId);
61 bb.writeInt(remoteNodeId);
62 bb.writeInt(remoteInterfaceId);
63 return bb.writerIndex() - iLenStartIndex;
64 }
65
66 /**
67 * Reads from channel buffer and return object of PcepNAIUnnumberedAdjacencyIpv4.
68 *
69 * @param bb of type channel buffer
70 * @return object of PcepNAIUnnumberedAdjacencyIpv4
71 */
72 public static PcepNaiUnnumberedAdjacencyIpv4 read(ChannelBuffer bb) {
73 int localNodeId;
74 int localInterfaceId;
75 int remoteNodeId;
76 int remoteInterfaceId;
77 localNodeId = bb.readInt();
78 localInterfaceId = bb.readInt();
79 remoteNodeId = bb.readInt();
80 remoteInterfaceId = bb.readInt();
81 return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
82 }
83
84 @Override
85 public int hashCode() {
86 return Objects.hash(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
87 }
88
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj) {
92 return true;
93 }
94 if (obj instanceof PcepNaiUnnumberedAdjacencyIpv4) {
95 PcepNaiUnnumberedAdjacencyIpv4 other = (PcepNaiUnnumberedAdjacencyIpv4) obj;
96 return Objects.equals(this.localNodeId, other.localNodeId)
97 && Objects.equals(this.localInterfaceId, other.localInterfaceId)
98 && Objects.equals(this.remoteNodeId, other.remoteNodeId)
99 && Objects.equals(this.remoteInterfaceId, other.remoteInterfaceId);
100 }
101 return false;
102 }
103
104 @Override
105 public String toString() {
106 return MoreObjects.toStringHelper(getClass())
bharat saraswale1806302015-08-21 12:16:46 +0530107 .add("localNodeId", localNodeId)
108 .add("localInterfaceId", localInterfaceId)
109 .add("remoteNodeId", remoteNodeId)
110 .add("remoteInterfaceId:", remoteInterfaceId)
bharat saraswalf7364db2015-08-11 13:39:31 +0530111 .toString();
112 }
113}