blob: 0716b502f8375da55664307dd753a1998a8ebf90 [file] [log] [blame]
Yotam Harcholf3f11152013-09-05 16:47:16 -07001package org.projectfloodlight.openflow.types;
2
Andreas Wundsam12cea882013-12-15 15:05:50 -08003import static org.hamcrest.CoreMatchers.equalTo;
Yotam Harcholf3f11152013-09-05 16:47:16 -07004import static org.junit.Assert.assertArrayEquals;
5import static org.junit.Assert.assertEquals;
Andreas Wundsamacaf6502013-12-15 15:08:21 -08006import static org.junit.Assert.assertFalse;
7import static org.junit.Assert.assertNotNull;
Andreas Wundsame04c86f2013-11-05 17:13:18 -08008import static org.junit.Assert.assertThat;
Andreas Wundsamacaf6502013-12-15 15:08:21 -08009import static org.junit.Assert.assertTrue;
Yotam Harcholf3f11152013-09-05 16:47:16 -070010import static org.junit.Assert.fail;
11
Ronald Li5d0ca652014-07-05 02:14:11 -070012import java.net.Inet4Address;
13import java.net.InetAddress;
14
Andreas Wundsame04c86f2013-11-05 17:13:18 -080015import org.hamcrest.CoreMatchers;
Yotam Harcholf3f11152013-09-05 16:47:16 -070016import org.jboss.netty.buffer.ChannelBuffers;
17import org.junit.Test;
18import org.projectfloodlight.openflow.exceptions.OFParseError;
19
Yotam Harchola289d552013-09-16 10:10:40 -070020public class IPv4AddressTest {
Yotam Harcholf3f11152013-09-05 16:47:16 -070021 byte[][] testAddresses = new byte[][] {
22 {0x01, 0x02, 0x03, 0x04 },
23 {127, 0, 0, 1},
24 {(byte) 192, (byte) 168, 0, 100 },
25 {(byte) 255, (byte) 255, (byte) 255, (byte) 255 }
26 };
27
28 String[] testStrings = {
29 "1.2.3.4",
30 "127.0.0.1",
31 "192.168.0.100",
32 "255.255.255.255"
33 };
34
35 int[] testInts = {
36 0x01020304,
37 0x7f000001,
38 (192 << 24) | (168 << 16) | 100,
39 0xffffffff
40 };
41
42 String[] invalidIPs = {
43 "",
44 ".",
45 "1.2..3.4",
46 "1.2.3.4.",
47 "257.11.225.1",
Gregor Maier7f987e62013-12-10 19:34:18 -080048 "256.11.225.1",
Yotam Harcholf3f11152013-09-05 16:47:16 -070049 "-1.2.3.4",
50 "1.2.3.4.5",
51 "1.x.3.4",
52 "1.2x.3.4"
53 };
54
55 String[] ipsWithMask = {
56 "1.2.3.4/24",
57 "192.168.130.140/255.255.192.0",
58 "127.0.0.1/8",
59 "8.8.8.8",
Gregor Maier7f987e62013-12-10 19:34:18 -080060 "8.8.8.8/32",
61 "0.0.0.0/0",
62 "192.168.130.140/255.0.255.0",
63 "1.2.3.4/0.127.0.255"
Yotam Harcholf3f11152013-09-05 16:47:16 -070064 };
65
66 boolean[] hasMask = {
67 true,
68 true,
69 true,
Andreas Wundsame04c86f2013-11-05 17:13:18 -080070 false,
Gregor Maier7f987e62013-12-10 19:34:18 -080071 false,
72 true,
73 true,
Andreas Wundsame04c86f2013-11-05 17:13:18 -080074 true
Yotam Harcholf3f11152013-09-05 16:47:16 -070075 };
76
77 byte[][][] ipsWithMaskValues = {
78 new byte[][] { new byte[] { (byte)0x01, (byte)0x02, (byte)0x03, (byte)0x04 }, new byte[] { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00 } },
79 new byte[][] { new byte[] { (byte)0xC0, (byte)0xA8, (byte)0x82, (byte)0x8C }, new byte[] { (byte)0xFF, (byte)0xFF, (byte)0xC0, (byte)0x00 } },
80 new byte[][] { new byte[] { (byte)0x7F, (byte)0x00, (byte)0x00, (byte)0x01 }, new byte[] { (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00 } },
Gregor Maier7f987e62013-12-10 19:34:18 -080081 new byte[][] { new byte[] { (byte)0x08, (byte)0x08, (byte)0x08, (byte)0x08 }, new byte[] { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF } },
82 new byte[][] { new byte[] { (byte)0x08, (byte)0x08, (byte)0x08, (byte)0x08 }, new byte[] { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF } },
83 new byte[][] { new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 } },
84 new byte[][] { new byte[] { (byte)0xC0, (byte)0xA8, (byte)0x82, (byte)0x8C }, new byte[] { (byte)0xFF, (byte)0x00, (byte)0xFF, (byte)0x00 } },
85 new byte[][] { new byte[] { (byte)0x01, (byte)0x02, (byte)0x03, (byte)0x04 }, new byte[] { (byte)0x00, (byte)0x7F, (byte)0x00, (byte)0xFF } }
86 };
87
88 int[] ipsWithMaskLengths = {
89 24,
90 18,
91 8,
92 32,
93 32,
94 0,
95 -1,
96 -1
97 };
98
99 String[] invalidIpsWithMask = {
100 "asdf",
101 "1.2.3.4/33",
102 "1.2.3.4/34",
103 "1.2.3.4/-1",
104 "1.2.3.4/256.0.0.0",
105 "1.256.3.4/255.255.0.0",
106 "1.2.3.4/255.255.0.0.0",
Yotam Harcholf3f11152013-09-05 16:47:16 -0700107 };
108
Andreas Wundsam12cea882013-12-15 15:05:50 -0800109 @Test
Aditya Vaja56b8b182014-03-11 13:13:58 -0700110 public void testLogicalOperatorsBroadcast() {
111 assertTrue(IPv4Address.NO_MASK.not().equals(IPv4Address.FULL_MASK));
112 assertTrue(IPv4Address.NO_MASK.or(IPv4Address.FULL_MASK).
113 equals(IPv4Address.NO_MASK));
114 assertTrue(IPv4Address.NO_MASK.and(IPv4Address.FULL_MASK).
115 equals(IPv4Address.FULL_MASK));
116
117 assertTrue(IPv4Address.NO_MASK.isBroadcast());
118 assertTrue(!IPv4Address.FULL_MASK.isBroadcast());
119 }
120
121 @Test
122 public void testMaskedSubnetBroadcast() {
123 assertTrue(IPv4AddressWithMask.of("10.10.10.1/24")
124 .getSubnetBroadcastAddress()
125 .equals(IPv4Address.of("10.10.10.255")));
126 assertTrue(IPv4AddressWithMask.of("10.10.10.1/24")
127 .isSubnetBroadcastAddress(IPv4Address.of("10.10.10.255")));
128 assertTrue(!IPv4AddressWithMask.of("10.10.10.1/24")
129 .isSubnetBroadcastAddress(IPv4Address.of("10.10.10.254")));
130 }
131
132 @Test
Andreas Wundsam12cea882013-12-15 15:05:50 -0800133 public void testMaskedMatchesCidr() {
134 IPv4AddressWithMask slash28 = IPv4AddressWithMask.of("10.0.42.16/28");
135
136 String[] notContained = {"0.0.0.0", "11.0.42.16", "10.0.41.1", "10.0.42.0", "10.0.42.15",
137 "10.0.42.32", "255.255.255.255" };
138
139 for(String n: notContained) {
140 assertThat(String.format("slash 28 %s should not contain address %s",
141 slash28, n),
142 slash28.matches(IPv4Address.of(n)), equalTo(false));
143 }
144 for(int i=16; i < 32; i++) {
145 IPv4Address c = IPv4Address.of(String.format("10.0.42.%d", i));
146 assertThat(String.format("slash 28 %s should contain address %s",
147 slash28, c),
148 slash28.matches(c), equalTo(true));
149 }
150 }
151
152 @Test
153 public void testMaskedMatchesArbitrary() {
154 // irregular octect on the 3rd bitmask requires '1'bit to be set
155 // 4 bit unset, all others arbitrary
156 IPv4AddressWithMask slash28 = IPv4AddressWithMask.of("1.2.1.4/255.255.5.255");
157
158 String[] notContained = {"0.0.0.0", "1.2.3.5", "1.2.3.3",
159 "1.2.0.4", "1.2.2.4", "1.2.4.4", "1.2.5.4", "1.2.6.4", "1.2.7.4",
160 "1.2.8.4", "1.2.12.4", "1.2.13.4"
161 };
162 String[] contained = {"1.2.1.4", "1.2.3.4", "1.2.9.4", "1.2.11.4", "1.2.251.4",
163 };
164
165 for(String n: notContained) {
166 assertThat(String.format("slash 28 %s should not contain address %s",
167 slash28, n),
168 slash28.matches(IPv4Address.of(n)), equalTo(false));
169 }
170 for(String c: contained) {
171 IPv4Address addr = IPv4Address.of(c);
172 assertThat(String.format("slash 28 %s should contain address %s",
173 slash28, addr),
174 slash28.matches(addr), equalTo(true));
175 }
176
177 }
178
Yotam Harcholf3f11152013-09-05 16:47:16 -0700179
180 @Test
Gregor Maier5615b6c2013-12-11 22:29:07 -0800181 public void testConstants() {
182 byte[] zeros = { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 };
183 byte[] ones = { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF };
184 // Make sure class initializtation and static assignment don't get
185 // messed up. Test everything twice for cached values
186 assertTrue(IPv4Address.NONE.isCidrMask());
187 assertEquals(0, IPv4Address.NONE.asCidrMaskLength());
188 assertArrayEquals(zeros, IPv4Address.NONE.getBytes());
189 assertTrue(IPv4Address.NONE.isCidrMask());
190 assertEquals(0, IPv4Address.NONE.asCidrMaskLength());
191 assertArrayEquals(zeros, IPv4Address.NONE.getBytes());
192
193 assertTrue(IPv4Address.NO_MASK.isCidrMask());
194 assertEquals(32, IPv4Address.NO_MASK.asCidrMaskLength());
195 assertArrayEquals(ones, IPv4Address.NO_MASK.getBytes());
196 assertTrue(IPv4Address.NO_MASK.isCidrMask());
197 assertEquals(32, IPv4Address.NO_MASK.asCidrMaskLength());
198 assertArrayEquals(ones, IPv4Address.NO_MASK.getBytes());
199
200 assertTrue(IPv4Address.FULL_MASK.isCidrMask());
201 assertEquals(0, IPv4Address.FULL_MASK.asCidrMaskLength());
202 assertArrayEquals(zeros, IPv4Address.FULL_MASK.getBytes());
203 assertTrue(IPv4Address.FULL_MASK.isCidrMask());
204 assertEquals(0, IPv4Address.FULL_MASK.asCidrMaskLength());
205 assertArrayEquals(zeros, IPv4Address.FULL_MASK.getBytes());
206 }
207
208
209 @Test
Yotam Harcholf3f11152013-09-05 16:47:16 -0700210 public void testOfString() {
211 for(int i=0; i < testAddresses.length; i++ ) {
Yotam Harchola289d552013-09-16 10:10:40 -0700212 IPv4Address ip = IPv4Address.of(testStrings[i]);
Yotam Harcholf3f11152013-09-05 16:47:16 -0700213 assertEquals(testInts[i], ip.getInt());
214 assertArrayEquals(testAddresses[i], ip.getBytes());
215 assertEquals(testStrings[i], ip.toString());
216 }
217 }
218
219 @Test
220 public void testOfByteArray() {
221 for(int i=0; i < testAddresses.length; i++ ) {
Yotam Harchola289d552013-09-16 10:10:40 -0700222 IPv4Address ip = IPv4Address.of(testAddresses[i]);
Yotam Harcholf3f11152013-09-05 16:47:16 -0700223 assertEquals(testInts[i], ip.getInt());
224 assertArrayEquals(testAddresses[i], ip.getBytes());
225 assertEquals(testStrings[i], ip.toString());
226 }
227 }
228
229 @Test
Ronald Lia7484222014-07-03 17:14:12 -0700230 public void testOfCidrMaskLength() {
231 for (int i = 0; i <= 32; i++) {
232 assertEquals(IPv4Address.ofCidrMaskLength(i).asCidrMaskLength(), i);
233 }
234
235 assertEquals(IPv4Address.ofCidrMaskLength(0).getInt(), 0x0000_0000);
236
237 assertEquals(IPv4Address.ofCidrMaskLength(1).getInt(), 0x8000_0000);
238 assertEquals(IPv4Address.ofCidrMaskLength(2).getInt(), 0xC000_0000);
239 assertEquals(IPv4Address.ofCidrMaskLength(3).getInt(), 0xE000_0000);
240 assertEquals(IPv4Address.ofCidrMaskLength(4).getInt(), 0xF000_0000);
241 assertEquals(IPv4Address.ofCidrMaskLength(5).getInt(), 0xF800_0000);
242 assertEquals(IPv4Address.ofCidrMaskLength(6).getInt(), 0xFC00_0000);
243 assertEquals(IPv4Address.ofCidrMaskLength(7).getInt(), 0xFE00_0000);
244 assertEquals(IPv4Address.ofCidrMaskLength(8).getInt(), 0xFF00_0000);
245
246 assertEquals(IPv4Address.ofCidrMaskLength(9).getInt(), 0xFF80_0000);
247 assertEquals(IPv4Address.ofCidrMaskLength(10).getInt(), 0xFFC0_0000);
248 assertEquals(IPv4Address.ofCidrMaskLength(11).getInt(), 0xFFE0_0000);
249 assertEquals(IPv4Address.ofCidrMaskLength(12).getInt(), 0xFFF0_0000);
250 assertEquals(IPv4Address.ofCidrMaskLength(13).getInt(), 0xFFF8_0000);
251 assertEquals(IPv4Address.ofCidrMaskLength(14).getInt(), 0xFFFC_0000);
252 assertEquals(IPv4Address.ofCidrMaskLength(15).getInt(), 0xFFFE_0000);
253 assertEquals(IPv4Address.ofCidrMaskLength(16).getInt(), 0xFFFF_0000);
254
255 assertEquals(IPv4Address.ofCidrMaskLength(17).getInt(), 0xFFFF_8000);
256 assertEquals(IPv4Address.ofCidrMaskLength(18).getInt(), 0xFFFF_C000);
257 assertEquals(IPv4Address.ofCidrMaskLength(19).getInt(), 0xFFFF_E000);
258 assertEquals(IPv4Address.ofCidrMaskLength(20).getInt(), 0xFFFF_F000);
259 assertEquals(IPv4Address.ofCidrMaskLength(21).getInt(), 0xFFFF_F800);
260 assertEquals(IPv4Address.ofCidrMaskLength(22).getInt(), 0xFFFF_FC00);
261 assertEquals(IPv4Address.ofCidrMaskLength(23).getInt(), 0xFFFF_FE00);
262 assertEquals(IPv4Address.ofCidrMaskLength(24).getInt(), 0xFFFF_FF00);
263
264 assertEquals(IPv4Address.ofCidrMaskLength(25).getInt(), 0xFFFF_FF80);
265 assertEquals(IPv4Address.ofCidrMaskLength(26).getInt(), 0xFFFF_FFC0);
266 assertEquals(IPv4Address.ofCidrMaskLength(27).getInt(), 0xFFFF_FFE0);
267 assertEquals(IPv4Address.ofCidrMaskLength(28).getInt(), 0xFFFF_FFF0);
268 assertEquals(IPv4Address.ofCidrMaskLength(29).getInt(), 0xFFFF_FFF8);
269 assertEquals(IPv4Address.ofCidrMaskLength(30).getInt(), 0xFFFF_FFFC);
270 assertEquals(IPv4Address.ofCidrMaskLength(31).getInt(), 0xFFFF_FFFE);
271 assertEquals(IPv4Address.ofCidrMaskLength(32).getInt(), 0xFFFF_FFFF);
272 }
273
274 @Test
Ronald Li5d0ca652014-07-05 02:14:11 -0700275 public void testWithMask() throws Exception {
276 // Sanity tests for the withMask*() syntactic sugars
277
278 IPv4Address original = IPv4Address.of("192.168.1.101");
279 IPv4Address expectedValue = IPv4Address.of("192.168.1.0");
280 IPv4Address expectedMask = IPv4Address.of("255.255.255.0");
281
282 IPv4AddressWithMask v;
283
Ronald Libbf01942014-07-07 17:00:13 -0700284 v = original.withMask(IPv4Address.of(new byte[] {-1, -1, -1, 0}));
Ronald Lica08d5f2014-07-05 02:43:18 -0700285 assertEquals(v.getValue(), expectedValue);
286 assertEquals(v.getMask(), expectedMask);
287
Ronald Libbf01942014-07-07 17:00:13 -0700288 v = original.withMask(IPv4Address.of(0xFFFF_FF00));
Ronald Li5d0ca652014-07-05 02:14:11 -0700289 assertEquals(v.getValue(), expectedValue);
290 assertEquals(v.getMask(), expectedMask);
291
Ronald Libbf01942014-07-07 17:00:13 -0700292 v = original.withMask(IPv4Address.of("255.255.255.0"));
Ronald Li5d0ca652014-07-05 02:14:11 -0700293 assertEquals(v.getValue(), expectedValue);
294 assertEquals(v.getMask(), expectedMask);
295
296 Inet4Address i4a = (Inet4Address) InetAddress.getByName("255.255.255.0");
Ronald Libbf01942014-07-07 17:00:13 -0700297 v = original.withMask(IPv4Address.of(i4a));
Ronald Li5d0ca652014-07-05 02:14:11 -0700298 assertEquals(v.getValue(), expectedValue);
299 assertEquals(v.getMask(), expectedMask);
300
301 v = original.withMaskOfLength(24);
302 assertEquals(v.getValue(), expectedValue);
303 assertEquals(v.getMask(), expectedMask);
304 }
305
306 @Test
Yotam Harcholf3f11152013-09-05 16:47:16 -0700307 public void testReadFrom() throws OFParseError {
308 for(int i=0; i < testAddresses.length; i++ ) {
Yotam Harchola289d552013-09-16 10:10:40 -0700309 IPv4Address ip = IPv4Address.read4Bytes(ChannelBuffers.copiedBuffer(testAddresses[i]));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700310 assertEquals(testInts[i], ip.getInt());
311 assertArrayEquals(testAddresses[i], ip.getBytes());
312 assertEquals(testStrings[i], ip.toString());
313 }
314 }
315
316
317 @Test
318 public void testInvalidIPs() throws OFParseError {
319 for(String invalid : invalidIPs) {
320 try {
Yotam Harchola289d552013-09-16 10:10:40 -0700321 IPv4Address.of(invalid);
Yotam Harcholf3f11152013-09-05 16:47:16 -0700322 fail("Invalid IP "+invalid+ " should have raised IllegalArgumentException");
323 } catch(IllegalArgumentException e) {
324 // ok
325 }
326 }
327 }
328
329 @Test
330 public void testOfMasked() throws OFParseError {
331 for (int i = 0; i < ipsWithMask.length; i++) {
Yotam Harchol9a617aa2013-09-16 14:10:17 -0700332 IPv4AddressWithMask value = IPv4AddressWithMask.of(ipsWithMask[i]);
Yotam Harcholf3f11152013-09-05 16:47:16 -0700333 if (!hasMask[i]) {
Yotam Harchola289d552013-09-16 10:10:40 -0700334 IPv4Address ip = value.getValue();
Yotam Harcholf3f11152013-09-05 16:47:16 -0700335 assertArrayEquals(ipsWithMaskValues[i][0], ip.getBytes());
Yotam Harcholf3f11152013-09-05 16:47:16 -0700336 }
Gregor Maier7f987e62013-12-10 19:34:18 -0800337 IPv4Address mask = value.getMask();
Gregor Maier5615b6c2013-12-11 22:29:07 -0800338 if (ipsWithMaskLengths[i] == -1) {
339 assertFalse(mask.isCidrMask());
340 try {
341 mask.asCidrMaskLength();
342 fail("Expected IllegalStateException not thrown");
343 } catch(IllegalStateException e) {
344 //expected
345 }
346 } else {
347 assertTrue(mask.isCidrMask());
348 assertEquals(ipsWithMaskLengths[i], mask.asCidrMaskLength());
349 }
Gregor Maier7f987e62013-12-10 19:34:18 -0800350 assertArrayEquals(ipsWithMaskValues[i][1], mask.getBytes());
351 byte[] ipBytes = new byte[4];
352 System.arraycopy(ipsWithMaskValues[i][0], 0, ipBytes, 0, 4);
353 assertEquals(ipBytes.length, value.getValue().getBytes().length);
354 for (int j = 0; j < ipBytes.length; j++) {
355 ipBytes[j] &= ipsWithMaskValues[i][1][j];
356 }
357
358 assertArrayEquals(ipBytes, value.getValue().getBytes());
359 assertThat(String.format("Byte comparison for mask of %s (%s)", ipsWithMask[i], value),
360 value.getMask().getBytes(), CoreMatchers.equalTo(ipsWithMaskValues[i][1]));
361 }
362 }
363
364 @Test
365 public void testOfMaskedInvalid() throws Exception {
366 for(String invalid : invalidIpsWithMask) {
367 try {
368 IPv4Address.of(invalid);
369 fail("Invalid IP "+invalid+ " should have raised IllegalArgumentException");
370 } catch(IllegalArgumentException e) {
371 // ok
372 }
373 }
374 }
375
376 @Test
377 public void testSuperclass() throws Exception {
378 for(String ipString: testStrings) {
379 IPAddress<?> superIp = IPAddress.of(ipString);
380 assertEquals(IPVersion.IPv4, superIp.getIpVersion());
381 assertEquals(IPv4Address.of(ipString), superIp);
382 }
383
384 for(String ipMaskedString: ipsWithMask) {
385 IPAddressWithMask<?> superIp = IPAddressWithMask.of(ipMaskedString);
386 assertEquals(IPVersion.IPv4, superIp.getIpVersion());
387 assertEquals(IPv4AddressWithMask.of(ipMaskedString), superIp);
Yotam Harcholf3f11152013-09-05 16:47:16 -0700388 }
389 }
Gregor Maier1ff55972013-12-11 02:22:56 -0800390
391 @Test
392 public void testOfExceptions() {
393 // We check if the message of a caught NPE is set to a useful message
394 // as a hacky way of verifying that we got an NPE thrown by use rather
395 // than one the JVM created for a null access.
396 try {
397 String s = null;
398 IPv4Address.of(s);
399 fail("Should have thrown NullPointerException");
400 } catch (NullPointerException e) {
401 assertNotNull(e.getMessage());
402 }
403 try {
404 byte[] b = null;
405 IPv4Address.of(b);
406 fail("Should have thrown NullPointerException");
407 } catch (NullPointerException e) {
408 assertNotNull(e.getMessage());
409 }
410 try {
411 byte[] b = new byte[3];
412 IPv4Address.of(b);
413 fail("Should have thrown IllegalArgumentException");
414 } catch (IllegalArgumentException e) {
415 // expected
416 }
417 try {
418 byte[] b = new byte[5];
419 IPv4Address.of(b);
420 fail("Should have thrown IllegalArgumentException");
421 } catch (IllegalArgumentException e) {
422 // expected
423 }
424 try {
425 IPv4AddressWithMask.of(null);
426 fail("Should have thrown NullPointerException");
427 } catch (NullPointerException e) {
428 assertNotNull(e.getMessage());
429 }
430 try {
431 IPv4AddressWithMask.of(IPv4Address.of("1.2.3.4"), null);
432 fail("Should have thrown NullPointerException");
433 } catch (NullPointerException e) {
434 assertNotNull(e.getMessage());
435 }
436 try {
437 IPv4AddressWithMask.of(null, IPv4Address.of("255.0.0.0"));
438 fail("Should have thrown NullPointerException");
439 } catch (NullPointerException e) {
440 assertNotNull(e.getMessage());
Yotam Harcholf3f11152013-09-05 16:47:16 -0700441 }
Aditya Vajab21043d2014-03-11 13:34:06 -0700442 try {
443 IPv4AddressWithMask.of(IPv4Address.of("10.10.10.0"),
444 IPv4Address.of("255.0.255.0"))
445 .getSubnetBroadcastAddress();
446 fail("Should have thrown IllegalArgumentException");
447 } catch (IllegalArgumentException e) {
448 assertNotNull(e.getMessage());
449 }
Ronald Lia7484222014-07-03 17:14:12 -0700450 try {
451 IPv4Address.ofCidrMaskLength(-1);
452 fail("Should have thrown IllegalArgumentException");
453 } catch (IllegalArgumentException e) {
454 assertNotNull(e.getMessage());
455 }
456 try {
457 IPv4Address.ofCidrMaskLength(33);
458 fail("Should have thrown IllegalArgumentException");
459 } catch (IllegalArgumentException e) {
460 assertNotNull(e.getMessage());
461 }
Yotam Harcholf3f11152013-09-05 16:47:16 -0700462 }
463}