2 * Copyright (c) 2015 Huawei, 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.nemo.renderer.openflow.physicalnetwork;
11 import org.opendaylight.nemo.renderer.openflow.FlowUtils;
12 import org.opendaylight.openflowplugin.libraries.liblldp.EtherTypes;
13 import org.opendaylight.openflowplugin.libraries.liblldp.Ethernet;
14 import org.opendaylight.openflowplugin.libraries.liblldp.NetUtils;
15 import org.opendaylight.openflowplugin.libraries.liblldp.PacketException;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Created by hj on 11/10/15.
25 public class OFPacketInListener implements PacketProcessingListener {
26 private static final Logger LOG = LoggerFactory.getLogger(OFPacketInListener.class);
27 private final FlowUtils ofFlowUtils;
28 public OFPacketInListener(FlowUtils ofFlowUtils) {
29 this.ofFlowUtils = ofFlowUtils;
33 public void onPacketReceived(PacketReceived packetReceived) {
34 if (null == packetReceived) {
37 byte[] payload = packetReceived.getPayload();
38 Ethernet ethernet = new Ethernet();
40 ethernet.deserialize(payload, 0, NetUtils.NUM_BITS_IN_A_BYTE * payload.length);
41 } catch (PacketException e) {
42 LOG.warn("Failed to decode packet in message: {}", packetReceived);
44 if (EtherTypes.ARP.shortValue() == ethernet.getEtherType()) {
45 NodeConnectorRef ingressNodeConnectorRef = packetReceived.getIngress();
46 // String strNodeId = ingressNodeConnectorRef
48 // .firstIdentifierOf(Node.class)
49 // .firstKeyOf(Node.class)
52 // String strPortId = ingressNodeConnectorRef
54 // .firstIdentifierOf(NodeConnector.class)
55 // .firstKeyOf(NodeConnector.class)
58 LOG.debug("Receive one arp packet in message:\r\n {}.", packetReceived);
59 ofFlowUtils.handleArp(packetReceived,ingressNodeConnectorRef);