Search in sources :

Example 51 with Identifier

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Identifier in project netvirt by opendaylight.

the class VpnInterfaceManager method addVpnInterfaceToVpn.

private void addVpnInterfaceToVpn(final InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier, final VpnInterface vpnInterface, final List<Adjacency> oldAdjs, final List<Adjacency> newAdjs, final InstanceIdentifier<VpnInterface> identifier, String vpnName) {
    final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
    final String interfaceName = key.getName();
    String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
    if (!VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
        Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceName);
        boolean isBgpVpnInternetVpn = VpnUtil.isBgpVpnInternet(dataBroker, vpnName);
        if (interfaceState != null) {
            try {
                final BigInteger dpnId = InterfaceUtils.getDpIdFromInterface(interfaceState);
                final int ifIndex = interfaceState.getIfIndex();
                jobCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName, () -> {
                    WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
                    WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
                    WriteTransaction writeInvTxn = dataBroker.newWriteOnlyTransaction();
                    LOG.info("addVpnInterface: VPN Interface add event - intfName {} vpnName {} on dpn {}", vpnInterface.getName(), vpnName, vpnInterface.getDpnId());
                    processVpnInterfaceUp(dpnId, vpnInterface, primaryRd, ifIndex, false, writeConfigTxn, writeOperTxn, writeInvTxn, interfaceState, vpnName);
                    if (oldAdjs != null && !oldAdjs.equals(newAdjs)) {
                        LOG.info("addVpnInterface: Adjacency changed upon VPNInterface {}" + " Update for swapping VPN {} case.", interfaceName, vpnName);
                        if (newAdjs != null) {
                            for (Adjacency adj : newAdjs) {
                                if (oldAdjs.contains(adj)) {
                                    oldAdjs.remove(adj);
                                } else {
                                    if (!isBgpVpnInternetVpn || VpnUtil.isAdjacencyEligibleToVpnInternet(dataBroker, adj)) {
                                        addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adj, dpnId, writeOperTxn, writeConfigTxn);
                                    }
                                }
                            }
                        }
                        for (Adjacency adj : oldAdjs) {
                            if (!isBgpVpnInternetVpn || VpnUtil.isAdjacencyEligibleToVpnInternet(dataBroker, adj)) {
                                delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId, writeOperTxn, writeConfigTxn);
                            }
                        }
                    }
                    ListenableFuture<Void> operFuture = writeOperTxn.submit();
                    try {
                        operFuture.get();
                    } catch (ExecutionException e) {
                        LOG.error("addVpnInterface: Exception encountered while submitting operational future for" + " addVpnInterface {} on vpn {}", vpnInterface.getName(), vpnName, e);
                        return null;
                    }
                    List<ListenableFuture<Void>> futures = new ArrayList<>();
                    ListenableFuture<Void> configFuture = writeConfigTxn.submit();
                    futures.add(configFuture);
                    Futures.addCallback(configFuture, new PostVpnInterfaceWorker(interfaceName, true, "Config"));
                    futures.add(writeInvTxn.submit());
                    LOG.info("addVpnInterface: Addition of interface {} in VPN {} on dpn {}" + " processed successfully", interfaceName, vpnName, dpnId);
                    return futures;
                });
            } catch (NumberFormatException | IllegalStateException e) {
                LOG.error("addVpnInterface: Unable to retrieve dpnId from interface operational data store for " + "interface {}. Interface addition on vpn {} failed", interfaceName, vpnName, e);
                return;
            }
        } else if (Boolean.TRUE.equals(vpnInterface.isRouterInterface())) {
            jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterface.getName(), () -> {
                WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
                createFibEntryForRouterInterface(primaryRd, vpnInterface, interfaceName, writeConfigTxn, vpnName);
                LOG.info("addVpnInterface: Router interface {} for vpn {} on dpn {}", interfaceName, vpnName, vpnInterface.getDpnId());
                ListenableFuture<Void> futures = writeConfigTxn.submit();
                String errorText = "addVpnInterfaceCall: Exception encountered while submitting writeConfigTxn" + " for interface " + vpnInterface.getName() + " on vpn " + vpnName;
                ListenableFutures.addErrorLogging(futures, LOG, errorText);
                return Collections.singletonList(futures);
            });
        } else {
            LOG.info("addVpnInterface: Handling addition of VPN interface {} on vpn {} skipped as interfaceState" + " is not available", interfaceName, vpnName);
        }
    } else {
        LOG.error("addVpnInterface: Handling addition of VPN interface {} on vpn {} dpn {} skipped" + " as vpn is pending delete", interfaceName, vpnName, vpnInterface.getDpnId());
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ArrayList(java.util.ArrayList) VpnInterfaceKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) ExecutionException(java.util.concurrent.ExecutionException) RouterInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.RouterInterface) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)

