Search in sources :

Example 6 with TenantId

use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.TenantId in project netvirt by opendaylight.

the class NeutronvpnManager method createSubnetmapNode.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void createSubnetmapNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId, NetworkAttributes.NetworkType networkType, long segmentationId) {
    try {
        InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
        synchronized (subnetId.getValue().intern()) {
            LOG.info("createSubnetmapNode: subnet ID {}", subnetId.toString());
            Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
            if (sn.isPresent()) {
                LOG.error("createSubnetmapNode: Subnetmap node for subnet ID {} already exists, returning", subnetId.getValue());
                return;
            }
            SubnetmapBuilder subnetmapBuilder = new SubnetmapBuilder().setKey(new SubnetmapKey(subnetId)).setId(subnetId).setSubnetIp(subnetIp).setTenantId(tenantId).setNetworkId(networkId).setNetworkType(networkType).setSegmentationId(segmentationId);
            LOG.debug("createSubnetmapNode: Adding a new subnet node in Subnetmaps DS for subnet {}", subnetId.getValue());
            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier, subnetmapBuilder.build());
        }
    } catch (TransactionCommitFailedException | ReadFailedException e) {
        LOG.error("createSubnetmapNode: Creating subnetmap node failed for subnet {}", subnetId.getValue());
    }
    // check if there are ports to update for already created Subnetmap node
    LOG.debug("createSubnetmapNode: Update created Subnetmap for subnet {} with ports", subnetId.getValue());
    for (Map.Entry<Uuid, Uuid> entry : unprocessedPortsMap.entrySet()) {
        if (entry.getValue().getValue().equals(subnetId.getValue())) {
            updateSubnetmapNodeWithPorts(subnetId, entry.getKey(), null);
            unprocessedPortsMap.remove(entry.getKey());
        }
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) 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) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetmapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder) Map(java.util.Map) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) RouterInterfacesMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterInterfacesMap)

Example 7 with TenantId

use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.TenantId 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)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)5 ArrayList (java.util.ArrayList)3 SubnetmapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey)3 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)2 SubnetOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey)2 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)2 SubnetmapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)2 VpnMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)2 Optional (com.google.common.base.Optional)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Nonnull (javax.annotation.Nonnull)1 Mockito.doReturn (org.mockito.Mockito.doReturn)1 SingleTransactionDataBroker.syncReadOptional (org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker.syncReadOptional)1 IVirtualPort (org.opendaylight.netvirt.ipv6service.api.IVirtualPort)1 IVirtualRouter (org.opendaylight.netvirt.ipv6service.api.IVirtualRouter)1 IVirtualSubnet (org.opendaylight.netvirt.ipv6service.api.IVirtualSubnet)1 SfDataPlaneLocatorName (org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.SfDataPlaneLocatorName)1