Initial opendaylight infrastructure commit!!
[controller.git] / opendaylight / sal / api / src / test / java / org / opendaylight / controller / sal / packet / ARPTest.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 org.junit.Test;
13 import org.opendaylight.controller.sal.packet.ARP;
14
15 import junit.framework.Assert;
16
17 public class ARPTest {
18
19     @Test
20     public void testGetHardwareType() {
21         ARP arp = new ARP();
22         byte[] hardwaretype = { 8, 6 };
23         arp.hdrFieldsMap.put("HardwareType", hardwaretype);
24         short hwtype = arp.getHardwareType();
25         Assert.assertTrue(hwtype == 2054);
26     }
27
28     @Test
29     public void testGetProtocolType() {
30         ARP arp = new ARP();
31         byte[] protocoltype = { 8, 0 };
32         arp.hdrFieldsMap.put("ProtocolType", protocoltype);
33         short ptype = arp.getProtocolType();
34         Assert.assertTrue(ptype == 2048);
35     }
36
37     @Test
38     public void testGetHardwareAddressLength() {
39         ARP arp = new ARP();
40         byte[] hardwareaddresslength = { 48 };
41         arp.hdrFieldsMap.put("HardwareAddressLength", hardwareaddresslength);
42         byte hwaddrlength = arp.getHardwareAddressLength();
43         Assert.assertTrue(hwaddrlength == 48);
44     }
45
46     @Test
47     public void testGetProtocolAddressLength() {
48         ARP arp = new ARP();
49         byte[] protocoladdresslength = { 32 };
50         arp.hdrFieldsMap.put("ProtocolAddressLength", protocoladdresslength);
51         byte paddrlength = arp.getProtocolAddressLength();
52         Assert.assertTrue(paddrlength == 32);
53     }
54
55     @Test
56     public void testGetOpCode() {
57         ARP arp = new ARP();
58         byte[] opcode = { 0, 2 };
59         arp.hdrFieldsMap.put("OpCode", opcode);
60         short opCode = arp.getOpCode();
61         Assert.assertTrue(opCode == 2);
62     }
63
64     @Test
65     public void testGetSenderHardwareAddress() {
66         ARP arp = new ARP();
67         byte[] hardwareaddress = { 48, 50, 120, 15, 66, 80 };
68         arp.hdrFieldsMap.put("SenderHardwareAddress", hardwareaddress);
69         byte[] hwAddress = arp.getSenderHardwareAddress();
70         Assert.assertTrue(hwAddress[0] == 48);
71         Assert.assertTrue(hwAddress[1] == 50);
72         Assert.assertTrue(hwAddress[2] == 120);
73         Assert.assertTrue(hwAddress[3] == 15);
74         Assert.assertTrue(hwAddress[4] == 66);
75         Assert.assertTrue(hwAddress[5] == 80);
76     }
77
78     @Test
79     public void testGetSenderProtocolAddress() {
80         ARP arp = new ARP();
81         byte[] protocoladdress = { 50, 100, 10, 20, 40, 80 };
82         arp.hdrFieldsMap.put("SenderProtocolAddress", protocoladdress);
83         byte[] pAddress = arp.getSenderProtocolAddress();
84         Assert.assertTrue(pAddress[0] == 50);
85         Assert.assertTrue(pAddress[1] == 100);
86         Assert.assertTrue(pAddress[2] == 10);
87         Assert.assertTrue(pAddress[3] == 20);
88         Assert.assertTrue(pAddress[4] == 40);
89         Assert.assertTrue(pAddress[5] == 80);
90     }
91
92     @Test
93     public void testGetTargetHardwareAddress() {
94         ARP arp = new ARP();
95         byte[] hardwareaddress = { 48, 50, 120, 15, 66, 80 };
96         arp.hdrFieldsMap.put("TargetHardwareAddress", hardwareaddress);
97         byte[] hwAddress = arp.getTargetHardwareAddress();
98         Assert.assertTrue(hwAddress[0] == 48);
99         Assert.assertTrue(hwAddress[1] == 50);
100         Assert.assertTrue(hwAddress[2] == 120);
101         Assert.assertTrue(hwAddress[3] == 15);
102         Assert.assertTrue(hwAddress[4] == 66);
103         Assert.assertTrue(hwAddress[5] == 80);
104     }
105
106     @Test
107     public void testGetTargetProtocolAddress() {
108         ARP arp = new ARP();
109         byte[] protocoladdress = { 50, 100, 10, 20, 40, 80 };
110         arp.hdrFieldsMap.put("TargetProtocolAddress", protocoladdress);
111         byte[] pAddress = arp.getTargetProtocolAddress();
112         Assert.assertTrue(pAddress[0] == 50);
113         Assert.assertTrue(pAddress[1] == 100);
114         Assert.assertTrue(pAddress[2] == 10);
115         Assert.assertTrue(pAddress[3] == 20);
116         Assert.assertTrue(pAddress[4] == 40);
117         Assert.assertTrue(pAddress[5] == 80);
118     }
119
120     @Test
121     public void testSetHardwareType() {
122         ARP arp = new ARP();
123         short hwtype = 2054;
124         arp.setHardwareType(hwtype);
125         byte[] hardwaretype = arp.hdrFieldsMap.get("HardwareType");
126         Assert.assertTrue(hardwaretype[0] == 8);
127         Assert.assertTrue(hardwaretype[1] == 6);
128     }
129
130     @Test
131     public void testSetProtocolType() {
132         ARP arp = new ARP();
133         short ptype = 2048;
134         arp.setProtocolType(ptype);
135         byte[] protocoltype = arp.hdrFieldsMap.get("ProtocolType");
136         Assert.assertTrue(protocoltype[0] == 8);
137         Assert.assertTrue(protocoltype[1] == 0);
138     }
139
140     @Test
141     public void testSetHardwareAddressLength() {
142         ARP arp = new ARP();
143         byte hwaddrlength = 48;
144         arp.setHardwareAddressLength(hwaddrlength);
145         byte[] hardwareaddresslength = arp.hdrFieldsMap
146                 .get("HardwareAddressLength");
147         Assert.assertTrue(hardwareaddresslength[0] == 48);
148     }
149
150     @Test
151     public void testSetProtocolAddressLength() {
152         ARP arp = new ARP();
153         byte PAddrlength = 32;
154         arp.setProtocolAddressLength(PAddrlength);
155         byte[] protocoladdresslength = arp.hdrFieldsMap
156                 .get("ProtocolAddressLength");
157         Assert.assertTrue(protocoladdresslength[0] == 32);
158     }
159
160     @Test
161     public void testSetOpCode() {
162         ARP arp = new ARP();
163         short opCode = (short) 2;
164         arp.setOpCode(opCode);
165         byte[] opcode = arp.hdrFieldsMap.get("OpCode");
166         //System.out.println(opCode);
167         Assert.assertTrue(opcode[0] == 0);
168         Assert.assertTrue(opcode[1] == 2);
169     }
170
171     @Test
172     public void testSetSenderHardwareAddress() {
173         ARP arp = new ARP();
174         byte[] hardwareaddress = { 48, 50, 120, 15, 66, 80 };
175         arp.setSenderHardwareAddress(hardwareaddress);
176         byte[] hwAddress = arp.hdrFieldsMap.get("SenderHardwareAddress");
177         Assert.assertTrue(hwAddress[0] == 48);
178         Assert.assertTrue(hwAddress[1] == 50);
179         Assert.assertTrue(hwAddress[2] == 120);
180         Assert.assertTrue(hwAddress[3] == 15);
181         Assert.assertTrue(hwAddress[4] == 66);
182         Assert.assertTrue(hwAddress[5] == 80);
183     }
184
185     @Test
186     public void testSetSenderProtocolAddress() {
187         ARP arp = new ARP();
188         byte[] protocoladdress = { 50, 100, 10, 20, 40, 80 };
189         arp.setSenderProtocolAddress(protocoladdress);
190         byte[] pAddress = arp.hdrFieldsMap.get("SenderProtocolAddress");
191         Assert.assertTrue(pAddress[0] == 50);
192         Assert.assertTrue(pAddress[1] == 100);
193         Assert.assertTrue(pAddress[2] == 10);
194         Assert.assertTrue(pAddress[3] == 20);
195         Assert.assertTrue(pAddress[4] == 40);
196         Assert.assertTrue(pAddress[5] == 80);
197     }
198
199     @Test
200     public void testSetTargetHardwareAddress() {
201         ARP arp = new ARP();
202         byte[] hardwareaddress = { 48, 50, 120, 15, 66, 80 };
203         arp.setTargetHardwareAddress(hardwareaddress);
204         byte[] hwAddress = arp.hdrFieldsMap.get("TargetHardwareAddress");
205         Assert.assertTrue(hwAddress[0] == 48);
206         Assert.assertTrue(hwAddress[1] == 50);
207         Assert.assertTrue(hwAddress[2] == 120);
208         Assert.assertTrue(hwAddress[3] == 15);
209         Assert.assertTrue(hwAddress[4] == 66);
210         Assert.assertTrue(hwAddress[5] == 80);
211     }
212
213     @Test
214     public void testSetTargetProtocolAddress() {
215         ARP arp = new ARP();
216         byte[] protocoladdress = { 50, 100, 10, 20, 40, 80 };
217         arp.setTargetProtocolAddress(protocoladdress);
218         byte[] pAddress = arp.hdrFieldsMap.get("TargetProtocolAddress");
219         Assert.assertTrue(pAddress[0] == 50);
220         Assert.assertTrue(pAddress[1] == 100);
221         Assert.assertTrue(pAddress[2] == 10);
222         Assert.assertTrue(pAddress[3] == 20);
223         Assert.assertTrue(pAddress[4] == 40);
224         Assert.assertTrue(pAddress[5] == 80);
225     }
226
227 }