Example 52 with Identifier

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Identifier in project netvirt by opendaylight.

the class VpnInterfaceManager method addVpnInterface.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void addVpnInterface(final InstanceIdentifier<VpnInterface> identifier, final VpnInterface vpnInterface, final List<Adjacency> oldAdjs, final List<Adjacency> newAdjs) {
    for (VpnInstanceNames vpnInterfaceVpnInstance : vpnInterface.getVpnInstanceNames()) {
        String vpnName = vpnInterfaceVpnInstance.getVpnName();
        addVpnInterfaceCall(identifier, vpnInterface, oldAdjs, newAdjs, vpnName);
    }
}
Also used : VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames)

Example 53 with Identifier

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Identifier in project netvirt by opendaylight.

the class VpnInterfaceOpListener method remove.

@Override
protected void remove(final InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, final VpnInterfaceOpDataEntry del) {
    final VpnInterfaceOpDataEntryKey key = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class, VpnInterfaceOpDataEntryKey.class);
    final String interfaceName = key.getName();
    jobCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName, () -> {
        WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
        postProcessVpnInterfaceRemoval(identifier, del, writeOperTxn);
        List<ListenableFuture<Void>> futures = new ArrayList<>();
        futures.add(writeOperTxn.submit());
        LOG.info("remove: Removed vpn operational data for interface {} on dpn {} vpn {}", del.getName(), del.getDpnId(), del.getVpnInstanceName());
        return futures;
    });
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) VpnInterfaceOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryKey) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 54 with Identifier

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Identifier in project netvirt by opendaylight.

the class FibEntriesListener method add.

@Override
protected void add(InstanceIdentifier<VrfEntry> identifier, VrfEntry add) {
    LOG.trace("Add Vrf Entry event - Key : {}, value : {}", identifier, add);
    final VrfTablesKey key = identifier.firstKeyOf(VrfTables.class, VrfTablesKey.class);
    String rd = key.getRouteDistinguisher();
    addLabelToVpnInstance(rd, add.getRoutePaths());
}
Also used : VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)

Example 55 with Identifier

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Identifier in project netvirt by opendaylight.

