3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
10 package org.opendaylight.controller.sal.packet;
12 import org.junit.Test;
13 import org.opendaylight.controller.sal.packet.ARP;
15 import junit.framework.Assert;
17 public class ARPTest {
20 public void testGetHardwareType() {
22 byte[] hardwaretype = { 8, 6 };
23 arp.hdrFieldsMap.put("HardwareType", hardwaretype);
24 short hwtype = arp.getHardwareType();
25 Assert.assertTrue(hwtype == 2054);
29 public void testGetProtocolType() {
31 byte[] protocoltype = { 8, 0 };
32 arp.hdrFieldsMap.put("ProtocolType", protocoltype);
33 short ptype = arp.getProtocolType();
34 Assert.assertTrue(ptype == 2048);
38 public void testGetHardwareAddressLength() {
40 byte[] hardwareaddresslength = { 48 };
41 arp.hdrFieldsMap.put("HardwareAddressLength", hardwareaddresslength);
42 byte hwaddrlength = arp.getHardwareAddressLength();
43 Assert.assertTrue(hwaddrlength == 48);
47 public void testGetProtocolAddressLength() {
49 byte[] protocoladdresslength = { 32 };
50 arp.hdrFieldsMap.put("ProtocolAddressLength", protocoladdresslength);
51 byte paddrlength = arp.getProtocolAddressLength();
52 Assert.assertTrue(paddrlength == 32);
56 public void testGetOpCode() {
58 byte[] opcode = { 0, 2 };
59 arp.hdrFieldsMap.put("OpCode", opcode);
60 short opCode = arp.getOpCode();
61 Assert.assertTrue(opCode == 2);
65 public void testGetSenderHardwareAddress() {
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);
79 public void testGetSenderProtocolAddress() {
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);
93 public void testGetTargetHardwareAddress() {
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);
107 public void testGetTargetProtocolAddress() {
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);
121 public void testSetHardwareType() {
124 arp.setHardwareType(hwtype);
125 byte[] hardwaretype = arp.hdrFieldsMap.get("HardwareType");
126 Assert.assertTrue(hardwaretype[0] == 8);
127 Assert.assertTrue(hardwaretype[1] == 6);
131 public void testSetProtocolType() {
134 arp.setProtocolType(ptype);
135 byte[] protocoltype = arp.hdrFieldsMap.get("ProtocolType");
136 Assert.assertTrue(protocoltype[0] == 8);
137 Assert.assertTrue(protocoltype[1] == 0);
141 public void testSetHardwareAddressLength() {
143 byte hwaddrlength = 48;
144 arp.setHardwareAddressLength(hwaddrlength);
145 byte[] hardwareaddresslength = arp.hdrFieldsMap
146 .get("HardwareAddressLength");
147 Assert.assertTrue(hardwareaddresslength[0] == 48);
151 public void testSetProtocolAddressLength() {
153 byte PAddrlength = 32;
154 arp.setProtocolAddressLength(PAddrlength);
155 byte[] protocoladdresslength = arp.hdrFieldsMap
156 .get("ProtocolAddressLength");
157 Assert.assertTrue(protocoladdresslength[0] == 32);
161 public void testSetOpCode() {
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);
172 public void testSetSenderHardwareAddress() {
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);
186 public void testSetSenderProtocolAddress() {
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);
200 public void testSetTargetHardwareAddress() {
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);
214 public void testSetTargetProtocolAddress() {
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);