blob: b22c779f97f16bd74a81ac3dbd63b2b449a2599b [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright 2011, Big Switch Networks, Inc.
3* Originally created by David Erickson, Stanford University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
18/**
19 *
20 */
Jonathan Hart96892d12014-03-26 20:21:29 -070021package net.onrc.onos.packet;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080022
23import static org.junit.Assert.assertEquals;
24import static org.junit.Assert.assertTrue;
25
26import java.util.Arrays;
27
Jonathan Hart96892d12014-03-26 20:21:29 -070028import net.onrc.onos.packet.Ethernet;
29
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080030import org.junit.Test;
31
32/**
33 * @author David Erickson (daviderickson@cs.stanford.edu)
34 *
35 */
36public class EthernetTest {
37 @Test
38 public void testToMACAddress() {
39 byte[] address = new byte[] { 0x0, 0x11, 0x22, (byte) 0xff,
40 (byte) 0xee, (byte) 0xdd};
41 assertTrue(Arrays.equals(address, Ethernet
42 .toMACAddress("00:11:22:ff:ee:dd")));
43 assertTrue(Arrays.equals(address, Ethernet
44 .toMACAddress("00:11:22:FF:EE:DD")));
45 }
46
47 @Test
48 public void testSerialize() {
49 Ethernet ethernet = new Ethernet()
50 .setDestinationMACAddress("de:ad:be:ef:de:ad")
51 .setSourceMACAddress("be:ef:de:ad:be:ef")
52 .setEtherType((short) 0);
53 byte[] expected = new byte[] { (byte) 0xde, (byte) 0xad, (byte) 0xbe,
54 (byte) 0xef, (byte) 0xde, (byte) 0xad, (byte) 0xbe,
55 (byte) 0xef, (byte) 0xde, (byte) 0xad, (byte) 0xbe,
56 (byte) 0xef, 0x0, 0x0 };
57 assertTrue(Arrays.equals(expected, ethernet.serialize()));
58 }
59
60 @Test
61 public void testToLong() {
62 assertEquals(
63 281474976710655L,
64 Ethernet.toLong(new byte[] { (byte) 0xff, (byte) 0xff,
65 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }));
66
67 assertEquals(
68 1103823438081L,
69 Ethernet.toLong(new byte[] { (byte) 0x01, (byte) 0x01,
70 (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01 }));
71
72 assertEquals(
73 141289400074368L,
74 Ethernet.toLong(new byte[] { (byte) 0x80, (byte) 0x80,
75 (byte) 0x80, (byte) 0x80, (byte) 0x80, (byte) 0x80 }));
76 }
77}