Search in sources :

Example 1 with ExpectedDataObjectNotFoundException

use of org.opendaylight.genius.datastoreutils.ExpectedDataObjectNotFoundException 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)

Aggregations

PrintStream (java.io.PrintStream)1 Inet4Address (java.net.Inet4Address)1 Inet6Address (java.net.Inet6Address)1 UnknownHostException (java.net.UnknownHostException)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 ExpectedDataObjectNotFoundException (org.opendaylight.genius.datastoreutils.ExpectedDataObjectNotFoundException)1 FibEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries)1 VrfTables (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables)1