X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=dhcpservice%2Fdhcpservice-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Fdhcpservice%2FDhcpUCastMacListener.java;fp=dhcpservice%2Fdhcpservice-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Fdhcpservice%2FDhcpUCastMacListener.java;h=472414eca8bcea1233c99008f045b9cdc3f2b8a4;hb=9909ff254706d57ff52ced55f83e2859257b7d6d;hp=0000000000000000000000000000000000000000;hpb=104b4cbca46f5a218ac21ef2655bb7947863bfce;p=vpnservice.git diff --git a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpUCastMacListener.java b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpUCastMacListener.java new file mode 100644 index 00000000..472414ec --- /dev/null +++ b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpUCastMacListener.java @@ -0,0 +1,112 @@ +/* + * 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 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.DataChangeScope; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.elanmanager.utils.ElanL2GwCacheUtils; +import org.opendaylight.vpnservice.datastoreutils.AsyncClusteredDataChangeListenerBase; +import org.opendaylight.vpnservice.mdsalutil.MDSALUtil; +import org.opendaylight.vpnservice.neutronvpn.api.l2gw.L2GatewayDevice; +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.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Optional; + +public class DhcpUCastMacListener extends AsyncClusteredDataChangeListenerBase implements AutoCloseable { + + private static final Logger logger = LoggerFactory.getLogger(DhcpUCastMacListener.class); + private DataBroker broker; + private ListenerRegistration listenerRegistration; + private DhcpExternalTunnelManager dhcpExternalTunnelManager; + + public DhcpUCastMacListener(DhcpExternalTunnelManager dhcpManager, DataBroker dataBroker) { + super(LocalUcastMacs.class, DhcpUCastMacListener.class); + this.broker = dataBroker; + this.dhcpExternalTunnelManager = dhcpManager; + } + + @Override + protected InstanceIdentifier getWildCardPath() { + return InstanceIdentifier.create(NetworkTopology.class).child(Topology.class).child(Node.class) + .augmentation(HwvtepGlobalAugmentation.class).child(LocalUcastMacs.class); + } + + @Override + public void close() throws Exception { + if (listenerRegistration != null) { + try { + listenerRegistration.close(); + } catch (final Exception e) { + logger.error("Error when cleaning up DataChangeListener.", e); + } + listenerRegistration = null; + } + logger.info("DhcpUCastMacListener Closed"); + } + + @Override + protected void remove(InstanceIdentifier identifier, + LocalUcastMacs del) { + // Flow removal for table 18 is handled in Neutron Port delete. + } + + @Override + protected void update(InstanceIdentifier identifier, + LocalUcastMacs original, LocalUcastMacs update) { + // TODO Auto-generated method stub + + } + + @Override + protected void add(InstanceIdentifier identifier, + LocalUcastMacs add) { + NodeId torNodeId = identifier.firstKeyOf(Node.class).getNodeId(); + InstanceIdentifier logicalSwitchRef = (InstanceIdentifier) add.getLogicalSwitchRef().getValue(); + Optional logicalSwitchOptional = MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL, logicalSwitchRef); + if ( !logicalSwitchOptional.isPresent() ) { + logger.error("Logical Switch ref doesn't have data {}", logicalSwitchRef); + return; + } + LogicalSwitches logicalSwitch = logicalSwitchOptional.get(); + String elanInstanceName = logicalSwitch.getHwvtepNodeName().getValue(); + L2GatewayDevice device = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanInstanceName, torNodeId.getValue()); + if (device == null) { + logger.error("Logical Switch Device with name {} is not present in L2GWCONN cache", elanInstanceName); + return; + } + IpAddress tunnelIp = device.getTunnelIp(); + BigInteger designatedDpnId = dhcpExternalTunnelManager.readDesignatedSwitchesForExternalTunnel(tunnelIp, elanInstanceName); + dhcpExternalTunnelManager.installDhcpFlowsForVms(tunnelIp, elanInstanceName, DhcpServiceUtils.getListOfDpns(broker), designatedDpnId, add.getMacEntryKey().getValue()); + } + + @Override + protected ClusteredDataChangeListener getDataChangeListener() { + return DhcpUCastMacListener.this; + } + + @Override + protected DataChangeScope getDataChangeScope() { + return DataChangeScope.SUBTREE; + } +} \ No newline at end of file