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