Migrate nemo to use liblldp from openflowplugin
[nemo.git] / nemo-renderers / openflow-renderer / src / main / java / org / opendaylight / nemo / renderer / openflow / physicalnetwork / OFPacketInListener.java
1 /*
2  * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.nemo.renderer.openflow.physicalnetwork;
10
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;
21
22 /**
23  * Created by hj on 11/10/15.
24  */
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;
30     }
31
32     @Override
33     public void onPacketReceived(PacketReceived packetReceived) {
34         if (null == packetReceived) {
35             return;
36         }
37         byte[] payload = packetReceived.getPayload();
38         Ethernet ethernet = new Ethernet();
39         try {
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);
43         }
44         if (EtherTypes.ARP.shortValue() == ethernet.getEtherType()) {
45             NodeConnectorRef ingressNodeConnectorRef = packetReceived.getIngress();
46 //            String strNodeId = ingressNodeConnectorRef
47 //                    .getValue()
48 //                    .firstIdentifierOf(Node.class)
49 //                    .firstKeyOf(Node.class)
50 //                    .getId()
51 //                    .getValue();
52 //            String strPortId = ingressNodeConnectorRef
53 //                    .getValue()
54 //                    .firstIdentifierOf(NodeConnector.class)
55 //                    .firstKeyOf(NodeConnector.class)
56 //                    .getId()
57 //                    .getValue();
58             LOG.debug("Receive one arp packet in message:\r\n {}.", packetReceived);
59             ofFlowUtils.handleArp(packetReceived,ingressNodeConnectorRef);
60         }
61     }
62 }