1faf01a7ce77d302d7ebeb56259124aa5b767c2f
[onosfw.git] /
1 package org.onosproject.pcepio.types;
2
3 import java.util.Objects;
4
5 import org.jboss.netty.buffer.ChannelBuffer;
6 import org.onosproject.pcepio.protocol.PcepNai;
7
8 import com.google.common.base.MoreObjects;
9
10 /**
11  * Provides Pcep Nai Unnumbered Adjacency Ipv4.
12  */
13 public class PcepNaiUnnumberedAdjacencyIpv4 implements PcepNai {
14     /**
15      * draft-ietf-pce-segment-routing-03 section    5.3.2.
16      */
17     public static final byte ST_TYPE = 0x05;
18
19     private final int localNodeId;
20     private final int localInterfaceId;
21     private final int remoteNodeId;
22     private final int remoteInterfaceId;
23
24     /**
25      * Constructor to initialize all the member variables.
26      *
27      * @param localNodeId local node id
28      * @param localInterfaceId local interface id
29      * @param remoteNodeId remote node id
30      * @param remoteInterfaceId remote interface id
31      */
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;
38     }
39
40     /**
41      * Returns PCEP Nai Unnumbered Adjacency Ipv4 object.
42      *
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
48      */
49     public static PcepNaiUnnumberedAdjacencyIpv4 of(int localNodeId, int localInterfaceId, int remoteNodeId,
50             int remoteInterfaceId) {
51         return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
52     }
53
54     @Override
55     public byte getType() {
56         return ST_TYPE;
57     }
58
59     @Override
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;
67     }
68
69     /**
70      * Reads from channel buffer and return object of PcepNAIUnnumberedAdjacencyIpv4.
71      *
72      * @param bb of type channel buffer
73      * @return object of PcepNAIUnnumberedAdjacencyIpv4
74      */
75     public static PcepNaiUnnumberedAdjacencyIpv4 read(ChannelBuffer bb) {
76         int localNodeId;
77         int localInterfaceId;
78         int remoteNodeId;
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);
85     }
86
87     @Override
88     public int hashCode() {
89         return Objects.hash(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
90     }
91
92     @Override
93     public boolean equals(Object obj) {
94         if (this == obj) {
95             return true;
96         }
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);
103         }
104         return false;
105     }
106
107     @Override
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)
114                 .toString();
115     }
116 }