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.netvirt.openstack.netvirt.providers.openflow13.services.arp;
11 import org.opendaylight.controller.liblldp.EtherTypes;
12 import org.opendaylight.controller.liblldp.Ethernet;
13 import org.opendaylight.controller.liblldp.NetUtils;
14 import org.opendaylight.controller.liblldp.PacketException;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public class ArpResolverUtils {
20 private static final Logger LOG = LoggerFactory.getLogger(ArpResolverUtils.class);
24 Ethernet.etherTypeClassMap.put(EtherTypes.ARP.shortValue(), Arp.class);
28 * Tries to deserialize received packet as ARP packet with IPv4 protocol address and MAC
31 * @param potentialArp the packet for deserialization
32 * @return ARP packet if received packet is ARP and deserialization was successful
34 public static Arp getArpFrom(PacketReceived potentialArp) {
35 byte[] payload = potentialArp.getPayload();
36 Ethernet ethPkt = new Ethernet();
38 ethPkt.deserialize(payload, 0, payload.length * NetUtils.NumBitsInAByte);
39 } catch (PacketException e) {
40 LOG.trace("Failed to decode the incoming packet. ignoring it.");
42 if (ethPkt.getPayload() instanceof Arp) {
43 return (Arp) ethPkt.getPayload();