Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.util; |
| 2 | |
Jonathan Hart | a88fd24 | 2014-04-03 11:24:54 -0700 | [diff] [blame] | 3 | import static org.junit.Assert.assertEquals; |
| 4 | import static org.junit.Assert.assertFalse; |
| 5 | import static org.junit.Assert.assertTrue; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 6 | |
Jonathan Hart | a88fd24 | 2014-04-03 11:24:54 -0700 | [diff] [blame] | 7 | import org.junit.Test; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 8 | |
| 9 | /** |
| 10 | * @author Sho Shimizu (sho.shimizu@gmail.com) |
| 11 | */ |
| 12 | public class MACAddressTest { |
| 13 | @Test |
| 14 | public void testValueOf() { |
| 15 | MACAddress address = MACAddress.valueOf("00:01:02:03:04:05"); |
| 16 | assertEquals(address, |
| 17 | MACAddress.valueOf(new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05})); |
| 18 | assertEquals("00:01:02:03:04:05", address.toString()); |
| 19 | |
| 20 | address = MACAddress.valueOf("FF:FE:FD:10:20:30"); |
| 21 | assertEquals(address, |
| 22 | MACAddress.valueOf(new byte[]{(byte) 0xFF, (byte) 0xFE, (byte) 0xFD, 0x10, 0x20, 0x30})); |
Pavlin Radoslavov | af839eb | 2013-12-19 00:02:34 -0800 | [diff] [blame] | 23 | assertEquals("ff:fe:fd:10:20:30", address.toString()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 24 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 25 | address = MACAddress.valueOf("00:11:22:aa:bb:cc"); |
| 26 | assertEquals(address, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 27 | MACAddress.valueOf(new byte[]{0x00, 0x11, 0x22, (byte) 0xaa, (byte) 0xbb, (byte) 0xcc})); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 28 | } |
| 29 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 30 | @Test(expected = NumberFormatException.class) |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 31 | public void testIllegalFormat() { |
| 32 | MACAddress.valueOf("0T:00:01:02:03:04"); |
| 33 | } |
| 34 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 35 | @Test(expected = IllegalArgumentException.class) |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 36 | public void testLongStringFields() { |
| 37 | MACAddress.valueOf("00:01:02:03:04:05:06"); |
| 38 | } |
| 39 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 40 | @Test(expected = IllegalArgumentException.class) |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 41 | public void testShortStringFields() { |
| 42 | MACAddress.valueOf("00:01:02:03:04"); |
| 43 | } |
| 44 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 45 | @Test(expected = IllegalArgumentException.class) |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 46 | public void testLongByteFields() { |
| 47 | MACAddress.valueOf(new byte[]{0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}); |
| 48 | } |
| 49 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 50 | @Test(expected = IllegalArgumentException.class) |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 51 | public void testShortByteField() { |
| 52 | MACAddress.valueOf(new byte[]{0x01, 0x01, 0x02, 0x03, 0x04}); |
| 53 | } |
| 54 | |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 55 | // Test data is imported from net.onrc.onos.core.packet.EthernetTest |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 56 | @Test |
| 57 | public void testToLong() { |
| 58 | assertEquals( |
| 59 | 281474976710655L, |
| 60 | MACAddress.valueOf(new byte[]{(byte) 0xff, (byte) 0xff, |
| 61 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}).toLong()); |
| 62 | |
| 63 | assertEquals( |
| 64 | 1103823438081L, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 65 | MACAddress.valueOf(new byte[]{(byte) 0x01, (byte) 0x01, |
| 66 | (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01}).toLong()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 67 | |
| 68 | assertEquals( |
| 69 | 141289400074368L, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 70 | MACAddress.valueOf(new byte[]{(byte) 0x80, (byte) 0x80, |
| 71 | (byte) 0x80, (byte) 0x80, (byte) 0x80, (byte) 0x80}).toLong()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 72 | |
| 73 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 74 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 75 | @Test |
| 76 | public void testIsBroadcast() { |
| 77 | assertTrue(MACAddress.valueOf("FF:FF:FF:FF:FF:FF").isBroadcast()); |
| 78 | assertFalse(MACAddress.valueOf("11:22:33:44:55:66").isBroadcast()); |
| 79 | } |
| 80 | |
| 81 | @Test |
| 82 | public void testIsMulticast() { |
| 83 | assertTrue(MACAddress.valueOf("01:80:C2:00:00:00").isMulticast()); |
| 84 | assertFalse(MACAddress.valueOf("FF:FF:FF:FF:FF:FF").isMulticast()); |
| 85 | assertFalse(MACAddress.valueOf("11:22:33:44:55:66").isBroadcast()); |
| 86 | } |
| 87 | } |