the class InterfaceStateChangeListener method update.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
    final String ifName = update.getName();
    try {
        OperStatus originalOperStatus = original.getOperStatus();
        OperStatus updateOperStatus = update.getOperStatus();
        if (originalOperStatus.equals(Interface.OperStatus.Unknown) || updateOperStatus.equals(Interface.OperStatus.Unknown)) {
            LOG.debug("Interface {} state change is from/to null/UNKNOWN. Ignoring the update event.", ifName);
            return;
        }
        if (update.getIfIndex() == null) {
            return;
        }
        if (L2vlan.class.equals(update.getType())) {
            LOG.info("VPN Interface update event - intfName {} from InterfaceStateChangeListener", update.getName());
            jobCoordinator.enqueueJob("VPNINTERFACE-" + ifName, () -> {
                List<ListenableFuture<Void>> futures = new ArrayList<>(3);
                futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeOperTxn -> {
                    futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeConfigTxn -> {
                        futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
                            final VpnInterface vpnIf = VpnUtil.getConfiguredVpnInterface(dataBroker, ifName);
                            if (vpnIf != null) {
                                final int ifIndex = update.getIfIndex();
                                BigInteger dpnId = BigInteger.ZERO;
                                try {
                                    dpnId = InterfaceUtils.getDpIdFromInterface(update);
                                } catch (Exception e) {
                                    LOG.error("remove: Unable to retrieve dpnId for interface {}", ifName, e);
                                    return;
                                }
                                if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
                                    for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.getVpnInstanceNames()) {
                                        String vpnName = vpnInterfaceVpnInstance.getVpnName();
                                        String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
                                        if (!vpnInterfaceManager.isVpnInstanceReady(vpnName)) {
                                            LOG.error("VPN Interface update event - intfName {} onto vpnName {} " + "running oper-driven UP, VpnInstance not ready," + " holding on", vpnIf.getName(), vpnName);
                                        } else if (VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
                                            LOG.error("update: Ignoring UP event for vpnInterface {}, as " + "vpnInstance {} with primaryRd {} is already marked for" + " deletion", vpnIf.getName(), vpnName, primaryRd);
                                        } else {
                                            vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnIf, primaryRd, ifIndex, true, writeConfigTxn, writeOperTxn, writeInvTxn, update, vpnName);
                                        }
                                    }
                                } else if (update.getOperStatus().equals(Interface.OperStatus.Down)) {
                                    for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.getVpnInstanceNames()) {
                                        String vpnName = vpnInterfaceVpnInstance.getVpnName();
                                        LOG.info("VPN Interface update event - intfName {} onto vpnName {}" + " running oper-driven DOWN", vpnIf.getName(), vpnName);
                                        Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.getVpnInterfaceOpDataEntry(dataBroker, vpnIf.getName(), vpnName);
                                        if (optVpnInterface.isPresent()) {
                                            VpnInterfaceOpDataEntry vpnOpInterface = optVpnInterface.get();
                                            vpnInterfaceManager.processVpnInterfaceDown(dpnId, vpnIf.getName(), ifIndex, update.getPhysAddress().getValue(), vpnOpInterface, true, writeConfigTxn, writeOperTxn, writeInvTxn);
                                        } else {
                                            LOG.error("InterfaceStateChangeListener Update DOWN - vpnInterface {}" + " not available, ignoring event", vpnIf.getName());
                                            continue;
                                        }
                                    }
                                }
                            } else {
                                LOG.debug("Interface {} is not a vpninterface, ignoring.", ifName);
                            }
                        }));
                    }));
                }));
                return futures;
            });
        }
    } catch (Exception e) {
        LOG.error("Exception observed in handling updation of VPN Interface {}. ", update.getName(), e);
    }
}
Also used : InterfacesState(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) InterfaceUtils(org.opendaylight.netvirt.vpnmanager.api.InterfaceUtils) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) Optional(com.google.common.base.Optional) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) BigInteger(java.math.BigInteger) Logger(org.slf4j.Logger) OperStatus(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) AsyncDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) FutureCallback(com.google.common.util.concurrent.FutureCallback) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) L2vlan(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) PostConstruct(javax.annotation.PostConstruct) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BigInteger(java.math.BigInteger) OperStatus(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)

Aggregations

Identifier (org.apache.cxf.ws.rm.v200702.Identifier)72 ArrayList (java.util.ArrayList)57 BigInteger (java.math.BigInteger)55 Test (org.junit.Test)52 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)35 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)30 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)29 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)25 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)23 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)19 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)19 ElanInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance)16 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)14 List (java.util.List)13 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)13 VpnInterfaceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)13 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)12 L2GatewayDevice (org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)11 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)10 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)10