Search in sources :

Example 6 with VpnInstanceNames

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.

the class InterfaceStateChangeListener method remove.

@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
    final String ifName = intrf.getName();
    BigInteger dpId = BigInteger.ZERO;
    try {
        if (L2vlan.class.equals(intrf.getType())) {
            LOG.info("VPN Interface remove event - intfName {} from InterfaceStateChangeListener", intrf.getName());
            try {
                dpId = InterfaceUtils.getDpIdFromInterface(intrf);
            } catch (Exception e) {
                LOG.error("Unable to retrieve dpnId from interface operational data store for interface" + " {}. Fetching from vpn interface op data store. ", ifName, e);
            }
            final BigInteger inputDpId = dpId;
            jobCoordinator.enqueueJob("VPNINTERFACE-" + ifName, () -> {
                List<ListenableFuture<Void>> futures = new ArrayList<>(3);
                ListenableFuture<Void> configFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeConfigTxn -> {
                    futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeOperTxn -> {
                        futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
                            VpnInterface cfgVpnInterface = VpnUtil.getConfiguredVpnInterface(dataBroker, ifName);
                            if (cfgVpnInterface == null) {
                                LOG.debug("Interface {} is not a vpninterface, ignoring.", ifName);
                                return;
                            }
                            for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.getVpnInstanceNames()) {
                                String vpnName = vpnInterfaceVpnInstance.getVpnName();
                                Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.getVpnInterfaceOpDataEntry(dataBroker, ifName, vpnName);
                                if (!optVpnInterface.isPresent()) {
                                    LOG.debug("Interface {} vpn {} is not a vpninterface, or deletion" + " triggered by northbound agent. ignoring.", ifName, vpnName);
                                    continue;
                                }
                                final VpnInterfaceOpDataEntry vpnInterface = optVpnInterface.get();
                                String gwMac = intrf.getPhysAddress() != null ? intrf.getPhysAddress().getValue() : vpnInterface.getGatewayMacAddress();
                                BigInteger dpnId = inputDpId;
                                if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
                                    dpnId = vpnInterface.getDpnId();
                                }
                                final int ifIndex = intrf.getIfIndex();
                                LOG.info("VPN Interface remove event - intfName {} onto vpnName {}" + " running oper-driver", vpnInterface.getName(), vpnName);
                                vpnInterfaceManager.processVpnInterfaceDown(dpnId, ifName, ifIndex, gwMac, vpnInterface, false, writeConfigTxn, writeOperTxn, writeInvTxn);
                            }
                        }));
                    }));
                });
                futures.add(configFuture);
                Futures.addCallback(configFuture, new PostVpnInterfaceThreadWorker(intrf.getName(), false, "Operational"));
                return futures;
            }, DJC_MAX_RETRIES);
        }
    } catch (Exception e) {
        LOG.error("Exception observed in handling deletion of VPN Interface {}. ", ifName, 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) ArrayList(java.util.ArrayList) 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) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)

Example 7 with VpnInstanceNames

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.

the class SubnetRouteInterfaceStateChangeListener method remove.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
    try {
        if (L2vlan.class.equals(intrf.getType())) {
            LOG.trace("SubnetRouteInterfaceListener remove: Received interface {} down event", intrf);
            List<Uuid> subnetIdList = getSubnetId(intrf);
            if (subnetIdList.isEmpty()) {
                LOG.trace("SubnetRouteInterfaceListener remove: Port {} doesn't exist in configDS", intrf.getName());
                return;
            }
            for (Uuid subnetId : subnetIdList) {
                jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId, () -> {
                    String interfaceName = intrf.getName();
                    BigInteger dpnId = BigInteger.ZERO;
                    LOG.info("{} remove: Received port DOWN event for interface {} in subnet {} ", LOGGING_PREFIX, interfaceName, subnetId);
                    try {
                        dpnId = InterfaceUtils.getDpIdFromInterface(intrf);
                    } catch (Exception e) {
                        LOG.error("{} remove: Unable to retrieve dpnId for interface {} in subnet {}. " + "Fetching from vpn interface itself", LOGGING_PREFIX, intrf.getName(), subnetId, e);
                    }
                    InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
                    Optional<VpnInterface> cfgVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
                    List<ListenableFuture<Void>> futures = new ArrayList<>();
                    if (!cfgVpnInterface.isPresent()) {
                        return futures;
                    }
                    boolean interfaceDownEligible = false;
                    for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().getVpnInstanceNames()) {
                        String vpnName = vpnInterfaceVpnInstance.getVpnName();
                        InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
                        Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, idOper);
                        if (optVpnInterface.isPresent()) {
                            BigInteger dpnIdLocal = dpnId;
                            if (dpnIdLocal.equals(BigInteger.ZERO)) {
                                dpnIdLocal = optVpnInterface.get().getDpnId();
                            }
                            if (!dpnIdLocal.equals(BigInteger.ZERO)) {
                                interfaceDownEligible = true;
                                break;
                            }
                        }
                    }
                    if (interfaceDownEligible) {
                        vpnSubnetRouteHandler.onInterfaceDown(dpnId, intrf.getName(), subnetId);
                    }
                    return futures;
                });
            }
        }
        LOG.info("{} remove: Processed interface {} down event in ", LOGGING_PREFIX, intrf.getName());
    } catch (Exception e) {
        LOG.error("{} remove: Exception observed in handling deletion of VPN Interface {}.", LOGGING_PREFIX, intrf.getName(), e);
    }
}
Also used : ArrayList(java.util.ArrayList) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) 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) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)

