Priyanka B | b2988fa | 2015-10-09 12:45:36 +0530 | [diff] [blame] | 1 | /* |
| 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 | package org.onosproject.bgpio.types; |
| 17 | |
Satish K | e70d88a | 2015-11-24 21:47:51 +0530 | [diff] [blame] | 18 | import java.util.Arrays; |
Priyanka B | b2988fa | 2015-10-09 12:45:36 +0530 | [diff] [blame] | 19 | |
| 20 | import org.jboss.netty.buffer.ChannelBuffer; |
| 21 | import org.onosproject.bgpio.protocol.IGPRouterID; |
| 22 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; |
| 24 | |
| 25 | import com.google.common.base.MoreObjects; |
| 26 | |
| 27 | /** |
| 28 | * Provides Implementation of IsIsNonPseudonode Tlv. |
| 29 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame^] | 30 | public class IsIsNonPseudonode implements IGPRouterID, BgpValueType { |
Priyanka B | e366178 | 2015-11-22 17:52:54 +0530 | [diff] [blame] | 31 | private static final Logger log = LoggerFactory.getLogger(IsIsNonPseudonode.class); |
Priyanka B | b2988fa | 2015-10-09 12:45:36 +0530 | [diff] [blame] | 32 | |
| 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 B | e366178 | 2015-11-22 17:52:54 +0530 | [diff] [blame] | 44 | this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length); |
Priyanka B | b2988fa | 2015-10-09 12:45:36 +0530 | [diff] [blame] | 45 | } |
| 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 K | e70d88a | 2015-11-24 21:47:51 +0530 | [diff] [blame] | 68 | return Arrays.hashCode(isoNodeID); |
Priyanka B | b2988fa | 2015-10-09 12:45:36 +0530 | [diff] [blame] | 69 | } |
| 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 K | e70d88a | 2015-11-24 21:47:51 +0530 | [diff] [blame] | 78 | return Arrays.equals(isoNodeID, other.isoNodeID); |
Priyanka B | b2988fa | 2015-10-09 12:45:36 +0530 | [diff] [blame] | 79 | } |
| 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 B | e366178 | 2015-11-22 17:52:54 +0530 | [diff] [blame] | 100 | cb.readBytes(isoNodeID); |
Priyanka B | b2988fa | 2015-10-09 12:45:36 +0530 | [diff] [blame] | 101 | 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 | } |