Search in sources :

Example 6 with FibEntries

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries 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

VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)5 FibEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries)4 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)3 VrfTables (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables)3 Optional (com.google.common.base.Optional)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 PostConstruct (javax.annotation.PostConstruct)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)2 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)2 MDSALUtil (org.opendaylight.genius.mdsalutil.MDSALUtil)2 NwConstants (org.opendaylight.genius.mdsalutil.NwConstants)2 IFibManager (org.opendaylight.netvirt.fibmanager.api.IFibManager)2 InterfaceUtils (org.opendaylight.netvirt.vpnmanager.api.InterfaceUtils)2