blob: 1d4ce5d4b1c0a6422d9768c0dc85a7f5caae60f2 [file] [log] [blame]
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -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 */
16
17package org.onosproject.pcepio.types;
18
19import java.util.Objects;
20
21import org.jboss.netty.buffer.ChannelBuffer;
22import org.onosproject.pcepio.protocol.PcepNai;
23
24import com.google.common.base.MoreObjects;
25
26/**
27 * Provides Pcep Nai Ipv4 Node Id.
28 */
29public class PcepNaiIpv4NodeId implements PcepNai {
30
31 public static final byte ST_TYPE = 0x01;
32
33 private final int ipv4NodeId;
34
35 /**
36 * Constructor to initialize ipv4NodeId.
37 *
38 * @param value ipv4 node id
39 */
40 public PcepNaiIpv4NodeId(int value) {
41 this.ipv4NodeId = value;
42 }
43
44 /**
45 * Returns an object of PcepNaiIpv4NodeId.
46 *
47 * @param value ipv4 node id
48 * @return object of PcepNaiIpv4NodeId
49 */
50 public static PcepNaiIpv4NodeId of(int value) {
51 return new PcepNaiIpv4NodeId(value);
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(ipv4NodeId);
63 return bb.writerIndex() - iLenStartIndex;
64 }
65
66 /**
67 * Reads from the channel buffer and returns object of PcepNAIIpv4NodeIdVer1.
68 *
69 * @param bb of channel buffer.
70 * @return object of PcepNAIIpv4NodeIdVer1
71 */
72 public static PcepNaiIpv4NodeId read(ChannelBuffer bb) {
73 return new PcepNaiIpv4NodeId(bb.readInt());
74 }
75
76 @Override
77 public int hashCode() {
78 return Objects.hash(ipv4NodeId);
79 }
80
81 @Override
82 public boolean equals(Object obj) {
83 if (this == obj) {
84 return true;
85 }
86 if (obj instanceof PcepNaiIpv4NodeId) {
87 PcepNaiIpv4NodeId other = (PcepNaiIpv4NodeId) obj;
88 return Objects.equals(this.ipv4NodeId, other.ipv4NodeId);
89 }
90 return false;
91 }
92
93 @Override
94 public String toString() {
Sho SHIMIZU7cdbcf72015-09-03 14:43:05 -070095 return MoreObjects.toStringHelper(getClass())
96 .add("IPv4NodeId", ipv4NodeId)
97 .toString();
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070098 }
99}