*/
package org.opendaylight.netvirt.natservice.internal;
-import com.google.common.base.Optional;
-import java.math.BigInteger;
-import javax.annotation.PostConstruct;
+import java.util.Optional;
+import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames;
+import org.opendaylight.infrautils.utils.concurrent.Executors;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.router.interfaces.RouterInterface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
public class NatInterfaceStateChangeListener
- extends AsyncDataTreeChangeListenerBase<Interface, NatInterfaceStateChangeListener> {
+ extends AbstractAsyncDataTreeChangeListener<Interface> {
private static final Logger LOG = LoggerFactory.getLogger(NatInterfaceStateChangeListener.class);
private final DataBroker dataBroker;
@Inject
public NatInterfaceStateChangeListener(final DataBroker dataBroker,
final NatSouthboundEventHandlers southboundEventHandlers) {
- super(Interface.class, NatInterfaceStateChangeListener.class);
+ super(dataBroker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class),
+ Executors.newListeningSingleThreadExecutor("NatInterfaceStateChangeListener", LOG));
this.dataBroker = dataBroker;
this.southboundEventHandlers = southboundEventHandlers;
}
- @Override
- @PostConstruct
public void init() {
LOG.info("{} init", getClass().getSimpleName());
- registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
- }
-
- @Override
- protected InstanceIdentifier<Interface> getWildCardPath() {
- return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
}
@Override
- protected NatInterfaceStateChangeListener getDataTreeChangeListener() {
- return NatInterfaceStateChangeListener.this;
+ @PreDestroy
+ public void close() {
+ super.close();
+ Executors.shutdownAndAwaitTermination(getExecutorService());
}
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
- protected void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
+ public void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
LOG.trace("add : Interface {} up event received", intrf);
if (!L2vlan.class.equals(intrf.getType())) {
LOG.debug("add : Interface {} is not Vlan Interface.Ignoring", intrf.getName());
return;
}
String interfaceName = intrf.getName();
- BigInteger intfDpnId;
+ Uint64 intfDpnId;
try {
intfDpnId = NatUtil.getDpIdFromInterface(intrf);
} catch (Exception e) {
LOG.error("add : Exception occured while retriving dpnid for interface {}", intrf.getName(), e);
return;
}
- if (BigInteger.ZERO.equals(intfDpnId)) {
+ if (Uint64.ZERO.equals(intfDpnId)) {
LOG.warn("add : Could not retrieve dp id for interface {} ", interfaceName);
return;
}
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
- protected void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
+ public void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
LOG.trace("remove : Interface {} removed event received", intrf);
if (!L2vlan.class.equals(intrf.getType())) {
LOG.debug("remove : Interface {} is not Vlan Interface.Ignoring", intrf.getName());
return;
}
String interfaceName = intrf.getName();
- BigInteger intfDpnId = BigInteger.ZERO;
+ Uint64 intfDpnId = Uint64.ZERO;
try {
intfDpnId = NatUtil.getDpIdFromInterface(intrf);
} catch (Exception e) {
LOG.warn("remove : Interface {} is not a VPN Interface, ignoring.", interfaceName);
return;
}
- for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().nonnullVpnInstanceNames()) {
+ for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().nonnullVpnInstanceNames().values()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = NatUtil
.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
}
}
}
- if (BigInteger.ZERO.equals(intfDpnId)) {
+ if (Uint64.ZERO.equals(intfDpnId)) {
LOG.warn("remove : Could not retrieve dpnid for interface {} ", interfaceName);
return;
}
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
- protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
+ public void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
LOG.trace("update : Operation Interface update event - Old: {}, New: {}", original, update);
if (!L2vlan.class.equals(update.getType())) {
LOG.debug("update : Interface {} is not Vlan Interface.Ignoring", update.getName());
return;
}
- BigInteger intfDpnId = BigInteger.ZERO;
+ Uint64 intfDpnId = Uint64.ZERO;
String interfaceName = update.getName();
try {
intfDpnId = NatUtil.getDpIdFromInterface(update);
LOG.warn("update : Interface {} is not a VPN Interface, ignoring.", interfaceName);
return;
}
- for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().nonnullVpnInstanceNames()) {
+ for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().nonnullVpnInstanceNames().values()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = NatUtil
.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
}
}
}
- if (BigInteger.ZERO.equals(intfDpnId)) {
+ if (Uint64.ZERO.equals(intfDpnId)) {
LOG.warn("remove : Could not retrieve dpnid for interface {} ", interfaceName);
return;
}