2 * Copyright © 2017 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.netvirt.cloudservicechain.listeners;
10 import java.util.Optional;
11 import javax.annotation.PostConstruct;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.netvirt.cloudservicechain.VPNServiceChainHandler;
18 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces;
19 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
20 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames;
21 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames.AssociatedSubnetType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.cloud.servicechain.state.rev160711.vpn.to.pseudo.port.list.VpnToPseudoPortData;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 public class CloudScVpnInterfaceListener
29 extends AsyncDataTreeChangeListenerBase<VpnInterface, CloudScVpnInterfaceListener> {
31 private static final Logger LOG = LoggerFactory.getLogger(CloudScVpnInterfaceListener.class);
32 private final DataBroker dataBroker;
33 private final VPNServiceChainHandler vpnScHandler;
36 public CloudScVpnInterfaceListener(final DataBroker dataBroker, final VPNServiceChainHandler vpnScHandler) {
37 super(VpnInterface.class, CloudScVpnInterfaceListener.class);
39 this.dataBroker = dataBroker;
40 this.vpnScHandler = vpnScHandler;
46 LOG.info("{} init", getClass().getSimpleName());
47 registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
51 protected CloudScVpnInterfaceListener getDataTreeChangeListener() {
52 return CloudScVpnInterfaceListener.this;
56 protected InstanceIdentifier<VpnInterface> getWildCardPath() {
57 return InstanceIdentifier.create(VpnInterfaces.class).child(VpnInterface.class);
61 protected void remove(InstanceIdentifier<VpnInterface> key, VpnInterface vpnIfaceRemoved) {
62 for (VpnInstanceNames vpnInstance : vpnIfaceRemoved.getVpnInstanceNames()) {
63 String vpnName = vpnInstance.getVpnName();
64 if (!vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V4AndV6Subnets)
65 && !vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V4Subnet)) {
69 Optional<VpnToPseudoPortData> optScfInfoForVpn = vpnScHandler.getScfInfoForVpn(vpnName);
70 if (!optScfInfoForVpn.isPresent()) {
71 LOG.trace("Vpn {} is not related to ServiceChaining. No further action", vpnName);
74 } catch (InterruptedException | ExecutionException e) {
75 LOG.error("Error reading the ServiceChaining information for VPN {}", vpnName, e);
79 vpnScHandler.unbindScfOnVpnInterface(vpnIfaceRemoved.key().getName());
83 protected void update(InstanceIdentifier<VpnInterface> key, VpnInterface dataObjectModificationBefore,
84 VpnInterface dataObjectModificationAfter) {
88 protected void add(InstanceIdentifier<VpnInterface> key, VpnInterface vpnIfaceAdded) {
89 for (VpnInstanceNames vpnInstance : vpnIfaceAdded.getVpnInstanceNames()) {
90 String vpnName = vpnInstance.getVpnName();
91 if (!vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V4AndV6Subnets)
92 && !vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V4Subnet)) {
96 Optional<VpnToPseudoPortData> optScfInfoForVpn = vpnScHandler.getScfInfoForVpn(vpnName);
97 if (!optScfInfoForVpn.isPresent()) {
98 LOG.trace("Vpn {} is not related to ServiceChaining. No further action", vpnName);
101 vpnScHandler.bindScfOnVpnInterface(vpnIfaceAdded.key().getName(),
102 optScfInfoForVpn.get().getScfTag());
103 } catch (InterruptedException | ExecutionException e) {
104 LOG.error("Error reading the ServiceChaining information for VPN {}", vpnName, e);