blob: 62e3f062c00cc77bc1c139d173d580279bd813b2 [file] [log] [blame]
Priyanka Bb2988fa2015-10-09 12:45:36 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Priyanka Bb2988fa2015-10-09 12:45:36 +05303 *
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
Jonathan Hart51539b82015-10-29 09:53:04 -070018import com.google.common.base.MoreObjects;
19import org.jboss.netty.buffer.ChannelBuffer;
20import org.onosproject.bgpio.protocol.IgpRouterId;
21
Priyanka B02040732015-11-29 11:30:29 +053022import java.nio.ByteBuffer;
Satish Ke70d88a2015-11-24 21:47:51 +053023import java.util.Arrays;
Priyanka Bb2988fa2015-10-09 12:45:36 +053024
Priyanka Bb2988fa2015-10-09 12:45:36 +053025/**
26 * Provides Implementation of IsIsNonPseudonode Tlv.
27 */
Jonathan Hart51539b82015-10-29 09:53:04 -070028public class IsIsNonPseudonode implements IgpRouterId, BgpValueType {
Priyanka Bb2988fa2015-10-09 12:45:36 +053029 public static final short TYPE = 515;
30 public static final short LENGTH = 6;
31
32 private final byte[] isoNodeID;
33
34 /**
35 * Constructor to initialize isoNodeID.
36 *
37 * @param isoNodeID ISO system-ID
38 */
39 public IsIsNonPseudonode(byte[] isoNodeID) {
Priyanka Be3661782015-11-22 17:52:54 +053040 this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length);
Priyanka Bb2988fa2015-10-09 12:45:36 +053041 }
42
43 /**
44 * Returns object of this class with specified isoNodeID.
45 *
46 * @param isoNodeID ISO system-ID
47 * @return object of IsIsNonPseudonode
48 */
49 public static IsIsNonPseudonode of(final byte[] isoNodeID) {
50 return new IsIsNonPseudonode(isoNodeID);
51 }
52
53 /**
54 * Returns ISO NodeID.
55 *
56 * @return ISO NodeID
57 */
Jonathan Hart51539b82015-10-29 09:53:04 -070058 public byte[] getIsoNodeId() {
Priyanka Bb2988fa2015-10-09 12:45:36 +053059 return isoNodeID;
60 }
61
62 @Override
63 public int hashCode() {
Satish Ke70d88a2015-11-24 21:47:51 +053064 return Arrays.hashCode(isoNodeID);
Priyanka Bb2988fa2015-10-09 12:45:36 +053065 }
66
67 @Override
68 public boolean equals(Object obj) {
69 if (this == obj) {
70 return true;
71 }
72 if (obj instanceof IsIsNonPseudonode) {
73 IsIsNonPseudonode other = (IsIsNonPseudonode) obj;
Satish Ke70d88a2015-11-24 21:47:51 +053074 return Arrays.equals(isoNodeID, other.isoNodeID);
Priyanka Bb2988fa2015-10-09 12:45:36 +053075 }
76 return false;
77 }
78
79 @Override
80 public int write(ChannelBuffer c) {
81 int iLenStartIndex = c.writerIndex();
82 c.writeShort(TYPE);
83 c.writeShort(LENGTH);
84 c.writeBytes(isoNodeID);
85 return c.writerIndex() - iLenStartIndex;
86 }
87
88 /**
89 * Reads the channel buffer and returns object of IsIsNonPseudonode.
90 *
91 * @param cb ChannelBuffer
92 * @return object of IsIsNonPseudonode
93 */
94 public static IsIsNonPseudonode read(ChannelBuffer cb) {
95 byte[] isoNodeID = new byte[LENGTH];
Priyanka Be3661782015-11-22 17:52:54 +053096 cb.readBytes(isoNodeID);
Priyanka Bb2988fa2015-10-09 12:45:36 +053097 return IsIsNonPseudonode.of(isoNodeID);
98 }
99
100 @Override
101 public short getType() {
102 return TYPE;
103 }
104
105 @Override
Priyanka B02040732015-11-29 11:30:29 +0530106 public int compareTo(Object o) {
107 if (this.equals(o)) {
108 return 0;
109 }
110 ByteBuffer value1 = ByteBuffer.wrap(this.isoNodeID);
111 ByteBuffer value2 = ByteBuffer.wrap(((IsIsNonPseudonode) o).isoNodeID);
112 return value1.compareTo(value2);
113 }
114
115 @Override
Priyanka Bb2988fa2015-10-09 12:45:36 +0530116 public String toString() {
117 return MoreObjects.toStringHelper(getClass())
118 .add("Type", TYPE)
119 .add("Length", LENGTH)
120 .add("ISONodeID", isoNodeID)
121 .toString();
122 }
Jonathan Hart51539b82015-10-29 09:53:04 -0700123}