Search in sources :

Example 11 with Subnetmaps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps in project netvirt by opendaylight.

the class ShowSubnet method doExecute.

@Override
@SuppressWarnings("checkstyle:RegexpSinglelineJava")
protected Object doExecute() throws Exception {
    if (subnetmap == null && subnetopdata == null && (options == null || options.isEmpty())) {
        getSubnet();
        System.out.println("Following subnetId is present in both subnetMap and subnetOpDataEntry\n");
        for (Subnetmap candidateSubnetmap : subnetmapList) {
            SubnetOpDataEntry data = subnetOpDataEntryMap.get(candidateSubnetmap.getId());
            if (data != null) {
                System.out.println(candidateSubnetmap.getId().toString() + "\n");
            }
        }
        System.out.println("\n\nFollowing subnetId is present in subnetMap but not in subnetOpDataEntry\n");
        for (Subnetmap candidateSubnetmap : subnetmapList) {
            SubnetOpDataEntry data = subnetOpDataEntryMap.get(candidateSubnetmap.getId());
            if (data == null) {
                System.out.println(candidateSubnetmap.getId().toString() + "\n");
            }
        }
        getshowVpnCLIHelp();
    } else if (subnetmap == null) {
        InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(new Uuid(subnetopdata))).build();
        Optional<SubnetOpDataEntry> optionalSubs = syncReadOptional(dataBroker, OPERATIONAL, subOpIdentifier);
        SubnetOpDataEntry data = optionalSubs.get();
        System.out.println("Fetching subnetmap for given subnetId\n");
        System.out.println("------------------------------------------------------------------------------");
        System.out.println("Key: " + data.getKey() + "\n" + "VrfId: " + data.getVrfId() + "\n" + "ElanTag: " + "" + data.getElanTag() + "\n" + "NhDpnId: " + data.getNhDpnId() + "\n" + "RouteAdvState: " + data.getRouteAdvState() + "\n" + "SubnetCidr: " + data.getSubnetCidr() + "\n" + "SubnetToDpnList: " + data.getSubnetToDpn() + "\n" + "VpnName: " + data.getVpnName() + "\n");
        System.out.println("------------------------------------------------------------------------------");
    }
    if (subnetmap == null && subnetopdata != null) {
        InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class).build();
        Optional<SubnetOpDataEntry> optionalSubnetOpDataEntries = syncReadOptional(dataBroker, OPERATIONAL, subOpIdentifier);
        if (optionalSubnetOpDataEntries.isPresent()) {
            optionalSubnetOpDataEntries.asSet().forEach(subnetOpDataEntry -> {
                SubnetOpDataEntry data = subnetOpDataEntry;
                System.out.println("Fetching subnetmapdataentry for given subnetId\n");
                System.out.println("------------------------" + "------------------------------------------------------");
                System.out.println("Key: " + data.getKey() + "\n" + "VrfId: " + data.getVrfId() + "\n" + "ElanTag: " + "" + data.getElanTag() + "\n" + "NhDpnId: " + data.getNhDpnId() + "\n" + "RouteAdvState: " + data.getRouteAdvState() + "\n" + "SubnetCidr: " + data.getSubnetCidr() + "\n" + "SubnetToDpnList: " + data.getSubnetToDpn() + "\n" + "VpnName: " + data.getVpnName() + "\n");
                System.out.println("------------------------" + "------------------------------------------------------");
            });
        }
    }
    if (subnetmap != null && subnetopdata == null) {
        InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(new Uuid(subnetmap))).build();
        Optional<Subnetmap> sn = syncReadOptional(dataBroker, CONFIGURATION, id);
        Subnetmap data = sn.get();
        System.out.println("Fetching subnetopdata for given subnetId\n");
        System.out.println("------------------------------------------------------------------------------");
        String getRouterInterfacePortId = (data.getRouterInterfacePortId() != null ? data.getRouterInterfacePortId().getValue() : "null");
        System.out.println("Key: " + data.getKey() + "\n" + "VpnId: " + data.getVpnId() + "\n" + "InternetVpnId: " + data.getInternetVpnId() + "\n" + "DirectPortList: " + data.getDirectPortList() + "\n" + "NetworkId: " + data.getNetworkId() + "\n" + "Network-type: " + data.getNetworkType() + "\n" + "Network-segmentation-Id: " + data.getSegmentationId() + "\n" + "PortList: " + data.getPortList() + "\n" + "RouterInterfaceFixedIp: " + data.getRouterInterfaceFixedIp() + "\n" + "RouterInterfacePortId: " + getRouterInterfacePortId + "\n" + "RouterIntfMacAddress: " + data.getRouterIntfMacAddress() + "\n" + "SubnetIp: " + data.getSubnetIp() + "\n" + "TenantId: " + data.getTenantId() + "\n");
        System.out.println("------------------------------------------------------------------------------");
    } else if (subnetopdata == null) {
        InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(new Uuid(subnetmap))).build();
        Optional<Subnetmap> sn = syncReadOptional(dataBroker, CONFIGURATION, id);
        Subnetmap data = sn.get();
        System.out.println("Fetching subnetopdata for given subnetId\n");
        System.out.println("------------------------------------------------------------------------------");
        String getRouterInterfacePortId = (data.getRouterInterfacePortId() != null ? data.getRouterInterfacePortId().getValue() : "null");
        System.out.println("Key: " + data.getKey() + "\n" + "VpnId: " + data.getVpnId() + "\n" + "InternetVpnId: " + data.getInternetVpnId() + "\n" + "DirectPortList: " + data.getDirectPortList() + "\n" + "NetworkId: " + data.getNetworkId() + "\n" + "Network-type: " + data.getNetworkType() + "\n" + "Network-segmentation-Id: " + data.getSegmentationId() + "\n" + "PortList: " + data.getPortList() + "\n" + "RouterInterfaceFixedIp: " + data.getRouterInterfaceFixedIp() + "\n" + "RouterInterfacePortId: " + getRouterInterfacePortId + "\n" + "RouterIntfMacAddress: " + data.getRouterIntfMacAddress() + "\n" + "SubnetIp: " + data.getSubnetIp() + "\n" + "TenantId: " + data.getTenantId() + "\n");
        System.out.println("------------------------------------------------------------------------------");
    } else {
        InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(new Uuid(subnetopdata))).build();
        Optional<SubnetOpDataEntry> optionalSubs = syncReadOptional(dataBroker, OPERATIONAL, subOpIdentifier);
        SubnetOpDataEntry data = optionalSubs.get();
        System.out.println("Fetching subnetmap for given subnetId\n");
        System.out.println("------------------------------------------------------------------------------");
        System.out.println("Key: " + data.getKey() + "\n" + "VrfId: " + data.getVrfId() + "\n" + "ElanTag: " + "" + data.getElanTag() + "\n" + "NhDpnId: " + data.getNhDpnId() + "\n" + "RouteAdvState: " + data.getRouteAdvState() + "\n" + "SubnetCidr: " + data.getSubnetCidr() + "\n" + "SubnetToDpnList: " + data.getSubnetToDpn() + "\n" + "VpnName: " + data.getVpnName() + "\n");
        System.out.println("------------------------------------------------------------------------------");
    }
    Boolean optionsSubnetopdataall = false;
    Boolean optionsSubnetmapall = false;
    if (options != null && !options.isEmpty()) {
        for (String opt : options) {
            String optLowCase = opt == null ? "" : opt.toLowerCase(Locale.ENGLISH);
            if (optLowCase.startsWith("subnetop")) {
                optionsSubnetopdataall = true;
            }
            if (optLowCase.startsWith("subnetmap")) {
                optionsSubnetmapall = true;
            }
        }
    }
    if (optionsSubnetopdataall) {
        InstanceIdentifier<SubnetOpData> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).build();
        Optional<SubnetOpData> optionalSubnetOpData = syncReadOptional(dataBroker, OPERATIONAL, subOpIdentifier);
        if (optionalSubnetOpData.isPresent()) {
            List<SubnetOpDataEntry> subnetOpDataEntryList = optionalSubnetOpData.get().getSubnetOpDataEntry();
            System.out.println("number of subnetOpDataEntry found are : " + subnetOpDataEntryList + "\n");
            subnetOpDataEntryList.forEach(subnetOpDataEntry -> {
                SubnetOpDataEntry data = subnetOpDataEntry;
                System.out.println("Fetching subnetmap for given subnetId\n");
                System.out.println("------------------------" + "------------------------------------------------------");
                System.out.println("Key: " + data.getKey() + "\n" + "VrfId: " + data.getVrfId() + "\n" + "ElanTag: " + "" + data.getElanTag() + "\n" + "NhDpnId: " + data.getNhDpnId() + "\n" + "RouteAdvState: " + data.getRouteAdvState() + "\n" + "SubnetCidr: " + data.getSubnetCidr() + "\n" + "SubnetToDpnList: " + data.getSubnetToDpn() + "\n" + "VpnName: " + data.getVpnName() + "\n");
                System.out.println("------------------------" + "------------------------------------------------------");
            });
        } else {
            System.out.println("No SubnetOpDataEntry present in Oper DS");
        }
    }
    if (optionsSubnetmapall) {
        InstanceIdentifier<Subnetmaps> subMapIdentifier = InstanceIdentifier.builder(Subnetmaps.class).build();
        Optional<Subnetmaps> optionalSubnetmaps = syncReadOptional(dataBroker, CONFIGURATION, subMapIdentifier);
        if (optionalSubnetmaps.isPresent()) {
            List<Subnetmap> subnetMapList = optionalSubnetmaps.get().getSubnetmap();
            System.out.println("number of subnetmaps found are : " + subnetMapList.size() + "\n");
            subnetMapList.forEach(sn -> {
                if (sn != null) {
                    System.out.println("Fetching subnetmap for given subnetId\n");
                    System.out.println("------------------------" + "------------------------------------------------------");
                    System.out.println("Uuid: " + sn.getId() + "\n" + "SubnetIp: " + sn.getSubnetIp() + "\n" + "NetworkId: " + sn.getNetworkId() + "\n" + "NetworkType: " + sn.getNetworkType() + "\nSegmentationId: " + sn.getSegmentationId() + "\n" + "TenantId: " + sn.getTenantId() + "\n" + "RouterId: " + sn.getRouterId() + "\n" + "RouterInterfacePortId: " + sn.getRouterInterfacePortId() + "\nRouterIntfMacAddress: " + sn.getRouterIntfMacAddress() + "\n" + "RouterInterfaceFixedIp: " + sn.getRouterInterfaceFixedIp() + "\n" + "VpnId: " + sn.getVpnId() + "\n" + "InternetVpnId: " + sn.getInternetVpnId() + "\n");
                    if (sn.getPortList() != null) {
                        System.out.println("There are " + sn.getPortList().size() + " port in the port-list");
                        for (int i = 0; i < sn.getPortList().size(); i++) {
                            System.out.println("\tport num " + i + " :\t" + sn.getPortList().get(i));
                        }
                    }
                    if (sn.getDirectPortList() != null) {
                        System.out.println("There are " + sn.getDirectPortList().size() + " port in the list of direct-port");
                        for (int i = 0; i < sn.getDirectPortList().size(); i++) {
                            System.out.println("\tdirect port num " + i + " :\t" + sn.getDirectPortList().get(i));
                        }
                    }
                    System.out.println("------------------------" + "------------------------------------------------------");
                }
            });
        } else {
            System.out.println("No Subnetmap present in Config DS");
        }
    }
    getshowVpnCLIHelp();
    return null;
}
Also used : Optional(com.google.common.base.Optional) SingleTransactionDataBroker.syncReadOptional(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker.syncReadOptional) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) SubnetOpData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.SubnetOpData) Subnetmaps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier)

