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;
14 import junit.framework.Assert;
16 public class ARPTest {
19 public void testGetHardwareType() {
21 byte[] hardwaretype = { 8, 6 };
22 arp.hdrFieldsMap.put("HardwareType", hardwaretype);
23 short hwtype = arp.getHardwareType();
24 Assert.assertTrue(hwtype == 2054);
28 public void testGetProtocolType() {
30 byte[] protocoltype = { 8, 0 };
31 arp.hdrFieldsMap.put("ProtocolType", protocoltype);
32 short ptype = arp.getProtocolType();
33 Assert.assertTrue(ptype == 2048);
37 public void testGetHardwareAddressLength() {
39 byte[] hardwareaddresslength = { 48 };
40 arp.hdrFieldsMap.put("HardwareAddressLength", hardwareaddresslength);
41 byte hwaddrlength = arp.getHardwareAddressLength();
42 Assert.assertTrue(hwaddrlength == 48);
46 public void testGetProtocolAddressLength() {
48 byte[] protocoladdresslength = { 32 };
49 arp.hdrFieldsMap.put("ProtocolAddressLength", protocoladdresslength);
50 byte paddrlength = arp.getProtocolAddressLength();
51 Assert.assertTrue(paddrlength == 32);
55 public void testGetOpCode() {
57 byte[] opcode = { 0, 2 };
58 arp.hdrFieldsMap.put("OpCode", opcode);
59 short opCode = arp.getOpCode();
60 Assert.assertTrue(opCode == 2);
64 public void testGetSenderHardwareAddress() {
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);
78 public void testGetSenderProtocolAddress() {
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);
92 public void testGetTargetHardwareAddress() {
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);
106 public void testGetTargetProtocolAddress() {
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);
120 public void testSetHardwareType() {
123 arp.setHardwareType(hwtype);
124 byte[] hardwaretype = arp.hdrFieldsMap.get("HardwareType");
125 Assert.assertTrue(hardwaretype[0] == 8);
126 Assert.assertTrue(hardwaretype[1] == 6);
130 public void testSetProtocolType() {
133 arp.setProtocolType(ptype);
134 byte[] protocoltype = arp.hdrFieldsMap.get("ProtocolType");
135 Assert.assertTrue(protocoltype[0] == 8);
136 Assert.assertTrue(protocoltype[1] == 0);
140 public void testSetHardwareAddressLength() {
142 byte hwaddrlength = 48;
143 arp.setHardwareAddressLength(hwaddrlength);
144 byte[] hardwareaddresslength = arp.hdrFieldsMap
145 .get("HardwareAddressLength");
146 Assert.assertTrue(hardwareaddresslength[0] == 48);
150 public void testSetProtocolAddressLength() {
152 byte PAddrlength = 32;
153 arp.setProtocolAddressLength(PAddrlength);
154 byte[] protocoladdresslength = arp.hdrFieldsMap
155 .get("ProtocolAddressLength");
156 Assert.assertTrue(protocoladdresslength[0] == 32);
160 public void testSetOpCode() {
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);
171 public void testSetSenderHardwareAddress() {
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);
185 public void testSetSenderProtocolAddress() {
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);
199 public void testSetTargetHardwareAddress() {
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);
213 public void testSetTargetProtocolAddress() {
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);