Example 8 with VpnInstanceNames

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.

the class InterfaceStateEventListener method getRouterIdForPort.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private String getRouterIdForPort(String interfaceName) {
    String routerName = null;
    VpnInterface vpnInterface = null;
    try {
        vpnInterface = NatUtil.getConfiguredVpnInterface(dataBroker, interfaceName);
    } catch (Exception ex) {
        LOG.error("getRouterIdForPort : Unable to process for interface {} as it is not configured", interfaceName, ex);
    }
    if (vpnInterface != null) {
        // getVpnName
        if (vpnInterface.getVpnInstanceNames() == null) {
            LOG.debug("getRouterIdForPort : vpnName not found for vpnInterface {} of port {}", vpnInterface, interfaceName);
        } else {
            for (VpnInstanceNames vpnInstance : vpnInterface.getVpnInstanceNames()) {
                String vpnName = vpnInstance.getVpnName();
                try {
                    routerName = NatUtil.getRouterIdfromVpnInstance(dataBroker, vpnName);
                } catch (Exception e) {
                    LOG.error("getRouterIdForPort : Unable to get routerId for vpnName {}", vpnName, e);
                }
                if (routerName != null) {
                    // check router is associated to external network
                    if (NatUtil.isSnatEnabledForRouterId(dataBroker, routerName)) {
                        LOG.debug("getRouterIdForPort : Retreived Router Id {} for vpnname {} " + "associated to interface {}", routerName, vpnName, interfaceName);
                        return routerName;
                    } else {
                        LOG.warn("getRouterIdForPort : Interface {} associated to routerId {} is not " + "associated to external network", interfaceName, routerName);
                    }
                } else {
                    LOG.warn("getRouterIdForPort : Router is not associated to vpnname {} for interface {}", vpnName, interfaceName);
                }
            }
        }
    } else {
        LOG.debug("getRouterIdForPort : Interface {} is not a vpninterface", interfaceName);
    }
    return null;
}
Also used : 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) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with VpnInstanceNames

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.

the class ShowVpn method doExecute.

