Bug 1245: Dropped Binding prefix from Binding Data APIs.
[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
16 public class EthernetTest {
17
18     @Test
19     public void testGetDestinationMACAddress() {
20         Ethernet eth = new Ethernet();
21         byte mac[] = { 10, 12, 14, 20, 55, 69 };
22         eth.hdrFieldsMap.put("DestinationMACAddress", mac);
23         byte[] dMAC = eth.getDestinationMACAddress();
24         Assert.assertTrue(dMAC[0] == 10);
25         Assert.assertTrue(dMAC[1] == 12);
26         Assert.assertTrue(dMAC[2] == 14);
27         Assert.assertTrue(dMAC[3] == 20);
28         Assert.assertTrue(dMAC[4] == 55);
29         Assert.assertTrue(dMAC[5] == 69);
30
31     }
32
33     @Test
34     public void testSourceMACAddress() {
35         Ethernet eth = new Ethernet();
36         byte mac[] = { 120, 30, 25, 80, 66, 99 };
37         eth.hdrFieldsMap.put("SourceMACAddress", mac);
38         byte[] sMAC = eth.getSourceMACAddress();
39         Assert.assertTrue(sMAC[0] == 120);
40         Assert.assertTrue(sMAC[1] == 30);
41         Assert.assertTrue(sMAC[2] == 25);
42         Assert.assertTrue(sMAC[3] == 80);
43         Assert.assertTrue(sMAC[4] == 66);
44         Assert.assertTrue(sMAC[5] == 99);
45
46     }
47
48     @Test
49     public void testGetEthertype() throws Exception {
50         Ethernet eth = new Ethernet();
51         byte ethType[] = { 8, 6 };
52         eth.hdrFieldsMap.put("EtherType", ethType);
53         short etherType = eth.getEtherType();
54         Assert.assertTrue(etherType == 2054);
55     }
56
57     @Test
58     public void testSetDestinationMACAddress() {
59         Ethernet eth = new Ethernet();
60         byte mac[] = { 10, 12, 14, 20, 55, 69 };
61         eth.setDestinationMACAddress(mac);
62         byte[] dMAC = eth.hdrFieldsMap.get("DestinationMACAddress");
63         Assert.assertTrue(dMAC[0] == 10);
64         Assert.assertTrue(dMAC[1] == 12);
65         Assert.assertTrue(dMAC[2] == 14);
66         Assert.assertTrue(dMAC[3] == 20);
67         Assert.assertTrue(dMAC[4] == 55);
68         Assert.assertTrue(dMAC[5] == 69);
69
70     }
71
72     @Test
73     public void testSetSourceMACAddress() {
74         Ethernet eth = new Ethernet();
75         byte mac[] = { 120, 30, 25, 80, 66, 99 };
76         eth.setSourceMACAddress(mac);
77         byte[] sMAC = eth.hdrFieldsMap.get("SourceMACAddress");
78         Assert.assertTrue(sMAC[0] == 120);
79         Assert.assertTrue(sMAC[1] == 30);
80         Assert.assertTrue(sMAC[2] == 25);
81         Assert.assertTrue(sMAC[3] == 80);
82         Assert.assertTrue(sMAC[4] == 66);
83         Assert.assertTrue(sMAC[5] == 99);
84
85     }
86
87     @Test
88     public void testSetEthertype() throws Exception {
89         Ethernet eth = new Ethernet();
90         short ethType = 2054;
91         eth.setEtherType(ethType);
92         byte[] etherType = eth.hdrFieldsMap.get("EtherType");
93         Assert.assertTrue(etherType[0] == 8);
94         Assert.assertTrue(etherType[1] == 6);
95
96     }
97
98 }