diff options
Diffstat (limited to 'framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java')
-rw-r--r-- | framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java | 72 |
1 files changed, 27 insertions, 45 deletions
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java index 35fd2493..094c4382 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java @@ -15,28 +15,23 @@ */ package org.onosproject.bgpio.types; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; +import java.nio.ByteBuffer; +import java.util.Arrays; import java.util.Objects; import org.jboss.netty.buffer.ChannelBuffer; import org.onosproject.bgpio.protocol.IGPRouterID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.MoreObjects; /** * Provides implementation of IsIsPseudonode Tlv. */ -public class IsIsPseudonode implements IGPRouterID, BGPValueType { - private static final Logger log = LoggerFactory.getLogger(IsIsPseudonode.class); - +public class IsIsPseudonode implements IGPRouterID, BgpValueType { public static final short TYPE = 515; public static final short LENGTH = 7; - private final List<Byte> isoNodeID; + private final byte[] isoNodeID; private byte psnIdentifier; /** @@ -45,8 +40,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { * @param isoNodeID ISO system-ID * @param psnIdentifier PSN identifier */ - public IsIsPseudonode(List<Byte> isoNodeID, byte psnIdentifier) { - this.isoNodeID = isoNodeID; + public IsIsPseudonode(byte[] isoNodeID, byte psnIdentifier) { + this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length); this.psnIdentifier = psnIdentifier; } @@ -57,7 +52,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { * @param psnIdentifier PSN identifier * @return object of IsIsPseudonode */ - public static IsIsPseudonode of(final List<Byte> isoNodeID, + public static IsIsPseudonode of(final byte[] isoNodeID, final byte psnIdentifier) { return new IsIsPseudonode(isoNodeID, psnIdentifier); } @@ -67,7 +62,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { * * @return ISO NodeID */ - public List<Byte> getISONodeID() { + public byte[] getISONodeID() { return isoNodeID; } @@ -82,7 +77,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { @Override public int hashCode() { - return Objects.hash(isoNodeID) & Objects.hash(psnIdentifier); + return Arrays.hashCode(isoNodeID) & Objects.hash(psnIdentifier); } @Override @@ -91,27 +86,9 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { return true; } if (obj instanceof IsIsPseudonode) { - int countObjSubTlv = 0; - int countOtherSubTlv = 0; - boolean isCommonSubTlv = true; IsIsPseudonode other = (IsIsPseudonode) obj; - Iterator<Byte> objListIterator = other.isoNodeID.iterator(); - countOtherSubTlv = other.isoNodeID.size(); - countObjSubTlv = isoNodeID.size(); - if (countObjSubTlv != countOtherSubTlv) { - return false; - } else { - while (objListIterator.hasNext() && isCommonSubTlv) { - Byte subTlv = objListIterator.next(); - if (isoNodeID.contains(subTlv) && other.isoNodeID.contains(subTlv)) { - isCommonSubTlv = Objects.equals(isoNodeID.get(isoNodeID.indexOf(subTlv)), - other.isoNodeID.get(other.isoNodeID.indexOf(subTlv))); - } else { - isCommonSubTlv = false; - } - } - return isCommonSubTlv && Objects.equals(psnIdentifier, other.psnIdentifier); - } + return Arrays.equals(isoNodeID, other.isoNodeID) + && Objects.equals(psnIdentifier, other.psnIdentifier); } return false; } @@ -121,11 +98,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { int iLenStartIndex = c.writerIndex(); c.writeShort(TYPE); c.writeShort(LENGTH); - Iterator<Byte> objListIterator = isoNodeID.iterator(); - while (objListIterator.hasNext()) { - byte value = objListIterator.next(); - c.writeByte(value); - } + c.writeBytes(isoNodeID, 0, LENGTH - 1); c.writeByte(psnIdentifier); return c.writerIndex() - iLenStartIndex; } @@ -137,12 +110,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { * @return object of IsIsPseudonode */ public static IsIsPseudonode read(ChannelBuffer cb) { - List<Byte> isoNodeID = new ArrayList<Byte>(); - byte value; - for (int i = 0; i < LENGTH; i++) { - value = cb.readByte(); - isoNodeID.add(value); - } + byte[] isoNodeID = new byte[LENGTH - 1]; + cb.readBytes(isoNodeID); byte psnIdentifier = cb.readByte(); return IsIsPseudonode.of(isoNodeID, psnIdentifier); } @@ -153,6 +122,19 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { } @Override + public int compareTo(Object o) { + if (this.equals(o)) { + return 0; + } + ByteBuffer value1 = ByteBuffer.wrap(this.isoNodeID); + ByteBuffer value2 = ByteBuffer.wrap(((IsIsPseudonode) o).isoNodeID); + if (value1.compareTo(value2) != 0) { + return value1.compareTo(value2); + } + return ((Byte) (this.psnIdentifier)).compareTo((Byte) (((IsIsPseudonode) o).psnIdentifier)); + } + + @Override public String toString() { return MoreObjects.toStringHelper(getClass()) .add("Type", TYPE) |