2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.arp;
11 import java.net.InetAddress;
13 import org.junit.Assert;
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.junit.rules.ExpectedException;
17 import org.opendaylight.controller.liblldp.EtherTypes;
18 import org.opendaylight.controller.liblldp.Ethernet;
19 import org.opendaylight.controller.liblldp.HexEncode;
20 import org.opendaylight.controller.liblldp.PacketException;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder;
24 public class ArpResolverUtilsTest {
27 public void getArpFromTest() throws Exception {
30 byte[] sha = HexEncode.bytesFromHexString("00:00:00:00:00:01");
31 byte[] spa = InetAddress.getByName("192.168.0.1").getAddress();
32 byte[] tha = HexEncode.bytesFromHexString("00:00:00:00:00:02");
33 byte[] tpa = InetAddress.getByName("192.168.0.2").getAddress();
35 int ptype = EtherTypes.IPv4.intValue();
40 arp.setSenderHardwareAddress(sha);
41 arp.setSenderProtocolAddress(spa);
42 arp.setTargetHardwareAddress(tha);
43 arp.setTargetProtocolAddress(tpa);
44 arp.setOperation(operation);
45 arp.setHardwareLength(hlen);
46 arp.setProtocolLength(plen);
47 arp.setHardwareType(htype);
48 arp.setProtocolType(ptype);
50 Ethernet arpFrame = new Ethernet().setSourceMACAddress(sha)
51 .setDestinationMACAddress(tha)
52 .setEtherType(EtherTypes.ARP.shortValue());
53 arpFrame.setPayload(arp);
54 PacketReceived packet = new PacketReceivedBuilder().setPayload(arpFrame.serialize()).build();
55 Arp arpOut = ArpResolverUtils.getArpFrom(packet);
56 Assert.assertEquals(arp, arpOut);
59 @Rule public ExpectedException e = ExpectedException.none();
61 public void getArpFromTest_notArpPacket() throws PacketException {
62 byte[] payload = {0xb, 0xe, 0xe, 0xf};
63 PacketReceived packet = new PacketReceivedBuilder().setPayload(payload).build();
64 e.expect(PacketException.class);
65 ArpResolverUtils.getArpFrom(packet);