Search in sources :

Example 86 with ReadFailedException

use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project netvirt by opendaylight.

the class VpnToDpnListener method programVpnScfFlowsOnDpn.

private void programVpnScfFlowsOnDpn(BigInteger dpnId, String vpnName, String rd, int addOrRemove) {
    String addedOrRemovedTxt = addOrRemove == NwConstants.ADD_FLOW ? " added " : " removed";
    LOG.debug("DpnToVpn {} event received: dpn={}  vpn={}  rd={}", addedOrRemovedTxt, dpnId, vpnName, rd);
    if (dpnId == null) {
        LOG.warn("Dpn to Vpn {} event received, but no DPN specified in event", addedOrRemovedTxt);
        return;
    }
    if (vpnName == null) {
        LOG.warn("Dpn to Vpn {} event received, but no VPN specified in event", addedOrRemovedTxt);
        return;
    }
    if (rd == null) {
        LOG.warn("Dpn to Vpn {} event received, but no RD specified in event", addedOrRemovedTxt);
        return;
    }
    try {
        Optional<VpnToPseudoPortData> optVpnToPseudoPortInfo = VpnServiceChainUtils.getVpnPseudoPortData(broker, rd);
        if (!optVpnToPseudoPortInfo.isPresent()) {
            LOG.debug("Dpn to Vpn {} event received: Could not find VpnPseudoLportTag for VPN name={}  rd={}", addedOrRemovedTxt, vpnName, rd);
            return;
        }
        VpnToPseudoPortData vpnToPseudoPortInfo = optVpnToPseudoPortInfo.get();
        // Vpn2Scf flows (LFIB + LportDispatcher)
        // TODO: Should we filter out by bgp origin
        List<VrfEntry> allVpnVrfEntries = VpnServiceChainUtils.getAllVrfEntries(broker, rd);
        vpnScHandler.programVpnToScfPipelineOnDpn(dpnId, allVpnVrfEntries, vpnToPseudoPortInfo.getScfTableId(), vpnToPseudoPortInfo.getScfTag(), vpnToPseudoPortInfo.getVpnLportTag().intValue(), addOrRemove);
        // Scf2Vpn flow (LportDispatcher)
        long vpnId = addOrRemove == NwConstants.ADD_FLOW ? VpnServiceChainUtils.getVpnId(broker, vpnName) : CloudServiceChainConstants.INVALID_VPN_TAG;
        VpnServiceChainUtils.programLPortDispatcherFlowForScfToVpn(mdsalMgr, vpnId, dpnId, vpnToPseudoPortInfo.getVpnLportTag().intValue(), addOrRemove);
    } catch (ReadFailedException e) {
        LOG.error("Error retrieving the VPN to pseudo-port data for {}", rd, e);
    }
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) VpnToPseudoPortData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.cloud.servicechain.state.rev160711.vpn.to.pseudo.port.list.VpnToPseudoPortData)

Example 87 with ReadFailedException

use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project netvirt by opendaylight.

the class WeightedCentralizedSwitchScheduler method addToDpnMaps.

private void addToDpnMaps(String routerName, List<Uuid> addedSubnetIds, BigInteger primarySwitchId) {
    if (addedSubnetIds == null || addedSubnetIds.isEmpty()) {
        LOG.debug("addToDpnMaps no subnets associated with {}", routerName);
        return;
    }
    String primaryRd = NatUtil.getPrimaryRd(dataBroker, routerName);
    WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
    for (Uuid subnetUuid : addedSubnetIds) {
        try {
            Subnetmap subnetMapEntry = SingleTransactionDataBroker.syncRead(dataBroker, LogicalDatastoreType.CONFIGURATION, getSubnetMapIdentifier(subnetUuid));
            Uuid routerPortUuid = subnetMapEntry.getRouterInterfacePortId();
            subnetIdToRouterPortMap.put(subnetUuid.getValue(), routerPortUuid.getValue());
            vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, routerName, primaryRd, routerPortUuid.getValue(), null, true);
            NatUtil.addToNeutronRouterDpnsMap(dataBroker, routerName, routerPortUuid.getValue(), primarySwitchId, writeOperTxn);
            NatUtil.addToDpnRoutersMap(dataBroker, routerName, routerPortUuid.getValue(), primarySwitchId, writeOperTxn);
        } catch (ReadFailedException e) {
            LOG.error("addToDpnMaps failed for {}", routerName);
        }
    }
    writeOperTxn.submit();
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)

