blob: e6b9d6071bf7c167f2a0d17cd2f284386f454962 [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
Satish Ke70d88a2015-11-24 21:47:51 +053018import java.util.Arrays;
Priyanka Bb2988fa2015-10-09 12:45:36 +053019
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.onosproject.bgpio.protocol.IGPRouterID;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
25import com.google.common.base.MoreObjects;
26
27/**
28 * Provides Implementation of IsIsNonPseudonode Tlv.
29 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053030public class IsIsNonPseudonode implements IGPRouterID, BgpValueType {
Priyanka Be3661782015-11-22 17:52:54 +053031 private static final Logger log = LoggerFactory.getLogger(IsIsNonPseudonode.class);
Priyanka Bb2988fa2015-10-09 12:45:36 +053032
33 public static final short TYPE = 515;
34 public static final short LENGTH = 6;
35
36 private final byte[] isoNodeID;
37
38 /**
39 * Constructor to initialize isoNodeID.
40 *
41 * @param isoNodeID ISO system-ID
42 */
43 public IsIsNonPseudonode(byte[] isoNodeID) {
Priyanka Be3661782015-11-22 17:52:54 +053044 this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length);
Priyanka Bb2988fa2015-10-09 12:45:36 +053045 }
46
47 /**
48 * Returns object of this class with specified isoNodeID.
49 *
50 * @param isoNodeID ISO system-ID
51 * @return object of IsIsNonPseudonode
52 */
53 public static IsIsNonPseudonode of(final byte[] isoNodeID) {
54 return new IsIsNonPseudonode(isoNodeID);
55 }
56
57 /**
58 * Returns ISO NodeID.
59 *
60 * @return ISO NodeID
61 */
62 public byte[] getISONodeID() {
63 return isoNodeID;
64 }
65
66 @Override
67 public int hashCode() {
Satish Ke70d88a2015-11-24 21:47:51 +053068 return Arrays.hashCode(isoNodeID);
Priyanka Bb2988fa2015-10-09 12:45:36 +053069 }
70
71 @Override
72 public boolean equals(Object obj) {
73 if (this == obj) {
74 return true;
75 }
76 if (obj instanceof IsIsNonPseudonode) {
77 IsIsNonPseudonode other = (IsIsNonPseudonode) obj;
Satish Ke70d88a2015-11-24 21:47:51 +053078 return Arrays.equals(isoNodeID, other.isoNodeID);
Priyanka Bb2988fa2015-10-09 12:45:36 +053079 }
80 return false;
81 }
82
83 @Override
84 public int write(ChannelBuffer c) {
85 int iLenStartIndex = c.writerIndex();
86 c.writeShort(TYPE);
87 c.writeShort(LENGTH);
88 c.writeBytes(isoNodeID);
89 return c.writerIndex() - iLenStartIndex;
90 }
91
92 /**
93 * Reads the channel buffer and returns object of IsIsNonPseudonode.
94 *
95 * @param cb ChannelBuffer
96 * @return object of IsIsNonPseudonode
97 */
98 public static IsIsNonPseudonode read(ChannelBuffer cb) {
99 byte[] isoNodeID = new byte[LENGTH];
Priyanka Be3661782015-11-22 17:52:54 +0530100 cb.readBytes(isoNodeID);
Priyanka Bb2988fa2015-10-09 12:45:36 +0530101 return IsIsNonPseudonode.of(isoNodeID);
102 }
103
104 @Override
105 public short getType() {
106 return TYPE;
107 }
108
109 @Override
110 public String toString() {
111 return MoreObjects.toStringHelper(getClass())
112 .add("Type", TYPE)
113 .add("Length", LENGTH)
114 .add("ISONodeID", isoNodeID)
115 .toString();
116 }
117}