2 * Copyright (c) 2014 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
8 package org.opendaylight.l2switch.arphandler.core;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.arp.rev140528.ArpPacketListener;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.arp.rev140528.ArpPacketReceived;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.arp.rev140528.arp.packet.received.packet.chain.packet.ArpPacket;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.basepacket.rev140528.packet.chain.grp.PacketChain;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.basepacket.rev140528.packet.chain.grp.packet.chain.packet.RawPacket;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.ethernet.rev140528.ethernet.packet.received.packet.chain.packet.EthernetPacket;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * ArpPacketHandler listens for incoming ARP packets and processes them.
22 public class ArpPacketHandler implements ArpPacketListener {
24 private final static Logger LOG = LoggerFactory.getLogger(ArpPacketHandler.class);
25 private PacketDispatcher packetDispatcher;
27 public ArpPacketHandler(PacketDispatcher packetDispatcher) {
28 this.packetDispatcher = packetDispatcher;
32 * The handler function for ARP packets.
34 * @param packetReceived
35 * The incoming packet.
38 public void onArpPacketReceived(ArpPacketReceived packetReceived) {
39 if (packetReceived == null || packetReceived.getPacketChain() == null) {
43 RawPacket rawPacket = null;
44 EthernetPacket ethernetPacket = null;
45 ArpPacket arpPacket = null;
46 for (PacketChain packetChain : packetReceived.getPacketChain()) {
47 if (packetChain.getPacket() instanceof RawPacket) {
48 rawPacket = (RawPacket) packetChain.getPacket();
49 } else if (packetChain.getPacket() instanceof EthernetPacket) {
50 ethernetPacket = (EthernetPacket) packetChain.getPacket();
51 } else if (packetChain.getPacket() instanceof ArpPacket) {
52 arpPacket = (ArpPacket) packetChain.getPacket();
55 if (rawPacket == null || ethernetPacket == null || arpPacket == null) {
59 packetDispatcher.dispatchPacket(packetReceived.getPayload(), rawPacket.getIngress(),
60 ethernetPacket.getSourceMac(), ethernetPacket.getDestinationMac());