Search in sources :

Example 1 with NetworkMap

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

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

the class NetvirtProvider method getLogicalInterfacesFromNeutronNetwork.

public List<String> getLogicalInterfacesFromNeutronNetwork(NeutronNetwork nw) {
    InstanceIdentifier<NetworkMap> networkMapIdentifier = getNetworkMapIdentifier(new Uuid(nw.getNetworkUuid()));
    NetworkMap networkMap = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier).orNull();
    if (networkMap == null) {
        LOG.warn("getLogicalInterfacesFromNeutronNetwork cant get NetworkMap for NW UUID [{}]", nw.getNetworkUuid());
        return Collections.emptyList();
    }
    List<String> interfaces = new ArrayList<>();
    List<Uuid> subnetUuidList = networkMap.getSubnetIdList();
    if (subnetUuidList != null) {
        for (Uuid subnetUuid : subnetUuidList) {
            InstanceIdentifier<Subnetmap> subnetId = getSubnetMapIdentifier(subnetUuid);
            Subnetmap subnet = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetId).orNull();
            if (subnet == null) {
                LOG.warn("getLogicalInterfacesFromNeutronNetwork cant get Subnetmap for NW UUID [{}] Subnet UUID " + "[{}]", nw.getNetworkUuid(), subnetUuid.getValue());
                continue;
            }
            if (subnet.getPortList() == null || subnet.getPortList().isEmpty()) {
                LOG.warn("getLogicalInterfacesFromNeutronNetwork No ports on Subnet: NW UUID [{}] Subnet UUID [{}]", nw.getNetworkUuid(), subnetUuid.getValue());
                continue;
            }
            subnet.getPortList().forEach(portId -> interfaces.add(portId.getValue()));
        }
    }
    return interfaces;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) NetworkMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap)

Example 3 with NetworkMap

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

the class DhcpServiceUtils method getSubnetIdsFromNetworkId.

public static List<Uuid> getSubnetIdsFromNetworkId(DataBroker broker, Uuid networkId) {
    InstanceIdentifier id = buildNetworkMapIdentifier(networkId);
    Optional<NetworkMap> optionalNetworkMap = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id);
    if (optionalNetworkMap.isPresent()) {
        return optionalNetworkMap.get().getSubnetIdList();
    }
    return null;
}
Also used : InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) NetworkMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap)

Example 4 with NetworkMap

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

the class SubnetRoutePacketInHandler method getTargetSubnetForPacketOut.

// return only the first VPN subnetopdataentry
private static SubnetOpDataEntry getTargetSubnetForPacketOut(DataBroker broker, long elanTag, int ipAddress) {
    ElanTagName elanInfo = VpnUtil.getElanInfoByElanTag(broker, elanTag);
    if (elanInfo == null) {
        LOG.error("{} getTargetDpnForPacketOut: Unable to retrieve ElanInfo for elanTag {}", LOGGING_PREFIX, elanTag);
        return null;
    }
    Optional<NetworkMap> optionalNetworkMap = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, VpnUtil.buildNetworkMapIdentifier(new Uuid(elanInfo.getName())));
    if (!optionalNetworkMap.isPresent()) {
        LOG.debug("{} getTargetDpnForPacketOut: No network map found for elan info {}", LOGGING_PREFIX, elanInfo.getName());
        return null;
    }
    List<Uuid> subnetList = optionalNetworkMap.get().getSubnetIdList();
    LOG.debug("{} getTargetDpnForPacketOut: Obtained subnetList as {} for network {}", LOGGING_PREFIX, subnetList, elanInfo.getName());
    for (Uuid subnetId : subnetList) {
        String vpnName = null;
        Subnetmap sn = VpnUtil.getSubnetmapFromItsUuid(broker, subnetId);
        if (sn != null && sn.getVpnId() != null) {
            vpnName = sn.getVpnId().getValue();
        }
        if (vpnName == null) {
            continue;
        }
        Optional<SubnetOpDataEntry> optionalSubs;
        optionalSubs = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, VpnUtil.buildSubnetOpDataEntryInstanceIdentifier(subnetId));
        if (!optionalSubs.isPresent()) {
            continue;
        }
        SubnetOpDataEntry subOpEntry = optionalSubs.get();
        if (subOpEntry.getNhDpnId() != null) {
            LOG.trace("{} getTargetDpnForPacketOut: Viewing Subnet {}", LOGGING_PREFIX, subnetId.getValue());
            boolean match = NWUtil.isIpInSubnet(ipAddress, subOpEntry.getSubnetCidr());
            LOG.trace("{} getTargetDpnForPacketOut: Viewing Subnet {} matching {}", LOGGING_PREFIX, subnetId.getValue(), match);
            if (match) {
                return subOpEntry;
            }
        }
    }
    return null;
}
Also used : ElanTagName(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) 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) NetworkMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap)

Example 5 with NetworkMap

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

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)5 NetworkMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap)5 NetworkMapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMapBuilder)3 ArrayList (java.util.ArrayList)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)2 ElanTagName (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName)1 SubnetOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)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 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)1