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; ...@@ -28,7 +28,7 @@ import com.google.common.base.MoreObjects;
28 * Provides Implementation of IsIsNonPseudonode Tlv. 28 * Provides Implementation of IsIsNonPseudonode Tlv.
29 */ 29 */
30 public class IsIsNonPseudonode implements IGPRouterID, BGPValueType { 30 public class IsIsNonPseudonode implements IGPRouterID, BGPValueType {
31 - protected static final Logger log = LoggerFactory.getLogger(IsIsNonPseudonode.class); 31 + private static final Logger log = LoggerFactory.getLogger(IsIsNonPseudonode.class);
32 32
33 public static final short TYPE = 515; 33 public static final short TYPE = 515;
34 public static final short LENGTH = 6; 34 public static final short LENGTH = 6;
...@@ -41,7 +41,7 @@ public class IsIsNonPseudonode implements IGPRouterID, BGPValueType { ...@@ -41,7 +41,7 @@ public class IsIsNonPseudonode implements IGPRouterID, BGPValueType {
41 * @param isoNodeID ISO system-ID 41 * @param isoNodeID ISO system-ID
42 */ 42 */
43 public IsIsNonPseudonode(byte[] isoNodeID) { 43 public IsIsNonPseudonode(byte[] isoNodeID) {
44 - this.isoNodeID = isoNodeID; 44 + this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length);
45 } 45 }
46 46
47 /** 47 /**
...@@ -97,7 +97,7 @@ public class IsIsNonPseudonode implements IGPRouterID, BGPValueType { ...@@ -97,7 +97,7 @@ public class IsIsNonPseudonode implements IGPRouterID, BGPValueType {
97 */ 97 */
98 public static IsIsNonPseudonode read(ChannelBuffer cb) { 98 public static IsIsNonPseudonode read(ChannelBuffer cb) {
99 byte[] isoNodeID = new byte[LENGTH]; 99 byte[] isoNodeID = new byte[LENGTH];
100 - cb.readBytes(isoNodeID, 0, LENGTH); 100 + cb.readBytes(isoNodeID);
101 return IsIsNonPseudonode.of(isoNodeID); 101 return IsIsNonPseudonode.of(isoNodeID);
102 } 102 }
103 103
......
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
15 */ 15 */
16 package org.onosproject.bgpio.types; 16 package org.onosproject.bgpio.types;
17 17
18 -import java.util.ArrayList; 18 +import java.util.Arrays;
19 -import java.util.Iterator;
20 -import java.util.List;
21 import java.util.Objects; 19 import java.util.Objects;
22 20
23 import org.jboss.netty.buffer.ChannelBuffer; 21 import org.jboss.netty.buffer.ChannelBuffer;
...@@ -36,7 +34,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { ...@@ -36,7 +34,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
36 public static final short TYPE = 515; 34 public static final short TYPE = 515;
37 public static final short LENGTH = 7; 35 public static final short LENGTH = 7;
38 36
39 - private final List<Byte> isoNodeID; 37 + private final byte[] isoNodeID;
40 private byte psnIdentifier; 38 private byte psnIdentifier;
41 39
42 /** 40 /**
...@@ -45,8 +43,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { ...@@ -45,8 +43,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
45 * @param isoNodeID ISO system-ID 43 * @param isoNodeID ISO system-ID
46 * @param psnIdentifier PSN identifier 44 * @param psnIdentifier PSN identifier
47 */ 45 */
48 - public IsIsPseudonode(List<Byte> isoNodeID, byte psnIdentifier) { 46 + public IsIsPseudonode(byte[] isoNodeID, byte psnIdentifier) {
49 - this.isoNodeID = isoNodeID; 47 + this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length);
50 this.psnIdentifier = psnIdentifier; 48 this.psnIdentifier = psnIdentifier;
51 } 49 }
52 50
...@@ -57,7 +55,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { ...@@ -57,7 +55,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
57 * @param psnIdentifier PSN identifier 55 * @param psnIdentifier PSN identifier
58 * @return object of IsIsPseudonode 56 * @return object of IsIsPseudonode
59 */ 57 */
60 - public static IsIsPseudonode of(final List<Byte> isoNodeID, 58 + public static IsIsPseudonode of(final byte[] isoNodeID,
61 final byte psnIdentifier) { 59 final byte psnIdentifier) {
62 return new IsIsPseudonode(isoNodeID, psnIdentifier); 60 return new IsIsPseudonode(isoNodeID, psnIdentifier);
63 } 61 }
...@@ -67,7 +65,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { ...@@ -67,7 +65,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
67 * 65 *
68 * @return ISO NodeID 66 * @return ISO NodeID
69 */ 67 */
70 - public List<Byte> getISONodeID() { 68 + public byte[] getISONodeID() {
71 return isoNodeID; 69 return isoNodeID;
72 } 70 }
73 71
...@@ -82,7 +80,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { ...@@ -82,7 +80,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
82 80
83 @Override 81 @Override
84 public int hashCode() { 82 public int hashCode() {
85 - return Objects.hash(isoNodeID) & Objects.hash(psnIdentifier); 83 + return Arrays.hashCode(isoNodeID) & Objects.hash(psnIdentifier);
86 } 84 }
87 85
88 @Override 86 @Override
...@@ -91,27 +89,9 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { ...@@ -91,27 +89,9 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
91 return true; 89 return true;
92 } 90 }
93 if (obj instanceof IsIsPseudonode) { 91 if (obj instanceof IsIsPseudonode) {
94 - int countObjSubTlv = 0;
95 - int countOtherSubTlv = 0;
96 - boolean isCommonSubTlv = true;
97 IsIsPseudonode other = (IsIsPseudonode) obj; 92 IsIsPseudonode other = (IsIsPseudonode) obj;
98 - Iterator<Byte> objListIterator = other.isoNodeID.iterator(); 93 + return Arrays.equals(isoNodeID, other.isoNodeID)
99 - countOtherSubTlv = other.isoNodeID.size(); 94 + && Objects.equals(psnIdentifier, other.psnIdentifier);
100 - countObjSubTlv = isoNodeID.size();
101 - if (countObjSubTlv != countOtherSubTlv) {
102 - return false;
103 - } else {
104 - while (objListIterator.hasNext() && isCommonSubTlv) {
105 - Byte subTlv = objListIterator.next();
106 - if (isoNodeID.contains(subTlv) && other.isoNodeID.contains(subTlv)) {
107 - isCommonSubTlv = Objects.equals(isoNodeID.get(isoNodeID.indexOf(subTlv)),
108 - other.isoNodeID.get(other.isoNodeID.indexOf(subTlv)));
109 - } else {
110 - isCommonSubTlv = false;
111 - }
112 - }
113 - return isCommonSubTlv && Objects.equals(psnIdentifier, other.psnIdentifier);
114 - }
115 } 95 }
116 return false; 96 return false;
117 } 97 }
...@@ -121,11 +101,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { ...@@ -121,11 +101,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
121 int iLenStartIndex = c.writerIndex(); 101 int iLenStartIndex = c.writerIndex();
122 c.writeShort(TYPE); 102 c.writeShort(TYPE);
123 c.writeShort(LENGTH); 103 c.writeShort(LENGTH);
124 - Iterator<Byte> objListIterator = isoNodeID.iterator(); 104 + c.writeBytes(isoNodeID, 0, LENGTH - 1);
125 - while (objListIterator.hasNext()) {
126 - byte value = objListIterator.next();
127 - c.writeByte(value);
128 - }
129 c.writeByte(psnIdentifier); 105 c.writeByte(psnIdentifier);
130 return c.writerIndex() - iLenStartIndex; 106 return c.writerIndex() - iLenStartIndex;
131 } 107 }
...@@ -137,12 +113,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { ...@@ -137,12 +113,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
137 * @return object of IsIsPseudonode 113 * @return object of IsIsPseudonode
138 */ 114 */
139 public static IsIsPseudonode read(ChannelBuffer cb) { 115 public static IsIsPseudonode read(ChannelBuffer cb) {
140 - List<Byte> isoNodeID = new ArrayList<Byte>(); 116 + byte[] isoNodeID = new byte[LENGTH - 1];
141 - byte value; 117 + cb.readBytes(isoNodeID);
142 - for (int i = 0; i < LENGTH; i++) {
143 - value = cb.readByte();
144 - isoNodeID.add(value);
145 - }
146 byte psnIdentifier = cb.readByte(); 118 byte psnIdentifier = cb.readByte();
147 return IsIsPseudonode.of(isoNodeID, psnIdentifier); 119 return IsIsPseudonode.of(isoNodeID, psnIdentifier);
148 } 120 }
......
...@@ -36,42 +36,4 @@ public class AreaIdTest { ...@@ -36,42 +36,4 @@ public class AreaIdTest {
36 .addEqualityGroup(tlv2) 36 .addEqualityGroup(tlv2)
37 .testEquals(); 37 .testEquals();
38 } 38 }
39 -
40 - /**
41 - * Test for OSPFNonPseudonode Tlv.
42 - */
43 - public static class OspfNonPseudonodeTest {
44 - private final int value1 = 0x12121212;
45 - private final int value2 = 0x12121211;
46 - private final OSPFNonPseudonode tlv1 = OSPFNonPseudonode.of(value1);
47 - private final OSPFNonPseudonode sameAsTlv1 = OSPFNonPseudonode.of(value1);
48 - private final OSPFNonPseudonode tlv2 = OSPFNonPseudonode.of(value2);
49 -
50 - @Test
51 - public void basics() {
52 - new EqualsTester()
53 - .addEqualityGroup(tlv1, sameAsTlv1)
54 - .addEqualityGroup(tlv2)
55 - .testEquals();
56 - }
57 - }
58 -
59 - /**
60 - * Test for IsIsNonPseudonode Tlv.
61 - */
62 - public static class IsIsNonPseudonodeTest {
63 - private final byte[] value1 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58};
64 - private final byte[] value2 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x59};
65 - private final IsIsNonPseudonode tlv1 = IsIsNonPseudonode.of(value1);
66 - private final IsIsNonPseudonode sameAsTlv1 = IsIsNonPseudonode.of(value1);
67 - private final IsIsNonPseudonode tlv2 = IsIsNonPseudonode.of(value2);
68 -
69 - @Test
70 - public void basics() {
71 - new EqualsTester()
72 - .addEqualityGroup(tlv1, sameAsTlv1)
73 - .addEqualityGroup(tlv2)
74 - .testEquals();
75 - }
76 - }
77 } 39 }
......
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 +
18 +import org.junit.Test;
19 +
20 +import com.google.common.testing.EqualsTester;
21 +
22 +/**
23 + * Test for IsIsNonPseudonode Tlv.
24 + */
25 +public class IsIsNonPseudonodeTest {
26 + private final byte[] value1 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58};
27 + private final byte[] value2 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x59};
28 + private final IsIsNonPseudonode tlv1 = IsIsNonPseudonode.of(value1);
29 + private final IsIsNonPseudonode sameAsTlv1 = IsIsNonPseudonode.of(value1);
30 + private final IsIsNonPseudonode tlv2 = IsIsNonPseudonode.of(value2);
31 +
32 + @Test
33 + public void testEquality() {
34 + new EqualsTester()
35 + .addEqualityGroup(tlv1, sameAsTlv1)
36 + .addEqualityGroup(tlv2)
37 + .testEquals();
38 + }
39 +}
...@@ -15,11 +15,6 @@ ...@@ -15,11 +15,6 @@
15 */ 15 */
16 package org.onosproject.bgpio.types; 16 package org.onosproject.bgpio.types;
17 17
18 -import java.util.ArrayList;
19 -import java.util.List;
20 -
21 -import org.jboss.netty.buffer.ChannelBuffer;
22 -import org.jboss.netty.buffer.ChannelBuffers;
23 import org.junit.Test; 18 import org.junit.Test;
24 19
25 import com.google.common.testing.EqualsTester; 20 import com.google.common.testing.EqualsTester;
...@@ -29,28 +24,13 @@ import com.google.common.testing.EqualsTester; ...@@ -29,28 +24,13 @@ import com.google.common.testing.EqualsTester;
29 */ 24 */
30 public class IsIsPseudonodeTest { 25 public class IsIsPseudonodeTest {
31 private final byte[] value1 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x02}; 26 private final byte[] value1 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x02};
32 - byte value;
33 - List<Byte> isoNodeID1 = new ArrayList<Byte>();
34 - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
35 private final byte[] value2 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x03}; 27 private final byte[] value2 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x03};
36 - List<Byte> isoNodeID2 = new ArrayList<Byte>(); 28 + private final IsIsPseudonode tlv1 = IsIsPseudonode.of(value1, (byte) 1);
37 - ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer(); 29 + private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(value1, (byte) 1);
38 - private final IsIsPseudonode tlv1 = IsIsPseudonode.of(isoNodeID1, (byte) 1); 30 + private final IsIsPseudonode tlv2 = IsIsPseudonode.of(value2, (byte) 1);
39 - private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(isoNodeID1, (byte) 1);
40 - private final IsIsPseudonode tlv2 = IsIsPseudonode.of(isoNodeID2, (byte) 1);
41 31
42 @Test 32 @Test
43 public void testEquality() { 33 public void testEquality() {
44 - buffer.writeBytes(value1);
45 - for (int i = 0; i < 6; i++) {
46 - value = buffer.readByte();
47 - isoNodeID1.add(value);
48 - }
49 - buffer1.writeBytes(value2);
50 - for (int i = 0; i < 6; i++) {
51 - value = buffer1.readByte();
52 - isoNodeID1.add(value);
53 - }
54 new EqualsTester() 34 new EqualsTester()
55 .addEqualityGroup(tlv1, sameAsTlv1) 35 .addEqualityGroup(tlv1, sameAsTlv1)
56 .addEqualityGroup(tlv2) 36 .addEqualityGroup(tlv2)
......