blob: 10b53145da6ce65073688bfd5cfbeb21e224157f [file] [log] [blame]
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -07003 *
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
Saritha8539a2e2017-01-05 11:58:54 +053019import java.util.Arrays;
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070020
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 Ipv6 Node Id.
28 */
29public class PcepNaiIpv6NodeId implements PcepNai {
30
31 public static final byte ST_TYPE = 0x02;
32 public static final byte IPV6_LEN = 0x10;
33
34 private final byte[] ipv6NodeId;
35
36 /**
37 * Constructor to initialize ipv6NodeId.
38 *
39 * @param value ipv6 node id
40 */
41 public PcepNaiIpv6NodeId(byte[] value) {
42 this.ipv6NodeId = value;
43 }
44
45 /**
46 * Return object of Pcep Nai Ipv6 Node ID.
47 *
48 * @param ipv6NodeId Ipv6 node ID.
49 * @return object of Pcep Nai Ipv6 Node ID.
50 */
51 public static PcepNaiIpv6NodeId of(byte[] ipv6NodeId) {
52 return new PcepNaiIpv6NodeId(ipv6NodeId);
53 }
54
55 @Override
56 public byte getType() {
57 return ST_TYPE;
58 }
59
60 @Override
61 public int write(ChannelBuffer cb) {
62 int iLenStartIndex = cb.writerIndex();
63 cb.writeBytes(ipv6NodeId);
64 return cb.writerIndex() - iLenStartIndex;
65 }
66
67 /**
68 * Reads from the channel buffer and returns object of PcepNAIIpv6NodeId.
69 *
70 * @param cb of type channel buffer.
71 * @return object of PcepNAIIpv6NodeId
72 */
73 public static PcepNaiIpv6NodeId read(ChannelBuffer cb) {
74 byte[] ipv6NodeId = new byte[IPV6_LEN];
75 cb.readBytes(ipv6NodeId, 0, IPV6_LEN);
76 return new PcepNaiIpv6NodeId(ipv6NodeId);
77 }
78
79 @Override
80 public int hashCode() {
Saritha8539a2e2017-01-05 11:58:54 +053081 return Arrays.hashCode(ipv6NodeId);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070082 }
83
84 @Override
85 public boolean equals(Object obj) {
86 if (this == obj) {
87 return true;
88 }
89 if (obj instanceof PcepNaiIpv6NodeId) {
90 PcepNaiIpv6NodeId other = (PcepNaiIpv6NodeId) obj;
Saritha8539a2e2017-01-05 11:58:54 +053091 return Arrays.equals(this.ipv6NodeId, other.ipv6NodeId);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070092 }
93 return false;
94 }
95
96 @Override
97 public String toString() {
Sho SHIMIZU7cdbcf72015-09-03 14:43:05 -070098 return MoreObjects.toStringHelper(getClass())
99 .add("IPV6NodeID", ipv6NodeId)
100 .toString();
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700101 }
102}