Priyanka B
Committed by Gerrit Code Review

IsIs and Ospf code fix

Change-Id: I4cebdb1af9ba68b673335d86f80a6b7498e0bfd1
......@@ -28,7 +28,7 @@ import com.google.common.base.MoreObjects;
* Provides Implementation of IsIsNonPseudonode Tlv.
*/
public class IsIsNonPseudonode implements IGPRouterID, BGPValueType {
protected static final Logger log = LoggerFactory.getLogger(IsIsNonPseudonode.class);
private static final Logger log = LoggerFactory.getLogger(IsIsNonPseudonode.class);
public static final short TYPE = 515;
public static final short LENGTH = 6;
......@@ -41,7 +41,7 @@ public class IsIsNonPseudonode implements IGPRouterID, BGPValueType {
* @param isoNodeID ISO system-ID
*/
public IsIsNonPseudonode(byte[] isoNodeID) {
this.isoNodeID = isoNodeID;
this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length);
}
/**
......@@ -97,7 +97,7 @@ public class IsIsNonPseudonode implements IGPRouterID, BGPValueType {
*/
public static IsIsNonPseudonode read(ChannelBuffer cb) {
byte[] isoNodeID = new byte[LENGTH];
cb.readBytes(isoNodeID, 0, LENGTH);
cb.readBytes(isoNodeID);
return IsIsNonPseudonode.of(isoNodeID);
}
......
......@@ -15,9 +15,7 @@
*/
package org.onosproject.bgpio.types;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Arrays;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
......@@ -36,7 +34,7 @@ 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 +43,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 +55,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 +65,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
*
* @return ISO NodeID
*/
public List<Byte> getISONodeID() {
public byte[] getISONodeID() {
return isoNodeID;
}
......@@ -82,7 +80,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 +89,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 +101,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 +113,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);
}
......
......@@ -36,42 +36,4 @@ public class AreaIdTest {
.addEqualityGroup(tlv2)
.testEquals();
}
/**
* Test for OSPFNonPseudonode Tlv.
*/
public static class OspfNonPseudonodeTest {
private final int value1 = 0x12121212;
private final int value2 = 0x12121211;
private final OSPFNonPseudonode tlv1 = OSPFNonPseudonode.of(value1);
private final OSPFNonPseudonode sameAsTlv1 = OSPFNonPseudonode.of(value1);
private final OSPFNonPseudonode tlv2 = OSPFNonPseudonode.of(value2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/**
* Test for IsIsNonPseudonode Tlv.
*/
public static class IsIsNonPseudonodeTest {
private final byte[] value1 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58};
private final byte[] value2 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x59};
private final IsIsNonPseudonode tlv1 = IsIsNonPseudonode.of(value1);
private final IsIsNonPseudonode sameAsTlv1 = IsIsNonPseudonode.of(value1);
private final IsIsNonPseudonode tlv2 = IsIsNonPseudonode.of(value2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
}
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.bgpio.types;
import org.junit.Test;
import com.google.common.testing.EqualsTester;
/**
* Test for IsIsNonPseudonode Tlv.
*/
public class IsIsNonPseudonodeTest {
private final byte[] value1 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58};
private final byte[] value2 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x59};
private final IsIsNonPseudonode tlv1 = IsIsNonPseudonode.of(value1);
private final IsIsNonPseudonode sameAsTlv1 = IsIsNonPseudonode.of(value1);
private final IsIsNonPseudonode tlv2 = IsIsNonPseudonode.of(value2);
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
......@@ -15,11 +15,6 @@
*/
package org.onosproject.bgpio.types;
import java.util.ArrayList;
import java.util.List;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
import com.google.common.testing.EqualsTester;
......@@ -29,28 +24,13 @@ import com.google.common.testing.EqualsTester;
*/
public class IsIsPseudonodeTest {
private final byte[] value1 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x02};
byte value;
List<Byte> isoNodeID1 = new ArrayList<Byte>();
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
private final byte[] value2 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x03};
List<Byte> isoNodeID2 = new ArrayList<Byte>();
ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer();
private final IsIsPseudonode tlv1 = IsIsPseudonode.of(isoNodeID1, (byte) 1);
private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(isoNodeID1, (byte) 1);
private final IsIsPseudonode tlv2 = IsIsPseudonode.of(isoNodeID2, (byte) 1);
private final IsIsPseudonode tlv1 = IsIsPseudonode.of(value1, (byte) 1);
private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(value1, (byte) 1);
private final IsIsPseudonode tlv2 = IsIsPseudonode.of(value2, (byte) 1);
@Test
public void testEquality() {
buffer.writeBytes(value1);
for (int i = 0; i < 6; i++) {
value = buffer.readByte();
isoNodeID1.add(value);
}
buffer1.writeBytes(value2);
for (int i = 0; i < 6; i++) {
value = buffer1.readByte();
isoNodeID1.add(value);
}
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
......