2 * Copyright (c) 2016, 2018 Ericsson India Global Services Pvt Ltd. 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.genius.interfacemanager.listeners;
10 import static org.opendaylight.genius.interfacemanager.renderer.hwvtep.utilities.SouthboundUtils.createGlobalNodeInstanceIdentifier;
11 import static org.opendaylight.genius.interfacemanager.renderer.hwvtep.utilities.SouthboundUtils.createPhysicalSwitchInstanceIdentifier;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.apache.aries.blueprint.annotation.service.Reference;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
18 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
19 import org.opendaylight.genius.interfacemanager.IfmConstants;
20 import org.opendaylight.genius.interfacemanager.renderer.hwvtep.confighelpers.HwVTEPConfigRemoveHelper;
21 import org.opendaylight.genius.interfacemanager.renderer.hwvtep.confighelpers.HwVTEPInterfaceConfigAddHelper;
22 import org.opendaylight.genius.interfacemanager.renderer.hwvtep.confighelpers.HwVTEPInterfaceConfigUpdateHelper;
23 import org.opendaylight.genius.interfacemanager.renderer.hwvtep.utilities.SouthboundUtils;
24 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
25 import org.opendaylight.mdsal.binding.api.DataBroker;
26 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
27 import org.opendaylight.serviceutils.tools.listener.AbstractSyncDataTreeChangeListener;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.interfaces._interface.NodeIdentifier;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 public class HwVTEPConfigListener extends AbstractSyncDataTreeChangeListener<Interface> {
41 private static final Logger LOG = LoggerFactory.getLogger(HwVTEPConfigListener.class);
43 private final ManagedNewTransactionRunner txRunner;
44 private final JobCoordinator coordinator;
47 public HwVTEPConfigListener(@Reference final DataBroker dataBroker, @Reference final JobCoordinator coordinator) {
48 super(dataBroker, LogicalDatastoreType.CONFIGURATION,
49 InstanceIdentifier.create(Interfaces.class).child(Interface.class));
50 this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
51 this.coordinator = coordinator;
55 public void remove(@NonNull InstanceIdentifier<Interface> instanceIdentifier, @NonNull Interface removedInterface) {
56 // HwVTEPs support only VXLAN
57 IfTunnel ifTunnel = removedInterface.augmentation(IfTunnel.class);
58 if (ifTunnel != null && ifTunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeVxlan.class)) {
59 ParentRefs parentRefs = removedInterface.augmentation(ParentRefs.class);
60 if (parentRefs != null && parentRefs.getNodeIdentifier() != null) {
61 LOG.debug("Received HwVTEP Interface Remove Event: {}", removedInterface.getName());
62 LOG.trace("Received HwVTEP Interface Remove Event: {}", removedInterface);
63 for (NodeIdentifier nodeIdentifier : parentRefs.getNodeIdentifier()) {
64 if (SouthboundUtils.HWVTEP_TOPOLOGY.equals(nodeIdentifier.getTopologyId())) {
65 coordinator.enqueueJob(removedInterface.getName(), () -> HwVTEPConfigRemoveHelper
66 .removeConfiguration(txRunner, removedInterface,
67 createPhysicalSwitchInstanceIdentifier(
68 nodeIdentifier.getNodeId()),
69 createGlobalNodeInstanceIdentifier(
70 nodeIdentifier.getNodeId())),
71 IfmConstants.JOB_MAX_RETRIES);
79 public void update(@NonNull InstanceIdentifier<Interface> instanceIdentifier, @NonNull Interface originalInterface,
80 @NonNull Interface updatedInterface) {
81 // HwVTEPs support only VXLAN
82 IfTunnel ifTunnel = originalInterface.augmentation(IfTunnel.class);
83 if (ifTunnel != null && ifTunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeVxlan.class)) {
84 ParentRefs parentRefs = originalInterface.augmentation(ParentRefs.class);
85 if (parentRefs != null && parentRefs.getNodeIdentifier() != null) {
86 LOG.debug("Received HwVTEP Interface Update Event: {}", originalInterface.getName());
87 LOG.trace("Received HwVTEP Interface Update Event: updatedInterface: {}, OriginalInterface: {}",
88 updatedInterface, originalInterface);
89 for (NodeIdentifier nodeIdentifier : parentRefs.getNodeIdentifier()) {
90 if (SouthboundUtils.HWVTEP_TOPOLOGY.equals(nodeIdentifier.getTopologyId())) {
91 coordinator.enqueueJob(originalInterface.getName(), () -> HwVTEPInterfaceConfigUpdateHelper
92 .updateConfiguration(txRunner,
93 createPhysicalSwitchInstanceIdentifier(nodeIdentifier.getNodeId()),
94 createGlobalNodeInstanceIdentifier(nodeIdentifier.getNodeId()),
95 updatedInterface, ifTunnel), IfmConstants.JOB_MAX_RETRIES);
103 public void add(@NonNull InstanceIdentifier<Interface> instanceIdentifier, @NonNull Interface newInterface) {
104 // HwVTEPs support only VXLAN
105 IfTunnel ifTunnel = newInterface.augmentation(IfTunnel.class);
106 if (ifTunnel != null && ifTunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeVxlan.class)) {
107 ParentRefs parentRefs = newInterface.augmentation(ParentRefs.class);
108 if (parentRefs != null && parentRefs.getNodeIdentifier() != null) {
109 LOG.debug("Received HwVTEP Interface Add Event: {}", newInterface.getName());
110 LOG.trace("Received HwVTEP Interface Add Event: {}", newInterface);
111 for (NodeIdentifier nodeIdentifier : parentRefs.getNodeIdentifier()) {
112 if (SouthboundUtils.HWVTEP_TOPOLOGY.equals(nodeIdentifier.getTopologyId())) {
113 coordinator.enqueueJob(newInterface.getName(), () -> HwVTEPInterfaceConfigAddHelper
114 .addConfiguration(txRunner,
115 createPhysicalSwitchInstanceIdentifier(nodeIdentifier.getNodeId()),
116 createGlobalNodeInstanceIdentifier(nodeIdentifier.getNodeId()),
117 newInterface, ifTunnel), IfmConstants.JOB_MAX_RETRIES);