blob: f742f21139f327ebf03ac3893d385798a0473a64 [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 */
21package net.floodlightcontroller.packet;
22
23import static org.junit.Assert.assertEquals;
24import static org.junit.Assert.assertTrue;
25
26import java.util.Arrays;
27
28import org.junit.Test;
29
30/**
31 * @author David Erickson (daviderickson@cs.stanford.edu)
32 *
33 */
34public class EthernetTest {
35 @Test
36 public void testToMACAddress() {
37 byte[] address = new byte[] { 0x0, 0x11, 0x22, (byte) 0xff,
38 (byte) 0xee, (byte) 0xdd};
39 assertTrue(Arrays.equals(address, Ethernet
40 .toMACAddress("00:11:22:ff:ee:dd")));
41 assertTrue(Arrays.equals(address, Ethernet
42 .toMACAddress("00:11:22:FF:EE:DD")));
43 }
44
45 @Test
46 public void testSerialize() {
47 Ethernet ethernet = new Ethernet()
48 .setDestinationMACAddress("de:ad:be:ef:de:ad")
49 .setSourceMACAddress("be:ef:de:ad:be:ef")
50 .setEtherType((short) 0);
51 byte[] expected = new byte[] { (byte) 0xde, (byte) 0xad, (byte) 0xbe,
52 (byte) 0xef, (byte) 0xde, (byte) 0xad, (byte) 0xbe,
53 (byte) 0xef, (byte) 0xde, (byte) 0xad, (byte) 0xbe,
54 (byte) 0xef, 0x0, 0x0 };
55 assertTrue(Arrays.equals(expected, ethernet.serialize()));
56 }
57
58 @Test
59 public void testToLong() {
60 assertEquals(
61 281474976710655L,
62 Ethernet.toLong(new byte[] { (byte) 0xff, (byte) 0xff,
63 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }));
64
65 assertEquals(
66 1103823438081L,
67 Ethernet.toLong(new byte[] { (byte) 0x01, (byte) 0x01,
68 (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01 }));
69
70 assertEquals(
71 141289400074368L,
72 Ethernet.toLong(new byte[] { (byte) 0x80, (byte) 0x80,
73 (byte) 0x80, (byte) 0x80, (byte) 0x80, (byte) 0x80 }));
74 }
75}