X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=dhcpservice%2Fdhcpservice-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Fdhcpservice%2FDhcpDesignatedDpnListener.java;fp=dhcpservice%2Fdhcpservice-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Fdhcpservice%2FDhcpDesignatedDpnListener.java;h=838cc46867863d5d2ddf30333f6254b3975b5ba4;hb=3e0f21d10b63d08737ce649b50c2412368147687;hp=0000000000000000000000000000000000000000;hpb=bc9a454112d4456fe65538bb887b3c0be0e3b5bc;p=vpnservice.git diff --git a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpDesignatedDpnListener.java b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpDesignatedDpnListener.java new file mode 100644 index 00000000..838cc468 --- /dev/null +++ b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpDesignatedDpnListener.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.vpnservice.dhcpservice; + +import java.math.BigInteger; +import java.util.List; + +import org.opendaylight.controller.md.sal.binding.api.ClusteredDataChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; +import org.opendaylight.vpnservice.datastoreutils.AsyncClusteredDataChangeListenerBase; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.dhcp.rev160428.DesignatedSwitchesForExternalTunnels; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.dhcp.rev160428.designated.switches._for.external.tunnels.DesignatedSwitchForTunnel; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DhcpDesignatedDpnListener extends AsyncClusteredDataChangeListenerBase implements AutoCloseable { + + private static final Logger LOG = LoggerFactory.getLogger(DhcpDesignatedDpnListener.class); + private ListenerRegistration listenerRegistration; + private DhcpExternalTunnelManager dhcpExternalTunnelManager; + private DataBroker broker; + + public DhcpDesignatedDpnListener(final DhcpExternalTunnelManager dhcpExternalTunnelManager, final DataBroker broker) { + super(DesignatedSwitchForTunnel.class, DhcpDesignatedDpnListener.class); + this.dhcpExternalTunnelManager = dhcpExternalTunnelManager; + this.broker = broker; + } + + @Override + public void close() throws Exception { + if (listenerRegistration != null) { + try { + listenerRegistration.close(); + } catch (final Exception e) { + LOG.error("Error when cleaning up DhcpDesignatedDpnListener.", e); + } + listenerRegistration = null; + } + LOG.debug("DhcpDesignatedDpnListener Listener Closed"); + } + + @Override + protected void remove(InstanceIdentifier identifier, DesignatedSwitchForTunnel del) { + dhcpExternalTunnelManager.removeFromLocalCache(BigInteger.valueOf(del.getDpId()), del.getTunnelRemoteIpAddress(), del.getElanInstanceName()); + dhcpExternalTunnelManager.unInstallDhcpFlowsForVms(del.getElanInstanceName(), del.getTunnelRemoteIpAddress(), DhcpServiceUtils.getListOfDpns(broker)); + } + + @Override + protected void update(InstanceIdentifier identifier, DesignatedSwitchForTunnel original, + DesignatedSwitchForTunnel update) { + BigInteger designatedDpnId = BigInteger.valueOf(update.getDpId()); + IpAddress tunnelRemoteIpAddress = update.getTunnelRemoteIpAddress(); + String elanInstanceName = update.getElanInstanceName(); + dhcpExternalTunnelManager.removeFromLocalCache(BigInteger.valueOf(original.getDpId()), original.getTunnelRemoteIpAddress(), original.getElanInstanceName()); + dhcpExternalTunnelManager.updateLocalCache(designatedDpnId, tunnelRemoteIpAddress, elanInstanceName); +/* List elanDpns = DhcpServiceUtils.getDpnsForElan(elanInstanceName, broker); + if (elanDpns == null || elanDpns.isEmpty()) { + dhcpExternalTunnelManager.installRemoteMcastMac(designatedDpnId, tunnelRemoteIpAddress, elanInstanceName); + }*/ + } + + @Override + protected void add(InstanceIdentifier identifier, DesignatedSwitchForTunnel add) { + BigInteger designatedDpnId = BigInteger.valueOf(add.getDpId()); + IpAddress tunnelRemoteIpAddress = add.getTunnelRemoteIpAddress(); + String elanInstanceName = add.getElanInstanceName(); + dhcpExternalTunnelManager.updateLocalCache(designatedDpnId, tunnelRemoteIpAddress, elanInstanceName); +/* List elanDpns = DhcpServiceUtils.getDpnsForElan(elanInstanceName, broker); + if (elanDpns == null || elanDpns.isEmpty()) { + dhcpExternalTunnelManager.installRemoteMcastMac(designatedDpnId, tunnelRemoteIpAddress, elanInstanceName); + }*/ + } + + @Override + protected InstanceIdentifier getWildCardPath() { + return InstanceIdentifier.create(DesignatedSwitchesForExternalTunnels.class).child(DesignatedSwitchForTunnel.class); + } + + @Override + protected ClusteredDataChangeListener getDataChangeListener() { + return DhcpDesignatedDpnListener.this; + } + + @Override + protected DataChangeScope getDataChangeScope() { + return AsyncDataBroker.DataChangeScope.SUBTREE; + } +}