Committed by
Gerrit Code Review
Using List in IsIsPseudonode
Change-Id: If0a52dcd2c21579d45d97152e05a760390d31c29
Showing
2 changed files
with
64 additions
and
13 deletions
... | @@ -15,6 +15,9 @@ | ... | @@ -15,6 +15,9 @@ |
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.Iterator; | ||
20 | +import java.util.List; | ||
18 | import java.util.Objects; | 21 | import java.util.Objects; |
19 | 22 | ||
20 | import org.jboss.netty.buffer.ChannelBuffer; | 23 | import org.jboss.netty.buffer.ChannelBuffer; |
... | @@ -28,12 +31,12 @@ import com.google.common.base.MoreObjects; | ... | @@ -28,12 +31,12 @@ import com.google.common.base.MoreObjects; |
28 | * Provides implementation of IsIsPseudonode Tlv. | 31 | * Provides implementation of IsIsPseudonode Tlv. |
29 | */ | 32 | */ |
30 | public class IsIsPseudonode implements IGPRouterID, BGPValueType { | 33 | public class IsIsPseudonode implements IGPRouterID, BGPValueType { |
31 | - protected static final Logger log = LoggerFactory.getLogger(IsIsPseudonode.class); | 34 | + private static final Logger log = LoggerFactory.getLogger(IsIsPseudonode.class); |
32 | 35 | ||
33 | public static final short TYPE = 515; | 36 | public static final short TYPE = 515; |
34 | public static final short LENGTH = 7; | 37 | public static final short LENGTH = 7; |
35 | 38 | ||
36 | - private final byte[] isoNodeID; | 39 | + private final List<Byte> isoNodeID; |
37 | private byte psnIdentifier; | 40 | private byte psnIdentifier; |
38 | 41 | ||
39 | /** | 42 | /** |
... | @@ -42,7 +45,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { | ... | @@ -42,7 +45,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { |
42 | * @param isoNodeID ISO system-ID | 45 | * @param isoNodeID ISO system-ID |
43 | * @param psnIdentifier PSN identifier | 46 | * @param psnIdentifier PSN identifier |
44 | */ | 47 | */ |
45 | - public IsIsPseudonode(byte[] isoNodeID, byte psnIdentifier) { | 48 | + public IsIsPseudonode(List<Byte> isoNodeID, byte psnIdentifier) { |
46 | this.isoNodeID = isoNodeID; | 49 | this.isoNodeID = isoNodeID; |
47 | this.psnIdentifier = psnIdentifier; | 50 | this.psnIdentifier = psnIdentifier; |
48 | } | 51 | } |
... | @@ -54,7 +57,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { | ... | @@ -54,7 +57,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { |
54 | * @param psnIdentifier PSN identifier | 57 | * @param psnIdentifier PSN identifier |
55 | * @return object of IsIsPseudonode | 58 | * @return object of IsIsPseudonode |
56 | */ | 59 | */ |
57 | - public static IsIsPseudonode of(final byte[] isoNodeID, final byte psnIdentifier) { | 60 | + public static IsIsPseudonode of(final List<Byte> isoNodeID, |
61 | + final byte psnIdentifier) { | ||
58 | return new IsIsPseudonode(isoNodeID, psnIdentifier); | 62 | return new IsIsPseudonode(isoNodeID, psnIdentifier); |
59 | } | 63 | } |
60 | 64 | ||
... | @@ -63,7 +67,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { | ... | @@ -63,7 +67,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { |
63 | * | 67 | * |
64 | * @return ISO NodeID | 68 | * @return ISO NodeID |
65 | */ | 69 | */ |
66 | - public byte[] getISONodeID() { | 70 | + public List<Byte> getISONodeID() { |
67 | return isoNodeID; | 71 | return isoNodeID; |
68 | } | 72 | } |
69 | 73 | ||
... | @@ -78,7 +82,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { | ... | @@ -78,7 +82,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { |
78 | 82 | ||
79 | @Override | 83 | @Override |
80 | public int hashCode() { | 84 | public int hashCode() { |
81 | - return Objects.hash(isoNodeID, psnIdentifier); | 85 | + return Objects.hash(isoNodeID) & Objects.hash(psnIdentifier); |
82 | } | 86 | } |
83 | 87 | ||
84 | @Override | 88 | @Override |
... | @@ -87,8 +91,27 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { | ... | @@ -87,8 +91,27 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { |
87 | return true; | 91 | return true; |
88 | } | 92 | } |
89 | if (obj instanceof IsIsPseudonode) { | 93 | if (obj instanceof IsIsPseudonode) { |
94 | + int countObjSubTlv = 0; | ||
95 | + int countOtherSubTlv = 0; | ||
96 | + boolean isCommonSubTlv = true; | ||
90 | IsIsPseudonode other = (IsIsPseudonode) obj; | 97 | IsIsPseudonode other = (IsIsPseudonode) obj; |
91 | - return Objects.equals(isoNodeID, other.isoNodeID) && Objects.equals(psnIdentifier, other.psnIdentifier); | 98 | + Iterator<Byte> objListIterator = other.isoNodeID.iterator(); |
99 | + countOtherSubTlv = other.isoNodeID.size(); | ||
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 | + } | ||
92 | } | 115 | } |
93 | return false; | 116 | return false; |
94 | } | 117 | } |
... | @@ -98,7 +121,11 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { | ... | @@ -98,7 +121,11 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { |
98 | int iLenStartIndex = c.writerIndex(); | 121 | int iLenStartIndex = c.writerIndex(); |
99 | c.writeShort(TYPE); | 122 | c.writeShort(TYPE); |
100 | c.writeShort(LENGTH); | 123 | c.writeShort(LENGTH); |
101 | - c.writeBytes(isoNodeID); | 124 | + Iterator<Byte> objListIterator = isoNodeID.iterator(); |
125 | + while (objListIterator.hasNext()) { | ||
126 | + byte value = objListIterator.next(); | ||
127 | + c.writeByte(value); | ||
128 | + } | ||
102 | c.writeByte(psnIdentifier); | 129 | c.writeByte(psnIdentifier); |
103 | return c.writerIndex() - iLenStartIndex; | 130 | return c.writerIndex() - iLenStartIndex; |
104 | } | 131 | } |
... | @@ -110,8 +137,12 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { | ... | @@ -110,8 +137,12 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { |
110 | * @return object of IsIsPseudonode | 137 | * @return object of IsIsPseudonode |
111 | */ | 138 | */ |
112 | public static IsIsPseudonode read(ChannelBuffer cb) { | 139 | public static IsIsPseudonode read(ChannelBuffer cb) { |
113 | - byte[] isoNodeID = new byte[LENGTH - 1]; | 140 | + List<Byte> isoNodeID = new ArrayList<Byte>(); |
114 | - cb.readBytes(isoNodeID, 0, LENGTH - 1); | 141 | + byte value; |
142 | + for (int i = 0; i < LENGTH; i++) { | ||
143 | + value = cb.readByte(); | ||
144 | + isoNodeID.add(value); | ||
145 | + } | ||
115 | byte psnIdentifier = cb.readByte(); | 146 | byte psnIdentifier = cb.readByte(); |
116 | return IsIsPseudonode.of(isoNodeID, psnIdentifier); | 147 | return IsIsPseudonode.of(isoNodeID, psnIdentifier); |
117 | } | 148 | } | ... | ... |
... | @@ -15,6 +15,11 @@ | ... | @@ -15,6 +15,11 @@ |
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; | ||
18 | import org.junit.Test; | 23 | import org.junit.Test; |
19 | 24 | ||
20 | import com.google.common.testing.EqualsTester; | 25 | import com.google.common.testing.EqualsTester; |
... | @@ -24,13 +29,28 @@ import com.google.common.testing.EqualsTester; | ... | @@ -24,13 +29,28 @@ import com.google.common.testing.EqualsTester; |
24 | */ | 29 | */ |
25 | public class IsIsPseudonodeTest { | 30 | public class IsIsPseudonodeTest { |
26 | private final byte[] value1 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x02}; | 31 | 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(); | ||
27 | private final byte[] value2 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x03}; | 35 | private final byte[] value2 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x03}; |
28 | - private final IsIsPseudonode tlv1 = IsIsPseudonode.of(value1, (byte) 1); | 36 | + List<Byte> isoNodeID2 = new ArrayList<Byte>(); |
29 | - private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(value1, (byte) 1); | 37 | + ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer(); |
30 | - private final IsIsPseudonode tlv2 = IsIsPseudonode.of(value2, (byte) 1); | 38 | + private final IsIsPseudonode tlv1 = IsIsPseudonode.of(isoNodeID1, (byte) 1); |
39 | + private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(isoNodeID1, (byte) 1); | ||
40 | + private final IsIsPseudonode tlv2 = IsIsPseudonode.of(isoNodeID2, (byte) 1); | ||
31 | 41 | ||
32 | @Test | 42 | @Test |
33 | public void testEquality() { | 43 | 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 | + } | ||
34 | new EqualsTester() | 54 | new EqualsTester() |
35 | .addEqualityGroup(tlv1, sameAsTlv1) | 55 | .addEqualityGroup(tlv1, sameAsTlv1) |
36 | .addEqualityGroup(tlv2) | 56 | .addEqualityGroup(tlv2) | ... | ... |
-
Please register or login to post a comment