Initial opendaylight infrastructure commit!!
[controller.git] / opendaylight / sal / api / src / test / java / org / opendaylight / controller / sal / packet / EthernetTest.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.sal.packet;
11
12 import junit.framework.Assert;
13
14 import org.junit.Test;
15 import org.opendaylight.controller.sal.packet.Ethernet;
16
17 public class EthernetTest {
18
19     @Test
20     public void testGetDestinationMACAddress() {
21         Ethernet eth = new Ethernet();
22         byte mac[] = { 10, 12, 14, 20, 55, 69 };
23         eth.hdrFieldsMap.put("DestinationMACAddress", mac);
24         byte[] dMAC = eth.getDestinationMACAddress();
25         Assert.assertTrue(dMAC[0] == 10);
26         Assert.assertTrue(dMAC[1] == 12);
27         Assert.assertTrue(dMAC[2] == 14);
28         Assert.assertTrue(dMAC[3] == 20);
29         Assert.assertTrue(dMAC[4] == 55);
30         Assert.assertTrue(dMAC[5] == 69);
31
32     }
33
34     @Test
35     public void testSourceMACAddress() {
36         Ethernet eth = new Ethernet();
37         byte mac[] = { 120, 30, 25, 80, 66, 99 };
38         eth.hdrFieldsMap.put("SourceMACAddress", mac);
39         byte[] sMAC = eth.getSourceMACAddress();
40         Assert.assertTrue(sMAC[0] == 120);
41         Assert.assertTrue(sMAC[1] == 30);
42         Assert.assertTrue(sMAC[2] == 25);
43         Assert.assertTrue(sMAC[3] == 80);
44         Assert.assertTrue(sMAC[4] == 66);
45         Assert.assertTrue(sMAC[5] == 99);
46
47     }
48
49     @Test
50     public void testGetEthertype() throws Exception {
51         Ethernet eth = new Ethernet();
52         byte ethType[] = { 8, 6 };
53         eth.hdrFieldsMap.put("EtherType", ethType);
54         short etherType = eth.getEtherType();
55         Assert.assertTrue(etherType == 2054);
56     }
57
58     @Test
59     public void testSetDestinationMACAddress() {
60         Ethernet eth = new Ethernet();
61         byte mac[] = { 10, 12, 14, 20, 55, 69 };
62         eth.setDestinationMACAddress(mac);
63         byte[] dMAC = eth.hdrFieldsMap.get("DestinationMACAddress");
64         Assert.assertTrue(dMAC[0] == 10);
65         Assert.assertTrue(dMAC[1] == 12);
66         Assert.assertTrue(dMAC[2] == 14);
67         Assert.assertTrue(dMAC[3] == 20);
68         Assert.assertTrue(dMAC[4] == 55);
69         Assert.assertTrue(dMAC[5] == 69);
70
71     }
72
73     @Test
74     public void testSetSourceMACAddress() {
75         Ethernet eth = new Ethernet();
76         byte mac[] = { 120, 30, 25, 80, 66, 99 };
77         eth.setSourceMACAddress(mac);
78         byte[] sMAC = eth.hdrFieldsMap.get("SourceMACAddress");
79         Assert.assertTrue(sMAC[0] == 120);
80         Assert.assertTrue(sMAC[1] == 30);
81         Assert.assertTrue(sMAC[2] == 25);
82         Assert.assertTrue(sMAC[3] == 80);
83         Assert.assertTrue(sMAC[4] == 66);
84         Assert.assertTrue(sMAC[5] == 99);
85
86     }
87
88     @Test
89     public void testSetEthertype() throws Exception {
90         Ethernet eth = new Ethernet();
91         short ethType = 2054;
92         eth.setEtherType(ethType);
93         byte[] etherType = eth.hdrFieldsMap.get("EtherType");
94         Assert.assertTrue(etherType[0] == 8);
95         Assert.assertTrue(etherType[1] == 6);
96
97     }
98
99 }