Merge "Adding learn action"
[openflowplugin.git] / applications / topology-lldp-discovery / src / main / java / org / opendaylight / openflowplugin / applications / topology / lldp / LLDPDiscoveryListener.java
1 /**
2  * Copyright (c) 2014 Cisco Systems, 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 package org.opendaylight.openflowplugin.applications.topology.lldp;
9
10 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
11 import org.opendaylight.openflowplugin.applications.topology.lldp.utils.LLDPDiscoveryUtils;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkDiscovered;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkDiscoveredBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
17
18 public class LLDPDiscoveryListener implements PacketProcessingListener {
19     private final LLDPLinkAger lldpLinkAger;
20     private final NotificationProviderService notificationService;
21
22     public LLDPDiscoveryListener(NotificationProviderService notificationService, LLDPLinkAger lldpLinkAger) {
23         this.notificationService = notificationService;
24         this.lldpLinkAger = lldpLinkAger;
25     }
26
27     @Override
28     public void onPacketReceived(PacketReceived lldp) {
29         NodeConnectorRef src = LLDPDiscoveryUtils.lldpToNodeConnectorRef(lldp.getPayload(), true);
30         if(src != null) {
31             LinkDiscoveredBuilder ldb = new LinkDiscoveredBuilder();
32             ldb.setDestination(lldp.getIngress());
33             ldb.setSource(new NodeConnectorRef(src));
34             LinkDiscovered ld = ldb.build();
35
36             notificationService.publish(ld);
37             lldpLinkAger.put(ld);
38         }
39     }
40 }