@Override
protected Object doExecute() {
    Map<String, Integer> vpnNameToConfigInterfaceMap = new HashMap<>();
    Map<String, Integer> vpnNameToOperInterfaceMap = new HashMap<>();
    if (detail == null) {
        showVpn();
        Set<String> vpnInstances = new HashSet();
        for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
            for (VpnInstanceNames vpnInterfaceVpnInstance : vpnInterface.getVpnInstanceNames()) {
                String vpnName = vpnInterfaceVpnInstance.getVpnName();
                if (vpnName != null) {
                    vpnInstances.add(vpnName);
                }
            }
        }
        for (String routerId : vpnInstances) {
            ifPresent = vpnNameToConfigInterfaceMap.get(routerId);
            if (ifPresent == null) {
                vpnNameToConfigInterfaceMap.put(routerId, 1);
            } else {
                vpnNameToConfigInterfaceMap.put(routerId, vpnNameToConfigInterfaceMap.get(routerId) + 1);
            }
        }
        for (VpnInterfaceOpDataEntry vpnInterfaceOp : vpnInterfaceOpList) {
            ifPresent = vpnNameToOperInterfaceMap.get(vpnInterfaceOp.getVpnInstanceName());
            if (ifPresent == null) {
                vpnNameToOperInterfaceMap.put(vpnInterfaceOp.getVpnInstanceName(), 1);
            } else {
                vpnNameToOperInterfaceMap.put(vpnInterfaceOp.getVpnInstanceName(), vpnNameToOperInterfaceMap.get(vpnInterfaceOp.getVpnInstanceName()) + 1);
            }
        }
        session.getConsole().println("-----------------------------------------------------------------------");
        session.getConsole().println(String.format("         %s   %14s  %5s  %5s", "VpnInstanceName", "RD", "Config Count", "Oper Count"));
        session.getConsole().println("\n-----------------------------------------------------------------------");
        for (VpnInstance vpnInstance : vpnInstanceList) {
            configCount = 0;
            operCount = 0;
            Integer count = vpnNameToConfigInterfaceMap.get(vpnInstance.getVpnInstanceName());
            if (count != null) {
                configCount = vpnNameToConfigInterfaceMap.get(vpnInstance.getVpnInstanceName());
                totalConfigCount = totalConfigCount + configCount;
            }
            count = vpnNameToOperInterfaceMap.get(vpnInstance.getVpnInstanceName());
            if (count != null) {
                operCount = vpnNameToOperInterfaceMap.get(vpnInstance.getVpnInstanceName());
                totalOperCount = totalOperCount + operCount;
            }
            VpnAfConfig addrFamily = vpnInstance.getIpv4Family() != null ? vpnInstance.getIpv4Family() : vpnInstance.getIpv6Family();
            session.getConsole().println(String.format("%-32s  %-10s  %-10s  %-10s", vpnInstance.getVpnInstanceName(), addrFamily.getRouteDistinguisher(), configCount, operCount));
        }
        session.getConsole().println("-----------------------------------------------------------------------");
        session.getConsole().println(String.format("Total Count:                    %19s    %8s", totalConfigCount, totalOperCount));
        session.getConsole().println(getshowVpnCLIHelp());
    } else {
        showVpn();
        session.getConsole().println("Present Config VpnInterfaces are:");
        for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
            if (VpnHelper.doesVpnInterfaceBelongToVpnInstance(detail, vpnInterface.getVpnInstanceNames())) {
                session.getConsole().println(vpnInterface.getName());
            }
        }
        session.getConsole().println("Present Oper VpnInterfaces are:");
        for (VpnInterfaceOpDataEntry vpnInterfaceOp : vpnInterfaceOpList) {
            if (vpnInterfaceOp.getVpnInstanceName().equals(detail)) {
                session.getConsole().println(vpnInterfaceOp.getName());
            }
        }
    }
    return null;
}
Also used : VpnAfConfig(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnAfConfig) 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) HashMap(java.util.HashMap) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) HashSet(java.util.HashSet)

Example 10 with VpnInstanceNames

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.

the class CloudScVpnInterfaceListener method add.

@Override
protected void add(InstanceIdentifier<VpnInterface> key, VpnInterface vpnIfaceAdded) {
    for (VpnInstanceNames vpnInstance : vpnIfaceAdded.getVpnInstanceNames()) {
        String vpnName = vpnInstance.getVpnName();
        if (!vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V4AndV6Subnets) && !vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V4Subnet)) {
            continue;
        }
        try {
            Optional<VpnToPseudoPortData> optScfInfoForVpn = vpnScHandler.getScfInfoForVpn(vpnName);
            if (!optScfInfoForVpn.isPresent()) {
                LOG.trace("Vpn {} is not related to ServiceChaining. No further action", vpnName);
                return;
            }
            vpnScHandler.bindScfOnVpnInterface(vpnIfaceAdded.getKey().getName(), optScfInfoForVpn.get().getScfTag());
        } catch (ReadFailedException e) {
            LOG.error("Error reading the SFC information for VPN {}", vpnName, e);
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) VpnToPseudoPortData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.cloud.servicechain.state.rev160711.vpn.to.pseudo.port.list.VpnToPseudoPortData)

Aggregations

VpnInstanceNames (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames)22 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)17 ArrayList (java.util.ArrayList)15 VpnInterfaceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)10 BigInteger (java.math.BigInteger)8 VpnInterfaceBuilder (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder)8 List (java.util.List)7 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)6 Adjacencies (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies)6 Optional (com.google.common.base.Optional)5 VpnInterfaceKey (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey)5 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)5 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)4 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)4 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)4 ManagedNewTransactionRunnerImpl (org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl)4 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)4