Committed by
Gerrit Code Review
[ONOS-2613] Unit test the BGP Update message
Change-Id: I8c5705dba44a2870c945d1150f701969ffca3804
Showing
1 changed file
with
35 additions
and
1 deletions
... | @@ -16,6 +16,8 @@ | ... | @@ -16,6 +16,8 @@ |
16 | 16 | ||
17 | package org.onosproject.bgpio.util; | 17 | package org.onosproject.bgpio.util; |
18 | 18 | ||
19 | +import java.net.InetAddress; | ||
20 | +import java.net.UnknownHostException; | ||
19 | import java.util.Arrays; | 21 | import java.util.Arrays; |
20 | 22 | ||
21 | import org.jboss.netty.buffer.ChannelBuffer; | 23 | import org.jboss.netty.buffer.ChannelBuffer; |
... | @@ -23,6 +25,8 @@ import org.jboss.netty.buffer.ChannelBuffers; | ... | @@ -23,6 +25,8 @@ import org.jboss.netty.buffer.ChannelBuffers; |
23 | import org.onlab.packet.IpAddress; | 25 | import org.onlab.packet.IpAddress; |
24 | import org.onlab.packet.IpPrefix; | 26 | import org.onlab.packet.IpPrefix; |
25 | import org.onosproject.bgpio.exceptions.BGPParseException; | 27 | import org.onosproject.bgpio.exceptions.BGPParseException; |
28 | +import org.slf4j.Logger; | ||
29 | +import org.slf4j.LoggerFactory; | ||
26 | 30 | ||
27 | import com.google.common.primitives.Ints; | 31 | import com.google.common.primitives.Ints; |
28 | 32 | ||
... | @@ -30,10 +34,11 @@ import com.google.common.primitives.Ints; | ... | @@ -30,10 +34,11 @@ import com.google.common.primitives.Ints; |
30 | * Provides methods to parse attribute header, validate length and type. | 34 | * Provides methods to parse attribute header, validate length and type. |
31 | */ | 35 | */ |
32 | public class Validation { | 36 | public class Validation { |
37 | + private static final Logger log = LoggerFactory.getLogger(Validation.class); | ||
33 | public static final byte FIRST_BIT = (byte) 0x80; | 38 | public static final byte FIRST_BIT = (byte) 0x80; |
34 | public static final byte SECOND_BIT = 0x40; | 39 | public static final byte SECOND_BIT = 0x40; |
35 | public static final byte THIRD_BIT = 0x20; | 40 | public static final byte THIRD_BIT = 0x20; |
36 | - public static final byte FOURTH_BIT = 0x01; | 41 | + public static final byte FOURTH_BIT = (byte) 0x10; |
37 | public static final byte IPV4_SIZE = 4; | 42 | public static final byte IPV4_SIZE = 4; |
38 | private boolean firstBit; | 43 | private boolean firstBit; |
39 | private boolean secondBit; | 44 | private boolean secondBit; |
... | @@ -42,6 +47,16 @@ public class Validation { | ... | @@ -42,6 +47,16 @@ public class Validation { |
42 | private int len; | 47 | private int len; |
43 | private boolean isShort; | 48 | private boolean isShort; |
44 | 49 | ||
50 | + /** | ||
51 | + * Constructor to initialize parameter. | ||
52 | + * | ||
53 | + * @param firstBit in AttributeFlags | ||
54 | + * @param secondBit in AttributeFlags | ||
55 | + * @param thirdBit in AttributeFlags | ||
56 | + * @param fourthBit in AttributeFlags | ||
57 | + * @param len length | ||
58 | + * @param isShort true if length is read as short otherwise false | ||
59 | + */ | ||
45 | Validation(boolean firstBit, boolean secondBit, boolean thirdBit, boolean fourthBit, int len, boolean isShort) { | 60 | Validation(boolean firstBit, boolean secondBit, boolean thirdBit, boolean fourthBit, int len, boolean isShort) { |
46 | this.firstBit = firstBit; | 61 | this.firstBit = firstBit; |
47 | this.secondBit = secondBit; | 62 | this.secondBit = secondBit; |
... | @@ -119,6 +134,25 @@ public class Validation { | ... | @@ -119,6 +134,25 @@ public class Validation { |
119 | } | 134 | } |
120 | 135 | ||
121 | /** | 136 | /** |
137 | + * Convert byte array to InetAddress. | ||
138 | + * | ||
139 | + * @param length of IpAddress | ||
140 | + * @param cb channelBuffer | ||
141 | + * @return InetAddress | ||
142 | + */ | ||
143 | + public static InetAddress toInetAddress(int length, ChannelBuffer cb) { | ||
144 | + byte[] address = new byte[length]; | ||
145 | + cb.readBytes(address, 0, length); | ||
146 | + InetAddress ipAddress = null; | ||
147 | + try { | ||
148 | + ipAddress = InetAddress.getByAddress(address); | ||
149 | + } catch (UnknownHostException e) { | ||
150 | + log.info("InetAddress convertion failed"); | ||
151 | + } | ||
152 | + return ipAddress; | ||
153 | + } | ||
154 | + | ||
155 | + /** | ||
122 | * Returns first bit in type flags. | 156 | * Returns first bit in type flags. |
123 | * | 157 | * |
124 | * @return first bit in type flags | 158 | * @return first bit in type flags | ... | ... |
-
Please register or login to post a comment