blob: 4e8926cf03351eb17c0a26d4616d1ed9ad86d4da [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070016package org.onosproject.pcepio.types;
17
18import java.util.Objects;
19
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.onosproject.pcepio.protocol.PcepNai;
22
23import com.google.common.base.MoreObjects;
24
25/**
26 * Provides Pcep Nai Unnumbered Adjacency Ipv4.
27 */
28public class PcepNaiUnnumberedAdjacencyIpv4 implements PcepNai {
29 /**
30 * draft-ietf-pce-segment-routing-03 section 5.3.2.
31 */
32 public static final byte ST_TYPE = 0x05;
33
34 private final int localNodeId;
35 private final int localInterfaceId;
36 private final int remoteNodeId;
37 private final int remoteInterfaceId;
38
39 /**
40 * Constructor to initialize all the member variables.
41 *
42 * @param localNodeId local node id
43 * @param localInterfaceId local interface id
44 * @param remoteNodeId remote node id
45 * @param remoteInterfaceId remote interface id
46 */
47 public PcepNaiUnnumberedAdjacencyIpv4(int localNodeId, int localInterfaceId, int remoteNodeId,
48 int remoteInterfaceId) {
49 this.localNodeId = localNodeId;
50 this.localInterfaceId = localInterfaceId;
51 this.remoteNodeId = remoteNodeId;
52 this.remoteInterfaceId = remoteInterfaceId;
53 }
54
55 /**
56 * Returns PCEP Nai Unnumbered Adjacency Ipv4 object.
57 *
58 * @param localNodeId local node id
59 * @param localInterfaceId local interface if
60 * @param remoteNodeId remote node id
61 * @param remoteInterfaceId remote interface id
62 * @return PCEP Nai Unnumbered Adjacency Ipv4 object
63 */
64 public static PcepNaiUnnumberedAdjacencyIpv4 of(int localNodeId, int localInterfaceId, int remoteNodeId,
65 int remoteInterfaceId) {
66 return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
67 }
68
69 @Override
70 public byte getType() {
71 return ST_TYPE;
72 }
73
74 @Override
75 public int write(ChannelBuffer bb) {
76 int iLenStartIndex = bb.writerIndex();
77 bb.writeInt(localNodeId);
78 bb.writeInt(localInterfaceId);
79 bb.writeInt(remoteNodeId);
80 bb.writeInt(remoteInterfaceId);
81 return bb.writerIndex() - iLenStartIndex;
82 }
83
84 /**
85 * Reads from channel buffer and return object of PcepNAIUnnumberedAdjacencyIpv4.
86 *
87 * @param bb of type channel buffer
88 * @return object of PcepNAIUnnumberedAdjacencyIpv4
89 */
90 public static PcepNaiUnnumberedAdjacencyIpv4 read(ChannelBuffer bb) {
91 int localNodeId;
92 int localInterfaceId;
93 int remoteNodeId;
94 int remoteInterfaceId;
95 localNodeId = bb.readInt();
96 localInterfaceId = bb.readInt();
97 remoteNodeId = bb.readInt();
98 remoteInterfaceId = bb.readInt();
99 return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
100 }
101
102 @Override
103 public int hashCode() {
104 return Objects.hash(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
105 }
106
107 @Override
108 public boolean equals(Object obj) {
109 if (this == obj) {
110 return true;
111 }
112 if (obj instanceof PcepNaiUnnumberedAdjacencyIpv4) {
113 PcepNaiUnnumberedAdjacencyIpv4 other = (PcepNaiUnnumberedAdjacencyIpv4) obj;
114 return Objects.equals(this.localNodeId, other.localNodeId)
115 && Objects.equals(this.localInterfaceId, other.localInterfaceId)
116 && Objects.equals(this.remoteNodeId, other.remoteNodeId)
117 && Objects.equals(this.remoteInterfaceId, other.remoteInterfaceId);
118 }
119 return false;
120 }
121
122 @Override
123 public String toString() {
124 return MoreObjects.toStringHelper(getClass())
125 .add("localNodeId", localNodeId)
126 .add("localInterfaceId", localInterfaceId)
127 .add("remoteNodeId", remoteNodeId)
Sho SHIMIZU7cdbcf72015-09-03 14:43:05 -0700128 .add("remoteInterfaceId", remoteInterfaceId)
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700129 .toString();
130 }
131}