Search in sources :

Example 1 with NetworkMapBuilder

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

the class NetvirtProviderTest method createNetworkMap.

private void createNetworkMap(String nwUuidStr, String subnetUuidStr, boolean storeSubnet, String portUuidStr) {
    SubnetmapBuilder subnetBuilder = new SubnetmapBuilder();
    if (!portUuidStr.isEmpty()) {
        List<Uuid> portIdList = new ArrayList<>();
        portIdList.add(new Uuid(portUuidStr));
        subnetBuilder.setPortList(portIdList);
    }
    Uuid subnetUuid = new Uuid(subnetUuidStr);
    subnetBuilder.setId(subnetUuid);
    List<Uuid> subnetIdList = new ArrayList<>();
    subnetIdList.add(subnetUuid);
    NetworkMapBuilder nwMapBuilder = createNetworkMap(nwUuidStr);
    nwMapBuilder.setSubnetIdList(subnetIdList);
    storeNetworkMap(new Uuid(nwUuidStr), nwMapBuilder.build());
    // Simulates NetworkMap has subnet list, but subnets dont exist
    if (storeSubnet) {
        storeSubnetMap(subnetUuid, subnetBuilder.build());
    }
}
Also used : 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) ArrayList(java.util.ArrayList) SubnetmapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)

Example 2 with NetworkMapBuilder

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

the class NetvirtProviderTest method createNetworkMap.

private NetworkMapBuilder createNetworkMap(String nwUuidStr) {
    Uuid nwUuid = new Uuid(nwUuidStr);
    NetworkMapBuilder nwMapBuilder = new NetworkMapBuilder();
    nwMapBuilder.setNetworkId(nwUuid);
    storeNetworkMap(nwUuid, nwMapBuilder.build());
    return nwMapBuilder;
}
Also used : 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)

Example 3 with NetworkMapBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMapBuilder 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)

Example 4 with NetworkMapBuilder

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

the class NeutronSubnetChangeListener method createSubnetToNetworkMapping.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void createSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
    try {
        InstanceIdentifier<NetworkMap> networkMapIdentifier = NeutronvpnUtils.buildNetworkMapIdentifier(networkId);
        Optional<NetworkMap> optionalNetworkMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
        NetworkMapBuilder nwMapBuilder = null;
        if (optionalNetworkMap.isPresent()) {
            nwMapBuilder = new NetworkMapBuilder(optionalNetworkMap.get());
        } else {
            nwMapBuilder = new NetworkMapBuilder().setKey(new NetworkMapKey(networkId)).setNetworkId(networkId);
            LOG.debug("Adding a new network node in NetworkMaps DS for network {}", networkId.getValue());
        }
        List<Uuid> subnetIdList = nwMapBuilder.getSubnetIdList();
        if (subnetIdList == null) {
            subnetIdList = new ArrayList<>();
        }
        subnetIdList.add(subnetId);
        nwMapBuilder.setSubnetIdList(subnetIdList);
        MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier, nwMapBuilder.build());
        LOG.debug("Created subnet-network mapping for subnet {} network {}", subnetId.getValue(), networkId.getValue());
    } catch (ReadFailedException | RuntimeException e) {
        LOG.error("Create subnet-network mapping failed for subnet {} network {}", subnetId.getValue(), networkId.getValue());
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) NetworkMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMapKey) 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

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)4 NetworkMapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMapBuilder)4 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 NetworkMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap)2 ArrayList (java.util.ArrayList)1 NetworkMapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMapKey)1 SubnetmapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)1