Example 12 with Subnetmaps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps in project netvirt by opendaylight.

the class ShowSubnet method getSubnet.

@SuppressWarnings("checkstyle:RegexpSinglelineJava")
private void getSubnet() throws ReadFailedException {
    List<SubnetOpDataEntry> subnetOpDataEntryList = new ArrayList<>();
    InstanceIdentifier<Subnetmaps> subnetmapsid = InstanceIdentifier.builder(Subnetmaps.class).build();
    InstanceIdentifier<SubnetOpData> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).build();
    Optional<Subnetmaps> optionalSubnetmaps = syncReadOptional(dataBroker, CONFIGURATION, subnetmapsid);
    if (!optionalSubnetmaps.isPresent()) {
        System.out.println("No Subnetmaps configured.");
    } else {
        subnetmapList = optionalSubnetmaps.get().getSubnetmap();
    }
    Optional<SubnetOpData> optionalSubnetOpData = syncReadOptional(dataBroker, OPERATIONAL, subOpIdentifier);
    if (!optionalSubnetOpData.isPresent()) {
        System.out.println("No SubnetOpData configured.");
    } else {
        subnetOpDataEntryList = optionalSubnetOpData.get().getSubnetOpDataEntry();
    }
    for (SubnetOpDataEntry subnetOpDataEntry : subnetOpDataEntryList) {
        subnetOpDataEntryMap.put(subnetOpDataEntry.getSubnetId(), subnetOpDataEntry);
    }
}
Also used : Subnetmaps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps) ArrayList(java.util.ArrayList) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) SubnetOpData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.SubnetOpData)

Aggregations

Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)11 ArrayList (java.util.ArrayList)8 Subnetmaps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps)8 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)6 HashMap (java.util.HashMap)3 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)3 Optional (com.google.common.base.Optional)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 SubnetOpData (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.SubnetOpData)2 SubnetOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)2 SubnetmapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey)2 Strings (com.google.common.base.Strings)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1