IsIs and Ospf code fix
Change-Id: I4cebdb1af9ba68b673335d86f80a6b7498e0bfd1
diff --git a/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java b/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java
index 73f28bb..8410157 100644
--- a/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java
+++ b/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java
@@ -28,7 +28,7 @@
* 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 @@
* @param isoNodeID ISO system-ID
*/
public IsIsNonPseudonode(byte[] isoNodeID) {
- this.isoNodeID = isoNodeID;
+ this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length);
}
/**
@@ -97,7 +97,7 @@
*/
public static IsIsNonPseudonode read(ChannelBuffer cb) {
byte[] isoNodeID = new byte[LENGTH];
- cb.readBytes(isoNodeID, 0, LENGTH);
+ cb.readBytes(isoNodeID);
return IsIsNonPseudonode.of(isoNodeID);
}
diff --git a/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java b/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
index 35fd249..99d5573 100644
--- a/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
+++ b/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
@@ -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 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 @@
* @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 @@
* @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 @@
*
* @return ISO NodeID
*/
- public List<Byte> getISONodeID() {
+ public byte[] getISONodeID() {
return isoNodeID;
}
@@ -82,7 +80,7 @@
@Override
public int hashCode() {
- return Objects.hash(isoNodeID) & Objects.hash(psnIdentifier);
+ return Arrays.hashCode(isoNodeID) & Objects.hash(psnIdentifier);
}
@Override
@@ -91,27 +89,9 @@
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 @@
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 @@
* @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);
}
diff --git a/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java b/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java
index 6a9e2ec..e11564a 100644
--- a/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java
+++ b/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java
@@ -36,42 +36,4 @@
.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();
- }
- }
}
diff --git a/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsNonPseudonodeTest.java b/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsNonPseudonodeTest.java
new file mode 100644
index 0000000..7ce4d5d
--- /dev/null
+++ b/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsNonPseudonodeTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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();
+ }
+}
diff --git a/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java b/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java
index 00e85dc..a2a7c2b 100644
--- a/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java
+++ b/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java
@@ -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 @@
*/
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)