Example 88 with ReadFailedException

use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project netvirt by opendaylight.

the class UpgradeStateListener method update.

@Override
public void update(@Nonnull Config original, Config updated) {
    if (natMode != NatserviceConfig.NatMode.Conntrack) {
        return;
    }
    LOG.info("UpgradeStateListener update from {} to {}", original, updated);
    if (!(original.isUpgradeInProgress() && !updated.isUpgradeInProgress())) {
        return;
    }
    SingleTransactionDataBroker reader = new SingleTransactionDataBroker(dataBroker);
    ExtRouters routers;
    try {
        routers = reader.syncRead(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(ExtRouters.class));
    } catch (ReadFailedException e) {
        LOG.error("Error reading external routers", e);
        return;
    }
    for (Routers router : routers.getRouters()) {
        List<ExternalIps> externalIps = router.getExternalIps();
        if (router.isEnableSnat() && externalIps != null && !externalIps.isEmpty()) {
            centralizedSwitchScheduler.scheduleCentralizedSwitch(router);
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 89 with ReadFailedException

use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project netvirt by opendaylight.

the class ShowFibCommand method doExecute.

@Override
protected Object doExecute() {
    PrintStream console = session.getConsole();
    if (prefixOrSubnetOption != null && prefixOrSubnetOption.length() > 0) {
        prefixOrSubnet = prefixOrSubnetOption.replace("[", "");
        prefixOrSubnet = prefixOrSubnet.replace("]", "");
        if (prefixOrSubnet.indexOf("/") < 0) {
            String maskFull = null;
            try {
                Inet4Address tempAdd = (Inet4Address) InetAddress.getByName(prefixOrSubnet);
                maskFull = "/32";
            } catch (SecurityException | UnknownHostException | ClassCastException e) {
                maskFull = null;
            }
            if (maskFull == null) {
                try {
                    Inet6Address tempAdd = (Inet6Address) InetAddress.getByName(prefixOrSubnet);
                    maskFull = "/128";
                } catch (SecurityException | UnknownHostException | ClassCastException e) {
                    maskFull = null;
                }
            }
            if (maskFull == null) {
                console.println("a part of cli " + SUBNET + " is wrong => " + prefixOrSubnet);
                return usage(console);
            }
            prefixOrSubnet += maskFull;
        }
    }
    console.println(HEADER);
    if (options == null && prefixOrSubnet == null && (addrFamList == null || addrFamList.isEmpty())) {
        InstanceIdentifier<FibEntries> id = InstanceIdentifier.create(FibEntries.class);
        try {
            FibEntries fibEntries = singleTxDb.syncRead(LogicalDatastoreType.CONFIGURATION, id);
            List<VrfTables> vrfTablesList = fibEntries.getVrfTables();
            if (vrfTablesList == null || vrfTablesList.isEmpty()) {
                console.println(" No Fib entries found");
                return null;
            }
            for (VrfTables vrfTable : vrfTablesList) {
                printVrfTable(vrfTable, console);
            }
        } catch (ExpectedDataObjectNotFoundException e404) {
            String errMsg = "FATAL: fib-entries container is missing from MD-SAL";
            console.println("\n" + errMsg);
            LOG.error(errMsg, e404);
        } catch (ReadFailedException rfe) {
            String errMsg = "Internal Error occurred while processing vpnservice:fib-show command";
            console.println("\n" + errMsg);
            LOG.error(errMsg, rfe);
        }
        return null;
    } else {
        String optionsLowerCase = options != null ? options.toLowerCase(Locale.getDefault()) : "";
        switch(optionsLowerCase) {
            case "fullhelp":
                return usage(console);
            default:
        }
        if ((addrFamList == null || addrFamList.isEmpty()) && (prefixOrSubnet == null || prefixOrSubnet.indexOf("/") < 5)) {
            console.println("any address family is requiered or " + SUBNET + " is wrong");
            usage(console);
        } else {
            boolean isIpv4 = false;
            boolean isIpv6 = false;
            boolean isL2vpn = false;
            if (addrFamList != null && addrFamList.size() > 0) {
                for (String addF : addrFamList) {
                    switch(addF.toLowerCase(Locale.getDefault())) {
                        case "ipv4":
                            isIpv4 = true;
                            break;
                        case "ipv6":
                            isIpv6 = true;
                            break;
                        case "l2vpn":
                            isL2vpn = true;
                            break;
                        default:
                    }
                }
            }
            InstanceIdentifier<FibEntries> id = InstanceIdentifier.create(FibEntries.class);
            try {
                FibEntries fibEntries = singleTxDb.syncRead(LogicalDatastoreType.CONFIGURATION, id);
                List<VrfTables> vrfTablesList = fibEntries.getVrfTables();
                if (vrfTablesList == null || vrfTablesList.isEmpty()) {
                    console.println(" No Fib entries found");
                    return null;
                }
                for (VrfTables vrfTable : vrfTablesList) {
                    printVrfTable(vrfTable, console, isIpv4, isIpv6, isL2vpn, prefixOrSubnet);
                }
            } catch (ExpectedDataObjectNotFoundException e404) {
                String errMsg = "FATAL: fib-entries container is missing from MD-SAL";
                console.println("\n" + errMsg);
                LOG.error(errMsg, e404);
            } catch (ReadFailedException rfe) {
                String errMsg = "Internal Error occurred while processing vpnservice:fib-show command";
                console.println("\n" + errMsg);
                LOG.error(errMsg, rfe);
            }
            return null;
        }
    }
    return null;
}
Also used : PrintStream(java.io.PrintStream) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Inet4Address(java.net.Inet4Address) UnknownHostException(java.net.UnknownHostException) ExpectedDataObjectNotFoundException(org.opendaylight.genius.datastoreutils.ExpectedDataObjectNotFoundException) FibEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries) Inet6Address(java.net.Inet6Address) VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables)

Example 90 with ReadFailedException

use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project netvirt by opendaylight.

the class NeutronSubnetChangeListener method deleteSubnetToNetworkMapping.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void deleteSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
    try {
        InstanceIdentifier<NetworkMap> networkMapIdentifier = NeutronvpnUtils.buildNetworkMapIdentifier(networkId);
        Optional<NetworkMap> optionalNetworkMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
        if (optionalNetworkMap.isPresent()) {
            NetworkMapBuilder nwMapBuilder = new NetworkMapBuilder(optionalNetworkMap.get());
            List<Uuid> subnetIdList = nwMapBuilder.getSubnetIdList();
            if (subnetIdList.remove(subnetId)) {
                if (subnetIdList.isEmpty()) {
                    MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
                    LOG.debug("Deleted network node in NetworkMaps DS for subnet {} network {}", subnetId.getValue(), networkId.getValue());
                } else {
                    nwMapBuilder.setSubnetIdList(subnetIdList);
                    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier, nwMapBuilder.build());
                    LOG.debug("Deleted subnet-network mapping for subnet {} network {}", subnetId.getValue(), networkId.getValue());
                }
            } else {
                LOG.error("Subnet {} is not mapped to network {}", subnetId.getValue(), networkId.getValue());
            }
        } else {
            LOG.error("network {} not present for subnet {} ", networkId, subnetId);
        }
    } catch (ReadFailedException | RuntimeException e) {
        LOG.error("Delete subnet-network mapping failed for subnet {} network {}", subnetId.getValue(), networkId.getValue());
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) NetworkMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMapBuilder) NetworkMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap)

Aggregations

ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)129 Optional (com.google.common.base.Optional)44 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)30 ArrayList (java.util.ArrayList)25 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)25 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)23 ExecutionException (java.util.concurrent.ExecutionException)17 Test (org.junit.Test)16 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)10 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)10 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)9 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)9 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)8 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)8 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)7 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)7 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)6 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)6 SingleTransactionDataBroker (org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker)6 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)6