Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.types; |
| 2 | |
Gregor Maier | 5615b6c | 2013-12-11 22:29:07 -0800 | [diff] [blame] | 3 | import static org.junit.Assert.*; |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 4 | |
| 5 | import java.net.Inet6Address; |
| 6 | import java.net.InetAddress; |
| 7 | import java.net.UnknownHostException; |
| 8 | |
Andreas Wundsam | e04c86f | 2013-11-05 17:13:18 -0800 | [diff] [blame] | 9 | import org.hamcrest.CoreMatchers; |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 10 | import org.jboss.netty.buffer.ChannelBuffers; |
| 11 | import org.junit.Test; |
| 12 | import org.projectfloodlight.openflow.exceptions.OFParseError; |
| 13 | |
Andreas Wundsam | e04c86f | 2013-11-05 17:13:18 -0800 | [diff] [blame] | 14 | import com.google.common.io.BaseEncoding; |
| 15 | |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 16 | public class IPv6AddressTest { |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 17 | |
| 18 | String[] testStrings = { |
| 19 | "::", |
| 20 | "::1", |
| 21 | "ffe0::", |
| 22 | "1:2:3:4:5:6:7:8" |
| 23 | }; |
| 24 | |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 25 | |
Andreas Wundsam | e04c86f | 2013-11-05 17:13:18 -0800 | [diff] [blame] | 26 | private final BaseEncoding hex = BaseEncoding.base16().omitPadding().lowerCase(); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 27 | |
Andreas Wundsam | e04c86f | 2013-11-05 17:13:18 -0800 | [diff] [blame] | 28 | private class WithMaskTaskCase { |
| 29 | final String input; |
| 30 | boolean hasMask; |
Gregor Maier | 7f987e6 | 2013-12-10 19:34:18 -0800 | [diff] [blame] | 31 | int expectedMaskLength = 128; |
Andreas Wundsam | e04c86f | 2013-11-05 17:13:18 -0800 | [diff] [blame] | 32 | byte[] expectedMask = hex.decode("ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff".replaceAll(" ", "")); |
| 33 | |
| 34 | public WithMaskTaskCase(String input) { |
| 35 | super(); |
| 36 | this.input = input; |
| 37 | } |
| 38 | |
Andreas Wundsam | e04c86f | 2013-11-05 17:13:18 -0800 | [diff] [blame] | 39 | public WithMaskTaskCase maskHex(String string) { |
| 40 | string = string.replaceAll(" ", ""); |
| 41 | this.hasMask = true; |
| 42 | expectedMask = hex.decode(string); |
| 43 | return this; |
| 44 | } |
| 45 | |
Gregor Maier | 7f987e6 | 2013-12-10 19:34:18 -0800 | [diff] [blame] | 46 | public WithMaskTaskCase expectedMaskLength(int expectedLength) { |
| 47 | this.expectedMaskLength = expectedLength; |
| 48 | return this; |
| 49 | } |
| 50 | |
Andreas Wundsam | e04c86f | 2013-11-05 17:13:18 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | WithMaskTaskCase[] withMasks = new WithMaskTaskCase[] { |
| 54 | new WithMaskTaskCase("1::1/80") |
Gregor Maier | 7f987e6 | 2013-12-10 19:34:18 -0800 | [diff] [blame] | 55 | .maskHex("ff ff ff ff ff ff ff ff ff ff 00 00 00 00 00 00") |
| 56 | .expectedMaskLength(80), |
Andreas Wundsam | e04c86f | 2013-11-05 17:13:18 -0800 | [diff] [blame] | 57 | |
| 58 | new WithMaskTaskCase("ffff:ffee:1::/ff00:ff00:ff00:ff00::") |
Gregor Maier | 7f987e6 | 2013-12-10 19:34:18 -0800 | [diff] [blame] | 59 | .maskHex("ff 00 ff 00 ff 00 ff 00 00 00 00 00 00 00 00 00") |
| 60 | .expectedMaskLength(-1), |
Gregor Maier | cef9e3e | 2013-12-11 22:41:36 -0800 | [diff] [blame] | 61 | new WithMaskTaskCase("1:2:3:4:5:6:7:8/1::ff00:ff00") |
| 62 | .maskHex("00 01 00 00 00 00 00 00 00 00 00 00 ff 00 ff 00") |
| 63 | .expectedMaskLength(-1), |
| 64 | new WithMaskTaskCase("1:2:3:4:5:6:7:8/::ff00:ff00") |
| 65 | .maskHex("00 00 00 00 00 00 00 00 00 00 00 00 ff 00 ff 00") |
| 66 | .expectedMaskLength(-1), |
| 67 | new WithMaskTaskCase("1:2:3:4:5:6:7:8/ffff:ffff:ffff:ffff:ffff::ff00:ff00") |
| 68 | .maskHex("ff ff ff ff ff ff ff ff ff ff 00 00 ff 00 ff 00") |
| 69 | .expectedMaskLength(-1), |
Andreas Wundsam | e04c86f | 2013-11-05 17:13:18 -0800 | [diff] [blame] | 70 | new WithMaskTaskCase("8:8:8:8:8:8:8:8"), |
| 71 | new WithMaskTaskCase("8:8:8:8:8:8:8:8"), |
| 72 | new WithMaskTaskCase("1:2:3:4:5:6:7:8/128"), |
| 73 | new WithMaskTaskCase("::/0") |
| 74 | .maskHex("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00") |
Gregor Maier | 7f987e6 | 2013-12-10 19:34:18 -0800 | [diff] [blame] | 75 | .expectedMaskLength(0), |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | @Test |
Aditya Vaja | 56b8b18 | 2014-03-11 13:13:58 -0700 | [diff] [blame] | 79 | public void testLogicalOperatorsBroadcast() { |
| 80 | assertTrue(IPv6Address.NO_MASK.not().equals(IPv6Address.FULL_MASK)); |
| 81 | assertTrue(IPv6Address.NO_MASK.or(IPv6Address.FULL_MASK). |
| 82 | equals(IPv6Address.NO_MASK)); |
| 83 | assertTrue(IPv6Address.NO_MASK.and(IPv6Address.FULL_MASK). |
| 84 | equals(IPv6Address.FULL_MASK)); |
| 85 | |
| 86 | assertTrue(IPv6Address.NO_MASK.isBroadcast()); |
| 87 | assertTrue(!IPv6Address.FULL_MASK.isBroadcast()); |
| 88 | } |
| 89 | |
| 90 | @Test |
| 91 | public void testMaskedSubnetBroadcast() { |
| 92 | assertTrue(IPv6AddressWithMask.of("10:10::1/112") |
| 93 | .getSubnetBroadcastAddress() |
| 94 | .equals(IPv6Address.of("10:10::ffff"))); |
| 95 | assertTrue(IPv6AddressWithMask.of("10:10::1/112") |
| 96 | .isSubnetBroadcastAddress(IPv6Address.of("10:10::ffff"))); |
| 97 | assertTrue(!IPv6AddressWithMask.of("10:10::1/112") |
| 98 | .isSubnetBroadcastAddress(IPv6Address.of("10:10::fffd"))); |
| 99 | } |
| 100 | |
| 101 | @Test |
Gregor Maier | 5615b6c | 2013-12-11 22:29:07 -0800 | [diff] [blame] | 102 | public void testConstants() { |
| 103 | byte[] zeros = { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, |
| 104 | (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, |
| 105 | (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, |
| 106 | (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }; |
| 107 | byte[] ones = { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, |
| 108 | (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, |
| 109 | (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, |
| 110 | (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF }; |
| 111 | // Make sure class initializtation and static assignment don't get |
| 112 | // messed up. Test everything twice for cached values |
| 113 | assertTrue(IPv6Address.NONE.isCidrMask()); |
| 114 | assertEquals(0, IPv6Address.NONE.asCidrMaskLength()); |
| 115 | assertArrayEquals(zeros, IPv6Address.NONE.getBytes()); |
| 116 | assertTrue(IPv6Address.NONE.isCidrMask()); |
| 117 | assertEquals(0, IPv6Address.NONE.asCidrMaskLength()); |
| 118 | assertArrayEquals(zeros, IPv6Address.NONE.getBytes()); |
| 119 | |
| 120 | assertTrue(IPv6Address.NO_MASK.isCidrMask()); |
| 121 | assertEquals(128, IPv6Address.NO_MASK.asCidrMaskLength()); |
| 122 | assertArrayEquals(ones, IPv6Address.NO_MASK.getBytes()); |
| 123 | assertTrue(IPv6Address.NO_MASK.isCidrMask()); |
| 124 | assertEquals(128, IPv6Address.NO_MASK.asCidrMaskLength()); |
| 125 | assertArrayEquals(ones, IPv6Address.NO_MASK.getBytes()); |
| 126 | |
| 127 | assertTrue(IPv6Address.FULL_MASK.isCidrMask()); |
| 128 | assertEquals(0, IPv6Address.FULL_MASK.asCidrMaskLength()); |
| 129 | assertArrayEquals(zeros, IPv6Address.FULL_MASK.getBytes()); |
| 130 | assertTrue(IPv6Address.FULL_MASK.isCidrMask()); |
| 131 | assertEquals(0, IPv6Address.FULL_MASK.asCidrMaskLength()); |
| 132 | assertArrayEquals(zeros, IPv6Address.FULL_MASK.getBytes()); |
| 133 | } |
| 134 | |
| 135 | @Test |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 136 | public void testMasked() throws UnknownHostException { |
Andreas Wundsam | e04c86f | 2013-11-05 17:13:18 -0800 | [diff] [blame] | 137 | for(WithMaskTaskCase w: withMasks) { |
| 138 | IPv6AddressWithMask value = IPv6AddressWithMask.of(w.input); |
| 139 | if (!w.hasMask) { |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 140 | IPv6Address ip = value.getValue(); |
Andreas Wundsam | e04c86f | 2013-11-05 17:13:18 -0800 | [diff] [blame] | 141 | InetAddress inetAddress = InetAddress.getByName(w.input.split("/")[0]); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 142 | |
| 143 | assertArrayEquals(ip.getBytes(), inetAddress.getAddress()); |
Andreas Wundsam | e04c86f | 2013-11-05 17:13:18 -0800 | [diff] [blame] | 144 | assertEquals(w.input.split("/")[0], ip.toString()); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 145 | } |
Gregor Maier | 7f987e6 | 2013-12-10 19:34:18 -0800 | [diff] [blame] | 146 | InetAddress inetAddress = InetAddress.getByName(w.input.split("/")[0]); |
| 147 | |
Gregor Maier | 5615b6c | 2013-12-11 22:29:07 -0800 | [diff] [blame] | 148 | if (w.expectedMaskLength == -1) { |
| 149 | assertFalse(value.getMask().isCidrMask()); |
| 150 | try { |
| 151 | value.getMask().asCidrMaskLength(); |
| 152 | fail("Expected IllegalStateException not thrown"); |
| 153 | } catch(IllegalStateException e) { |
| 154 | //expected |
| 155 | } |
| 156 | } else { |
| 157 | assertTrue(value.getMask().isCidrMask()); |
| 158 | assertEquals("Input " + w.input, w.expectedMaskLength, |
| 159 | value.getMask().asCidrMaskLength()); |
| 160 | } |
Gregor Maier | 7f987e6 | 2013-12-10 19:34:18 -0800 | [diff] [blame] | 161 | |
| 162 | byte[] address = inetAddress.getAddress(); |
| 163 | assertEquals(address.length, value.getValue().getBytes().length); |
| 164 | |
| 165 | for (int j = 0; j < address.length; j++) { |
| 166 | address[j] &= w.expectedMask[j]; |
| 167 | } |
| 168 | |
| 169 | assertThat("Address bytes for input " + w.input + ", value=" + value, value.getValue().getBytes(), CoreMatchers.equalTo(address)); |
| 170 | assertThat("mask check for input " + w.input + ", value=" + value, value.getMask().getBytes(), CoreMatchers.equalTo(w.expectedMask)); |
| 171 | } |
| 172 | for (int i = 0; i <= 128; i++) { |
| 173 | String ipString = String.format("8001:2::1/%d", i); |
| 174 | IPv6AddressWithMask value = IPv6AddressWithMask.of(ipString); |
| 175 | assertEquals("Input " + ipString, i, value.getMask().asCidrMaskLength()); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | |
| 180 | @Test |
| 181 | public void testOfString() throws UnknownHostException { |
| 182 | for(int i=0; i < testStrings.length; i++ ) { |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 183 | IPv6Address ip = IPv6Address.of(testStrings[i]); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 184 | InetAddress inetAddress = InetAddress.getByName(testStrings[i]); |
| 185 | |
| 186 | assertArrayEquals(ip.getBytes(), inetAddress.getAddress()); |
| 187 | assertEquals(testStrings[i], ip.toString()); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | @Test |
| 192 | public void testOfByteArray() throws UnknownHostException { |
| 193 | for(int i=0; i < testStrings.length; i++ ) { |
| 194 | byte[] bytes = Inet6Address.getByName(testStrings[i]).getAddress(); |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 195 | IPv6Address ip = IPv6Address.of(bytes); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 196 | assertEquals(testStrings[i], ip.toString()); |
| 197 | assertArrayEquals(bytes, ip.getBytes()); |
| 198 | } |
| 199 | } |
| 200 | |
Ronald Li | fea1789 | 2014-07-03 18:36:06 -0700 | [diff] [blame] | 201 | private static void testOfCidrMaskLengthHelper( |
| 202 | int cidrMaskLength, String ipStr) throws UnknownHostException { |
| 203 | byte[] ba0 = IPv6Address.ofCidrMaskLength(cidrMaskLength).getBytes(); |
| 204 | byte[] ba1 = Inet6Address.getByName(ipStr).getAddress(); |
| 205 | assertArrayEquals(ba0, ba1); |
| 206 | } |
| 207 | |
| 208 | @Test |
| 209 | public void testOfCidrMaskLength() throws UnknownHostException { |
| 210 | for (int i = 0; i <= 128; i++) { |
| 211 | assertTrue(IPv6Address.ofCidrMaskLength(i).isCidrMask()); |
| 212 | assertEquals(IPv6Address.ofCidrMaskLength(i).asCidrMaskLength(), i); |
| 213 | } |
| 214 | testOfCidrMaskLengthHelper(0, "::"); |
| 215 | testOfCidrMaskLengthHelper(1, "8000::"); |
| 216 | testOfCidrMaskLengthHelper(2, "c000::"); |
| 217 | testOfCidrMaskLengthHelper(8, "ff00::"); |
| 218 | testOfCidrMaskLengthHelper(16, "ffff::"); |
| 219 | testOfCidrMaskLengthHelper(17, "ffff:8000::"); |
| 220 | testOfCidrMaskLengthHelper(31, "ffff:fffe::"); |
| 221 | testOfCidrMaskLengthHelper(32, "ffff:ffff::"); |
| 222 | testOfCidrMaskLengthHelper(33, "ffff:ffff:8000::"); |
| 223 | testOfCidrMaskLengthHelper(46, "ffff:ffff:fffc::"); |
| 224 | testOfCidrMaskLengthHelper(48, "ffff:ffff:ffff::"); |
| 225 | testOfCidrMaskLengthHelper(55, "ffff:ffff:ffff:fe00::"); |
| 226 | testOfCidrMaskLengthHelper(56, "ffff:ffff:ffff:ff00::"); |
| 227 | testOfCidrMaskLengthHelper(59, "ffff:ffff:ffff:ffe0::"); |
| 228 | testOfCidrMaskLengthHelper(63, "ffff:ffff:ffff:fffe::"); |
| 229 | testOfCidrMaskLengthHelper(64, "ffff:ffff:ffff:ffff::"); |
| 230 | testOfCidrMaskLengthHelper(65, "ffff:ffff:ffff:ffff:8000::"); |
| 231 | testOfCidrMaskLengthHelper(67, "ffff:ffff:ffff:ffff:e000::"); |
| 232 | testOfCidrMaskLengthHelper(100, "ffff:ffff:ffff:ffff:ffff:ffff:f000::"); |
| 233 | testOfCidrMaskLengthHelper(101, "ffff:ffff:ffff:ffff:ffff:ffff:f800::"); |
| 234 | testOfCidrMaskLengthHelper(126, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc"); |
| 235 | testOfCidrMaskLengthHelper(127, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe"); |
| 236 | testOfCidrMaskLengthHelper(128, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); |
| 237 | } |
| 238 | |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 239 | @Test |
| 240 | public void testReadFrom() throws OFParseError, UnknownHostException { |
| 241 | for(int i=0; i < testStrings.length; i++ ) { |
| 242 | byte[] bytes = Inet6Address.getByName(testStrings[i]).getAddress(); |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 243 | IPv6Address ip = IPv6Address.read16Bytes(ChannelBuffers.copiedBuffer(bytes)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 244 | assertEquals(testStrings[i], ip.toString()); |
| 245 | assertArrayEquals(bytes, ip.getBytes()); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | String[] invalidIPs = { |
| 250 | "", |
| 251 | ":", |
| 252 | "1:2:3:4:5:6:7:8:9", |
| 253 | "1:2:3:4:5:6:7:8:", |
| 254 | "1:2:3:4:5:6:7:8g", |
| 255 | "1:2:3:", |
| 256 | "12345::", |
| 257 | "1::3::8", |
| 258 | "::3::" |
| 259 | }; |
| 260 | |
| 261 | @Test |
| 262 | public void testInvalidIPs() throws OFParseError { |
| 263 | for(String invalid : invalidIPs) { |
| 264 | try { |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 265 | IPv6Address.of(invalid); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 266 | fail("Invalid IP "+invalid+ " should have raised IllegalArgumentException"); |
| 267 | } catch(IllegalArgumentException e) { |
| 268 | // ok |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | @Test |
| 274 | public void testZeroCompression() throws OFParseError { |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 275 | assertEquals("::", IPv6Address.of("::").toString(true, false)); |
| 276 | assertEquals("0:0:0:0:0:0:0:0", IPv6Address.of("::").toString(false, false)); |
| 277 | assertEquals("0000:0000:0000:0000:0000:0000:0000:0000", IPv6Address.of("::").toString(false, true)); |
| 278 | assertEquals("1::4:5:6:0:8", IPv6Address.of("1:0:0:4:5:6:0:8").toString(true, false)); |
| 279 | assertEquals("1:0:0:4::8", IPv6Address.of("1:0:0:4:0:0:0:8").toString(true, false)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 280 | } |
Gregor Maier | 7f987e6 | 2013-12-10 19:34:18 -0800 | [diff] [blame] | 281 | |
| 282 | @Test |
| 283 | public void testSuperclass() throws Exception { |
| 284 | for(String ipString: testStrings) { |
| 285 | IPAddress<?> superIp = IPAddress.of(ipString); |
| 286 | assertEquals(IPVersion.IPv6, superIp.getIpVersion()); |
| 287 | assertEquals(IPv6Address.of(ipString), superIp); |
| 288 | } |
| 289 | |
| 290 | for(WithMaskTaskCase w: withMasks) { |
| 291 | String ipMaskedString = w.input; |
| 292 | IPAddressWithMask<?> superIp = IPAddressWithMask.of(ipMaskedString); |
| 293 | assertEquals(IPVersion.IPv6, superIp.getIpVersion()); |
| 294 | assertEquals(IPv6AddressWithMask.of(ipMaskedString), superIp); |
| 295 | } |
| 296 | } |
Gregor Maier | 1ff5597 | 2013-12-11 02:22:56 -0800 | [diff] [blame] | 297 | |
| 298 | @Test |
| 299 | public void testOfExceptions() throws Exception { |
| 300 | try { |
| 301 | IPv6AddressWithMask.of(null); |
| 302 | fail("Should have thrown NullPointerException"); |
| 303 | } catch (NullPointerException e) { |
| 304 | assertNotNull(e.getMessage()); |
| 305 | } |
| 306 | try { |
| 307 | String s = null; |
| 308 | IPv6Address.of(s); |
| 309 | fail("Should have thrown NullPointerException"); |
| 310 | } catch (NullPointerException e) { |
| 311 | assertNotNull(e.getMessage()); |
| 312 | } |
| 313 | try { |
| 314 | byte[] b = null; |
| 315 | IPv6Address.of(b); |
| 316 | fail("Should have thrown NullPointerException"); |
| 317 | } catch (NullPointerException e) { |
| 318 | assertNotNull(e.getMessage()); |
| 319 | } |
| 320 | try { |
| 321 | byte[] b = new byte[7]; |
| 322 | IPv6Address.of(b); |
| 323 | fail("Should have thrown IllegalArgumentException"); |
| 324 | } catch (IllegalArgumentException e) { |
| 325 | // expected |
| 326 | } |
| 327 | try { |
| 328 | byte[] b = new byte[9]; |
| 329 | IPv6Address.of(b); |
| 330 | fail("Should have thrown IllegalArgumentException"); |
| 331 | } catch (IllegalArgumentException e) { |
| 332 | // expected |
| 333 | } |
| 334 | try { |
| 335 | IPv6AddressWithMask.of(IPv6Address.of("1::"), null); |
| 336 | fail("Should have thrown NullPointerException"); |
| 337 | } catch (NullPointerException e) { |
| 338 | assertNotNull(e.getMessage()); |
| 339 | } |
| 340 | try { |
| 341 | IPv6AddressWithMask.of(null, IPv6Address.of("255::")); |
| 342 | fail("Should have thrown NullPointerException"); |
| 343 | } catch (NullPointerException e) { |
| 344 | assertNotNull(e.getMessage()); |
| 345 | } |
Aditya Vaja | b21043d | 2014-03-11 13:34:06 -0700 | [diff] [blame] | 346 | try { |
| 347 | IPv6AddressWithMask.of(IPv6Address.of("10:10::0"), |
| 348 | IPv6Address.of("ffff:0:ffff::")) |
| 349 | .getSubnetBroadcastAddress(); |
| 350 | fail("Should have thrown IllegalArgumentException"); |
| 351 | } catch (IllegalArgumentException e) { |
| 352 | assertNotNull(e.getMessage()); |
| 353 | } |
Ronald Li | fea1789 | 2014-07-03 18:36:06 -0700 | [diff] [blame] | 354 | try { |
| 355 | IPv6Address.ofCidrMaskLength(-1); |
| 356 | fail("Should have thrown IllegalArgumentException"); |
| 357 | } catch (IllegalArgumentException e) { |
| 358 | assertNotNull(e.getMessage()); |
| 359 | } |
| 360 | try { |
| 361 | IPv6Address.ofCidrMaskLength(129); |
| 362 | fail("Should have thrown IllegalArgumentException"); |
| 363 | } catch (IllegalArgumentException e) { |
| 364 | assertNotNull(e.getMessage()); |
| 365 | } |
Gregor Maier | 1ff5597 | 2013-12-11 02:22:56 -0800 | [diff] [blame] | 366 | } |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 367 | } |