blob: 427aa92909b69f246826defb7e5367ce225f01e6 [file] [log] [blame]
Priyanka Bb2988fa2015-10-09 12:45:36 +05301/*
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 */
16package org.onosproject.bgpio.types;
17
Priyanka B02040732015-11-29 11:30:29 +053018import java.nio.ByteBuffer;
Satish Ke70d88a2015-11-24 21:47:51 +053019import java.util.Arrays;
Priyanka Bb2988fa2015-10-09 12:45:36 +053020
21import org.jboss.netty.buffer.ChannelBuffer;
22import org.onosproject.bgpio.protocol.IGPRouterID;
Priyanka Bb2988fa2015-10-09 12:45:36 +053023
24import com.google.common.base.MoreObjects;
25
26/**
27 * Provides Implementation of IsIsNonPseudonode Tlv.
28 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053029public class IsIsNonPseudonode implements IGPRouterID, BgpValueType {
Priyanka Bb2988fa2015-10-09 12:45:36 +053030 public static final short TYPE = 515;
31 public static final short LENGTH = 6;
32
33 private final byte[] isoNodeID;
34
35 /**
36 * Constructor to initialize isoNodeID.
37 *
38 * @param isoNodeID ISO system-ID
39 */
40 public IsIsNonPseudonode(byte[] isoNodeID) {
Priyanka Be3661782015-11-22 17:52:54 +053041 this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length);
Priyanka Bb2988fa2015-10-09 12:45:36 +053042 }
43
44 /**
45 * Returns object of this class with specified isoNodeID.
46 *
47 * @param isoNodeID ISO system-ID
48 * @return object of IsIsNonPseudonode
49 */
50 public static IsIsNonPseudonode of(final byte[] isoNodeID) {
51 return new IsIsNonPseudonode(isoNodeID);
52 }
53
54 /**
55 * Returns ISO NodeID.
56 *
57 * @return ISO NodeID
58 */
59 public byte[] getISONodeID() {
60 return isoNodeID;
61 }
62
63 @Override
64 public int hashCode() {
Satish Ke70d88a2015-11-24 21:47:51 +053065 return Arrays.hashCode(isoNodeID);
Priyanka Bb2988fa2015-10-09 12:45:36 +053066 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73 if (obj instanceof IsIsNonPseudonode) {
74 IsIsNonPseudonode other = (IsIsNonPseudonode) obj;
Satish Ke70d88a2015-11-24 21:47:51 +053075 return Arrays.equals(isoNodeID, other.isoNodeID);
Priyanka Bb2988fa2015-10-09 12:45:36 +053076 }
77 return false;
78 }
79
80 @Override
81 public int write(ChannelBuffer c) {
82 int iLenStartIndex = c.writerIndex();
83 c.writeShort(TYPE);
84 c.writeShort(LENGTH);
85 c.writeBytes(isoNodeID);
86 return c.writerIndex() - iLenStartIndex;
87 }
88
89 /**
90 * Reads the channel buffer and returns object of IsIsNonPseudonode.
91 *
92 * @param cb ChannelBuffer
93 * @return object of IsIsNonPseudonode
94 */
95 public static IsIsNonPseudonode read(ChannelBuffer cb) {
96 byte[] isoNodeID = new byte[LENGTH];
Priyanka Be3661782015-11-22 17:52:54 +053097 cb.readBytes(isoNodeID);
Priyanka Bb2988fa2015-10-09 12:45:36 +053098 return IsIsNonPseudonode.of(isoNodeID);
99 }
100
101 @Override
102 public short getType() {
103 return TYPE;
104 }
105
106 @Override
Priyanka B02040732015-11-29 11:30:29 +0530107 public int compareTo(Object o) {
108 if (this.equals(o)) {
109 return 0;
110 }
111 ByteBuffer value1 = ByteBuffer.wrap(this.isoNodeID);
112 ByteBuffer value2 = ByteBuffer.wrap(((IsIsNonPseudonode) o).isoNodeID);
113 return value1.compareTo(value2);
114 }
115
116 @Override
Priyanka Bb2988fa2015-10-09 12:45:36 +0530117 public String toString() {
118 return MoreObjects.toStringHelper(getClass())
119 .add("Type", TYPE)
120 .add("Length", LENGTH)
121 .add("ISONodeID", isoNodeID)
122 .toString();
123 }
124}